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 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
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 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
- 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")
PieceWiseLinFunc¶
- class pyspike.PieceWiseLinFunc.PieceWiseLinFunc(x, y1, y2)[source]¶
Bases:
object
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
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 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
- 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")
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
- 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
- pyspike.DiscreteFunc.average_profile(profiles)[source]¶
Computes the average profile from the given ISI- or SPIKE-profiles.
- Parameters
profiles – list of
PieceWiseConstFunc
orPieceWiseLinFunc
representing ISI- or SPIKE-profiles to be averaged.- Returns
the averages profile \(<S_{isi}>\) or \(<S_{spike}>\).
- Return type
PieceWiseConstFunc
orPieceWiseLinFunc
Functions¶
ISI-distance¶
isi_distance.py Module containing several functions to compute the ISI profiles and distances Copyright 2014-2015, Mario Mulansky <mario.mulansky@gmx.net> Distributed under the BSD License
- pyspike.isi_distance.isi_distance(*args, **kwargs)[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.\]In the multivariate case it is the integral over the multivariate ISI-profile, i.e. the average profile over all spike train pairs:
\[D_I = \int_0^T \frac{2}{N(N-1)} \sum_{<i,j>} I^{i,j},\]where the sum goes over all pairs <i,j>
Valid call structures:
isi_distance(st1, st2) # returns the bi-variate distance isi_distance(st1, st2, st3) # multi-variate 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 isi-distance \(D_I\).
- Return type
double
- pyspike.isi_distance.isi_distance_bi(spike_train1, spike_train2, interval=None, **kwargs)[source]¶
Specific function to compute the bivariate ISI-distance. This is a deprecated function and should not be called directly. Use
isi_distance()
to compute ISI-distances.- 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, **kwargs)[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, **kwargs)[source]¶
Specific function to compute the multivariate ISI-distance. This is a deprecfated function and should not be called directly. Use
isi_distance()
to compute ISI-distances.- 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(*args, **kwargs)[source]¶
Computes the isi-distance profile \(I(t)\) of the given spike trains. Returns the profile as a PieceWiseConstFunc object. The ISI-values are defined positive \(I(t)>=0\).
Valid call structures:
isi_profile(st1, st2) # returns the bi-variate profile isi_profile(st1, st2, st3) # multi-variate 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 ISI-profile of all pairs of spike-trains:
\[<I(t)> = \frac{2}{N(N-1)} \sum_{<i,j>} I^{i,j},\]where the sum goes over all pairs <i,j>
- Returns
The isi-distance profile \(I(t)\)
- Return type
- pyspike.isi_distance.isi_profile_bi(spike_train1, spike_train2, **kwargs)[source]¶
Specific function to compute a bivariate ISI-profile. This is a deprecated function and should not be called directly. Use
isi_profile()
to compute ISI-profiles.- Parameters
spike_train1 (
SpikeTrain
) – First spike train.spike_train2 (
SpikeTrain
) – Second spike train.
- Returns
The isi-distance profile \(I(t)\)
- Return type
- pyspike.isi_distance.isi_profile_multi(spike_trains, indices=None, **kwargs)[source]¶
Specific function to compute the multivariate ISI-profile for a set of spike trains. This is a deprecated function and should not be called directly. Use
isi_profile()
to compute ISI-profiles.- 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-distance¶
- pyspike.spike_distance.spike_distance(*args, **kwargs)[source]¶
Computes the SPIKE-distance \(D_S\) of the given spike trains. The spike-distance 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 bi-variate distance spike_distance(st1, st2, st3) # multi-variate 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:
\[D_S = \int_0^T \frac{2}{N(N-1)} \sum_{<i,j>} S^{i, j} dt\]- Returns
The spike-distance \(D_S\).
- Return type
double
- pyspike.spike_distance.spike_distance_bi(spike_train1, spike_train2, interval=None, **kwargs)[source]¶
Specific function to compute a bivariate SPIKE-distance. This is a deprecated function and should not be called directly. Use
spike_distance()
to compute SPIKE-distances.- 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, **kwargs)[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, **kwargs)[source]¶
Specific function to compute a multivariate SPIKE-distance. This is a deprecated function and should not be called directly. Use
spike_distance()
to compute SPIKE-distances.- 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(*args, **kwargs)[source]¶
Computes the spike-distance profile \(S(t)\) of the given spike trains. Returns the profile as a PieceWiseConstLin object. The SPIKE-values are defined positive \(S(t)>=0\).
Valid call structures:
spike_profile(st1, st2) # returns the bi-variate profile spike_profile(st1, st2, st3) # multi-variate 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 spike-distance profile is defined as the average of all pairs of spike-trains:
\[<S(t)> = \frac{2}{N(N-1)} \sum_{<i,j>} S^{i, j}`,\]where the sum goes over all pairs <i,j>
- Returns
The spike-distance profile \(S(t)\)
- Return type
PieceWiseConstLin
- pyspike.spike_distance.spike_profile_bi(spike_train1, spike_train2, **kwargs)[source]¶
Specific function to compute a bivariate SPIKE-profile. This is a deprecated function and should not be called directly. Use
spike_profile()
to compute SPIKE-profiles.- Parameters
spike_train1 (
SpikeTrain
) – First spike train.spike_train2 (
SpikeTrain
) – Second spike train.
- Returns
The spike-distance profile \(S(t)\).
- Return type
- pyspike.spike_distance.spike_profile_multi(spike_trains, indices=None, **kwargs)[source]¶
Specific function to compute a multivariate SPIKE-profile. This is a deprecated function and should not be called directly. Use
spike_profile()
to compute SPIKE-profiles.- 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-synchronization¶
- pyspike.spike_sync.filter_by_spike_sync(spike_trains, threshold, indices=None, max_tau=None, return_removed_spikes=False, **kwargs)[source]¶
Removes the spikes with a multi-variate spike_sync value below threshold.
- pyspike.spike_sync.spike_sync(*args, **kwargs)[source]¶
Computes the spike synchronization value 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 bi-variate spike synchronization spike_sync(st1, st2, st3) # multi-variate result for 3 spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains spike_sync(spike_trains) # spike-sync of the list of spike trains spike_sync(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
The multivariate SPIKE-Sync 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, **kwargs)[source]¶
Specific function to compute a bivariate SPIKE-Sync value. This is a deprecated function and should not be called directly. Use
spike_sync()
to compute SPIKE-Sync 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
- pyspike.spike_sync.spike_sync_matrix(spike_trains, indices=None, interval=None, max_tau=None, **kwargs)[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, **kwargs)[source]¶
Specific function to compute a multivariate SPIKE-Sync value. This is a deprecated function and should not be called directly. Use
spike_sync()
to compute SPIKE-Sync 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 multi-variate spike synchronization value SYNC.
- Return type
double
- pyspike.spike_sync.spike_sync_profile(*args, **kwargs)[source]¶
Computes the spike-synchronization 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 multi-variate 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 (N-1).
Valid call structures:
spike_sync_profile(st1, st2) # returns the bi-variate profile spike_sync_profile(st1, st2, st3) # multi-variate 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 (N-1).
- Returns
The spike-sync profile \(S_{sync}(t)\).
- Return type
pyspike.function.DiscreteFunction
- pyspike.spike_sync.spike_sync_profile_bi(spike_train1, spike_train2, max_tau=None, **kwargs)[source]¶
Specific function to compute a bivariate SPIKE-Sync-profile. This is a deprecated function and should not be called directly. Use
spike_sync_profile()
to compute SPIKE-Sync-profiles.- 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-sync profile \(S_{sync}(t)\).
- Return type
pyspike.function.DiscreteFunction
- pyspike.spike_sync.spike_sync_profile_multi(spike_trains, indices=None, max_tau=None, **kwargs)[source]¶
Specific function to compute a multivariate SPIKE-Sync-profile. This is a deprecated function and should not be called directly. Use
spike_sync_profile()
to compute SPIKE-Sync-profiles.- 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. 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
Directionality¶
- pyspike.spike_directionality.optimal_spike_train_sorting(spike_trains, indices=None, interval=None, max_tau=None, full_output=False, **kwargs)[source]¶
Finds the best sorting of the given spike trains by computing the spike directionality matrix and optimize the order using simulated annealing. For a detailed description of the algorithm see: http://iopscience.iop.org/article/10.1088/1367-2630/aa68c3/meta
- 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.) – time interval filter given as a pair of floats, if None the full spike trains are used (default=None).
max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound (default=None).
full_output – If true, then function will additionally return the number of performed iterations (default=False)
- Returns
(p, F) - tuple with the optimal permutation and synfire indicator. if full_output=True , (p, F, iter) is returned.
- pyspike.spike_directionality.permutate_matrix(D, p)[source]¶
Helper function that applies the permutation p to the columns and rows of matrix D. Return the permutated matrix \(D'[n,m] = D[p[n], p[m]]\).
- Parameters
D – The matrix.
d – The permutation.
- Returns
The permuated matrix D’, ie \(D'[n,m] = D[p[n], p[m]]\)
- pyspike.spike_directionality.spike_directionality(spike_train1, spike_train2, normalize=True, interval=None, max_tau=None, **kwargs)[source]¶
Computes the overall spike directionality of the first spike train with respect to the second spike train.
- Parameters
spike_train1 (
pyspike.SpikeTrain
) – First spike train.spike_train2 (
pyspike.SpikeTrain
) – Second spike train.normalize – Normalize by the number of spikes (multiplicity).
max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound.
- Returns
The spike train order profile \(E(t)\).
- pyspike.spike_directionality.spike_directionality_matrix(spike_trains, normalize=True, indices=None, interval=None, max_tau=None, **kwargs)[source]¶
Computes the spike directionality matrix for the given spike trains.
- Parameters
spike_trains (List of
pyspike.SpikeTrain
) – List of spike trains.normalize – Normalize by the number of spikes (multiplicity).
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 spike-directionality values.
- pyspike.spike_directionality.spike_directionality_values(*args, **kwargs)[source]¶
Computes the spike directionality value for each spike in each spike train. Returns a list containing an array of spike directionality values for every given spike train.
Valid call structures:
spike_directionality_values(st1, st2) # returns the bi-variate profile spike_directionality_values(st1, st2, st3) # multi-variate profile of 3 # spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains spike_directionality_values(spike_trains) # profile of the list of spike trains spike_directionality_values(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
Additonal arguments: :param max_tau: Upper bound for coincidence window (default=None). :param indices: list of indices defining which spike trains to use,
if None all given spike trains are used (default=None)
- Returns
The spike directionality values \(D^n_i\) as a list of arrays.
- pyspike.spike_directionality.spike_train_order(*args, **kwargs)[source]¶
Computes the spike train order (Synfire Indicator) of the given spike trains.
Valid call structures:
spike_train_order(st1, st2, normalize=True) # normalized bi-variate # spike train order spike_train_order(st1, st2, st3) # multi-variate result of 3 spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains spike_train_order(spike_trains) # result for the list of spike trains spike_train_order(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
- Additonal arguments:
max_tau Upper bound for coincidence window, default=None.
normalize Flag indicating if the reslut should be normalized by the number of spikes , default=`False`
- Returns
The spike train order value (Synfire Indicator)
- pyspike.spike_directionality.spike_train_order_bi(spike_train1, spike_train2, normalize=True, interval=None, max_tau=None, **kwargs)[source]¶
Computes the overall spike train order value (Synfire Indicator) for two spike trains.
- Parameters
spike_train1 (
pyspike.SpikeTrain
) – First spike train.spike_train2 (
pyspike.SpikeTrain
) – Second spike train.normalize – Normalize by the number of spikes (multiplicity).
max_tau – Maximum coincidence window size. If 0 or None, the coincidence window has no upper bound.
- Returns
The spike train order value (Synfire Indicator)
- pyspike.spike_directionality.spike_train_order_multi(spike_trains, indices=None, normalize=True, interval=None, max_tau=None, **kwargs)[source]¶
Computes the overall spike train order value (Synfire Indicator) for many spike trains.
- 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)
normalize – Normalize by the number of spike (multiplicity).
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
Spike train order values (Synfire Indicator) F for the given spike trains.
- Return type
double
- pyspike.spike_directionality.spike_train_order_profile(*args, **kwargs)[source]¶
Computes the spike train order profile \(E(t)\) of the given spike trains. Returns the profile as a DiscreteFunction object.
Valid call structures:
spike_train_order_profile(st1, st2) # returns the bi-variate profile spike_train_order_profile(st1, st2, st3) # multi-variate profile of 3 # spike trains spike_trains = [st1, st2, st3, st4] # list of spike trains spike_train_order_profile(spike_trains) # profile of the list of spike trains spike_train_order_profile(spike_trains, indices=[0, 1]) # use only the spike trains # given by the indices
Additonal arguments: :param max_tau: Upper bound for coincidence window, default=None. :param indices: list of indices defining which spike trains to use,
if None all given spike trains are used (default=None)
- Returns
The spike train order profile \(E(t)\)
- Return type
DiscreteFunction
- pyspike.spike_directionality.spike_train_order_profile_bi(spike_train1, spike_train2, max_tau=None, **kwargs)[source]¶
Computes the spike train order profile P(t) of the two given spike trains. Returns the profile as a DiscreteFunction object.
- 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 train order profile \(E(t)\).
- Return type
pyspike.function.DiscreteFunction
- pyspike.spike_directionality.spike_train_order_profile_multi(spike_trains, indices=None, max_tau=None, **kwargs)[source]¶
Computes the multi-variate spike train order profile for a set of spike trains. For each spike in the set of spike trains, the multi-variate profile is defined as the sum of asymmetry values 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
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.import_spike_trains_from_time_series(file_name, start_time, time_bin, separator=None, comment='#')[source]¶
Imports spike trains from time series consisting of 0 and 1 denoting the absence or presence of a spike. Each line in the data file represents one spike train.
- Parameters
file_name – The name of the data file containing the time series.
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.
- 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.reconcile_spike_trains(spike_trains)[source]¶
make sure that Spike trains meet PySpike rules In: spike_trains - a list of SpikeTrain objects Out: spike_trains - same list with some fixes:
t_start and t_end are the same for every train
The spike times are sorted
No duplicate times in any train
spike times outside of t_start,t_end removed
- pyspike.spikes.reconcile_spike_trains_bi(spike_train1, spike_train2)[source]¶
fix up a pair of spike trains
- pyspike.spikes.save_spike_trains_to_txt(spike_trains, file_name, separator=' ', precision=8)[source]¶
Saves the given spike trains into a file with the given file name. Each spike train will be stored in one line in the text file with the times separated by separator.
- Parameters
spike_trains – List of
SpikeTrain
objectsfile_name – The name of the text file.
- 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