Skip to main content

Contrastive Prediction of Point Process Observations (C3PO)

Unsupervised model to infer latent generative processes from point processes occuring in $\mathbb{R}^d$ spcae. Developed with focus for inferring neural states from waveform features of unclustered spike events.

Analysis associated with the publication "Learning predictive latent structure from unclustered neural spike trains" available at the publication repository.

Installation

Local

conda env create c3po
conda activate c3po
conda install pip
pip install c3po-neuro

Optional dependencies:

c3po-neuro[gpu] #For gpu acceleration.
c3po-neuro[cloud] #For loading of cloud models stored on higging face

Try it out on the cloud

Run C3PO on public DANDI recordings in Google Colab with no local installation required. Enter the Dandiset ID and the path to an NWB file containing sorted spikes. The notebook sets up C3PO in the Colab runtime, trains a model on a GPU, and displays a PCA plot of the inferred context. You can download the trained model and analysis outputs as a ZIP archive or save them to Google Drive. Open the C3PO demo in Google Colab.

Quick Start

Sorted Data (Tutorial)

C3PO provides functions for constructing and training sorted spike models from several sources:

  • Data published on the DANDI archive: c3po.utils.train_from_dandi()
  • Data stored within a local NWB file: c3po.utils.train_from_nwb()
  • A loaded array of spike times and neuron ids: c3po.utils.train_from_sorted_data()

By default, these will train with the architecture and parameters used in the publication data screening. Alternative model architectures can be passed as arguments. For a walk through of these options, see the deep-dive tutorial notebook

Clusterless Data (Tutorial)

C3PO can infer latent neural states directly from spike times and waveform features, without spike sorting. Each event is represented by its timestamp and a feature vector, such as peak amplitudes across recording channels.

From extracted waveform features, use the function

  • c3po.utils.clusterless.train_from_waveform_data()

Alternative model architectures can be passed as arguments. For a walk through of some of these options, see the deep-dive tutorial notebook

Details

Model declaration

In both intuition and implementation, the c3po model is broken into three modules. Details and derivation of the overall architecture and role of each of these components is described in the documentation:

  • encoder model: Accepts the waveform feature vector $W$ and embeds it into a lower latent_dim space as the embedded mark vector $Z$.
  • context model: Embeds the history of marks $\set{Z_j}_{j=1}^i$ into a context feature vector $C_i$
  • rate-prediction model: Estimates the set of context-dependent parameters $\theta(Z_i,C_j)$ used to calculate the hazard function of a given embedded waveform $H(\theta(Z_j, C_i),\Delta t_i)$. Implemented options for the emission process model are found here.

The complete model is agnostic to the deep learning architecture used to implement each of these modules. For example, the context model can be implemented as any history- coding model including a RNN, a wavenet architecture, or causal transformers. To specify which of the the implemented versions of each module to use, each has a factory constructor which accepts a key for the architecture type and a dictionary or arguments for the module (e.g. number of layers, convolutional filter size, etc.).

A complete c3po model for training is defined by the C3PO class. The initialization of the class requires constructor arguments for each of the modules and definition of the embedded dimension size. An example is given below.

# hyperparams
latent_dim = 10
context_dim = 10
# encoder
encoder_widths = [128, 128, 64]
encoder_args = dict(
    encoder_model="simple",
    widths=encoder_widths,
)
# context
dilations = [1, 2, 4, 8, 16]
kernels = [10, 20, 64, 64, 128]
dilations = dilations * 2
kernels = kernels * 2
context_args = dict(
    context_model="wavenet",
    layer_dilations=dilations,
    layer_kernel_size=kernels,
    expanded_dim=32,
    smoothing=10,
)
# rate model
rate_args = dict(
    rate_model="sharedSpace",
)
distribution = "poisson"
n_neg_samples = 128
model = C3PO(
    encoder_args,
    context_args,
    rate_args,
    distribution,
    latent_dim,
    context_dim,
    n_neg_samples,
)

Loss functions

NCE (DEFAULT): The noise contrastive estimation loss is given by: $\mathcal{L} = - \mathbb{E}_i[\log \frac{H_i/H'_i}{\sum_j H_j/H'_j}]$. Example execution of the C3PO method shown below:

#define model
model = C3PO(
    encoder_args,
    context_args,
    rate_args,
    distribution,
    latent_dim,
    context_dim,
    n_neg_samples,
    return_embeddings_in_call=True,
)
run_model = jax.jit(model.apply)

# forward pass to get \theta params and embedded values
pos_params, neg_params, z, c, neg_z = run_model(params, x, delta_t, rand_key)
# loss
loss =  model.contrastive_loss(
    pos_params,
    neg_params,
    delta_t,
    z[:, 1:],
    neg_z,
)

MLE: Maximum likelihood loss is given by $\mathcal{L}=\mathbb{E}_i[-\log H_i+\log\bar{S}_i]$ and is provided as a method of the C3PO class. Example execution shown below:

# define model
model = C3PO(
    encoder_args,
    context_args,
    rate_args,
    distribution,
    latent_dim,
    context_dim,
    n_neg_samples,
    predicted_sequence_length,
)
run_model = jax.jit(model.apply)
# forward pass to get \theta params
pos_params, neg_params = run_model(params, x, delta_t, rand_key)
# loss
loss = model.mle_loss(
    pos_params, neg_params, delta_t,
)

Similar Methods

  • Contrastive Predictive Coding (CPC)
    • Works for continuous time rather than point processes
  • Temporal Neural Networks (e.g. Hawkes process)
    • designed for categorically labeled events
  • CEBRA
    • designed for sorted spiking data
    • semi-supervised definition of matching states

Metadata

Release files for c3po-neuro 0.1.2

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

Source distribution (sdist)

Source distribution for c3po-neuro 0.1.2
File Size Uploaded Provenance Actions
c3po_neuro-0.1.2.tar.gz 17.7 MB With provenance Details for c3po_neuro-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for c3po-neuro 0.1.2
File Interpreter ABI Platform Actions
c3po_neuro-0.1.2-py3-none-any.whl Python 3 none any Details for c3po_neuro-0.1.2-py3-none-any.whl

Total release size: 17.8 MB

Release files / c3po_neuro-0.1.2.tar.gz

Download URL c3po_neuro-0.1.2.tar.gz
Size 17.7 MB
Tags Source
SHA-256 checksum
How to use checksums
a666e392002bf775847c10b340651359a5d258c4d00ad7407aecafa42cf11092
BLAKE2b-256 checksum
How to use checksums
42b0f3f36101457146506d42c4277fef94eef5da686d787925ce5c3381b3fb3b
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 13, 2026.

Transparency log

Release files / c3po_neuro-0.1.2-py3-none-any.whl

Download URL c3po_neuro-0.1.2-py3-none-any.whl
Size 92.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b483f93abfd575a19b7620c765457921be9ab9a231345c7e9ec998059859cd8c
BLAKE2b-256 checksum
How to use checksums
97d5404452a86fbe9751742900a79e6b520af76d823c404a622a8b30a9cdd0f8
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 13, 2026.

Transparency log

Security for c3po-neuro 0.1.2

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 c3po_neuro-0.1.2.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 13, 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