diff --git a/src/rbm/state.py b/src/rbm/state.py index 1dc557f..3058bc9 100644 --- a/src/rbm/state.py +++ b/src/rbm/state.py @@ -55,7 +55,7 @@ class RbmState: np.savez(filename, whv=self.w_hv, bv=self.b_v, bh=self.b_h) print(f"{filename} saved successfully!") - def init(self, mu: float = 0.5, std: float = 1.0): + def init(self, mu: float = 0.0, std: float = 1.0): self.w_hv = uniform(self.w_hv.shape, mu, std) self.b_v = uniform(self.b_v.shape, 0, 0) self.b_h = uniform(self.b_h.shape, 0, 0) diff --git a/src/rbm/train.py b/src/rbm/train.py index 0573dab..0f53149 100644 --- a/src/rbm/train.py +++ b/src/rbm/train.py @@ -218,9 +218,9 @@ def train(entity: Entity, batch: Mat, status: Status): if not keep_running: break + # Reset gradient + entity.grad_zero() for mini_batch in to_mini_batch(batch, mini_batch_size): - # Reset gradient - entity.grad_zero() # Contrastive divergence learning: calculate gradients dwhv, dbv, dbh = cd_func(entity, mini_batch)