- numGibbs no longer part of EntityParameter

- refactored forward and reconstruct
- conditionally use optimizer for training
This commit is contained in:
2025-12-19 17:15:10 +01:00
parent a47922cb1c
commit d3c9fe4681
4 changed files with 124 additions and 41 deletions
+10 -4
View File
@@ -1,8 +1,10 @@
from .status import Status
from .train import train
from .train import train, Optimizer
from .stack import Stack, StackType
from .matrix import Mat, np
USE_OPTIMIZER = False
class StackDeep(Stack):
def __init__(self, name: str, work_dir: str = '.'):
Stack.__init__(self, StackType.Deep, name, work_dir)
@@ -12,7 +14,7 @@ class StackDeep(Stack):
for index, layer in enumerate(self.layers):
if index == from_layer_id:
break
_batch = layer.entity.v_to_ph(_batch)
_batch = layer.entity.forward(_batch)
return _batch
@@ -20,8 +22,12 @@ class StackDeep(Stack):
_batch = np.copy(batch)
for index, layer in enumerate(self.layers):
print(f"Train layer {index} for {layer.training_params.num_epochs} epochs")
_batch = self.batch_from(batch, index)
train(layer.entity, _batch, layer.training_params, status=status)
if USE_OPTIMIZER:
optim = Optimizer(layer.entity, layer.training_params)
_batch = optim(_batch, status=status)
else:
_batch = self.batch_from(batch, index)
train(layer.entity, _batch, layer.training_params, status=status)
def pass_up(self, visible: Mat, from_layer_id: int = 0):