1+ import torch
2+
3+ from bindsnet .network import Network
4+ from bindsnet .network .nodes import LIFNodes
5+ from bindsnet .network .topology import MulticompartmentConnection
6+ from bindsnet .network .topology_features import Weight , Bias , Mask
7+ from bindsnet .learning .MCC_learning import PostPre
8+
9+ network = Network (dt = 1.0 )
10+ source_layer = LIFNodes (n = 5 , traces = True )
11+ target_layer = LIFNodes (n = 5 , traces = True )
12+
13+
14+ network .add_layer (source_layer , name = "input" )
15+ network .add_layer (target_layer , name = "output" )
16+
17+ weight = Weight (
18+ name = 'weight_feature' ,
19+ value = torch .rand (5 , 5 ),
20+ learning_rule = PostPre ,
21+ nu = (1e-4 , 1e-2 )
22+ )
23+ bias = Bias (name = 'bias_feature' , value = torch .rand (5 , 5 ))
24+
25+ mask = torch .tril (torch .ones ((5 , 5 )), diagonal = - 1 ).bool ()
26+
27+ connection = MulticompartmentConnection (
28+ source = source_layer ,
29+ target = target_layer ,
30+ pipeline = [weight , Mask (name = 'mask' , value = mask ), bias ],
31+ device = 'cpu'
32+ )
33+ network .add_connection (connection , source = "input" , target = "output" )
34+ print (connection .pipeline [0 ].value )
35+ network .run (
36+ inputs = {"input" : torch .bernoulli (torch .rand (250 , 5 )).byte ()}, time = 250
37+ )
38+ print (connection .pipeline [0 ].value )
0 commit comments