improved tests

This commit is contained in:
2026-01-06 09:44:45 +01:00
parent ec5d259ff7
commit 42520e5761
3 changed files with 17 additions and 19 deletions
+10 -8
View File
@@ -1,22 +1,24 @@
from rbm.model import Model
from rbm.entity import Entity, EntityParams
from rbm.entity import Entity, EntityParams, TrainingParams
from rbm.matrix import Mat, np
from rbm.train import TrainingParams
class TestModel(Model):
def __init__(self, name: str, work_dir: str = '.'):
super().__init__(name, work_dir)
self.unit1 = Entity((16, 64), EntityParams())
self.unit2 = Entity((64, 16), EntityParams())
self.unit3 = Entity((16, 64), EntityParams())
self.unit1 = Entity((1024, 333), EntityParams(), TrainingParams(learning_rate=0.1, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
self.unit2 = Entity((333, 64), EntityParams(), TrainingParams(learning_rate=0.1, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
self.unit3 = Entity((64, 128), EntityParams(), TrainingParams(learning_rate=0.1, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
self.unit4 = Entity((128, 128), EntityParams(), TrainingParams(learning_rate=0.1, momentum=0.9, do_rao_blackwell=True, num_epochs=1000))
def forward(self, x: Mat):
x = self.unit1.forward(x)
x = self.unit2.forward(x)
x = self.unit3.forward(x)
x = self.unit4.forward(x)
return x
def backward(self, x: Mat):
x = self.unit4.reconstruct(x)
x = self.unit3.reconstruct(x)
x = self.unit2.reconstruct(x)
x = self.unit1.reconstruct(x)
@@ -27,16 +29,16 @@ if __name__ == "__main__":
model = TestModel("TestModel", "results")
# Init state
model.init(0.01)
model.init(0.1)
# load state
model.load()
# create batch
batch = (np.random.rand(64, 16) > 0.5).astype(np.float64)
batch = (np.random.rand(64, 1024) > 0.5).astype(np.float64)
# Train
model.train(batch, TrainingParams(learning_rate=0.01, momentum=0.9, do_rao_blackwell=True, num_epochs=1000, num_gibbs_samples=3))
model.train(batch)
# save state
model.save()