Skip to content

Commit

Permalink
Merge pull request #530 from BindsNET/hananel
Browse files Browse the repository at this point in the history
Changing execution order in Izhikevich  and inject Vmem in network forward
  • Loading branch information
Hananel-Hazan committed Dec 23, 2021
2 parents 06222d8 + a1e656f commit 0a39f7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 8 additions & 8 deletions bindsnet/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ def run(
# Get input to this layer (one-step mode).
current_inputs.update(self._get_inputs(layers=[l]))

# Inject voltage to neurons.
inject_v = injects_v.get(l, None)
if inject_v is not None:
if inject_v.ndimension() == 1:
self.layers[l].v += inject_v
else:
self.layers[l].v += inject_v[t]

if l in current_inputs:
self.layers[l].forward(x=current_inputs[l])
else:
Expand All @@ -392,14 +400,6 @@ def run(
else:
self.layers[l].s[:, unclamp[t]] = 0

# Inject voltage to neurons.
inject_v = injects_v.get(l, None)
if inject_v is not None:
if inject_v.ndimension() == 1:
self.layers[l].v += inject_v
else:
self.layers[l].v += inject_v[t]

# Run synapse updates.
for c in self.connections:
self.connections[c].update(
Expand Down
5 changes: 3 additions & 2 deletions bindsnet/network/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,6 @@ def forward(self, x: torch.Tensor) -> None:
:param x: Inputs to the layer.
"""
# Check for spiking neurons.
self.s = self.v >= self.thresh

# Voltage and recovery reset.
self.v = torch.where(self.s, self.c, self.v)
Expand All @@ -1292,6 +1290,9 @@ def forward(self, x: torch.Tensor) -> None:
if self.lbound is not None:
self.v.masked_fill_(self.v < self.lbound, self.lbound)

# Check for spiking neurons.
self.s = self.v >= self.thresh

super().forward(x)

def reset_state_variables(self) -> None:
Expand Down

0 comments on commit 0a39f7d

Please sign in to comment.