Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of behaviour of Sigma Neuron Dynamic Process in fixed-point representation #875

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading