Metadata-Version: 2.4
Name: commsubspace
Version: 0.4.0
Summary: Communication subspaces between neural populations: CCA, reduced-rank regression and contrastive communication subspaces (cCS).
Author-email: Eliezyer de Oliveira <eliezyer.deoliveira@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/eliezyer/commsubspace
Project-URL: Issues, https://github.com/eliezyer/commsubspace/issues
Keywords: neuroscience,communication subspace,CCA,reduced rank regression,contrastive
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: scikit-learn
Dynamic: license-file

# contrastive communication subspace

Python code for **contrastive communication subspace** and also implementations of regular communication subspace (CS) analysis between two neural populations (region 1 and region 2):

- `ReducedRankRegress` - reduced-rank regression (RRR) from region 1 to region 2. The original method used for CS in Semedo et al., 2019
- `CrossDecomposition` - CCA (`method='correlation'`) and PLS-SVD (`method='covariance'`). Other ways of achieving CS
- `cCS` - **contrastive communication subspace**: finds pairs of directions whose coupling between the two regions differs most between two conditions (A and B). Objectives: `'difference'`, `'ratio'`, `'normalized_difference'` and `'normalized_index'`.

All data arrays are `(n_samples, n_features)`.

## Installation

```bash
pip install commsubspace
```

Requires Python >= 3.10, NumPy, SciPy and scikit-learn.

## Quick start

```python
import numpy as np
from commsubspace import cCS, CrossDecomposition, ReducedRankRegress

rng = np.random.default_rng(0)
region1_A, region2_A = rng.standard_normal((500, 20)), rng.standard_normal((500, 15))  # condition A
region1_B, region2_B = rng.standard_normal((400, 20)), rng.standard_normal((400, 15))  # condition B

# Contrastive communication subspace: coupling that differs between conditions A and B.
ccs = cCS(method="normalized_index").fit(region1_A, region2_A, region1_B, region2_B)
print(ccs.region1_loadings_.shape, ccs.contrast_values_.shape)  # (20, N_dim), (N_dim,)

# Canonical correlation analysis between the two regions (condition A only).
cca = CrossDecomposition(method="correlation").fit(region1_A, region2_A)
scores_region1, scores_region2 = cca.transform(region1_A, region2_A)

# Reduced-rank regression of region 2 on region 1, with 3 predictive dimensions.
rrr = ReducedRankRegress(rank=3).fit(region1_A, region2_A)
predicted_region2 = rrr.predict(region1_A)
```

See the docstrings of `cCS`, `CrossDecomposition` and `ReducedRankRegress` for all options, fitted attributes and
units. Fitted `cCS` objects carry a `meta_` dictionary with the parameters, random seed and analysis version.

## License

MIT, see `LICENSE`.
