The stgen module
This module offers various stochastic generators for point processes that can be used as spike trains.
The StGen class
Creation
Create an StGen object:
>>> st_gen = StGen()
This will initialize the stochastic generator and by default try to create a numpy random generator instance.
Optionally, you can also pass a random number generator instance to the constructor:
>>> import numpy >>> st_gen = StGen(rng = numpy.random.RandomState())
If you want to seed the random number generator with a specific seed, you can do so in the constructor:
>>> st_gen = StGen(seed = 1234567)
Alternatively, you can re-seed the random number generator when the StGen object has already been created:
>>> st_gen.seed(7654321)
Poisson processes
Using the StGen-object, you can generate point processes with inter-spike-intervals distributed according to a exponential distribution (Poisson process):
>>> st_gen = StGen() >>> spike_train_poisson = st_gen.poisson_generator(rate = 100., t_start = 0., t_stop = 2500.)
This generates a NeuroTools.SpikeTrain object, containing spike times with an approximate rate of 100 Hz and a duration of 2.5 seconds.
If you want a numpy array of spike times rather than a SpikeTrain object, specify the array keyword:
>>> spike_train_array = st_gen.poisson_generator(rate = 100., array = True)
Dynamic Poisson processes
StGen can also generate inhomogeneous Poisson processes, i.e. spike trains with dynamically changing rates:
>>> spike_train_dyn = st_gen.inh_poisson_generator(rate = [50., 80., 30.],
t = [0., 1000., 2000.],
t_stop = 2.5,
array = False)
This will generate a SpikeTrain object containing spike times with a rate parameter of 50 Hz for one second, followed by 80 Hz for one second, and finally 30 Hz for half a second. Note that t[0] is used as tstart.
Inhomogeneous Gamma renewal processes
StGen can also generate inhomogeneous Gamma renewal processes. Implemented is the thinning method, as described in:
Luc Devroye, "Non-Uniform Random Variate Generation" (originally published with Springer-Verlag, New York, 1986)
available in PDF form here: http://cg.scs.carleton.ca/~luc/rnbookindex.html
>>> a = numpy.array([3.0,3.0,3.0]) >>> rate = numpy.array([50., 80., 30.]) >>> b = 1.0/a/rate >>> t = [0., 1000., 2000.] >>> spike_train_dyn = st_gen.inh_gamma_generator(a, b, t, t_stop = 2.5, array = False)
This will generate a SpikeTrain object containing gamma renewal process spike times with a "shape parameter" a=3.0, and a rate of 50 Hz for one second, followed by 80 Hz for one second, and finally 30 Hz for half a second. Note that t[0] is used as t_start.
Other generators include: inh_adaptingmarkov_generator, inh_2Dadaptingmarkov_generator, OU_generator, shotnoise_fromspikes For more information on these generators see the online help, or the source code.
For examples, see trunk/examples/stgen
