pyspike package¶
Classes¶
SpikeTrain¶

class
pyspike.SpikeTrain.
SpikeTrain
(spike_times, edges, is_sorted=True)[source]¶ Bases:
object
Class representing spike trains for the PySpike Module.

__init__
(spike_times, edges, is_sorted=True)[source]¶ Constructs the SpikeTrain.
Parameters:  spike_times – ordered array of spike times.
 edges – The edges of the spike train. Given as a pair of floats (T0, T1) or a single float T1, where then T0=0 is assumed.
 is_sorted – If False, the spike times will sorted by np.sort.

copy
()[source]¶ Returns a copy of this spike train. Use this function if you want to create a real (deep) copy of this spike train. Simple assignment t2 = t1 does not create a copy of the spike train data, but a reference as numpy.array is used for storing the data.
Returns: SpikeTrain
copy of this spike train.

PieceWiseConstFunc¶

class
pyspike.PieceWiseConstFunc.
PieceWiseConstFunc
(x, y)[source]¶ Bases:
object
A class representing a piecewise constant function.

__init__
(x, y)[source]¶ Constructs the piecewise const function.
Parameters:  x – array of length N+1 defining the edges of the intervals of the pwc function.
 y – array of length N defining the function values at the intervals.

add
(f)[source]¶ Adds another PieceWiseConst function to this function. Note: only functions defined on the same interval can be summed.
Parameters: f – PieceWiseConstFunc
function to be added.Return type: None

almost_equal
(other, decimal=14)[source]¶ Checks if the function is equal to another function up to decimal precision.
Parameters: other – another PieceWiseConstFunc
Returns: True if the two functions are equal up to decimal decimals, False otherwise Return type: bool

avrg
(interval=None)[source]¶ Computes the average of the piecewise const function: \(a = 1/T \int_0^T f(x) dx\) where T is the length of the interval.
Parameters: interval (Pair, sequence of pairs, or None.) – averaging interval given as a pair of floats, a sequence of pairs for averaging multiple intervals, or None, if None the average over the whole function is computed. Returns: the average a. Return type: float

copy
()[source]¶ Returns a copy of itself
Return type: PieceWiseConstFunc

get_plottable_data
()[source]¶ Returns two arrays containing x and ycoordinates for immeditate plotting of the piecewise function.
Returns: (x_plot, y_plot) containing plottable data Return type: pair of np.array Example:
x, y = f.get_plottable_data() plt.plot(x, y, 'o', label="Piecewise const function")

PieceWiseLinFunc¶

class
pyspike.PieceWiseLinFunc.
PieceWiseLinFunc
(x, y1, y2)[source]¶ A class representing a piecewise linear function.

__init__
(x, y1, y2)[source]¶ Constructs the piecewise linear function.
Parameters:  x – array of length N+1 defining the edges of the intervals of the pwc function.
 y1 – array of length N defining the function values at the left of the intervals.
 y2 – array of length N defining the function values at the right of the intervals.

add
(f)[source]¶ Adds another PieceWiseLin function to this function. Note: only functions defined on the same interval can be summed.
Parameters: f – PieceWiseLinFunc
function to be added.Return type: None

almost_equal
(other, decimal=14)[source]¶ Checks if the function is equal to another function up to decimal precision.
Parameters: other – another PieceWiseLinFunc
Returns: True if the two functions are equal up to decimal decimals, False otherwise Return type: bool

avrg
(interval=None)[source]¶ Computes the average of the piecewise linear function: \(a = 1/T \int_0^T f(x) dx\) where T is the interval length.
Parameters: interval (Pair, sequence of pairs, or None.) – averaging interval given as a pair of floats, a sequence of pairs for averaging multiple intervals, or None, if None the average over the whole function is computed. Returns: the average a. Return type: float

copy
()[source]¶ Returns a copy of itself
Return type: PieceWiseLinFunc

get_plottable_data
()[source]¶ Returns two arrays containing x and ycoordinates for immeditate plotting of the piecewise function.
Returns: (x_plot, y_plot) containing plottable data Return type: pair of np.array Example:
x, y = f.get_plottable_data() plt.plot(x, y, 'o', label="Piecewise const function")

DiscreteFunc¶

class
pyspike.DiscreteFunc.
DiscreteFunc
(x, y, multiplicity)[source]¶ Bases:
object
A class representing values defined on a discrete set of points.

__init__
(x, y, multiplicity)[source]¶ Constructs the discrete function.
Parameters:  x – array of length N defining the points at which the values are defined.
 y – array of length N degining the values at the points x.
 multiplicity – array of length N defining the multiplicity of the values.

