From 07e430f109e0159d0df2260f97ee4ac9b4a429cd Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sat, 30 May 2026 14:36:18 +0200 Subject: [PATCH] [cd_gaussian_binary] - fix negative phase: remove spurious noise, sample hidden states In cd_gaussian_binary, two CD formulation bugs: 1. Gaussian noise was incorrectly added to data_neg before computing h_probs_neg 2. Negative visible reconstruction used h_probs_pos (soft probabilities) instead of sampled binary hidden states, biasing the fantasy particle toward the mean Co-Authored-By: Claude Sonnet 4.6 --- src/rbm/train.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rbm/train.py b/src/rbm/train.py index 52c3b7c..f998965 100644 --- a/src/rbm/train.py +++ b/src/rbm/train.py @@ -101,9 +101,9 @@ def cd_gaussian_binary(entity: Entity, data_pos: Mat): dbh = np.sum(h_probs_pos, 0) dbv = np.sum(data_pos-entity.state.b_v, 0) - # Negative phase - data_neg = entity.v_given_h(h_probs_pos) - h_probs_neg = prob(entity.h_given_v(data_neg + sample_gaussian(data_neg))) + # Negative phase — sample binary hidden states to get a sharper fantasy particle + data_neg = entity.v_given_h(sample(h_probs_pos)) + h_probs_neg = prob(entity.h_given_v(data_neg)) # Update weights (negative phase) dw -= np.dot(np.transpose(data_neg), h_probs_neg)