pymaid.sparseness

pymaid.sparseness(x, which='LTS')[source]

Calculate sparseness.

Sparseness comes in two flavors:

Lifetime kurtosis (LTK) quantifies the widths of tuning curves (according to Muench & Galizia, 2016):

S = \Bigg\{ \frac{1}{N} \sum^N_{i=1} \Big[ \frac{r_i - \overline{r}}{\sigma_r} \Big] ^4  \Bigg\} - 3

where N is the number of observations, r_i the value of observation i, and \overline{r} and \sigma_r the mean and the standard deviation of the observations’ values, respectively. LTK is assuming a normal, or at least symmetric distribution.

Lifetime sparseness (LTS) quantifies selectivity (Bhandawat et al., 2007):

S = \frac{1}{1-1/N} \Bigg[1- \frac{\big(\sum^N_{j=1} r_j / N\big)^2}{\sum^N_{j=1} r_j^2 / N} \Bigg]

where N is the number of observations, and r_j is the value of an observation.

Notes

NaN values will be ignored. You can use that to e.g. ignore zero values in a large connectivity matrix by changing these values to NaN before passing it to pymaid.sparseness.

Parameters
  • x (DataFrame | array-like) – (N, M) dataset with N (rows) observations for M (columns) neurons. One-dimensional data will be converted to two dimensions (N rows, 1 column).

  • which ("LTS" | "LTK") – Determines whether lifetime sparseness (LTS) or lifetime kurtosis (LTK) is returned.

Returns

pandas.Series if input was pandas DataFrame, else numpy.array.

Return type

sparseness

Examples

Calculate sparseness of olfactory inputs to group of neurons:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> # Generate adjacency matrix
>>> adj = pymaid.adjacency_matrix(s='annotation:WTPN2017_excitatory_uPN_right',
...                               t='annotation:ASB LHN')
>>> # Calculate lifetime sparseness
>>> S = pymaid.sparseness(adj, which='LTS')
>>> # Plot distribution
>>> ax = S.plot.hist(bins=np.arange(0, 1, .1))
>>> ax.set_xlabel('LTS')
>>> plt.show()