softmax function in c++
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric> double myfunction(double num) {
return exp(num);
} template <typename T>
void softmax(const typename::std::vector<T> &v, typename::std::vector<T> &s){
double sum=0.0;
transform(v.begin(), v.end(), s.begin(), myfunction);
sum=accumulate(s.begin(), s.end(), sum);
for(size_t i=; i<s.size(); ++i)
s.at(i)/=sum;
} int main() {
double a[]={1.0, 3.0, 2.0};
std::vector<double> v_a(a, a+sizeof a/sizeof a[]), v_b(v_a);
std::vector<double>::const_iterator it=v_a.begin();
for(; it!=v_a.end(); ++it) {
std::cout<<*it<<" ";
}
std::cout<<std::endl;
softmax(v_a, v_b);
it=v_b.begin();
for(; it!=v_b.end(); ++it) {
std::cout<<*it<<" ";
}
std::cout<<std::endl;
return ;
}
softmax function in c++的更多相关文章
- sigmoid function vs softmax function
DIFFERENCE BETWEEN SOFTMAX FUNCTION AND SIGMOID FUNCTION 二者主要的区别见于, softmax 用于多分类,sigmoid 则主要用于二分类: ...
- The Softmax function and its derivative
https://eli.thegreenplace.net/2016/the-softmax-function-and-its-derivative/ Eli Bendersky's website ...
- sigmoid function和softmax function
sigmoid函数(也叫逻辑斯谛函数): 引用wiki百科的定义: A logistic function or logistic curve is a common “S” shape (sigm ...
- Derivative of the softmax loss function
Back-propagation in a nerual network with a Softmax classifier, which uses the Softmax function: \[\ ...
- Softmax回归(Softmax Regression)
转载请注明出处:http://www.cnblogs.com/BYRans/ 多分类问题 在一个多分类问题中,因变量y有k个取值,即.例如在邮件分类问题中,我们要把邮件分为垃圾邮件.个人邮件.工作邮件 ...
- Negative log-likelihood function
Softmax function Softmax 函数 \(y=[y_1,\cdots,y_m]\) 定义如下: \[y_i=\frac{exp(z_i)}{\sum\limits_{j=1}^m{e ...
- softmax分类算法原理(用python实现)
逻辑回归神经网络实现手写数字识别 如果更习惯看Jupyter的形式,请戳Gitthub_逻辑回归softmax神经网络实现手写数字识别.ipynb 1 - 导入模块 import numpy as n ...
- 【机器学习基础】对 softmax 和 cross-entropy 求导
目录 符号定义 对 softmax 求导 对 cross-entropy 求导 对 softmax 和 cross-entropy 一起求导 References 在论文中看到对 softmax 和 ...
- TensorFlow(2)Softmax Regression
Softmax Regression Chapter Basics generate random Tensors Three usual activation function in Neural ...
随机推荐
- Python之爬虫-中国大学排名
Python之爬虫-中国大学排名 #!/usr/bin/env python # coding: utf-8 import bs4 import requests from bs4 import Be ...
- AD转换器的主要指标
AD转换器的主要指标如下: (1)分辨率(Resolution).指数字量变化一个最小量时模拟信号的变化量,定义为满刻度与2n的比值.分辨率又称精度,通常以数字信号的位数来表示.定义满刻度于2^n的比 ...
- Vue如何mock数据模拟Ajax请求
我们在做一个项目时前期可能没有后端提供接口模拟数据,那么作为前端就需要自己写json文件模拟数据加载.网上往往参考的都是不全面的,比如get请求没问题但是post请求就报错了.在Vue中只需要vue- ...
- 移动Web解决方案的链接收藏
信息类 html5 浏览器兼容性查询 - 浏览器内建对象文档 es5规范浏览器兼容性表格 es6规范浏览器兼容性表格 stackoverflow 最靠谱的问题解决方案 github 开源代码网站 全球 ...
- wps填充1到1000
A1单元格1 ,选中,填充,序列,确定
- css3 & background & background-image
css3 & background & background-image https://developer.mozilla.org/en-US/docs/Web/CSS/backgr ...
- UVALive7042(博弈论)
题意: Bob和Alice在有向图内玩游戏,n个顶点,m条边. 每人一颗棋子,初始位置分别是x,y. Bob先手,轮流操作,每次只能走一条有向边. 结束条件: 1.不能操作的人输 2.两个棋子重合Bo ...
- Eclipse完成Maven + Spring Boot + Mybatis + jsp
Spring Boot 完成WEB项目开发 开发工具:eclipse 框架:Maven:Spring Boot:Mybatis 界面:jsp:javascript:css 前言: 在SpringBoo ...
- laravel5.4新特性
http://www.cnblogs.com/webskill/category/1067140.html laravel 5.4 新特性 component and slot 使用: 1.compo ...
- Office 连供打印机无法进纸怎么办 卡纸,塞纸怎么办
我昨天打印还好好的,今天无法进纸了,哪怕只放一张纸,也是左边进去一点点,然后就塞住了,吸不下去了. 因为你的打印机里面有异物.你把连供拆掉(当心墨水流出来,把墨盒拆掉之后放高一点并用纸巾包住,不要 ...