Fix Bernoulli-only sample() applied to Gaussian visible/hidden units
Matutils::sample() always binary-thresholds (src > uniform(src)), but it was the only sampler in the codebase and was called unconditionally on h_probs/v_probs/miniBatch in several CD Gibbs-loop branches regardless of doGaussianVisible/doGaussianHidden. Binary-thresholding a Gaussian unit's continuous activation is meaningless -- it would corrupt any Gaussian-visible/hidden RBM (image-domain experiments via the GUI or TEST target); doesn't affect poet's plain BB-RBM path since both flags are false there. Add sample_gaussian() (mean + N(0,1) noise) alongside the existing Bernoulli sample() in matutils.hpp, plus Rbm::sampleVisible/sampleHidden helpers that dispatch to the right one per the RBM's configured type. Replace every visible/hidden Gibbs-step sample() call in cd_jens (the active path) and cd_hinton (compiled but currently unused, behind USE_CD_HINTON) with the appropriate dispatch helper, and fix the same issue in Rbm::train's doSampleBatch path. Behavior is unchanged for any RBM with doGaussianVisible/doGaussianHidden both false (confirmed: poet.elf f output identical before/after). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016K8Gu7Qejd11JbdiHZqYAs
This commit is contained in:
+8
-1
@@ -164,7 +164,14 @@ private:
|
||||
void cd(arma::mat const &v_states, arma::mat &dwhv, arma::mat &dbhv, arma::mat &dbv);
|
||||
arma::mat v_to_h(const arma::mat &visible) const;
|
||||
arma::mat h_to_v(const arma::mat &hidden) const;
|
||||
|
||||
|
||||
// Sample a visible/hidden unit's state from its probability/mean matrix,
|
||||
// dispatching to the Bernoulli or Gaussian sampler per doGaussianVisible/
|
||||
// doGaussianHidden -- CD's Gibbs steps must not binary-threshold a
|
||||
// Gaussian unit's continuous activation.
|
||||
arma::mat sampleVisible(const arma::mat &visible) const;
|
||||
arma::mat sampleHidden(const arma::mat &hidden) const;
|
||||
|
||||
};
|
||||
|
||||
#endif /* RBM_HPP */
|
||||
|
||||
Reference in New Issue
Block a user