Computation-Aware State-Space Model (CASSM)
Latent variable dynamical modeling is a classical problem in neuroscience.
Typically, we assume neural population acitivity lies in some low-dimensional space. In the figure above, the synthetic dynamics are generated by the 3D Lorenz system.
A readout map defines the interaction between neurons as we move from latent space to neural space, and then we sample from that trajectory to obtain spikes.
Latent variable dynamical models attempt to learn the latent dynamics, readout maps, and noise models for this problem.
CASSM provides PyTorch implementations of computation-aware filtering and smoothing models for high-dimensional neural time series. Unlike the original Computation-Aware Kalman Filter (CAKF), here we also learn the models themselves. Just bring your data, and we'll learn everything else.
In effect, we are solving Gaussian Process regression problems efficiently using Bayesian Filtering and Smoothing: no more cubic-time algorithms in the sequence length. After CASSM, Gaussian Process Factor Analysis (GPFA) should only be used for very small recordings. Any larger recordings with long sequence lengths and many neurons will want to use this repository.
Please see the paper for more details.
Installation
Install from PyPI:
pip install cassm
Install the package in editable mode from the repository root:
pip install -e .
For development and tests, install the optional development dependencies:
pip install -e ".[dev]"
Quick Start
import torch
from torch.utils.data import DataLoader, TensorDataset
from cassm.datasets.synthetic_data import LorenzData
from cassm.models import CASSM
from cassm.utils.preprocessing import smooth_firing_rate
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
train_data, valid_data, _, valid_truth, _, _ = LorenzData(
num_inits=4,
neurons=120,
num_trials=4,
device="cpu",
seed=2,
)
train_data = smooth_firing_rate(train_data.numpy()).to(device)
valid_data = smooth_firing_rate(valid_data.numpy()).to(device)
valid_truth = valid_truth.to(device)
train_loader = DataLoader(train_data, batch_size=4, shuffle=True)
test_loader = DataLoader(TensorDataset(valid_data, valid_truth), batch_size=4)
model = CASSM(
projection_dim=10,
nneurons=train_data.shape[-1],
timesteps=train_data.shape[1],
dt=0.01,
device=device,
save_model=False,
).to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=5e-2)
model.train_model(
epochs=3,
optimizer=optimizer,
train_loader=train_loader,
test_loader=test_loader,
)
# filtering output
filtered_state, filtered_noise = model.filter(valid_data, return_type="prediction")
# trial averaged predictions
predicted_rate, predicted_noise = model.predict_rate(valid_data)
See tutorials/cassm_lorenz_tutorial.ipynb for a fuller walkthrough.
Repository Layout
src/cassm: package source codetests: package teststutorials: user-facing notebookspyproject.toml: package metadata and tooling configuration
Testing
pytest
License
CASSM is released under the MIT License. See LICENSE.
Metadata
Release files for cassm 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cassm-0.2.0.tar.gz | 335.0 kB | Without provenance | Details for cassm-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cassm-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for cassm-0.2.0-py3-none-any.whl |
Total release size: 393.1 kB
Release files / cassm-0.2.0.tar.gz
| Download URL | cassm-0.2.0.tar.gz |
|---|---|
| Size | 335.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1347c78a389f3c8db18302e8d96ff49630cde151c88cb65ef8ff739a946082f
|
|
BLAKE2b-256 checksum How to use checksums |
3e73c149a46ea47ad19685b280c3adbf85ac8d8c95762d2eb31b7354846d14e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / cassm-0.2.0-py3-none-any.whl
| Download URL | cassm-0.2.0-py3-none-any.whl |
|---|---|
| Size | 58.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
045cf3f547a0f170bc9bbd981beea797884353f6bed1953e19c7c13a9b9fbf5b
|
|
BLAKE2b-256 checksum How to use checksums |
72fec8120939dd3396da048483a00e017d307cf33c85169720f172b32391517b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for cassm 0.2.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.