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.
get_spikes_non_empty()[source]

Returns the spikes of this spike train with auxiliary spikes in case of empty spike trains.

sort()[source]

Sorts the spike times of this spike train using np.sort

PieceWiseConstFunc

class pyspike.PieceWiseConstFunc.PieceWiseConstFunc(x, y)[source]

Bases: object

A class representing a piece-wise constant function.

__init__(x, y)[source]

Constructs the piece-wise 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:fPieceWiseConstFunc 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 piece-wise 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 y-coordinates for immeditate plotting of the piece-wise 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="Piece-wise const function")
integral(interval=None)[source]

Returns the integral over the given interval.

Parameters:interval (Pair of floats or None.) – integration interval given as a pair of floats, if None the integral over the whole function is computed.
Returns:the integral
Return type:float
mul_scalar(fac)[source]

Multiplies the function with a scalar value

Parameters:fac (double) – Value to multiply
Return type:None

PieceWiseLinFunc

class pyspike.PieceWiseLinFunc.PieceWiseLinFunc(x, y1, y2)[source]

A class representing a piece-wise linear function.

__init__(x, y1, y2)[source]

Constructs the piece-wise 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:fPieceWiseLinFunc 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 piece-wise 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 y-coordinates for immeditate plotting of the piece-wise 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="Piece-wise const function")
integral(interval=None)[source]

Returns the integral over the given interval.

Parameters:interval (Pair of floats or None.) – integration interval given as a pair of floats, if None the integral over the whole function is computed.
Returns:the integral
Return type:float
mul_scalar(fac)[source]

Multiplies the function with a scalar value

Parameters:fac (double) – Value to multiply
Return type:None

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:fDiscreteFunc 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 y-coordinates 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
mul_scalar(fac)[source]

Multiplies the function with a scalar value

Parameters:fac (double) – Value to multiply
Return type:None
pyspike.DiscreteFunc.average_profile(profiles)[source]

Computes the average profile from the given ISI- or SPIKE-profiles.

Parameters:profiles – list of PieceWiseConstFunc or PieceWiseLinFunc representing ISI- or SPIKE-profiles to be averaged.
Returns:the averages profile \(<S_{isi}>\) or \(<S_{spike}>\).
Return type:PieceWiseConstFunc or PieceWiseLinFunc

Functions

ISI-distance

pyspike.isi_distance.isi_distance(spike_train1, spike_train2, interval=None)[source]

Computes the ISI-distance \(D_I\) of the given spike trains. The isi-distance is the integral over the isi distance profile \(I(t)\):

\[D_I = \int_{T_0}^{T_1} I(t) dt.\]
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 isi-distance \(D_I\).

Return type:

double

pyspike.isi_distance.isi_distance_matrix(spike_trains, indices=None, interval=None)[source]

Computes the time averaged isi-distance of all pairs of spike-trains.

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

pyspike.isi_distance.isi_distance_multi(spike_trains, indices=None, interval=None)[source]

computes the multi-variate isi-distance for a set of spike-trains. That is the time average of the multi-variate spike profile:

\[\begin{split}D_I = \int_0^T \frac{2}{N(N-1)} \sum_{<i,j>} I^{i,j},\end{split}\]

where the sum goes over all pairs <i,j>

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 time-averaged multivariate ISI distance \(D_I\)

Return type:

double

pyspike.isi_distance.isi_profile(spike_train1, spike_train2)[source]

Computes the isi-distance profile \(I(t)\) of the two given spike trains. Retruns the profile as a PieceWiseConstFunc object. The ISI-values are defined positive \(I(t)>=0\).

Parameters:
  • spike_train1 (SpikeTrain) – First spike train.
  • spike_train2 (SpikeTrain) – Second spike train.
Returns:

The isi-distance profile \(I(t)\)

Return type:

PieceWiseConstFunc

pyspike.isi_distance.isi_profile_multi(spike_trains, indices=None)[source]

