|
| 1 | +import pylab |
| 2 | +import numpy |
| 3 | +from pyNN.random import RandomDistribution |
| 4 | +from pyNN.utility.plotting import Figure, Panel |
| 5 | +import pyNN.spiNNaker as p |
| 6 | +from spynnaker.pyNN.extra_algorithms.splitter_components import ( |
| 7 | + SplitterPoissonDelegate, SplitterAbstractPopulationVertexNeuronsSynapses) |
| 8 | + |
| 9 | +p.setup(timestep=0.1, time_scale_factor=1) |
| 10 | +p.set_number_of_neurons_per_core(p.IF_curr_exp, 64) |
| 11 | +p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 64) |
| 12 | +n_neurons = 500 |
| 13 | +n_exc = int(round(n_neurons * 0.8)) |
| 14 | +n_inh = int(round(n_neurons * 0.2)) |
| 15 | +weight_exc = 0.1 |
| 16 | +weight_inh = -5.0 * weight_exc |
| 17 | +weight_input = 0.001 |
| 18 | + |
| 19 | +pop_input_splitter = SplitterPoissonDelegate() |
| 20 | +pop_input = p.Population(100, p.SpikeSourcePoisson(rate=0.0), |
| 21 | + additional_parameters={ |
| 22 | + "max_rate": 50.0, |
| 23 | + "seed": 0, |
| 24 | + "splitter": pop_input_splitter}, |
| 25 | + label="Input") |
| 26 | + |
| 27 | +pop_exc_splitter = \ |
| 28 | + SplitterAbstractPopulationVertexNeuronsSynapses(1, 128, False) |
| 29 | +pop_exc = p.Population(n_exc, p.IF_curr_exp, label="Excitatory", |
| 30 | + additional_parameters={"splitter": pop_exc_splitter, |
| 31 | + "seed": 1}) |
| 32 | +pop_inh_splitter = \ |
| 33 | + SplitterAbstractPopulationVertexNeuronsSynapses(1, 128, False) |
| 34 | +pop_inh = p.Population(n_inh, p.IF_curr_exp, label="Inhibitory", |
| 35 | + additional_parameters={"splitter": pop_inh_splitter, |
| 36 | + "seed": 2}) |
| 37 | +stim_exc_splitter = SplitterPoissonDelegate() |
| 38 | +stim_exc = p.Population( |
| 39 | + n_exc, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Exc", |
| 40 | + additional_parameters={"seed": 3, "splitter": stim_exc_splitter}) |
| 41 | +stim_inh_splitter = SplitterPoissonDelegate() |
| 42 | +stim_inh = p.Population( |
| 43 | + n_inh, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Inh", |
| 44 | + additional_parameters={"seed": 4, "splitter": stim_inh_splitter}) |
| 45 | + |
| 46 | +delays_exc = RandomDistribution( |
| 47 | + "normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6) |
| 48 | +weights_exc = RandomDistribution( |
| 49 | + "normal_clipped", mu=weight_exc, sigma=0.1, low=0, high=numpy.inf) |
| 50 | +conn_exc = p.FixedProbabilityConnector(0.1) |
| 51 | +synapse_exc = p.StaticSynapse(weight=weights_exc, delay=delays_exc) |
| 52 | +delays_inh = RandomDistribution( |
| 53 | + "normal_clipped", mu=0.75, sigma=0.375, low=1.0, high=1.6) |
| 54 | +weights_inh = RandomDistribution( |
| 55 | + "normal_clipped", mu=weight_inh, sigma=0.1, low=-numpy.inf, high=0) |
| 56 | +conn_inh = p.FixedProbabilityConnector(0.1) |
| 57 | +synapse_inh = p.StaticSynapse(weight=weights_inh, delay=delays_inh) |
| 58 | +p.Projection( |
| 59 | + pop_exc, pop_exc, conn_exc, synapse_exc, receptor_type="excitatory", |
| 60 | + label="exc_exc") |
| 61 | +p.Projection( |
| 62 | + pop_exc, pop_inh, conn_exc, synapse_exc, receptor_type="excitatory", |
| 63 | + label="exc_inh") |
| 64 | +p.Projection( |
| 65 | + pop_inh, pop_inh, conn_inh, synapse_inh, receptor_type="inhibitory", |
| 66 | + label="inh_inh") |
| 67 | +p.Projection( |
| 68 | + pop_inh, pop_exc, conn_inh, synapse_inh, receptor_type="inhibitory", |
| 69 | + label="inh_exc") |
| 70 | + |
| 71 | +conn_stim = p.OneToOneConnector() |
| 72 | +synapse_stim = p.StaticSynapse(weight=weight_exc, delay=1.0) |
| 73 | +p.Projection( |
| 74 | + stim_exc, pop_exc, conn_stim, synapse_stim, receptor_type="excitatory", |
| 75 | + label="stim_exc_exc") |
| 76 | +p.Projection( |
| 77 | + stim_inh, pop_inh, conn_stim, synapse_stim, receptor_type="excitatory", |
| 78 | + label="stim_inh_inh") |
| 79 | + |
| 80 | +delays_input = RandomDistribution( |
| 81 | + "normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6) |
| 82 | +weights_input = RandomDistribution( |
| 83 | + "normal_clipped", mu=weight_input, sigma=0.01, low=0, high=numpy.inf) |
| 84 | +p.Projection(pop_input, pop_exc, p.AllToAllConnector(), p.StaticSynapse( |
| 85 | + weight=weights_input, delay=delays_input), |
| 86 | + label="input_exc") |
| 87 | + |
| 88 | +pop_exc.initialize( |
| 89 | + v=RandomDistribution("uniform", low=-65.0, high=-55.0)) |
| 90 | +pop_inh.initialize( |
| 91 | + v=RandomDistribution("uniform", low=-65.0, high=-55.0)) |
| 92 | + |
| 93 | +pop_exc.record("spikes") |
| 94 | + |
| 95 | +p.run(1000) |
| 96 | + |
| 97 | +pop_input.set(rate=50.0) |
| 98 | +p.run(1000) |
| 99 | + |
| 100 | +pop_input.set(rate=10.0) |
| 101 | +p.run(1000) |
| 102 | + |
| 103 | +pop_input.set(rate=20.0) |
| 104 | +p.run(1000) |
| 105 | + |
| 106 | +data = pop_exc.get_data("spikes") |
| 107 | +end_time = p.get_current_time() |
| 108 | + |
| 109 | +p.end() |
| 110 | + |
| 111 | +Figure( |
| 112 | + # raster plot of the presynaptic neuron spike times |
| 113 | + Panel(data.segments[0].spiketrains, |
| 114 | + yticks=True, markersize=2.0, xlim=(0, end_time)), |
| 115 | + title="Balanced Random Network", |
| 116 | + annotations="Simulated with {}".format(p.name()) |
| 117 | +) |
| 118 | +pylab.show() |
0 commit comments