add
(f)[source]¶ Adds another DiscreteFunc function to this function. Note: only functions defined on the same interval can be summed.
Parameters: f – DiscreteFunc
function to be added.Return type: None

almost_equal
(other, decimal=14)[source]¶ Checks if the function is equal to another function up to decimal precision.
Parameters: other – another DiscreteFunc
Returns: True if the two functions are equal up to decimal decimals, False otherwise Return type: bool

avrg
(interval=None, normalize=True)[source]¶ Computes the average of the interval sequence: \(a = 1/N \sum f_n\) where N is the number of intervals.
Parameters: interval (Pair, sequence of pairs, or None.) – averaging interval given as a pair of floats, a sequence of pairs for averaging multiple intervals, or None, if None the average over the whole function is computed. Returns: the average a. Return type: float

copy
()[source]¶ Returns a copy of itself
Return type: DiscreteFunc

get_plottable_data
(averaging_window_size=0)[source]¶ Returns two arrays containing x and ycoordinates for plotting the interval sequence. The optional parameter averaging_window_size determines the size of an averaging window to smoothen the profile. If this value is 0, no averaging is performed.
Parameters: averaging_window_size – size of the averaging window, default=0. Returns: (x_plot, y_plot) containing plottable data Return type: pair of np.array Example:
x, y = f.get_plottable_data() plt.plot(x, y, 'o', label="Discrete function")

integral
(interval=None)[source]¶ Returns the integral over the given interval. For the discrete function, this amounts to two values: the sum over all values and the sum over all multiplicities.
Parameters: interval (Pair, sequence of pairs, or None.) – integration interval given as a pair of floats, or a sequence of pairs in case of multiple intervals, if None the integral over the whole function is computed. Returns: the summed values and the summed multiplicity Return type: pair of float


pyspike.DiscreteFunc.
average_profile
(profiles)[source]¶ Computes the average profile from the given ISI or SPIKEprofiles.
Parameters: profiles – list of PieceWiseConstFunc
orPieceWiseLinFunc
representing ISI or SPIKEprofiles to be averaged.Returns: the averages profile \(<S_{isi}>\) or \(<S_{spike}>\). Return type: PieceWiseConstFunc
orPieceWiseLinFunc
Functions¶
ISIdistance¶

pyspike.isi_distance.
isi_distance
(*args, **kwargs)[source]¶ Computes the ISIdistance \(D_I\) of the given spike trains. The isidistance is the integral over the isi distance profile \(I(t)\):
\[D_I = \int_{T_0}^{T_1} I(t) dt.\]In the multivariate case it is the integral over the multivariate ISIprofile, i.e. the average profile over all spike train pairs:
\[\begin{split}D_I = \int_0^T \frac{2}{N(N1)} \sum_{<i,j>} I^{i,j},\end{split}\]where the sum goes over all pairs <i,j>
Valid call structures:
isi_distance(st1, st2) # returns the bivariate distance isi_distance(st1, st2, st3) # multivariate distance of 3 spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains isi_distance(spike_trains) # distance of the list of spike trains isi_distance(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
Returns: The isidistance \(D_I\). Return type: double

