我一直在尝试为人工神经元编写代码,其中 10 个输入介于 -1 和 1 之间,10 个随机权重也在 -1 和 1 之间,所有值都正确到小数点后两位。再加上 50% 的时间随机权重需要为负数。输出需要是输入*权重之和。代码需要使用Dev-C++用c编程编写
我已经阅读了很多与该主题相关的论文,也阅读了该站点上的一些教程,但没有一个是用 C 语言编写的。
最佳答案
给定一个权重 vector ,以下函数构造输入和权重的标量积,添加偏置项并将结果传递给 sigmoid 函数(未测试):
#include<vector>
#include<algorithm>
#include<functional>
std::vector<double> weights; //initialize randomly between [-1,1], last entry contains bias
auto sigmoid=[](double x){return 1.0/(1.0-std::exp(x));};
auto neuron_output(std::vector<double> const& input)
{
double ret = std::inner_product(input.begin(), input.end(), weights.begin(), 0.0);
ret += weights.back(); //add bias
return sigmoid(ret); //apply sigmoid
}
关于c++ - 人工神经元程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26779035/