我不确定如何引用此神经网络训练方法中的权重
I'm not sure how to refer to the weights in this Neural Network Train method
我正在用C++编写自己的神经网络类实现。我不确定如何引用此语句的权重:
in = in + (inputs [l] * calcWeights [l]) ;
原因是权重可能多于输入。这是我的代码:
void Train (int numInputs, int numOutputs, double inputs [], double outputs []) {
// Set the Random Seed:
srand (time (0)) ;
// Weights (n input(s) * n output(s) = n weight branch(es)):
double calcWeights [numInputs * numOutputs] ;
// Errors (n input(s) * n output(s) = n error branch(es)):
double errors [numInputs * numOutputs] ;
// Set the Weights to random:
for (int j = 0 ; j < numInputs ; j = j + 1) {
calcWeights [j] = ((-1 * numInputs) + (((double) rand ()) % (1 * numInputs))) ;
}
// Train:
int i = 0 ;
double in = 0 ;
double out [numOutputs] ;
while (i < 14999) {
// Get the estimated output:
for (int k = 0 ; k < numOutputs ; k = k + 1) {
for (int l = 0 ; l < numInputs ; l = l + 1) {
in = in + (inputs [l] * calcWeights [l]) ;
}
out [k] = in + GetBias () ;
}
for (int m = 0 ; m < numOutputs ; m = m + 1) {
error [m] = outputs [m] - out [m]
}
// Increment the iterator:
i = i + 1 ;
}
}
从您在评论中的澄清来看,我相信稍微修改一下您的循环会给您想要的东西。
for (int k = 0 ; k < numOutputs ; k = k + 1) {
in = 0; //Reset in to 0 at the beginning of each output loop
for (int l = 0 ; l < numInputs ; l = l + 1) {
in = in + (inputs [l] * calcWeights [l + k*numInputs]) ;
}
out [k] = in + GetBias () ;
}
您还应该确保初始化上述所有权重。
for (int j = 0 ; j < (numInputs * numOutputs) ; j = j + 1) {
calcWeights [j] = ((-1 * numInputs) + (((double) rand ()) % (1 * numInputs))) ;
}
对于几种样式选择,我只想指出,您可以将k = k + 1
替换为简单的++k
。同样,您可以将in = in + ...;
替换为in += ...;
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 神经网络不学习.卡在50%
- OpenCV 3 中的神经网络权重
- 用 Python 训练神经网络并在 C++ 中部署
- 部署在张量流中训练的神经网络来火炬C++的最佳方法是什么?
- 我不确定如何引用此神经网络训练方法中的权重
- 如何在不同的平台/技术中使用经过训练的神经网络?
- 为什么我的神经网络停滞在一定的成本附近?
- 具有静态 std::array 的神经网络比使用动态 C 数组的神经网络慢
- 为什么小型和大型加载的神经网络占用相同数量的 RAM?
- 一维阵列的运动检测(神经网络或其他选项?
- 神经网络和图像分类
- 使用在R中训练的神经网络来预测C 中的新数据
- 神经网络高估了手写数字的输出
- 如何将可重读的神经网络导出到C 中的文件
- 如何在C++程序中连接 MATLAB 中构建的经过训练的神经网络
- 为什么 dlib 的神经网络 xml 导出包含的层参数与训练器指定的参数不同?
- 如何在Caffe中对复发性卷积神经网络进行建模
- 对于tanh激活函数神经网络,对负/非数值数据进行归一化的最佳方法是什么
- 在c/c++中实现神经网络的方法是什么?