diff --git a/source/Rbm.cpp b/source/Rbm.cpp index c1642a7..7e5fe87 100644 --- a/source/Rbm.cpp +++ b/source/Rbm.cpp @@ -265,18 +265,17 @@ void Rbm::cd_jens(arma::mat const &v_states, arma::mat &dw, arma::mat &dbh, arma arma::mat h_probs = toHiddenProbs(v_states); arma::mat h_states; - // Sample hidden - if (m_params.doGaussianHidden) - { - h_states = h_probs + arma::randn(h_probs.n_rows, h_probs.n_cols); - } - else if (m_params.doRaoBlackwell) + // Sample hidden. Rao-Blackwellization uses the mean for the positive-phase + // gradient (lower variance) regardless of unit type; previously a Gaussian + // hidden unit always got the noisy sample here even with doRaoBlackwell + // set, ignoring the flag and adding avoidable gradient variance. + if (m_params.doRaoBlackwell) { h_states = h_probs; } else { - h_states = sample(h_probs); + h_states = sampleHidden(h_probs); } // Update weights (positive phase)