2017-08-01 34 views
0

有几个线程需要一种方法来模拟python中的时间不均匀泊松过程。 NeuroTools模块通过inh_poisson_generator()函数提供了一种简单的方法。这个函数的帮助是在这个线程的底部介绍的。该功能最初设计用于模拟尖峰火车,并使用减薄方法。 我想在2000ms内模拟一列尖峰火车。峰值速率(以赫兹为单位)每毫秒变化一次,并且包含在20个尖峰/秒和160个尖峰/秒之间。我已经试过这使用下面的代码来模拟:使用细化方法和NeuroTools python模块来模拟时间不均匀的泊松过程

import NeuroTools 
import numpy as np 
from NeuroTools import stgen 
import matplotlib.pyplot as plt 
import random 

st_gen = stgen.StGen() 
time = np.arange(0, 2000) 
t_rate = [] 
for i in range (2000): 
    t_rate.append(random.randrange(20, 161, 1)) 
t_rate = np.array(t_rate) 

Psim = st_gen.inh_poisson_generator(rate = t_rate, t = time, t_stop = 2000, array = True) 

然而,代码返回极少数的时间戳(例如,阵列([397.55345905,1208.79804513,1478.03525045,1982.63643262]),这没有任何意义,以我,我希望得到任何帮助这一点。

inh_poisson_generator(self, rate, t, t_stop, array=False) method of NeuroTools.stgen.StGen instance 
Returns a SpikeTrain whose spikes are a realization of an inhomogeneous 
poisson process (dynamic rate). The implementation uses the thinning 
method, as presented in the references. 

Inputs: 
    rate - an array of the rates (Hz) where rate[i] is active on interval 
      [t[i],t[i+1]] 
    t  - an array specifying the time bins (in milliseconds) at which to 
      specify the rate 
    t_stop - length of time to simulate process (in ms) 
    array - if True, a numpy array of sorted spikes is returned, 
      rather than a SpikeList object. 

Note: 
    t_start=t[0] 

References: 

Eilif Muller, Lars Buesing, Johannes Schemmel, and Karlheinz Meier 
Spike-Frequency Adapting Neural Ensembles: Beyond Mean Adaptation and Renewal Theories 
Neural Comput. 2007 19: 2958-3010. 

Devroye, L. (1986). Non-uniform random variate generation. New York: Springer-Verlag. 

Examples: 
    >> time = arange(0,1000) 
    >> stgen.inh_poisson_generator(time,sin(time), 1000)enter code here 

回答

1

我真的不知道答案给你,而是因为这个职位让我上手NeuroTools,我想我会分享我的小例子,这是工作正常

对于inh_poisson_generator()以Hz为单位,所有时间以毫秒为单位。我使用的平均速率为每秒1.6次,所以我预计会收到4000个事件。结果证实,这很好!

我想这可能是一个问题,你正在使用非连续的速度。然而,我几乎不知道任何有关此功能实现的算法..

我希望我的例子可以帮助你莫名其妙!

import NeuroTools 
from NeuroTools import stgen 
v0=1.6 #spikes/ms 
Amp=1 # amplitude in spikes/ms 
w=4/1000 # periodic frequency in spikes/ms 
st_gen = stgen.StGen() 
tstop=2500.0 
intervals=np.arange(0,tstop,0.05) 
rate=np.array([]) 
for tt in intervals: 
    v_next=v0+Amp*math.sin(2*math.pi*w*tt) 
    if (v_next>0.0): 
      rate=np.append(rate,v_next*1000) 
    else: rate=np.append(rate,0.0) 
PSim=st_gen.inh_poisson_generator(rate=rate,t = intervals, t_stop = 2500.0, array = True) # important to have rate in Hz and all other times in ms 
print len(PSim) 
print np.mean(rate)/1000*tstop