-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpoisson_utils.py
51 lines (49 loc) · 2.24 KB
/
poisson_utils.py
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
import string
from pylab import *
#from scipy.interpolate import interp1d # needs liblapack, not available on cluster nodes
# Have just extracted the Poisson generating routines from neuroutils.py
# so that I don't need to import scipy and thus it will run on all gj nodes.
def poissonTrain(runtime, firingrate, refractory):
lastfiredtime = 0 # s
ornstimvector = []
if firingrate > 0:
while lastfiredtime < runtime:
# numpy.random.exponential
isi = exponential(1/firingrate) # inter-spike interval 'isi' of a Poisson spike generator is exponentially distributed r*exp(-r*isi)
if isi < refractory:
continue ###### Do not fire
else:
#### FIRED! append time of firing
lastfiredtime += isi
if lastfiredtime < runtime:
ornstimvector.append(lastfiredtime)
return ornstimvector
def poissonTrainVaryingRate(runtime, maxfiringrate, refractory, tvec, ratevec):
"""
This uses the spike thinning algorithm outlined in Dayan and Abbott 2001.
firing rate should never exceed maxfiringrate. I typically give twice the estimated max to be safe.
tvec and ratevec are lists t and rate respectively,
from which I obtain a rate(t) function by linear interpolation (numpy).
"""
lastfiredtime = 0 # s
ornstimvector = []
# Do not want to increase dependency on scipy.interpolate
# as not installed on all nodes on cluster -- use numpy
#rate = interp1d(tvec, ratevec, kind='linear')
while lastfiredtime < runtime:
# numpy.random.exponential
# inter-spike interval 'isi' of a homogeneous (const rate 'r') Poisson spike generator
# is exponentially distributed r*exp(-r*isi)
isi = exponential(1/maxfiringrate)
if isi < refractory:
continue ###### Do not fire
else:
lastfiredtime += isi
if lastfiredtime > runtime:
break
# spike thinning by rate(t)/maxfiringrate
# numpy.random.uniform
if uniform(0,1) < interp(lastfiredtime,tvec,ratevec)/maxfiringrate:
#### FIRED! append time of firing
ornstimvector.append(lastfiredtime)
return ornstimvector