diff --git a/src/rbm/entity.py b/src/rbm/entity.py index 6c3ec64..7885a37 100644 --- a/src/rbm/entity.py +++ b/src/rbm/entity.py @@ -76,6 +76,7 @@ class Entity: self.enable_training = enable_training self.state = RbmState.from_layer_params(shape) self.grad = RbmState.from_layer_params(shape) + self.name = f"Entity-{shape[0]}x{shape[1]}" self.type = None if params.do_gaussian_visible: if params.do_gaussian_hidden: diff --git a/src/rbm/status.py b/src/rbm/status.py index b3108b2..6663973 100644 --- a/src/rbm/status.py +++ b/src/rbm/status.py @@ -1,25 +1,27 @@ +from .entity import Entity + class Status: def __init__(self, update_interval=10): self.progress = -1 self.update_interval = update_interval @staticmethod - def print_status(status: dict): + def print_status(entity: Entity, status: dict): print("-------------------------------------------") for key in status.keys(): value = status[key]['value'] unit = status[key]['unit'] if isinstance(value, float): - print(f"{key} : {value:0.6f}{unit}") + print(f"{entity.name}: {key} : {value:0.6f}{unit}") else: - print(f"{key} : {value}{unit}") + print(f"{entity.name}: {key} : {value}{unit}") - def on_change(self, status: dict|None=None) -> bool: + def on_change(self, entity: Entity, status: dict|None=None) -> bool: if status is None: self.progress = -1 return True - do_continue = self.on_report(status=status) + do_continue = self.on_report(entity, status=status) return do_continue def want_report(self, progress) -> bool: @@ -28,6 +30,6 @@ class Status: return True return False - def on_report(self, status: dict) -> bool: - Status.print_status(status) + def on_report(self, entity: Entity, status: dict) -> bool: + Status.print_status(entity, status) return True \ No newline at end of file diff --git a/src/rbm/train.py b/src/rbm/train.py index 38fca06..921d7c0 100644 --- a/src/rbm/train.py +++ b/src/rbm/train.py @@ -203,7 +203,7 @@ def train(entity: Entity, batch: Mat, status: Status): d_progress = 100.0 / (batch.shape[0]*params.num_epochs) progress = 0 keep_running = True - status.on_change() + status.on_change(entity) cd_func = None if entity.type == Entity.Type.GB_RBM: cd_func = cd_gaussian_binary @@ -232,7 +232,7 @@ def train(entity: Entity, batch: Mat, status: Status): if status.want_report(round(progress)): # Calculate error err_rms = rms_error_accu(batch - entity.reconstruct(entity.forward(batch))) - if not status.on_change({"progress": {"value": round(progress), "unit": "%"}, + if not status.on_change(entity, {"progress": {"value": round(progress), "unit": "%"}, "err_rms": {"value": err_rms, "unit": ""}}): keep_running = False break @@ -241,7 +241,7 @@ def train(entity: Entity, batch: Mat, status: Status): # Update final status err_rms = rms_error_accu(batch - entity.reconstruct(entity.forward(batch))) - status.on_change({"progress": {"value": round(progress), "unit": "%"}, + status.on_change(entity, {"progress": {"value": round(progress), "unit": "%"}, "err_rms_total": {"value": err_rms, "unit": ""}}) return True