Stochastic spike train generation

Functions to generate spike trains from analog signals, or to generate random spike trains.

Some functions are based on the NeuroTools stgen module, which was mostly written by Eilif Muller, or from the NeuroTools signals.analogs module.

elephant.spike_train_generation.compound_poisson_process(rate, A, t_stop, shift=None, t_start=array(0.) * ms)[source]

Generate a Compound Poisson Process (CPP; see _[1]) with a given amplitude distribution A and stationary marginal rates r.

The CPP process is a model for parallel, correlated processes with Poisson spiking statistics at pre-defined firing rates. It is composed of len(A)-1 spike trains with a correlation structure determined by the amplitude distribution A: A[j] is the probability that a spike occurs synchronously in any j spike trains.

The CPP is generated by creating a hidden mother Poisson process, and then copying spikes of the mother process to j of the output spike trains with probability A[j].

Note that this function decorrelates the firing rate of each SpikeTrain from the probability for that SpikeTrain to participate in a synchronous event (which is uniform across SpikeTrains).

Parameters:
ratepq.Quantity
Average rate of each spike train generated. Can be:
  • a single value, all spike trains will have same rate rate
  • an array of values (of length len(A)-1), each indicating the firing rate of one process in output
Anp.ndarray

CPP’s amplitude distribution. A[j] represents the probability of a synchronous event of size j among the generated spike trains. The sum over all entries of A must be equal to one.

t_stoppq.Quantity

The end time of the output spike trains.

shiftpq.Quantity, optional

If None, the injected synchrony is exact. If shift is a pq.Quantity, all the spike trains are shifted independently by a random amount in the interval [-shift, +shift]. Default: None

t_startpq.Quantity, optional

The t_start time of the output spike trains. Default: 0 pq.ms

Returns:
list of neo.SpikeTrain

SpikeTrains with specified firing rates forming the CPP with amplitude distribution A.

References

[1]Staude, Rotter, Gruen (2010) J Comput Neurosci 29:327-350.
elephant.spike_train_generation.cpp(rate, A, t_stop, shift=None, t_start=array(0.) * ms)

Generate a Compound Poisson Process (CPP; see _[1]) with a given amplitude distribution A and stationary marginal rates r.

The CPP process is a model for parallel, correlated processes with Poisson spiking statistics at pre-defined firing rates. It is composed of len(A)-1 spike trains with a correlation structure determined by the amplitude distribution A: A[j] is the probability that a spike occurs synchronously in any j spike trains.

The CPP is generated by creating a hidden mother Poisson process, and then copying spikes of the mother process to j of the output spike trains with probability A[j].

Note that this function decorrelates the firing rate of each SpikeTrain from the probability for that SpikeTrain to participate in a synchronous event (which is uniform across SpikeTrains).

Parameters:
ratepq.Quantity
Average rate of each spike train generated. Can be:
  • a single value, all spike trains will have same rate rate
  • an array of values (of length len(A)-1), each indicating the firing rate of one process in output
Anp.ndarray

CPP’s amplitude distribution. A[j] represents the probability of a synchronous event of size j among the generated spike trains. The sum over all entries of A must be equal to one.

t_stoppq.Quantity

The end time of the output spike trains.

shiftpq.Quantity, optional

If None, the injected synchrony is exact. If shift is a pq.Quantity, all the spike trains are shifted independently by a random amount in the interval [-shift, +shift]. Default: None

t_startpq.Quantity, optional

The t_start time of the output spike trains. Default: 0 pq.ms

Returns:
list of neo.SpikeTrain

SpikeTrains with specified firing rates forming the CPP with amplitude distribution A.

References

[1]Staude, Rotter, Gruen (2010) J Comput Neurosci 29:327-350.
elephant.spike_train_generation.homogeneous_gamma_process(a, b, t_start=array(0.) * ms, t_stop=array(1000.) * ms, as_array=False)[source]

Returns a spike train whose spikes are a realization of a gamma process with the given parameters, starting at time t_start and stopping time t_stop (average rate will be b/a). All numerical values should be given as Quantities, e.g. 100*pq.Hz.

Parameters:
aint or float

The shape parameter of the gamma distribution.

bpq.Quantity

The rate parameter of the gamma distribution.

t_startpq.Quantity, optional

The beginning of the spike train. Default: 0 * pq.ms.

t_stoppq.Quantity, optional

The end of the spike train. Default: 1000 * pq.ms.

as_arraybool, optional

If True, a NumPy array of sorted spikes is returned, rather than a neo.SpikeTrain object. Default: False.

Returns:
spiketrainneo.SpikeTrain or np.ndarray

