对 C++ 代码中的神经网络梯度下降部分感到困惑
Confused on Neural Net gradient descend part in c++ code
我打算用 C++ 制作自己的神经网络库,并且我正在检查其他人的代码以确保我在正确的轨道上......下面是一个示例代码,我正在尝试从中学习..
该代码中的所有内容都有意义,除了梯度下降部分,在该部分中,他通过添加正学习率来更新权重...我们难道不需要取负梯度来达到最优吗? ?
行号:137 - 157。
double Neuron::eta = 0.10;
void Neuron::updateInputWeights(Layer &prevLayer)
{
// The weights to be updated are in the Connection container
// in the nuerons in the preceding layer
for(unsigned n = 0; n < prevLayer.size(); ++n)
{
Neuron &neuron = prevLayer[n];
double oldDeltaWeight = neuron.m_outputWeights[m_myIndex].deltaWeight;
double newDeltaWeight =
// Individual input, magnified by the gradient and train rate:
eta
* neuron.getOutputVal()
* m_gradient
// Also add momentum = a fraction of the previous delta weight
+ alpha
* oldDeltaWeight;
// updating Weights
neuron.m_outputWeights[m_myIndex].deltaWeight = newDeltaWeight;
neuron.m_outputWeights[m_myIndex].weight += newDeltaWeight;
}
}
里面的东西都是为了权重更新加的东西,里面没有负号
https://github.com/huangzehao/SimpleNeuralNetwork/blob/master/src/neural-net.cpp
幸好它工作正常,这让我很奇怪....
我问过我认识的每个人这个问题,他们都很困惑。
这是创建神经网络库的视频演示...与上面的代码相同。
是的,这确实令人困惑,但我认为这是这一行的症结所在。 (我可能是错的,但如果你说训练有效,那么唯一可能改变标志的线应该是这个。)
eta * neuron.getOutputVal() * m_gradient
其中 neuron.getOutputVal()
提供更新方向。
我打算用 C++ 制作自己的神经网络库,并且我正在检查其他人的代码以确保我在正确的轨道上......下面是一个示例代码,我正在尝试从中学习..
该代码中的所有内容都有意义,除了梯度下降部分,在该部分中,他通过添加正学习率来更新权重...我们难道不需要取负梯度来达到最优吗? ?
行号:137 - 157。
double Neuron::eta = 0.10;
void Neuron::updateInputWeights(Layer &prevLayer)
{
// The weights to be updated are in the Connection container
// in the nuerons in the preceding layer
for(unsigned n = 0; n < prevLayer.size(); ++n)
{
Neuron &neuron = prevLayer[n];
double oldDeltaWeight = neuron.m_outputWeights[m_myIndex].deltaWeight;
double newDeltaWeight =
// Individual input, magnified by the gradient and train rate:
eta
* neuron.getOutputVal()
* m_gradient
// Also add momentum = a fraction of the previous delta weight
+ alpha
* oldDeltaWeight;
// updating Weights
neuron.m_outputWeights[m_myIndex].deltaWeight = newDeltaWeight;
neuron.m_outputWeights[m_myIndex].weight += newDeltaWeight;
}
}
里面的东西都是为了权重更新加的东西,里面没有负号
https://github.com/huangzehao/SimpleNeuralNetwork/blob/master/src/neural-net.cpp
幸好它工作正常,这让我很奇怪....
我问过我认识的每个人这个问题,他们都很困惑。
这是创建神经网络库的视频演示...与上面的代码相同。
是的,这确实令人困惑,但我认为这是这一行的症结所在。 (我可能是错的,但如果你说训练有效,那么唯一可能改变标志的线应该是这个。)
eta * neuron.getOutputVal() * m_gradient
其中 neuron.getOutputVal()
提供更新方向。