-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstruct_pl_split.py
More file actions
executable file
·107 lines (90 loc) · 3.71 KB
/
struct_pl_split.py
File metadata and controls
executable file
·107 lines (90 loc) · 3.71 KB
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
# Copyright (c) 2021 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import matplotlib.pyplot as plt
import numpy
import pyNN.utility.plotting as plot
import pyNN.spiNNaker as sim
n_neurons = 64
simtime = 5000
sim.setup(timestep=1.0)
sim.set_number_of_synapse_cores(sim.IF_curr_exp, 1)
sim.set_allow_delay_extensions(sim.IF_curr_exp, False)
pre_pop = sim.Population(n_neurons, sim.IF_curr_exp(), label="Pre")
post_pop = sim.Population(n_neurons, sim.IF_curr_exp(), label="Post")
pre_noise = sim.Population(
n_neurons, sim.SpikeSourcePoisson(rate=10.0), label="Noise_Pre")
post_noise = sim.Population(
n_neurons, sim.SpikeSourcePoisson(rate=10.0), label="Noise_Post")
pre_pop.record("spikes")
post_pop.record("spikes")
training = sim.Population(
n_neurons,
sim.SpikeSourcePoisson(rate=10.0, start=1500.0, duration=1500.0),
label="Training")
sim.Projection(pre_noise, pre_pop, sim.OneToOneConnector(),
synapse_type=sim.StaticSynapse(weight=2.0))
sim.Projection(post_noise, post_pop, sim.OneToOneConnector(),
synapse_type=sim.StaticSynapse(weight=2.0))
sim.Projection(training, pre_pop, sim.OneToOneConnector(),
synapse_type=sim.StaticSynapse(weight=5.0, delay=1.0))
sim.Projection(training, post_pop, sim.OneToOneConnector(),
synapse_type=sim.StaticSynapse(weight=5.0, delay=10.0))
# Structurally plastic connection between pre_pop and post_pop
partner_selection_last_neuron = sim.RandomSelection()
formation_distance = sim.DistanceDependentFormation(
grid=[numpy.sqrt(n_neurons), numpy.sqrt(n_neurons)],
sigma_form_forward=.5 # spread of feed-forward connections
)
elimination_weight = sim.RandomByWeightElimination(
threshold=.2 # Use same weight as initial weight for static connections
)
structure_model_without_stdp = sim.StructuralMechanismStatic(
# Partner selection, formation and elimination rules from above
partner_selection_last_neuron, formation_distance, elimination_weight,
# Use this weight when creating a new synapse
initial_weight=5,
# Use this weight for synapses at start of simulation
weight=5,
# Use this delay when creating a new synapse
initial_delay=5,
# Use this weight for synapses at the start of simulation
delay=5,
# Maximum allowed fan-in per target-layer neuron
s_max=32,
# Frequency of rewiring in Hz
f_rew=10 ** 4
)
plastic_projection = sim.Projection(
pre_pop, post_pop,
sim.FixedProbabilityConnector(0.), # No initial connections
synapse_type=structure_model_without_stdp,
label="structurally_plastic_projection"
)
sim.run(simtime)
pre_neo = pre_pop.get_data(variables=["spikes"])
pre_spikes = pre_neo.segments[0].spiketrains
post_neo = post_pop.get_data(variables=["spikes"])
post_spikes = post_neo.segments[0].spiketrains
print(plastic_projection.get('weight', format="list"))
sim.end()
line_properties = [{'color': 'red', 'markersize': 5},
{'color': 'blue', 'markersize': 2}]
plot.Figure(
# plot spikes
plot.Panel(pre_spikes, post_spikes, yticks=True, xlim=(0, simtime),
line_properties=line_properties),
title="STDP Network Example",
annotations=f"Simulated with {sim.name()}"
)
plt.show()