Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ dist/*
logs/*
.pytest_cache/*
.vscode/*
.idea
data/*
5 changes: 5 additions & 0 deletions bindsnet/network/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def __init__(
pipeline: list = [],
manual_update: bool = False,
traces: bool = False,
mask: torch.Tensor = None,
**kwargs,
) -> None:
# language=rst
Expand All @@ -408,11 +409,13 @@ def __init__(
:param manual_update: Set to :code:`True` to disable automatic updates (applying learning rules) to connection features.
False by default, updates called after each time step
:param traces: Set to :code:`True` to record history of connection activity (for monitors)
:param mask: A mask to zero out weights
"""

super().__init__(source, target, device, pipeline, **kwargs)
self.traces = traces
self.manual_update = manual_update
self.mask = mask
if self.traces:
self.activity = None

Expand Down Expand Up @@ -487,6 +490,8 @@ def update(self, **kwargs) -> None:
# Pipeline learning
for f in self.pipeline:
f.update(**kwargs)
if type(f).__name__ == 'Weight' and self.mask is not None:
f.value.masked_fill_(self.mask, 0)

def normalize(self) -> None:
# language=rst
Expand Down
37 changes: 37 additions & 0 deletions examples/dosidicus/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import torch

from bindsnet.network import Network
from bindsnet.network.nodes import LIFNodes
from bindsnet.network.topology import MulticompartmentConnection
from bindsnet.network.topology_features import Weight, Bias
from bindsnet.learning.MCC_learning import PostPre


network = Network(dt=1.0)
neurons_number = 7
layer = LIFNodes(n=neurons_number, traces=True)
network.add_layer(layer, name="input")
network.add_layer(layer, name="output")
mask = ~torch.tril(torch.ones((neurons_number, neurons_number)), diagonal=-1).bool()
weight = Weight(
name='weight_feature',
value=torch.rand(neurons_number, neurons_number) * mask,
learning_rule=PostPre,
nu=(1e-4, 1e-2)
)
bias = Bias(
name='bias_feature',
value=torch.rand(neurons_number, neurons_number)
)
connection = MulticompartmentConnection(
source=layer,
target=layer,
pipeline=[weight, bias],
mask=mask,
device='cpu'
)
network.add_connection(connection, source="input", target="output")
network.run(
inputs={"input": torch.bernoulli(torch.rand(250, neurons_number)).byte()},
time=250
)
Loading