Utils¶
-
spykes.utils.
circ_corr
(alpha1, alpha2)[source]¶ Helper function to compute the circular correlation.
-
spykes.utils.
get_sort_indices
(data, by=None, order='descend')[source]¶ Helper function to calculate sorting indices given sorting condition.
Parameters: - data (2-D numpy array) – Array with shape
(n_neurons, n_bins)
. - by (str or list) – If
rate
, sort by firing rate. Iflatency
, sort by peak latency. If a list or array is provided, it must correspond to integer indices to be used as sorting indices. If no sort order is provided, the data is returned as-is. - order (str) – Direction to sort in (either
descend
orascend
).
Returns: The sort indices as a Numpy array, with one index per element in
data
(i.e.data[sort_idxs]
gives the sorted data).Return type: list
- data (2-D numpy array) – Array with shape
-
spykes.utils.
grad_slow_exp
(z, eta)[source]¶ Computes the gradient of a slowly rising exponential function.
This is defined as:
\[\begin{split}\nabla q = \begin{cases} \exp(eta) & \text{if } z > eta \\ \exp(z) & \text{if } z \leq eta \end{cases}\end{split}\]Parameters: - z (array) – The dependent variable, before calling the
slow_exp()
function. - eta (float) – The threshold parameter used in the original
slow_exp()
call.
Returns: The gradient with respect to
z
of the output ofslow_exp()
.Return type: array
- z (array) – The dependent variable, before calling the
-
spykes.utils.
set_matplotlib_defaults
(plt=None)[source]¶ Sets publication quality defaults for matplotlib.
Parameters: plt (matplotlib.pyplot instance) – The plt instance.
-
spykes.utils.
slow_exp
(z, eta)[source]¶ Applies a slowly rising exponential function to some data.
This function defines a slowly rising exponential that linearizes above the threshold parameter
eta
. Mathematically, this is defined as:\[\begin{split}q = \begin{cases} (z + 1 - eta) * \exp(eta) & \text{if } z > eta \\ \exp(eta) & \text{if } z \leq eta \end{cases}\end{split}\]The gradient of this function is defined in
grad_slow_exp()
.Parameters: - z (array) – The data to apply the
slow_exp()
function to. - eta (float) – The threshold parameter.
Returns: The resulting slow exponential, with the same shape as
z
.Return type: array
- z (array) – The data to apply the
-
spykes.utils.
train_test_split
(*datasets, **split)[source]¶ Splits test data into training and testing data.
This is a replacement for the Scikit Learn version of the function (which is being deprecated).
Parameters: - datasets (list of Numpy arrays) – The datasets as Numpy arrays, where the first dimension is the batch dimension.
- n (int) – Number of test samples to split off (only n or percent may be specified).
- percent (int) – Percentange of test samples to split off.
Returns: If only one dataset is provided, this method returns a tuple of training and testing data; otherwise, it returns a list of such tuples.
Return type: tuple of train / test data, or list of tuples