1 | #!/usr/bin/python |
---|

2 | import pyNN.spiNNaker as p |
---|

3 | import numpy, pylab |
---|

4 | |
---|

5 | p.setup(timestep=1.0, min_delay = 1.0, max_delay = 16.0) |
---|

6 | |
---|

7 | |
---|

8 | cell_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 | |
---|

19 | populations = list() |
---|

20 | projections = list() |
---|

21 | |
---|

22 | weight_to_spike = 0.5 |
---|

23 | delay = 2 |
---|

24 | end_time = 1100 |
---|

25 | |
---|

26 | spikeArray = {'spike_times': [range(0,end_time,50),range(3,end_time,50),range(6,end_time,50),range(9,end_time,50)]} |
---|

27 | populations.append(p.Population(4, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) |
---|

28 | |
---|

29 | populations.append(p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1')) |
---|

30 | |
---|

31 | # Plastic Connection between pre_pop and post_pop |
---|

32 | t_rule = p.SpikePairRule(tau_plus=0.5, tau_minus=0.5, nearest=True) |
---|

33 | w_rule = p.AdditiveWeightDependence(w_min=0.0, w_max=2, A_plus=0.5, A_minus=0.5) |
---|

34 | stdp_model = p.STDPMechanism( |
---|

35 | timing_dependence = t_rule, |
---|

36 | weight_dependence = w_rule, |
---|

37 | mad=True |
---|

38 | ) |
---|

39 | |
---|

40 | projections.append(p.Projection(populations[0], populations[1], p.AllToAllConnector(weights = weight_to_spike, delays = delay), synapse_dynamics = p.SynapseDynamics(slow = stdp_model))) |
---|

41 | |
---|

42 | populations[0].record() |
---|

43 | populations[1].record() |
---|

44 | |
---|

45 | p.run(end_time) |
---|

46 | |
---|

47 | spikes_1 = populations[0].getSpikes(compatible_output=True) |
---|

48 | spikes_2 = populations[1].getSpikes(compatible_output=True) |
---|

49 | spikes_2[:,0] += 4 |
---|

50 | spikes=numpy.ndarray([len(spikes_1)+len(spikes_2),2]) |
---|

51 | spikes[0:len(spikes_1)]=spikes_1 |
---|

52 | spikes[len(spikes_1):]=spikes_2 |
---|

53 | |
---|

54 | if 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() |
---|

63 | else: |
---|

64 | print "No spikes received" |
---|

65 | |
---|

66 | p.end() |
---|