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.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:
rate : quantities.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
A : array

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_stop : quantities.Quantity

The end time of the output spike trains.

shift : None or quantities.Quantity, optional

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

t_start : quantities.Quantity, optional

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

Returns:
List of neo.SpikeTrains

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.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:
rate : quantities.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
A : array

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_stop : quantities.Quantity

The end time of the output spike trains.

shift : None or quantities.Quantity, optional

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

t_start : quantities.Quantity, optional

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

Returns:
List of neo.SpikeTrains

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.0) * ms, t_stop=array(1000.0) * 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*Hz.

Parameters:
a : int or float

The shape parameter of the gamma distribution.

b : Quantity scalar with dimension 1/time

The rate parameter of the gamma distribution.

t_start : Quantity scalar with dimension time

The beginning of the spike train.

t_stop : Quantity scalar with dimension time

The end of the spike train.

as_array : bool

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

Raises:
ValueError : If t_start and t_stop are not of type pq.Quantity.

Examples

>>> from quantities import Hz, ms
>>> spikes = homogeneous_gamma_process(2.0, 50*Hz, 0*ms, 1000*ms)
>>> spikes = homogeneous_gamma_process(
        5.0, 20*Hz, 5000*ms, 10000*ms, as_array=True)
elephant.spike_train_generation.homogeneous_poisson_process(rate, t_start=array(0.0) * ms, t_stop=array(1000.0) * ms, as_array=False)[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*Hz.

Parameters:
rate : Quantity scalar with dimension 1/time

The rate of the discharge.

t_start : Quantity scalar with dimension time

The beginning of the spike train.

t_stop : Quantity scalar with dimension time

The end of the spike train.

as_array : bool

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

Raises:
ValueError : If t_start and t_stop are not of type pq.Quantity.

Examples

>>> from quantities import Hz, ms
>>> spikes = homogeneous_poisson_process(50*Hz, 0*ms, 1000*ms)
>>> spikes = homogeneous_poisson_process(
    20*Hz, 5000*ms, 10000*ms, as_array=True)
elephant.spike_train_generation.inhomogeneous_poisson_process(rate, as_array=False)[source]

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

Parameters:
rate : neo.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_array : bool

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

Raises
——
ValueError : If rate contains any negative value.
elephant.spike_train_generation.peak_detection(signal, threshold=array(0.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:
signal : neo AnalogSignal object

‘signal’ is an analog signal.

threshold : A quantity, e.g. in mV

‘threshold’ contains a value that must be reached for an event to be detected.

sign : ‘above’ or ‘below’

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

format : None or ‘raw’

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

Returns:
result_st : neo SpikeTrain object

‘result_st’ 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.0) * ms, coincidences='deterministic', t_start=array(0.0) * ms, min_delay=array(0.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_stop: quantities.Quantity

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

rate: quantities.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_c: quantities.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.

n: int, optional

If rate is a single 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: 1

jitter: quantities.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.

coincidences: string, 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_start: quantities.Quantity, optional

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

min_delay: quantities.Quantity, optional

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

return_coinc: bool, 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

EXAMPLE:

>>> import quantities as qt
>>> import jelephant.core.stocmod as sm
>>> sip, coinc = sm.sip_poisson(n=10, n=0, t_stop=1*qt.sec,             rate=20*qt.Hz,  rate_c=4, return_coinc = True)
elephant.spike_train_generation.spike_extraction(signal, threshold=array(0.0) * mV, sign='above', time_stamps=None, extr_interval=(array(-2.0) * ms, array(4.0) * 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. Similar to spike_train_generation.peak_detection.

Parameters:
signal : neo AnalogSignal object

‘signal’ is an analog signal.

threshold : A quantity, e.g. in mV

‘threshold’ contains a value that must be reached for an event to be detected. Default: 0.0 * mV.

sign : ‘above’ or ‘below’

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

time_stamps: None, quantity array or Object with .times interface

if ‘spike_train’ is a quantity array or exposes a quantity array exposes the .times interface, it 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_interval: unpackable time quantities, len == 2

‘extr_interval’ specifies the time interval around the time_stamps where the waveform is extracted. The default is an interval of ‘6 ms’. Default: (-2 * ms, 4 * ms).

Returns:
result_st : neo SpikeTrain object

‘result_st’ 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.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:
signal : neo AnalogSignal object

‘signal’ is an analog signal.

threshold : A quantity, e.g. in mV

‘threshold’ contains a value that must be reached for an event to be detected. Default: 0.0 * mV.

sign : ‘above’ or ‘below’

‘sign’ determines whether to count thresholding crossings that cross above or below the threshold.

format : None or ‘raw’

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

Returns:
result_st : neo SpikeTrain object

‘result_st’ contains the spike times of each of the events (spikes) extracted from the signal.