From 905ae8da8177366b3ef501a2ccea703bc3abece2 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Thu, 18 Dec 2025 11:39:45 +0100 Subject: [PATCH] - layer: only calculate rms_error_accu() if status report is necessary - Status: added wants_report --- src/rbm/layer.py | 10 ++++++---- src/rbm/rbm.py | 2 +- src/rbm/status.py | 16 +++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/rbm/layer.py b/src/rbm/layer.py index c7a079e..947f055 100644 --- a/src/rbm/layer.py +++ b/src/rbm/layer.py @@ -69,10 +69,12 @@ class Layer: self.state.w_hv += inc_whv # 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": ""}}): - keep_running = False - break + if status.want_report(round(training_seen*d_progress)): + 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": ""}}): + keep_running = False + break training_seen += 1 diff --git a/src/rbm/rbm.py b/src/rbm/rbm.py index bf0f20a..3b41969 100644 --- a/src/rbm/rbm.py +++ b/src/rbm/rbm.py @@ -13,7 +13,7 @@ def cv_show(name: str, vec: np.array, shape): class MyStatus(Status): def __init__(self, _stack: StackDeep, _batch: np.ndarray): - Status.__init__(self, update_interval=2) + Status.__init__(self, update_interval=10) self.stack = _stack self.batch = _batch self.index = 0 diff --git a/src/rbm/status.py b/src/rbm/status.py index dab1511..9dd5213 100644 --- a/src/rbm/status.py +++ b/src/rbm/status.py @@ -15,17 +15,15 @@ class Status: print(f"{key} : {value}{unit}") def on_change(self, status: dict) -> bool: - do_continue = True - if status == {}: - self.progress = -1 - - if "progress" in status.keys(): - progress = status["progress"]['value'] - if self.progress < 0 or progress - self.progress >= self.update_interval: - self.progress = progress - do_continue = self.on_report(status=status) + do_continue = self.on_report(status=status) return do_continue + def want_report(self, progress) -> bool: + if self.progress < 0 or progress - self.progress >= self.update_interval: + self.progress = progress + return True + return False + def on_report(self, status: dict) -> bool: return True \ No newline at end of file