pyspike.isi_distance.
isi_distance_bi
(spike_train1, spike_train2, interval=None)[source]¶ Specific function to compute the bivariate ISIdistance. This is a deprecated function and should not be called directly. Use
isi_distance()
to compute ISIdistances.Parameters:  spike_train1 (
SpikeTrain
) – First spike train.  spike_train2 (
SpikeTrain
) – Second spike train.  interval (Pair of floats or None.) – averaging interval given as a pair of floats (T0, T1), if None the average over the whole function is computed.
Returns: The isidistance \(D_I\).
Return type: double
 spike_train1 (

pyspike.isi_distance.
isi_distance_matrix
(spike_trains, indices=None, interval=None)[source]¶ Computes the time averaged isidistance of all pairs of spiketrains.
Parameters:  spike_trains – list of
SpikeTrain
 indices (list or None) – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
 interval (Pair of floats or None.) – averaging interval given as a pair of floats, if None the average over the whole function is computed.
Returns: 2D array with the pair wise time average isi distances \(D_{I}^{ij}\)
Return type: np.array
 spike_trains – list of

pyspike.isi_distance.
isi_distance_multi
(spike_trains, indices=None, interval=None)[source]¶ Specific function to compute the multivariate ISIdistance. This is a deprecfated function and should not be called directly. Use
isi_distance()
to compute ISIdistances.Parameters:  spike_trains – list of
SpikeTrain
 indices – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
 interval (Pair of floats or None.) – averaging interval given as a pair of floats, if None the average over the whole function is computed.
Returns: The timeaveraged multivariate ISI distance \(D_I\)
Return type: double
 spike_trains – list of

pyspike.isi_distance.
isi_profile
(*args, **kwargs)[source]¶ Computes the isidistance profile \(I(t)\) of the given spike trains. Returns the profile as a PieceWiseConstFunc object. The ISIvalues are defined positive \(I(t)>=0\).
Valid call structures:
isi_profile(st1, st2) # returns the bivariate profile isi_profile(st1, st2, st3) # multivariate profile of 3 spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains isi_profile(spike_trains) # profile of the list of spike trains isi_profile(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
The multivariate ISI distance profile for a set of spike trains is defined as the average ISIprofile of all pairs of spiketrains:
\[\begin{split}<I(t)> = \frac{2}{N(N1)} \sum_{<i,j>} I^{i,j},\end{split}\]where the sum goes over all pairs <i,j>
Returns: The isidistance profile \(I(t)\) Return type: PieceWiseConstFunc

pyspike.isi_distance.
isi_profile_bi
(spike_train1, spike_train2)[source]¶ Specific function to compute a bivariate ISIprofile. This is a deprecated function and should not be called directly. Use
isi_profile()
to compute ISIprofiles.Parameters:  spike_train1 (
SpikeTrain
) – First spike train.  spike_train2 (
SpikeTrain
) – Second spike train.
Returns: The isidistance profile \(I(t)\)
Return type:  spike_train1 (

pyspike.isi_distance.
isi_profile_multi
(spike_trains, indices=None)[source]¶ Specific function to compute the multivariate ISIprofile for a set of spike trains. This is a deprecated function and should not be called directly. Use
isi_profile()
to compute ISIprofiles.Parameters:  spike_trains – list of
SpikeTrain
 indices – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
Returns: The averaged isi profile \(<I(t)>\)
Return type:  spike_trains – list of
SPIKEdistance¶

pyspike.spike_distance.
spike_distance
(*args, **kwargs)[source]¶ Computes the SPIKEdistance \(D_S\) of the given spike trains. The spikedistance is the integral over the spike distance profile \(D(t)\):
\[D_S = \int_{T_0}^{T_1} S(t) dt.\]Valid call structures:
spike_distance(st1, st2) # returns the bivariate distance spike_distance(st1, st2, st3) # multivariate distance of 3 spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains spike_distance(spike_trains) # distance of the list of spike trains spike_distance(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
In the multivariate case, the spike distance is given as the integral over the multivariate profile, that is the average profile of all spike train pairs:
\[\begin{split}D_S = \int_0^T \frac{2}{N(N1)} \sum_{<i,j>} S^{i, j} dt\end{split}\]Returns: The spikedistance \(D_S\). Return type: double

pyspike.spike_distance.
spike_distance_bi
(spike_train1, spike_train2, interval=None)[source]¶ Specific function to compute a bivariate SPIKEdistance. This is a deprecated function and should not be called directly. Use
spike_distance()
to compute SPIKEdistances.Parameters:  spike_train1 (
SpikeTrain
) – First spike train.  spike_train2 (
SpikeTrain
) – Second spike train.  interval (Pair of floats or None.) – averaging interval given as a pair of floats (T0, T1), if None the average over the whole function is computed.
Returns: The spikedistance.
Return type: double
 spike_train1 (

pyspike.spike_distance.
spike_distance_matrix
(spike_trains, indices=None, interval=None)[source]¶ Computes the time averaged spikedistance of all pairs of spiketrains.
Parameters:  spike_trains – list of
SpikeTrain
 indices (list or None) – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
 interval (Pair of floats or None.) – averaging interval given as a pair of floats, if None the average over the whole function is computed.
Returns: 2D array with the pair wise time average spike distances \(D_S^{ij}\)
Return type: np.array
 spike_trains – list of

pyspike.spike_distance.
spike_distance_multi
(spike_trains, indices=None, interval=None)[source]¶ Specific function to compute a multivariate SPIKEdistance. This is a deprecated function and should not be called directly. Use
spike_distance()
to compute SPIKEdistances.Parameters:  spike_trains – list of
SpikeTrain
 indices (list or None) – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
 interval (Pair of floats or None.) – averaging interval given as a pair of floats, if None the average over the whole function is computed.
Returns: The averaged multivariate spike distance \(D_S\).
Return type: double
 spike_trains – list of

pyspike.spike_distance.
spike_profile
(*args, **kwargs)[source]¶ Computes the spikedistance profile \(S(t)\) of the given spike trains. Returns the profile as a PieceWiseConstLin object. The SPIKEvalues are defined positive \(S(t)>=0\).
Valid call structures:
spike_profile(st1, st2) # returns the bivariate profile spike_profile(st1, st2, st3) # multivariate profile of 3 spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains spike_profile(spike_trains) # profile of the list of spike trains spike_profile(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
The multivariate spikedistance profile is defined as the average of all pairs of spiketrains:
\[\begin{split}<S(t)> = \frac{2}{N(N1)} \sum_{<i,j>} S^{i, j}`,\end{split}\]where the sum goes over all pairs <i,j>
Returns: The spikedistance profile \(S(t)\) Return type: PieceWiseConstLin

pyspike.spike_distance.
spike_profile_bi
(spike_train1, spike_train2)[source]¶ Specific function to compute a bivariate SPIKEprofile. This is a deprecated function and should not be called directly. Use
spike_profile()
to compute SPIKEprofiles.Parameters:  spike_train1 (
SpikeTrain
) – First spike train.  spike_train2 (
SpikeTrain
) – Second spike train.
Returns: The spikedistance profile \(S(t)\).
Return type:  spike_train1 (

pyspike.spike_distance.
spike_profile_multi
(spike_trains, indices=None)[source]¶ Specific function to compute a multivariate SPIKEprofile. This is a deprecated function and should not be called directly. Use
spike_profile()
to compute SPIKEprofiles.Parameters:  spike_trains – list of
SpikeTrain
 indices (list or None) – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
Returns: The averaged spike profile \(<S>(t)\)
Return type:  spike_trains – list of
SPIKEsynchronization¶

pyspike.spike_sync.
spike_sync
(*args, **kwargs)[source]¶ Computes the spike synchronization value SYNC of the given spike trains. The spike synchronization value is the computed as the total number of coincidences divided by the total number of spikes:
\[SYNC = \sum_n C_n / N.\]Valid call structures:
spike_sync(st1, st2) # returns the bivariate spike synchronization spike_sync(st1, st2, st3) # multivariate result for 3 spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains spike_sync(spike_trains) # spikesync of the list of spike trains spike_sync(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
The multivariate SPIKESync is again defined as the overall ratio of all coincidence values divided by the total number of spikes.
Returns: The spike synchronization value. Return type: double

pyspike.spike_sync.
spike_sync_bi
(spike_train1, spike_train2, interval=None, max_tau=None)[source]¶ Specific function to compute a bivariate SPIKESync value. This is a deprecated function and should not be called directly. Use
spike_sync()
to compute SPIKESync values.Parameters:  spike_train1 (
pyspike.SpikeTrain
) – First spike train.  spike_train2 (
pyspike.SpikeTrain
) – Second spike train.  interval (Pair of floats or None.) – averaging interval given as a pair of floats (T0, T1), if None the average over the whole function is computed.
 max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound.
Returns: The spike synchronization value.
Return type: double
 spike_train1 (

pyspike.spike_sync.
spike_sync_matrix
(spike_trains, indices=None, interval=None, max_tau=None)[source]¶ Computes the overall spikesynchronization value of all pairs of spiketrains.
Parameters:  spike_trains – list of
pyspike.SpikeTrain
 indices (list or None) – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
 interval (Pair of floats or None.) – averaging interval given as a pair of floats, if None the average over the whole function is computed.
 max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound.
Returns: 2D array with the pair wise time spike synchronization values \(SYNC_{ij}\)
Return type: np.array
 spike_trains – list of

pyspike.spike_sync.
spike_sync_multi
(spike_trains, indices=None, interval=None, max_tau=None)[source]¶ Specific function to compute a multivariate SPIKESync value. This is a deprecated function and should not be called directly. Use
spike_sync()
to compute SPIKESync values.Parameters:  spike_trains – list of
pyspike.SpikeTrain
 indices (list or None) – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
 interval (Pair of floats or None.) – averaging interval given as a pair of floats, if None the average over the whole function is computed.
 max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound.
Returns: The multivariate spike synchronization value SYNC.
Return type: double
 spike_trains – list of

pyspike.spike_sync.
spike_sync_profile
(*args, **kwargs)[source]¶ Computes the spikesynchronization profile S_sync(t) of the given spike trains. Returns the profile as a DiscreteFunction object. In the bivariate case, he S_sync values are either 1 or 0, indicating the presence or absence of a coincidence. For multivariate cases, each spike in the set of spike trains, the profile is defined as the number of coincidences divided by the number of spike trains pairs involving the spike train of containing this spike, which is the number of spike trains minus one (N1).
Valid call structures:
spike_sync_profile(st1, st2) # returns the bivariate profile spike_sync_profile(st1, st2, st3) # multivariate profile of 3 sts sts = [st1, st2, st3, st4] # list of spike trains spike_sync_profile(sts) # profile of the list of spike trains spike_sync_profile(sts, indices=[0, 1]) # use only the spike trains # given by the indices
In the multivariate case, the profile is defined as the number of coincidences for each spike in the set of spike trains divided by the number of spike trains pairs involving the spike train of containing this spike, which is the number of spike trains minus one (N1).
Returns: The spikesync profile \(S_{sync}(t)\). Return type: pyspike.function.DiscreteFunction

pyspike.spike_sync.
spike_sync_profile_bi
(spike_train1, spike_train2, max_tau=None)[source]¶ Specific function to compute a bivariate SPIKESyncprofile. This is a deprecated function and should not be called directly. Use
spike_sync_profile()
to compute SPIKESyncprofiles.Parameters:  spike_train1 (
pyspike.SpikeTrain
) – First spike train.  spike_train2 (
pyspike.SpikeTrain
) – Second spike train.  max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound.
Returns: The spikesync profile \(S_{sync}(t)\).
Return type: pyspike.function.DiscreteFunction
 spike_train1 (

pyspike.spike_sync.
spike_sync_profile_multi
(spike_trains, indices=None, max_tau=None)[source]¶ Specific function to compute a multivariate SPIKESyncprofile. This is a deprecated function and should not be called directly. Use
spike_sync_profile()
to compute SPIKESyncprofiles.Parameters:  spike_trains – list of
pyspike.SpikeTrain
 indices (list or None) – list of indices defining which spike trains to use, if None all given spike trains are used (default=None)
 max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound.
Returns: The multivariate spike sync profile \(<S_{sync}>(t)\)
Return type: pyspike.function.DiscreteFunction
 spike_trains – list of
PSTH¶

pyspike.psth.
psth
(spike_trains, bin_size)[source]¶ Computes the peristimulus time histogram of a set of
SpikeTrain
. The PSTH is simply the histogram of merged spike events. Thebin_size
defines the width of the histogram bins.Parameters:  spike_trains – list of
SpikeTrain
 bin_size – width of the histogram bins.
Returns: The PSTH as a
PieceWiseConstFunc
 spike_trains – list of
Helper functions¶

pyspike.spikes.
generate_poisson_spikes
(rate, interval)[source]¶ Generates a Poisson spike train with the given rate in the given time interval
Parameters:  rate – The rate of the spike trains
 interval (pair of doubles or double) – A pair (T_start, T_end) of values representing the start and end time of the spike train measurement or a single value representing the end time, the T_start is then assuemd as 0. Auxiliary spikes will be added to the spike train at the beginning and end of this interval, if they are not yet present.
Returns: Poisson spike train as a
SpikeTrain

pyspike.spikes.
load_spike_trains_from_txt
(file_name, edges, separator=' ', comment='#', is_sorted=False, ignore_empty_lines=True)[source]¶ Loads a number of spike trains from a text file. Each line of the text file should contain one spike train as a sequence of spike times separated by separator. Empty lines as well as lines starting with comment are neglected. The edges represents the start and the end of the spike trains.
Parameters:  file_name – The name of the text file.
 edges – A pair (T_start, T_end) of values representing the start and end time of the spike train measurement or a single value representing the end time, the T_start is then assuemd as 0.
 separator – The character used to seprate the values in the text file
 comment – Lines starting with this character are ignored.
 sort – If true, the spike times are order via np.sort, default=True
Returns: list of
SpikeTrain

pyspike.spikes.
merge_spike_trains
(spike_trains)[source]¶ Merges a number of spike trains into a single spike train.
Parameters: spike_trains – list of SpikeTrain
Returns: spike train with the merged spike times

pyspike.spikes.
spike_train_from_string
(s, edges, sep=' ', is_sorted=False)[source]¶ Converts a string of times into a
SpikeTrain
.Parameters:  s – the string with (ordered) spike times.
 edges – interval defining the edges of the spike train. Given as a pair of floats (T0, T1) or a single float T1, where T0=0 is assumed.
 sep – The separator between the time numbers, default=’ ‘.
 is_sorted – if True, the spike times are not sorted after loading, if False, spike times are sorted with np.sort
Returns: