From f6bccd37377cfac51bef48d1dc72940c467eab49 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Thu, 18 Dec 2025 12:31:32 +0100 Subject: [PATCH] fixed deep stack status update --- src/rbm/entity.py | 5 +++-- src/rbm/stack_deep.py | 8 ++++---- src/rbm/status.py | 7 +++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/rbm/entity.py b/src/rbm/entity.py index abf12de..addeff6 100644 --- a/src/rbm/entity.py +++ b/src/rbm/entity.py @@ -16,7 +16,7 @@ class Entity: if batch_size == 0: batch_size = training_remain - status.on_change({}) + status.on_change() d_progress = 100.0 / (training_remain/batch_size * self.params.num_epochs) batch_row_index = 0 training_seen = 0 @@ -49,8 +49,9 @@ class Entity: self.state.b_h += inc_bh self.state.w_hv += inc_whv - # Calculate error + # check if status update is needed if status.want_report(round(training_seen*d_progress)): + # Calculate error err_rms = rms_error_accu(mini_batch - self.h_to_pv(self.v_to_ph(v_states))) if not status.on_change({"progress": {"value": round(training_seen * d_progress), "unit": "%"}, "err_rms": {"value": err_rms, "unit": ""}}): diff --git a/src/rbm/stack_deep.py b/src/rbm/stack_deep.py index 0b12a23..62497e5 100644 --- a/src/rbm/stack_deep.py +++ b/src/rbm/stack_deep.py @@ -12,7 +12,7 @@ class StackDeep(Stack): for index, layer in enumerate(self.layers): if index == from_layer_id: break - _batch = layer.v_to_ph(_batch) + _batch = layer.entity.v_to_ph(_batch) return _batch @@ -21,19 +21,19 @@ class StackDeep(Stack): for index, layer in enumerate(self.layers): print(f"Train layer {index}") _batch = self.batch_from(batch, index) - layer.train(_batch, cd_func=cd_jens, status=status) + layer.entity.train(_batch, cd_func=cd_jens, status=status) def pass_up(self, visible: np.ndarray, from_layer_id: int = 0): h = np.matrix.copy(visible) for layer in self.layers[from_layer_id:]: - h = layer.gibbs_v_to_h(h) + h = layer.entity.gibbs_v_to_h(h) return h def pass_down(self, hidden: np.ndarray, from_layer_id: int = 0): v = np.matrix.copy(hidden) for layer in list(reversed(self.layers))[from_layer_id:]: - v = layer.gibbs_h_to_v(v) + v = layer.entity.gibbs_h_to_v(v) return v def pass_down_up(self, visible: np.ndarray, from_layer_id: int = 0): diff --git a/src/rbm/status.py b/src/rbm/status.py index 9dd5213..b0c4c5e 100644 --- a/src/rbm/status.py +++ b/src/rbm/status.py @@ -14,9 +14,12 @@ class Status: else: print(f"{key} : {value}{unit}") - def on_change(self, status: dict) -> bool: - do_continue = self.on_report(status=status) + def on_change(self, status: dict|None=None) -> bool: + if status is None: + self.progress = -1 + return True + do_continue = self.on_report(status=status) return do_continue def want_report(self, progress) -> bool: