braintools.analysis.population.participation_ratio

braintools.analysis.population.participation_ratio#

braintools.analysis.population.participation_ratio(x)#

Participation ratio (effective dimensionality) of population activity.

\[\mathrm{PR} = \frac{\left(\sum_i \lambda_i\right)^2}{\sum_i \lambda_i^2} = \frac{\operatorname{tr}(C)^2}{\operatorname{tr}(C^2)},\]

where \(\lambda_i\) are the eigenvalues of the feature covariance matrix \(C\) [1] [2]. It ranges from 1 (one dominant dimension) to D (isotropic variance).

Parameters:

x (array_like or brainunit.Quantity) – Activity of shape (T, D) (samples by features). Units cancel.

Returns:

0-d participation ratio. nan for constant data (zero variance).

Return type:

Array

Raises:

ValueError – If x is not 2-D or has fewer than two samples.

See also

pca

The covariance spectrum itself.

Notes

Computed from traces without an eigendecomposition, using the smaller of the (D, D) covariance and the (T, T) Gram matrix (both have the same non-zero spectrum). The normalisation (ddof) cancels. Jittable, vmappable and differentiable (except for constant data).

References

Examples

>>> import jax
>>> import jax.numpy as jnp
>>> from braintools.analysis import population
>>> x = jax.random.normal(jax.random.PRNGKey(0), (2000, 4))
>>> round(float(population.participation_ratio(x)))
4
>>> latent = jax.random.normal(jax.random.PRNGKey(1), (2000, 1))
>>> round(float(population.participation_ratio(latent @ jnp.ones((1, 4)))), 3)
1.0