Skip to main content

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

pip install commsubspace

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

Quick start

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.

Metadata

Release files for commsubspace 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for commsubspace 0.4.0
File Size Uploaded Provenance Actions
commsubspace-0.4.0.tar.gz 20.0 kB With provenance Details for commsubspace-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for commsubspace 0.4.0
File Interpreter ABI Platform Actions
commsubspace-0.4.0-py3-none-any.whl Python 3 none any Details for commsubspace-0.4.0-py3-none-any.whl

Total release size: 41.0 kB

Release files / commsubspace-0.4.0.tar.gz

Download URL commsubspace-0.4.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8084be9218dd1722d4e01366df37e8c32bb8678f55f46a9344322db2a321ff43
BLAKE2b-256 checksum
How to use checksums
0f1425416ec3ff9fe9590b5a6ff7ac84a036e6c9574ac2f9ee1f35c4fc07e18e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / commsubspace-0.4.0-py3-none-any.whl

Download URL commsubspace-0.4.0-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f02fb747e9564b08ab8d12dc109a97a63606ab452cff57fe83877e3c2d5b02bc
BLAKE2b-256 checksum
How to use checksums
e1dd3886834cb3fed4316d2fa35d5d0248bb5a4581f33daf60df6d980a774a11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for commsubspace 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for commsubspace-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page