computes the multi-variate isi distance profile for a set of spike trains. That is the average isi-distance of all pairs of spike-trains:

\[\begin{split}<I(t)> = \frac{2}{N(N-1)} \sum_{<i,j>} I^{i,j},\end{split}\]

where the sum goes over all pairs <i,j>

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:

PieceWiseConstFunc

SPIKE-distance

pyspike.spike_distance.spike_distance(spike_train1, spike_train2, interval=None)[source]

Computes the spike-distance \(D_S\) of the given spike trains. The spike-distance is the integral over the spike distance profile \(S(t)\):

\[D_S = \int_{T_0}^{T_1} S(t) dt.\]
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 spike-distance.

Return type:

double

pyspike.spike_distance.spike_distance_matrix(spike_trains, indices=None, interval=None)[source]

Computes the time averaged spike-distance of all pairs of spike-trains.

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

pyspike.spike_distance.spike_distance_multi(spike_trains, indices=None, interval=None)[source]

Computes the multi-variate spike distance for a set of spike trains. That is the time average of the multi-variate spike profile:

\[\begin{split}D_S = \int_0^T \frac{2}{N(N-1)} \sum_{<i,j>} S^{i, j} dt\end{split}\]

where the sum goes over all pairs <i,j>

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 multi-variate spike distance \(D_S\).

Return type:

double

pyspike.spike_distance.spike_profile(spike_train1, spike_train2)[source]

Computes the spike-distance profile \(S(t)\) of the two given spike trains. Returns the profile as a PieceWiseLinFunc object. The SPIKE-values are defined positive \(S(t)>=0\).

Parameters:
  • spike_train1 (SpikeTrain) – First spike train.
  • spike_train2 (SpikeTrain) – Second spike train.
Returns:

The spike-distance profile \(S(t)\).

Return type:

PieceWiseLinFunc

pyspike.spike_distance.spike_profile_multi(spike_trains, indices=None)[source]

Computes the multi-variate spike distance profile for a set of spike trains. That is the average spike-distance of all pairs of spike-trains:

\[\begin{split}<S(t)> = \frac{2}{N(N-1)} \sum_{<i,j>} S^{i, j}`,\end{split}\]

where the sum goes over all pairs <i,j>

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:

PieceWiseLinFunc

SPIKE-synchronization

pyspike.spike_sync.spike_sync(spike_train1, spike_train2, interval=None, max_tau=None)[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.\]
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

pyspike.spike_sync.spike_sync_matrix(spike_trains, indices=None, interval=None, max_tau=None)[source]

Computes the overall spike-synchronization value of all pairs of spike-trains.

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

pyspike.spike_sync.spike_sync_multi(spike_trains, indices=None, interval=None, max_tau=None)[source]

Computes the multi-variate spike synchronization value for a set of spike trains.

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 multi-variate spike synchronization value SYNC.

Return type:

double

pyspike.spike_sync.spike_sync_profile(spike_train1, spike_train2, max_tau=None)[source]

Computes the spike-synchronization profile S_sync(t) of the two given spike trains. Returns the profile as a DiscreteFunction object. The S_sync values are either 1 or 0, indicating the presence or absence of a coincidence.

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 spike-distance profile \(S_{sync}(t)\).

Return type:

pyspike.function.DiscreteFunction

pyspike.spike_sync.spike_sync_profile_multi(spike_trains, indices=None, max_tau=None)[source]

Computes the multi-variate spike synchronization profile for a set of spike trains. For each spike in the set of spike trains, the multi-variate 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 (N-1).

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 multi-variate spike sync profile \(<S_{sync}>(t)\)

Return type:

pyspike.function.DiscreteFunction

PSTH

pyspike.psth.psth(spike_trains, bin_size)[source]

Computes the peri-stimulus time histogram of a set of SpikeTrain. The PSTH is simply the histogram of merged spike events. The bin_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

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:

SpikeTrain

Table Of Contents

Previous topic

PySpike

This Page