-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test1.py
156 lines (142 loc) · 3.69 KB
/
Test1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from pymonntorch import (
NeuronGroup,
SynapseGroup,
Recorder,
EventRecorder,
)
from conex import (
Neocortex,
prioritize_behaviors,
)
from conex.behaviors.neurons import (
SimpleDendriteStructure,
SimpleDendriteComputation,
LIF,
SpikeTrace,
NeuronAxon,
Fire,
KWTA,
)
from conex.behaviors.synapses import (
SynapseInit,
WeightInitializer,
SimpleDendriticInput,
SimpleSTDP,
WeightNormalization,
WeightClip,
LateralDendriticInput,
)
import torch
import InputData
from plotTest import plot
import activity as act
import copy
RECORDER_INDEX = 460
EV_RECORDER_INDEX = 461
OUT_R = 10
OUT_THRESHOLD = 15
OUT_TAU = 3
OUT_V_RESET = 0
OUT_V_REST = 5
OUT_TRACE_TAU = 10.0
# OUT_R = 10
# OUT_THRESHOLD = -55
# OUT_TAU = 3
# OUT_V_RESET = -70
# OUT_V_REST = -65
# OUT_TRACE_TAU = 1.0
def Test(
parameters,
input_data,
n=0,
title="",
):
net = Neocortex(dt=1)
input_layer = NeuronGroup(
net=net,
size=parameters["input_size"],
tag="input_layer",
behavior={
**prioritize_behaviors(
[
SimpleDendriteStructure(),
SimpleDendriteComputation(),
LIF(
R=OUT_R,
threshold=OUT_THRESHOLD,
tau=OUT_TAU,
v_reset=OUT_V_RESET,
v_rest=OUT_V_REST,
), # 260
Fire(), # 340
SpikeTrace(tau_s=parameters["tau_src"]),
NeuronAxon(),
]
),
**{
345: input_data,
350: act.Activity(),
RECORDER_INDEX: Recorder(
variables=["v", "I", "T"],
tag="in_recorder",
),
EV_RECORDER_INDEX: EventRecorder("spikes", tag="in_ev_recorder"),
},
},
)
output_layer = NeuronGroup(
net=net,
size=parameters["output_size"],
tag="output_layer",
behavior={
**prioritize_behaviors(
[
SimpleDendriteStructure(),
SimpleDendriteComputation(),
LIF(
R=OUT_R,
threshold=parameters["output_thresholds"],
tau=OUT_TAU,
v_reset=OUT_V_RESET,
v_rest=OUT_V_REST,
),
Fire(),
SpikeTrace(tau_s=parameters["tau_dst"]),
NeuronAxon(),
*parameters["output_p_behaviors"],
]
),
**parameters["output_behaviors"],
},
)
sg_in_out = SynapseGroup(
net=net,
src=input_layer,
dst=output_layer,
tag="Proximal,sg_in_out",
behavior={
**prioritize_behaviors(
[
SynapseInit(),
WeightInitializer(
weights=parameters["W"],
),
SimpleDendriticInput(current_coef=parameters["j_0"]),
]
),
},
)
sg_in_out.add_behavior(
RECORDER_INDEX, Recorder(variables=["weights"], tag="sg_inp_out")
)
net.initialize(info=False)
net.simulate_iterations(
(parameters["duration"] + 10) * (n or parameters["output_size"])
)
plot(
net=net,
ngs=[input_layer, output_layer],
title=parameters["title"],
scaling_factor=parameters["scaling_factor"],
env_recorder_index=EV_RECORDER_INDEX,
)