1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <numeric>
  6.  
  7. double myfunction(double num) {
  8. return exp(num);
  9. }
  10.  
  11. template <typename T>
  12. void softmax(const typename::std::vector<T> &v, typename::std::vector<T> &s){
  13. double sum=0.0;
  14. transform(v.begin(), v.end(), s.begin(), myfunction);
  15. sum=accumulate(s.begin(), s.end(), sum);
  16. for(size_t i=; i<s.size(); ++i)
  17. s.at(i)/=sum;
  18. }
  19.  
  20. int main() {
  21. double a[]={1.0, 3.0, 2.0};
  22. std::vector<double> v_a(a, a+sizeof a/sizeof a[]), v_b(v_a);
  23. std::vector<double>::const_iterator it=v_a.begin();
  24. for(; it!=v_a.end(); ++it) {
  25. std::cout<<*it<<" ";
  26. }
  27. std::cout<<std::endl;
  28. softmax(v_a, v_b);
  29. it=v_b.begin();
  30. for(; it!=v_b.end(); ++it) {
  31. std::cout<<*it<<" ";
  32. }
  33. std::cout<<std::endl;
  34. return ;
  35. }

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. c++基础_回文数

    #include <iostream> using namespace std; int main(){ ;i<;i++){ ; int n=i;//暂存该四位数来计算 ,以防改变i ...

  2. ubuntu14.04 Google Chrome can not be run as root

    问题如下图:

  3. jQuery实现上传进度条效果

    效果:(点击上传按钮) See the Pen pjGNJr by moyu (@MoYu1991) on CodePen. html代码:   <!DOCTYPE html> <h ...

  4. CodeForcesGym 100524A Astronomy Problem

    Astronomy Problem Time Limit: 8000ms Memory Limit: 524288KB This problem will be judged on CodeForce ...

  5. poj3440--Coin Toss(几何上的概率)

    Coin Toss Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3946   Accepted: 1076 Descrip ...

  6. Django:(7)auth用户认证组件 & 中间件

    用户认证组件 用户认证组件: 功能:用session记录登陆验证状态 前提:用户表:django自带的auth_user 创建超级用户的命令: python manage.py createsuper ...

  7. 洛谷 通天系列 P1760 P1757 P1759

    P1760 通天之汉诺塔 汉诺塔问题.一个高精乘单精解决 ans=2^n-1 /*by SilverN*/ #include<algorithm> #include<iostream ...

  8. Linux下汇编语言学习笔记12 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  9. 又见古老的Typosquatting攻击:这次入侵Npm窃取开发者身份凭证

    有些攻击方式虽然听起来很幼稚,但有时候却也可以生效,比如typosquatting攻击——我们上次看到这种攻击是在去年6月份,这本身也是种很古老的攻击方式. 所谓的typosquatting,主要是通 ...

  10. ArcGIS Python 编码问题

    吐槽一下ArcGIS自带的 Python IDE, 没有代码补全 没有函数提示 没有代码折叠 没有行号 撤销操作还有问题 字符编码还有各种问题 .........   花了2天时间才琢磨出来的经验 环 ...