#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++的更多相关文章

  1. sigmoid function vs softmax function

    DIFFERENCE BETWEEN SOFTMAX FUNCTION AND SIGMOID FUNCTION 二者主要的区别见于, softmax 用于多分类,sigmoid 则主要用于二分类: ...

  2. The Softmax function and its derivative

    https://eli.thegreenplace.net/2016/the-softmax-function-and-its-derivative/  Eli Bendersky's website ...

  3. sigmoid function和softmax function

    sigmoid函数(也叫逻辑斯谛函数):  引用wiki百科的定义: A logistic function or logistic curve is a common “S” shape (sigm ...

  4. Derivative of the softmax loss function

    Back-propagation in a nerual network with a Softmax classifier, which uses the Softmax function: \[\ ...

  5. Softmax回归(Softmax Regression)

    转载请注明出处:http://www.cnblogs.com/BYRans/ 多分类问题 在一个多分类问题中,因变量y有k个取值,即.例如在邮件分类问题中,我们要把邮件分为垃圾邮件.个人邮件.工作邮件 ...

  6. 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 ...

  7. softmax分类算法原理(用python实现)

    逻辑回归神经网络实现手写数字识别 如果更习惯看Jupyter的形式,请戳Gitthub_逻辑回归softmax神经网络实现手写数字识别.ipynb 1 - 导入模块 import numpy as n ...

  8. 【机器学习基础】对 softmax 和 cross-entropy 求导

    目录 符号定义 对 softmax 求导 对 cross-entropy 求导 对 softmax 和 cross-entropy 一起求导 References 在论文中看到对 softmax 和 ...

  9. TensorFlow(2)Softmax Regression

    Softmax Regression Chapter Basics generate random Tensors Three usual activation function in Neural ...

随机推荐

  1. python while、continue、break

    while循环实现用户登录 _user = "tom" _passwd = "abc123" counter = 0 while counter < 3: ...

  2. Python关于函数作为返回值的理解(3分钟就看完了)

    话不多说,直接看例子,上代码: def line_conf(): def line(x): return 2 * x + 1 return line #return a function object ...

  3. 牛客网补题 New Game!(原Wannafly summer camp day2原题)

    思路:这个题在秦皇岛的时候好像没有写出来,反正我是没有写出来,题解是听懂了:把直线和圆都看做一个结点,圆和直线用点到直线的距离与半径差求出来,圆和圆之间用点和点之间的距离和半径差表示,最后最短路跑一遍 ...

  4. 精帖转载(关于stock problem)

    Note: this is a repost(重新投寄) of my original post here with updated solutions(解决方案) for this problem ...

  5. 【转】ASP.NET MVC 4 RC的JS/CSS打包压缩功能

    原文链接:http://www.cnblogs.com/shanyou/archive/2012/06/22/2558580.html 打包(Bundling)及压缩(Minification)指的是 ...

  6. C语言判断一个数能否被3和5整除

    #include <stdio.h> /* 判断一个数能不能同时被3和5整除 --------soulsjie 20170525----- */ void main(){ int inpu ...

  7. 创建私有 Gems 源

    1.安装依赖 yum install gem -y gem install builder   2.安装.配置nginx的文件列表 添加/etc/nginx/default.d/mirrors.con ...

  8. HDU 1800 hash 找出现最多次数的字符串的次数

    乘法hash: 这类hash函数利用了乘法的不相关性 int Hash(char *str){    int seed = 131 , value=0;    while(*str != '\0'){ ...

  9. zoj 2676 dinic模板求实型最小割(可做dinic模板)

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #inc ...

  10. Less Time, More profit 最大权闭合子图(最大流最小割)

    The city planners plan to build N plants in the city which has M shops. Each shop needs products fro ...