From 575ceb4ef1bf1d1f43385537134f2efb65d5032e Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 17 Dec 2025 13:15:09 +0100 Subject: [PATCH] revised status --- src/rbm/layer.py | 18 +++++++----------- src/rbm/status.py | 26 ++++++++++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/rbm/layer.py b/src/rbm/layer.py index cbf6d25..f87d983 100644 --- a/src/rbm/layer.py +++ b/src/rbm/layer.py @@ -34,8 +34,8 @@ class Layer: if batch_size == 0: batch_size = training_remain + status.on_change({}) d_progress = 100.0 / (training_remain/batch_size * self.params.num_epochs) - last_progress = 0 batch_row_index = 0 training_seen = 0 keep_running = True @@ -67,19 +67,15 @@ class Layer: self.state.b_h += inc_bh self.state.w_hv += inc_whv - progress = round(training_seen*d_progress) - if progress != last_progress: - # Calculate error - status.progress = round(progress) - status.err = rms_error_accu(mini_batch - self.h_to_pv(self.v_to_ph(v_states))) - if not status.on_change(): - keep_running = False - break + # 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 - last_progress = progress training_seen += 1 - status.on_change() + status.on_change({"progress": {"value": round(training_seen*d_progress), "unit": "%"}, "err_rms": {"value": err_rms, "unit": ""}}) def v_to_ph(self, v: np.ndarray) -> np.ndarray: state = self.state.v_to_h(v) diff --git a/src/rbm/status.py b/src/rbm/status.py index bc87687..e970be5 100644 --- a/src/rbm/status.py +++ b/src/rbm/status.py @@ -1,16 +1,18 @@ class Status: def __init__(self): - self.progress = 0 - self.err = -1.0 - self.err_total = -1.0 - self.l1 = -1.0 - self.l2 = -1.0 + self.progress = -1 - def on_change(self) -> bool: - print("-------------------------------------------") - print(f"Progress : {self.progress} %") - print(f"error (per mini batch) : {self.err}") - print(f"error (total) : {self.err_total}") - print(f"L1 : {self.l1}") - print(f"L2 : {self.l2}") + def on_change(self, status: dict) -> bool: + if status == {}: + self.progress = -1 + + if "progress" in status.keys(): + progress = status["progress"]['value'] + if self.progress < 0 or progress - self.progress >= 10: + self.progress = progress + print("-------------------------------------------") + for key in status.keys(): + value = status[key]['value'] + unit = status[key]['unit'] + print(f"{key} : {value}{unit}") return True