State-space inference in JAX: Kalman and particle filters, tempered SMC, and SMC2 across CPU and accelerators
Project description
smcx
smcx is a JAX library for state-space inference: exact Gaussian filtering and smoothing, particle filters, adaptive tempered SMC, and SMC² with a small, function-oriented API. It runs on CPU, CUDA, and TPU through JAX, and on Apple-silicon GPUs through the optional jax-mps backend.
Features include:
- exact linear-Gaussian Kalman filtering and RTS smoothing;
- bootstrap, auxiliary, guided, and Liu–West particle filters;
- adaptive tempered SMC and nested SMC² parameter inference;
- systematic, stratified, multinomial, and residual resampling;
- filtering diagnostics, scoring rules, trajectory reconstruction, and ArviZ export; and
- structured latent-state PyTrees and explicit time-varying inputs.
smcx supplies inference algorithms, not model or distribution classes. Linear-Gaussian models are dense arrays; particle models are ordinary JAX callables, so they can be written directly or adapted from libraries such as Dynamax. Filtering and smoothing remain separate functions joined by typed posterior containers, allowing research code to replace one stage without subclassing or rerunning the other.
Installation
smcx requires Python 3.11 or later.
pip install smcx
Install the optional extras for Apple-silicon GPU execution or ArviZ reporting with:
pip install "smcx[metal]"
pip install "smcx[arviz]"
The metal extra uses jax-mps and is available on macOS arm64. Metal is
float32-only; releases are tested on a physical M-series GPU as well as
on CPU.
Documentation
The documentation includes a quickstart, guides for custom models and ArviZ reporting, and the complete API reference.
Quick example
import jax.numpy as jnp
import jax.random as jr
import smcx
a, q, r = 0.9, 0.5, 0.3
def initial_sampler(key, num_particles):
return jr.normal(key, (num_particles, 1))
def transition_sampler(key, state):
return a * state + jnp.sqrt(q) * jr.normal(key, state.shape)
def log_observation(y, state):
error = y[0] - state[0]
return -0.5 * (jnp.log(2 * jnp.pi * r) + error**2 / r)
observations = jnp.array([0.2, -0.1, 0.4, 0.7, 0.3])[:, None]
posterior = smcx.bootstrap_filter(
jr.key(0),
initial_sampler,
transition_sampler,
log_observation,
observations,
num_particles=10_000,
)
posterior.marginal_loglik
smcx.weighted_mean(posterior)
smcx.diagnose(posterior)
Callbacks describe one particle; smcx vectorizes them over the cloud. Every stochastic operation takes an explicit PRNG key, and posterior containers are JAX PyTrees.
Citation
If smcx contributes to academic work, cite the release used. The
repository's Cite this repository menu is generated from
CITATION.cff
and provides BibTeX and APA entries.
Sources and attribution
The broader Feynman–Kac architecture follows Chopin and Papaspiliopoulos's An Introduction to Sequential Monte Carlo. The implemented methods draw on these primary sources:
- Exact Gaussian state estimation: Kalman (1960) and Rauch, Tung, and Striebel (1965).
- Particle filters: Gordon, Salmond, and Smith (1993), Pitt and Shephard (1999), Doucet, Godsill, and Andrieu (2000), and Liu and West (2001).
- Static and parameter inference: Del Moral, Doucet, and Jasra (2006) and Chopin, Jacob, and Papaspiliopoulos (2013).
- Resampling and diagnostics: Douc, Cappé, and Moulines (2005), Lee and Whiteley (2018), Zhang and Stephens (2009), and Vehtari et al. (2024).
- Scoring rules: Matheson and Winkler (1976) and Gneiting and Raftery (2007).
- Reporting: ArviZ.
Numerical validation references
The exact Gaussian outputs are independently validated against Dynamax 1.0.2 and statsmodels 0.14.6. They are comparison implementations, not code lineage: no code from either project is copied or translated. Exact commits, environments, licenses, and observed differences are recorded with the frozen multivariate fixture.
Contributing
Contributions are welcome. See
CONTRIBUTING.md
for the development setup and pull-request conventions.
License
smcx is distributed under the Apache License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smcx-1.7.0.tar.gz.
File metadata
- Download URL: smcx-1.7.0.tar.gz
- Upload date:
- Size: 53.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1de9bdbbf2f5e1291b0769cccd7c42661bcab74ea85aecc9ec55ea3f80f1d98
|
|
| MD5 |
4de939b6feb90a8f6eaf6dee1dd01fc5
|
|
| BLAKE2b-256 |
5a4754593d4a4bb519a8b7d84c6bd7812c30b60d467a5e52368bab778863f3c8
|
Provenance
The following attestation bundles were made for smcx-1.7.0.tar.gz:
Publisher:
release.yml on michaelellis003/smcx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smcx-1.7.0.tar.gz -
Subject digest:
a1de9bdbbf2f5e1291b0769cccd7c42661bcab74ea85aecc9ec55ea3f80f1d98 - Sigstore transparency entry: 2229089759
- Sigstore integration time:
-
Permalink:
michaelellis003/smcx@05e1af940bd5575e4b39765d4aedd149a7450202 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/michaelellis003
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@05e1af940bd5575e4b39765d4aedd149a7450202 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file smcx-1.7.0-py3-none-any.whl.
File metadata
- Download URL: smcx-1.7.0-py3-none-any.whl
- Upload date:
- Size: 63.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c70925da572a90096a6fc0afd9dae0c162bf43ba4258bedd04e02a9ad793274
|
|
| MD5 |
c4a31b546b430fe0e0ca6f127e936b4d
|
|
| BLAKE2b-256 |
6acb03856d253ffc1e2646c58c80182a8fbd085ab0c6db1b763ab11fd08304b9
|
Provenance
The following attestation bundles were made for smcx-1.7.0-py3-none-any.whl:
Publisher:
release.yml on michaelellis003/smcx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smcx-1.7.0-py3-none-any.whl -
Subject digest:
5c70925da572a90096a6fc0afd9dae0c162bf43ba4258bedd04e02a9ad793274 - Sigstore transparency entry: 2229090235
- Sigstore integration time:
-
Permalink:
michaelellis003/smcx@05e1af940bd5575e4b39765d4aedd149a7450202 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/michaelellis003
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@05e1af940bd5575e4b39765d4aedd149a7450202 -
Trigger Event:
workflow_run
-
Statement type: