# Cell assembly detection (CAD)¶

CAD [cad1] is a method aimed to capture structures of higher-order correlation in massively parallel spike trains. In particular, it is able to extract patterns of spikes with arbitrary configuration of time lags (time interval between spikes in a pattern), and at multiple time scales, e.g. from synchronous patterns to firing rate co-modulations.

CAD consists of a statistical parametric testing done on the level of pairs of neurons, followed by an agglomerative recursive algorithm, in order to detect and test statistically precise repetitions of spikes in the data. In particular, pairs of neurons are tested for significance under the null hypothesis of independence, and then the significant pairs are agglomerated into higher order patterns.

Given a list of discretized (binned) spike trains by a given temporal scale (bin_size), assumed to be recorded in parallel, the CAD analysis can be applied as demonstrated in this short toy example of 5 parallel spike trains that exhibit fully synchronous events of order 5.

`cell_assembly_detection` (binned_spiketrain, ...) |
Perform the CAD analysis [cad1] for the binned (discretized) spike trains given in the input. |

## Visualization¶

Visualization of CAD method is covered in Viziphant
`viziphant.patterns.plot_patterns()`

## See Also¶

elephant.spade.spade : advanced synchronous patterns detection

## Examples¶

```
>>> import quantities as pq
>>> import numpy as np
>>> from elephant.cell_assembly_detection import cell_assembly_detection
>>> from elephant.spike_train_generation import compound_poisson_process
>>> from elephant.conversion import BinnedSpikeTrain
```

Generate correlated data and bin it with a bin_size of 10ms.

```
>>> np.random.seed(30)
>>> spiketrains = compound_poisson_process(rate=15*pq.Hz,
... amplitude_distribution=[0, 0.95, 0, 0, 0, 0, 0.05], t_stop=5*pq.s)
>>> bst = BinnedSpikeTrain(spiketrains, bin_size=10 * pq.ms)
>>> bst.rescale('ms')
```

Call of the method.

```
>>> patterns = cell_assembly_detection(bst, max_lag=2)
>>> patterns[0]
{'neurons': [0, 2],
'lags': array([0.]) * ms,
'pvalue': [5.3848138041122556e-05],
'times': array([ 90., 160., 170., 550., 790., 910., 930., 1420., 1470.,
1480., 1650., 2030., 2220., 2570., 3130., 3430., 3480., 3610.,
3800., 3830., 3930., 4080., 4560., 4600., 4670.]) * ms,
'signature': [[1, 83], [2, 25]]}
```

Refer to the Viziphant documentation regarding the visualization of this example.