braintools.analysis.population.avalanches#
- braintools.analysis.population.avalanches(counts, threshold=0, max_avalanches=None)#
Detect neuronal avalanches in a population count series.
An avalanche is a maximal run of consecutive bins in which the count exceeds
threshold[1]. Its duration is the number of bins in the run and its size is the sum ofcounts - thresholdover the run (the number of events forthreshold=0). Runs that touch the start or the end of the series count as avalanches.- Parameters:
counts (
Any) – Population event counts per time bin, shape(T,), for exampleSpikeTrains.bin(bin_size).sum(axis=1).threshold (
Any) – Activity threshold; bins withcounts > thresholdare active.max_avalanches (
int|None) – Static length of the padded outputs. Defaults toT // 2 + 1, which can hold every possible avalanche. When more avalanches occur, only the firstmax_avalanchesare kept andnis clipped.
- Returns:
Named tuple
(sizes, durations, n).sizesanddurationshave shape(max_avalanches,)and are padded with zeros after the firstnentries.sizeshas the dtype ofcounts - threshold.- Return type:
- Raises:
ValueError – If
countsis not 1-D, ormax_avalanches < 1.
See also
branching_ratioRatio of descendants to ancestors.
Notes
Runs are found without a loop over time: the run index of every active bin is a cumulative sum of run starts, and the sizes and durations are segment sums. Works under
jax.jitandjax.vmap(for example over trials). The output shape depends only onTandmax_avalanches.References
Examples
>>> import jax.numpy as jnp >>> from braintools.analysis.population import avalanches >>> counts = jnp.array([2, 1, 0, 0, 3, 0, 1, 4, 2]) >>> res = avalanches(counts, max_avalanches=4) >>> res.sizes, res.durations, res.n (Array([3, 3, 7, 0], dtype=int32), Array([2, 1, 3, 0], dtype=int32), Array(3, dtype=int32)) >>> >>> # Get the counts from a spike raster: >>> from braintools.spike import SpikeTrains >>> raster = jnp.zeros((10, 4)).at[jnp.array([1, 2, 6]), jnp.array([0, 3, 1])].set(1.) >>> st = SpikeTrains.from_dense(raster, dt=1.) >>> avalanches(st.bin(1.).sum(axis=1)).n Array(2, dtype=int32)