Homogeneous Gamma process realization, stored in neo.SpikeTrain if as_array is False (default) and np.ndarray otherwise.

Raises:
ValueError

If t_start and t_stop are not of type pq.Quantity.

Examples

>>> import quantities as pq
>>> spikes = homogeneous_gamma_process(2.0, 50*pq.Hz, 0*pq.ms,
...                                       1000*pq.ms)
>>> spikes = homogeneous_gamma_process(
...        5.0, 20*pq.Hz, 5000*pq.ms, 10000*pq.ms, as_array=True)
elephant.spike_train_generation.homogeneous_poisson_process(rate, t_start=array(0.) * ms, t_stop=array(1000.) * ms, as_array=False, refractory_period=None)[source]

Returns a spike train whose spikes are a realization of a Poisson process with the given rate, starting at time t_start and stopping time t_stop.

All numerical values should be given as Quantities, e.g. 100*pq.Hz.

Parameters:
ratepq.Quantity

The rate of the discharge.

t_startpq.Quantity, optional

The beginning of the spike train. Default: 0 * pq.ms.

t_stoppq.Quantity, optional

The end of the spike train. Default: 1000 * pq.ms.

as_arraybool, optional

If True, a NumPy array of sorted spikes is returned, rather than a neo.SpikeTrain object. Default: False.

refractory_periodpq.Quantity or None, optional

pq.Quantity scalar with dimension time. The time period after one spike no other spike is emitted. Default: None.

Returns:
spiketrainneo.SpikeTrain or np.ndarray

Homogeneous Poisson process realization, stored in neo.SpikeTrain if as_array is False (default) and np.ndarray otherwise.

Raises:
ValueError

If one of rate, t_start and t_stop is not of type pq.Quantity.

If refractory_period is not None or not of type pq.Quantity.

If refractory_period is not None and the period between two successive spikes (1 / rate) is smaller than the refractory_period.

Examples

>>> import quantities as pq
>>> spikes = homogeneous_poisson_process(50*pq.Hz, t_start=0*pq.ms,
...     t_stop=1000*pq.ms)
>>> spikes = homogeneous_poisson_process(
...     20*pq.Hz, t_start=5000*pq.ms, t_stop=10000*pq.ms, as_array=True)
>>> spikes = homogeneous_poisson_process(50*pq.Hz, t_start=0*pq.ms,
...     t_stop=1000*pq.ms, refractory_period = 3*pq.ms)
elephant.spike_train_generation.inhomogeneous_poisson_process(rate, as_array=False, refractory_period=None)[source]

Returns a spike train whose spikes are a realization of an inhomogeneous Poisson process with the given rate profile.

Parameters:
rateneo.AnalogSignal

A neo.AnalogSignal representing the rate profile evolving over time. Its values have all to be >=0. The output spiketrain will have t_start = rate.t_start and t_stop = rate.t_stop

as_arraybool, optional

If True, a NumPy array of sorted spikes is returned, rather than a SpikeTrain object. Default: False.

refractory_periodpq.Quantity or None, optional

pq.Quantity scalar with dimension time. The time period after one spike no other spike is emitted. Default: None.

Returns:
spiketrainneo.SpikeTrain or np.ndarray

Inhomogeneous Poisson process realization, of type neo.SpikeTrain if as_array is False (default) and np.ndarray otherwise.

Raises:
ValueError

If rate contains a negative value.

If refractory_period is not None or not of type pq.Quantity.

If refractory_period is not None and the period between two successive spikes (1 / rate) is smaller than the refractory_period.

elephant.spike_train_generation.peak_detection(signal, threshold=array(0.) * mV, sign='above', format=None)[source]

Return the peak times for all events that cross threshold. Usually used for extracting spike times from a membrane potential. Similar to spike_train_generation.threshold_detection.

Parameters:
signalneo.AnalogSignal

An analog input signal.

thresholdpq.Quantity, optional

Contains a value that must be reached for an event to be detected. Default: 0.*pq.mV.

sign{‘above’, ‘below’}, optional

Determines whether to count threshold crossings that cross above or below the threshold. Default: ‘above’.

format{None, ‘raw’}, optional

Whether to return as SpikeTrain (None) or as a plain array of times (‘raw’). Default: None.

Returns:
result_stneo.SpikeTrain

Contains the spike times of each of the events (spikes) extracted from the signal.

elephant.spike_train_generation.single_interaction_process(rate, rate_c, t_stop, n=2, jitter=array(0.) * ms, coincidences='deterministic', t_start=array(0.) * ms, min_delay=array(0.) * ms, return_coinc=False)[source]

