|
23 | 23 | # exec('import pyNN.%s as pynn' % simulator_Name) |
24 | 24 |
|
25 | 25 |
|
26 | | -def poisson_generator(rate, rng, t_start=0.0, t_stop=1000.0, array=True, |
27 | | - debug=False): |
28 | | - """ |
29 | | - Returns a SpikeTrain whose spikes are a realization of a Poisson process |
30 | | - with the given rate (Hz) and stopping time t_stop (milliseconds). |
31 | | -
|
32 | | - Note: t_start is always 0.0, thus all realizations are as if |
33 | | - they spiked at t=0.0, though this spike is not included in the SpikeList. |
34 | | -
|
35 | | - Inputs: |
36 | | - rate - the rate of the discharge (in Hz) |
37 | | - t_start - the beginning of the SpikeTrain (in ms) |
38 | | - t_stop - the end of the SpikeTrain (in ms) |
39 | | - array - if True, a numpy array of sorted spikes is returned, |
40 | | - rather than a SpikeTrain object. |
41 | | -
|
42 | | - Examples: |
43 | | - >> gen.poisson_generator(50, 0, 1000) |
44 | | - >> gen.poisson_generator(20, 5000, 10000, array=True) |
45 | | -
|
46 | | - See also: |
47 | | - inh_poisson_generator, inh_gamma_generator, |
48 | | - inh_adaptingmarkov_generator |
49 | | - """ |
50 | | - |
51 | | - n = (t_stop - t_start) / 1000.0 * rate |
52 | | - number = np.ceil(n + 3 * np.sqrt(n)) |
53 | | - if number < 100: |
54 | | - number = min(5 + np.ceil(2 * n), 100) |
55 | | - |
56 | | - if number > 0: |
57 | | - isi = rng.exponential(1.0 / rate, number) * 1000.0 |
58 | | - if number > 1: |
59 | | - spikes = np.add.accumulate(isi) |
60 | | - else: |
61 | | - spikes = isi |
62 | | - else: |
63 | | - spikes = np.array([]) |
64 | | - |
65 | | - spikes += t_start |
66 | | - i = np.searchsorted(spikes, t_stop) |
67 | | - |
68 | | - extra_spikes = [] |
69 | | - if i == len(spikes): |
70 | | - # ISI buf overrun |
71 | | - |
72 | | - t_last = spikes[-1] + rng.exponential(1.0 / rate, 1)[0] * 1000.0 |
73 | | - |
74 | | - while (t_last < t_stop): |
75 | | - extra_spikes.append(t_last) |
76 | | - t_last += rng.exponential(1.0 / rate, 1)[0] * 1000.0 |
77 | | - |
78 | | - spikes = np.concatenate((spikes, extra_spikes)) |
79 | | - |
80 | | - if debug: |
81 | | - print("ISI buf overrun handled. len(spikes)=%d," |
82 | | - " len(extra_spikes)=%d" % (len(spikes), len(extra_spikes))) |
83 | | - |
84 | | - else: |
85 | | - spikes = np.resize(spikes, (i,)) |
86 | | - |
87 | | - if debug: |
88 | | - return spikes, extra_spikes |
89 | | - else: |
90 | | - return [round(x) for x in spikes] |
91 | | - |
92 | | - |
93 | 26 | # Total number of neurons |
94 | 27 | Neurons = 1000 |
95 | 28 | sim_time = 1000.0 |
|
0 commit comments