diff --git a/source/Rbm.cpp b/source/Rbm.cpp index 7e5fe87..a8f566e 100644 --- a/source/Rbm.cpp +++ b/source/Rbm.cpp @@ -361,12 +361,21 @@ void Rbm::train(arma::mat const &batch, IListener* pListener) // Adjust weight and biases inc_bv = m_params.momentum*inc_bv + m_params.learningRate/numcases*dbv; inc_bh = m_params.momentum*inc_bh + m_params.learningRate/numcases*dbh; - inc_whv = m_params.momentum*inc_whv + m_params.learningRate*(dwhv/numcases - m_params.weightDecay*m_whv); + inc_whv = m_params.momentum*inc_whv + m_params.learningRate*dwhv/numcases; m_bv += inc_bv; m_bh += inc_bh; m_whv += inc_whv; + // Weight decay applied directly to the weights, outside the + // momentum recursion above -- folding it into inc_whv would let + // momentum geometrically amplify its effective strength to + // roughly weightDecay/(1-momentum), well past the configured value. + if (m_params.weightDecay != 0.0) + { + m_whv -= m_params.learningRate*m_params.weightDecay*m_whv; + } + progress += dProgress*miniBatchSizeActual; status.progress = (int)(progress + 0.5);