softmax函数

#include <vector>
#include <cmath> //math.h
std::vector<double> vsoftmax(std::vector<double> &v) {
	double sum=0;
	for(auto iter:v) {
		sum+=exp(iter);
	}

	std::vector<double> res;
	for(int i=0;i<v.size();i++) {
		res.push_back(exp(v[i])/sum);
	}

	return res;
}

posted @ 2019-04-22 11:27  JohnRed  阅读(134)  评论(0编辑  收藏  举报