Skip to content

Commit

Permalink
Update of behaviour of Sigma Neuron Dynamic Process in fixed-point re…
Browse files Browse the repository at this point in the history
…presentation (#875)

* add sdnfixed udated with correct sdn implementation

* cleaning

---------

Co-authored-by: bamsumit <[email protected]>
Co-authored-by: Mathis Richter <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent 54560b2 commit 36bb33e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/lava/proc/sdn/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,35 @@ def run_spk(self) -> None:
s_out_scaled = self.dynamics(a_in_data)
s_out = np.right_shift(s_out_scaled, self.state_exp)
self.s_out.send(s_out)


@implements(proc=SigmaDelta, protocol=LoihiProtocol)
@requires(CPU)
@tag('fixed_pt')
class PySigmaDeltaModelFixedCorrected(AbstractSigmaDeltaModel):
"""Fixed point implementation of Sigma Delta neuron."""
a_in = LavaPyType(PyInPort.VEC_DENSE, np.int32, precision=24)
s_out = LavaPyType(PyOutPort.VEC_DENSE, np.int32, precision=24)

vth: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=24)
sigma: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=24)
act: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=24)
residue: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=24)
error: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=24)
bias: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=16)

spike_exp: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=3)
state_exp: np.ndarray = LavaPyType(np.ndarray, np.int32, precision=3)
cum_error: np.ndarray = LavaPyType(np.ndarray, bool, precision=1)

def run_spk(self) -> None:
# Receive synaptic input
a_in_data = self.a_in.recv()
self.sigma = self.sigma_dynamics(a_in_data)
act = self.activation_dynamics(self.sigma)
delta = act - self.act
s_out_scaled = np.where(np.abs(delta) >= self.vth, delta, 0)
s_out = np.right_shift(s_out_scaled, self.state_exp)
delta = np.left_shift(s_out, self.state_exp)
self.act += delta
self.s_out.send(s_out)

0 comments on commit 36bb33e

Please sign in to comment.