Generates a multidimensional Poisson SIP (single interaction process) plus independent Poisson processes

A Poisson SIP consists of Poisson time series which are independent except for simultaneous events in all of them. This routine generates a SIP plus additional parallel independent Poisson processes.

See _[1].

Parameters:
t_stoppq.Quantity

Total time of the simulated processes. The events are drawn between 0 and t_stop.

ratepq.Quantity

Overall mean rate of the time series to be generated (coincidence rate rate_c is subtracted to determine the background rate). Can be: * a float, representing the overall mean rate of each process. If

so, it must be higher than rate_c.

  • an iterable of floats (one float per process), each float representing the overall mean rate of a process. If so, all the entries must be larger than rate_c.
rate_cpq.Quantity

Coincidence rate (rate of coincidences for the n-dimensional SIP). The SIP spike trains will have coincident events with rate rate_c plus independent ‘background’ events with rate rate-rate_c.

nint, optional

If rate is a single pq.Quantity value, n specifies the number of SpikeTrains to be generated. If rate is an array, n is ignored and the number of SpikeTrains is equal to len(rate). Default: 2

jitterpq.Quantity, optional

Jitter for the coincident events. If jitter == 0, the events of all n correlated processes are exactly coincident. Otherwise, they are jittered around a common time randomly, up to +/- jitter. Default: 0 * pq.ms

coincidences{‘deterministic’, ‘stochastic’}, optional

Whether the total number of injected coincidences must be determin- istic (i.e. rate_c is the actual rate with which coincidences are generated) or stochastic (i.e. rate_c is the mean rate of coincid- ences):

  • ‘deterministic’: deterministic rate
  • ‘stochastic’: stochastic rate

Default: ‘deterministic’

t_startpq.Quantity, optional

Starting time of the series. If specified, it must be lower than t_stop. Default: 0 * pq.ms

min_delaypq.Quantity, optional

Minimum delay between consecutive coincidence times. Default: 0 * pq.ms

return_coincbool, optional

Whether to return the coincidence times for the SIP process Default: False

Returns:
output: list

Realization of a SIP consisting of n Poisson processes characterized by synchronous events (with the given jitter) If return_coinc is True, the coincidence times are returned as a second output argument. They also have an associated time unit (same as t_stop).

References

[1]Kuhn, Aertsen, Rotter (2003) Neural Comput 15(1):67-101

Examples

>>> import quantities as pq
>>> import elephant.spike_train_generation as stg
# TODO: check if rate_c=4 is correct.
>>> sip, coinc = stg.single_interaction_process(rate=20*pq.Hz,  rate_c=4,
...                                             t_stop=1*pq.s,
...                                             n=10, return_coinc = True)
elephant.spike_train_generation.spike_extraction(signal, threshold=array(0.) * mV, sign='above', time_stamps=None, extr_interval=(array(-2.) * ms, array(4.) * ms))[source]

Return the peak times for all events that cross threshold and the waveforms. Usually used for extracting spikes from a membrane potential to calculate waveform properties.

Parameters:
signalneo.AnalogSignal

An analog input signal.

thresholdpq.Quantity, optional

Contains a value that must be reached for an event to be detected. Default: 0.0 * pq.mV.

sign{‘above’, ‘below’}, optional

Determines whether to count threshold crossings that cross above or below the threshold. Default: ‘above’.

time_stampspq.Quantity, optional

If spike_train is a pq.Quantity array, time_stamps provides the time stamps around which the waveform is extracted. If it is None, the function peak_detection is used to calculate the time_stamps from signal. Default: None.

extr_intervaltuple of pq.Quantity

Specifies the time interval around the time_stamps where the waveform is extracted. Default: (-2 * pq.ms, 4 * pq.ms).

Returns:
result_stneo.SpikeTrain

Contains the time_stamps of each of the spikes and the waveforms in result_st.waveforms.

elephant.spike_train_generation.threshold_detection(signal, threshold=array(0.) * mV, sign='above')[source]

Returns the times when the analog signal crosses a threshold. Usually used for extracting spike times from a membrane potential. Adapted from version in NeuroTools.

Parameters:
signalneo.AnalogSignal

An analog input signal.

thresholdpq.Quantity, optional

Contains a value that must be reached for an event to be detected. Default: 0.0 * pq.mV.

sign{‘above’, ‘below’}, optional

Determines whether to count threshold crossings that cross above or below the threshold. Default: ‘above’.

Returns:
result_stneo.SpikeTrain

Contains the spike times of each of the events (spikes) extracted from the signal.