From a1e7a803d11a44698dfc9b71cc71a5b3c766bf92 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 17 Dec 2025 14:04:26 +0100 Subject: [PATCH] fixed armadillo read --- src/rbm/rbm.py | 20 +++++++++++++++----- src/rbm/stack.py | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/rbm/rbm.py b/src/rbm/rbm.py index e8dafa7..fd2c667 100644 --- a/src/rbm/rbm.py +++ b/src/rbm/rbm.py @@ -1,3 +1,5 @@ +import os.path + import numpy as np from layer import Layer from stack import Stack, StackType, StackException @@ -35,7 +37,7 @@ def read_armadillo(filename: str) -> np.ndarray: print(f"shape: {shape}") result = np.zeros(shape=shape, dtype=np.float64) - line = fp.readline().replace("\n", '').split(' ') + line = fp.readline().replace("\n", '').split(' ') line = line[1:] data = [float(s) for s in line] for row in range(shape[0]): @@ -43,15 +45,23 @@ def read_armadillo(filename: str) -> np.ndarray: return result -def main(): + +def main(prj_name: str = "test"): + work_dir = "../../results" + prj_root = "/home/jens/work/repos/Rbm" + prj_path = os.path.join(prj_root, f"{prj_name}.prj") # Create stack from project file - stack = StackFactory.from_file("/home/jens/work/repos/Rbm/test.prj", work_dir="../../results") + stack = StackFactory.from_file(prj_path, work_dir=work_dir) + + # Init state + stack.state_init(0.01) # Load state stack.state_load() # Load train data - batch = read_armadillo("/home/jens/work/repos/Rbm/test.training.dat") + training_data_path = os.path.join(prj_root, f"{prj_name}.training.dat") + batch = read_armadillo(training_data_path) # Train stack.train(batch) @@ -60,5 +70,5 @@ def main(): stack.state_save() if __name__ == "__main__": - main() + main("norb_small_16h") print("Test: [passed]") diff --git a/src/rbm/stack.py b/src/rbm/stack.py index ebabf99..adcc9a1 100644 --- a/src/rbm/stack.py +++ b/src/rbm/stack.py @@ -41,7 +41,7 @@ class Stack: return layer return None - def init(self, std: float): + def state_init(self, std: float): for layer in self.layers: layer.init(std)