22from ngclearn .components .jaxComponent import JaxComponent
33from jax import numpy as jnp , jit
44from ngclearn .utils import tensorstats
5+ from ngcsimlib .compilers .process import transition
56
67class LaplacianErrorCell (JaxComponent ): ## Rate-coded/real-valued error unit/cell
78 """
@@ -66,8 +67,9 @@ def __init__(self, name, n_units, batch_size=1, scale=1., shape=None, **kwargs):
6667 self .modulator = Compartment (restVals + 1.0 ) ## to be set/consumed
6768 self .mask = Compartment (restVals + 1.0 )
6869
70+ @transition (output_compartments = ["dshift" , "dtarget" , "dScale" , "L" , "mask" ])
6971 @staticmethod
70- def _advance_state (dt , shift , target , Scale , modulator , mask ): ## compute Laplacian error cell output
72+ def advance_state (dt , shift , target , Scale , modulator , mask ): ## compute Laplacian error cell output
7173 # Moves Laplacian cell dynamics one step forward. Specifically, this routine emulates the error unit
7274 # behavior of the local cost functional:
7375 # FIXME: Currently, below does: L(targ, shift) = -||targ - shift||_1/scale
@@ -85,16 +87,9 @@ def _advance_state(dt, shift, target, Scale, modulator, mask): ## compute Laplac
8587 mask = mask * 0. + 1. ## "eat" the mask as it should only apply at time t
8688 return dshift , dtarget , dScale , jnp .squeeze (L ), mask
8789
88- @resolver (_advance_state )
89- def advance_state (self , dshift , dtarget , dScale , L , mask ):
90- self .dshift .set (dshift )
91- self .dtarget .set (dtarget )
92- self .dScale .set (dScale )
93- self .L .set (L )
94- self .mask .set (mask )
95-
90+ @transition (output_compartments = ["dshift" , "dtarget" , "dScale" , "target" , "shift" , "modulator" , "L" , "mask" ])
9691 @staticmethod
97- def _reset (batch_size , n_units , scale_shape ):
92+ def reset (batch_size , n_units , scale_shape ):
9893 restVals = jnp .zeros ((batch_size , n_units ))
9994 dshift = restVals
10095 dtarget = restVals
@@ -106,17 +101,6 @@ def _reset(batch_size, n_units, scale_shape):
106101 mask = jnp .ones ((batch_size , n_units ))
107102 return dshift , dtarget , dScale , target , shift , modulator , L , mask
108103
109- @resolver (_reset )
110- def reset (self , dshift , dtarget , dScale , target , shift , modulator , L , mask ):
111- self .dshift .set (dshift )
112- self .dtarget .set (dtarget )
113- self .dScale .set (dScale )
114- self .target .set (target )
115- self .shift .set (shift )
116- self .modulator .set (modulator )
117- self .L .set (L )
118- self .mask .set (mask )
119-
120104 @classmethod
121105 def help (cls ): ## component help function
122106 properties = {
0 commit comments