elephant.spike_train_synchrony.spike_contrast

elephant.spike_train_synchrony.spike_contrast(spiketrains, t_start=None, t_stop=None, min_bin=array(10.) * ms, bin_shrink_factor=0.9, return_trace=False)[source]

Calculates the synchrony of spike trains, according to (Ciba et al., 2018). The spike trains can have different lengths.

Original implementation by: Philipp Steigerwald [s160857@th-ab.de]

Visualization is covered in viziphant.spike_train_synchrony.plot_spike_contrast().

Parameters:
spiketrainslist of neo.SpikeTrain

A list of input spike trains to calculate the synchrony from.

t_startpq.Quantity, optional

The beginning of the spike train. If None, it’s taken as the minimum value of t_start values of the input spike trains. Default: None

t_stoppq.Quantity, optional

The end of the spike train. If None, it’s taken as the maximum value of t_stop of the input spike trains. Default: None

min_binpq.Quantity, optional

Sets the minimum value for the bin_min that is calculated by the algorithm and defines the smallest bin size to compute the histogram of the input spiketrains. Default: 0.01 ms

bin_shrink_factorfloat, optional

A multiplier to shrink the bin size on each iteration. The value must be in range (0, 1). Default: 0.9

return_tracebool, optional

If set to True, returns a history of spike-contrast synchrony, computed for a range of different bin sizes, alongside with the maximum value of the synchrony. Default: False

Returns:
synchronyfloat

Returns the synchrony of the input spike trains.

spike_contrast_tracenamedtuple

If return_trace is set to True, a SpikeContrastTrace namedtuple is returned with the following attributes:

.contrast - the average sum of differences of the number of spikes in subsuequent bins;

.active_spiketrains - the average number of spikes per bin, weighted by the number of spike trains containing at least one spike inside the bin;

.synchrony - the product of contrast and active_spiketrains;

.bin_size - the X axis, a list of bin sizes that correspond to these traces.

Raises:
ValueError

If bin_shrink_factor is not in (0, 1) range.

If the input spike trains constist of a single spiketrain.

If all input spike trains contain no more than 1 spike.

TypeError

If the input spike trains is not a list of neo.SpikeTrain objects.

If t_start, t_stop, or min_bin are not time quantities.

Examples

>>> import quantities as pq
>>> import numpy as np
>>> from elephant.spike_train_generation import StationaryPoissonProcess
>>> from elephant.spike_train_synchrony import spike_contrast
>>> np.random.seed(225)
>>> spiketrain_1 = StationaryPoissonProcess(rate=20*pq.Hz,
...     t_stop=1000*pq.ms).generate_spiketrain()
>>> spiketrain_2 = StationaryPoissonProcess(rate=20*pq.Hz,
...     t_stop=1000*pq.ms).generate_spiketrain()
>>> round(spike_contrast([spiketrain_1, spiketrain_2]),3)
0.419