improved tests
This commit is contained in:
@@ -4,19 +4,20 @@ from rbm.model import Model
|
|||||||
|
|
||||||
WORK_DIR = "../../results"
|
WORK_DIR = "../../results"
|
||||||
USE_OPTIMIZER = True
|
USE_OPTIMIZER = True
|
||||||
|
N_VIS = 3000
|
||||||
|
N_CASES = 1000
|
||||||
class TestModel(Model):
|
class TestModel(Model):
|
||||||
def __init__(self, name: str, work_dir: str = '.', do_gaussian_hidden=False):
|
def __init__(self, name: str, work_dir: str = '.', do_gaussian_hidden=False):
|
||||||
super().__init__(name, work_dir)
|
super().__init__(name, work_dir)
|
||||||
|
|
||||||
if do_gaussian_hidden:
|
if do_gaussian_hidden:
|
||||||
# Hidden gaussian
|
# Hidden gaussian
|
||||||
self.unit1 = Entity((3, 64), EntityParams(do_gaussian_visible=True, do_gaussian_hidden=True),
|
self.unit1 = Entity((N_VIS, 64), EntityParams(do_gaussian_visible=True, do_gaussian_hidden=True),
|
||||||
TrainingParams(learning_rate=0.01, momentum=0.9, num_epochs=1000))
|
TrainingParams(learning_rate=0.01, momentum=0.9, num_epochs=1000))
|
||||||
else:
|
else:
|
||||||
# Hidden binary
|
# Hidden binary
|
||||||
self.unit1 = Entity((3, 64), EntityParams(do_gaussian_visible=True, do_gaussian_hidden=False),
|
self.unit1 = Entity((N_VIS, 1000), EntityParams(do_gaussian_visible=True, do_gaussian_hidden=False),
|
||||||
TrainingParams(learning_rate=0.001, momentum=0.9, num_epochs=1000))
|
TrainingParams(learning_rate=0.005, momentum=0.9, num_epochs=1000, mini_batch_size=1000))
|
||||||
|
|
||||||
def forward(self, x: Mat):
|
def forward(self, x: Mat):
|
||||||
x = self.unit1.forward(x)
|
x = self.unit1.forward(x)
|
||||||
@@ -41,11 +42,11 @@ def linear():
|
|||||||
model.load()
|
model.load()
|
||||||
|
|
||||||
# Prepare training data
|
# Prepare training data
|
||||||
training_batch = (np.random.rand(150, 3, dtype=np.float64) - 0.5)
|
training_batch = np.random.randn(N_CASES, N_VIS, dtype=np.float64)
|
||||||
|
|
||||||
# Normalize training data
|
# Normalize training data
|
||||||
mean_training_batch = np.reshape(np.repeat(np.mean(training_batch, axis=1), 3, axis=0), training_batch.shape)
|
mean_training_batch = np.reshape(np.repeat(np.mean(training_batch, axis=1), N_VIS, axis=0), training_batch.shape)
|
||||||
var_training_batch = np.reshape(np.repeat(np.std(training_batch, axis=1), 3, axis=0), training_batch.shape)
|
var_training_batch = np.reshape(np.repeat(np.std(training_batch, axis=1), N_VIS, axis=0), training_batch.shape)
|
||||||
training_batch = (training_batch - mean_training_batch) / var_training_batch
|
training_batch = (training_batch - mean_training_batch) / var_training_batch
|
||||||
|
|
||||||
# Train layer
|
# Train layer
|
||||||
@@ -59,7 +60,7 @@ def linear():
|
|||||||
for pattern in test_batch:
|
for pattern in test_batch:
|
||||||
h = model.forward(pattern)
|
h = model.forward(pattern)
|
||||||
v = model.reconstruct(h)
|
v = model.reconstruct(h)
|
||||||
print(f"P{pattern} : {v}")
|
# print(f"P{pattern} : {v}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
linear()
|
linear()
|
||||||
|
|||||||
Reference in New Issue
Block a user