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 ...
随机推荐
- Windows系列原版系统镜像下载
原版系统镜像下载 Windows 10 系统 Windows 10 企业版 1511版 (64位) Windows 10 Enterprise, Version 1511 (x64) – DVD (C ...
- Python爬虫入门教程: All IT eBooks多线程爬取
All IT eBooks多线程爬取-写在前面 对一个爬虫爱好者来说,或多或少都有这么一点点的收集癖 ~ 发现好的图片,发现好的书籍,发现各种能存放在电脑上的东西,都喜欢把它批量的爬取下来. 然后放着 ...
- 集训第六周 数学概念与方法 概率 N题
N - 概率 Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status ...
- Thawte SSL Web Server 多域型SSL证书
Thawte SSL Web Server 多域型SSL证书,最多支持25个域名,需要验证域名所有权和申请单位信息,属于企业验证型SSL证书,提供40位/56位/128位,最高支持256位自适应加密. ...
- 解决idea创建ssm项目找不到mybatis的mapper的xml文件问题
http://blog.csdn.net/v19freedom/article/details/69855302 后来上网搜了下,别人给出的答复 idea在build工程的时候 遇到maven项目 使 ...
- 九度oj 题目1516:调整数组顺序使奇数位于偶数前面
题目1516:调整数组顺序使奇数位于偶数前面 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:3416 解决:1091 题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序, ...
- poj 1733离散化(map)+并查集
http://blog.sina.com.cn/s/blog_803d08c00100y2yy.html #include<stdio.h> #include<iostream> ...
- Flask(1):基本示例、配置文件、路由、请求和响应、模板渲染
Flask的特点: - pip install flask - 短小精悍.可扩展性强的 web框架 注意:上下文管理机制 - 依赖 wsgi:werkzeug Flask的简单示例: from fla ...
- 【ZJOI2017 Round1练习】D8T1 mushroom(点分治)
题意: 思路: num[a[u]]表示存在a[u]这个颜色且终点在u子树中的链长总和 ans[i]表示以当前的u为根,前面的子树对i的贡献之和 ..]of longint; size,f,ans,su ...
- n个点中求任意两点组成斜率的最大值
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1100 首先按x坐标排序,然后相邻的三个点A,B,C 组成的三条直线必然有 ...