2015/nlp15: stdp_test.py

File stdp_test.py, 2.0 KB (added by sergiodavies, 4 years ago)

Example of synaptic plasticity, presented during the PyNN introduction

Line 
1#!/usr/bin/python
2import pyNN.spiNNaker as p
3import numpy, pylab
4
5p.setup(timestep=1.0, min_delay = 1.0, max_delay = 16.0)
6
7
8cell_params_lif = {'cm'        : 0.25, # nF
9                     'i_offset'  : 0.0,
10                     'tau_m'     : 20.0,
11                     'tau_refrac': 2.0,
12                     'tau_syn_E' : 5.0,
13                     'tau_syn_I' : 5.0,
14                     'v_reset'   : -70.0,
15                     'v_rest'    : -65.0,
16                     'v_thresh'  : -50.0
17                     }
18
19populations = list()
20projections = list()
21
22weight_to_spike = 0.5
23delay = 2
24end_time = 1100
25
26spikeArray = {'spike_times': [range(0,end_time,50),range(3,end_time,50),range(6,end_time,50),range(9,end_time,50)]}
27populations.append(p.Population(4, p.SpikeSourceArray, spikeArray, label='inputSpikes_1'))
28
29populations.append(p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1'))
30
31# Plastic Connection between pre_pop and post_pop
32t_rule = p.SpikePairRule(tau_plus=0.5, tau_minus=0.5, nearest=True)
33w_rule = p.AdditiveWeightDependence(w_min=0.0, w_max=2, A_plus=0.5, A_minus=0.5)
34stdp_model = p.STDPMechanism(
35    timing_dependence = t_rule,
36    weight_dependence = w_rule,
37    mad=True
38)
39
40projections.append(p.Projection(populations[0], populations[1], p.AllToAllConnector(weights = weight_to_spike, delays = delay), synapse_dynamics = p.SynapseDynamics(slow = stdp_model)))
41
42populations[0].record()
43populations[1].record()
44
45p.run(end_time)
46
47spikes_1 = populations[0].getSpikes(compatible_output=True)
48spikes_2 = populations[1].getSpikes(compatible_output=True)
49spikes_2[:,0] += 4
50spikes=numpy.ndarray([len(spikes_1)+len(spikes_2),2])
51spikes[0:len(spikes_1)]=spikes_1
52spikes[len(spikes_1):]=spikes_2
53
54if spikes is not None:
55    # print spikes
56    pylab.figure()
57    pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".")
58    pylab.ylabel('neuron id')
59    pylab.ylim( -1, 5 )
60    pylab.xlabel('Time/ms')
61    pylab.title('spikes')
62    pylab.show()
63else:
64    print "No spikes received"
65
66p.end()