Skip to main content

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;
  • a public runner for caller-owned particle-filter kernels;
  • 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 custom particle filters 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 caller-owned particle-filter runner was informed by the functional state/information protocol in BlackJAX 1.6.2 and the separation of orchestration from history in particles 0.4. These are design credits; no code was copied or translated. The implemented methods draw on these primary sources:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smcx-1.8.0.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smcx-1.8.0-py3-none-any.whl (67.6 kB view details)

Uploaded Python 3

File details

Details for the file smcx-1.8.0.tar.gz.

File metadata

  • Download URL: smcx-1.8.0.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for smcx-1.8.0.tar.gz
Algorithm Hash digest
SHA256 ebdbb79bf5b72aa8dd0300f2b14f60722828b0055a831d02f2748026428a41b7
MD5 3b4b2e5c485a5ac20e8c33c0ba149dad
BLAKE2b-256 f9608f27cbe12adcfdca9021308c2e83c74cb67a137f261ce5fb8846148b6b30

See more details on using hashes here.

Provenance

The following attestation bundles were made for smcx-1.8.0.tar.gz:

Publisher: release.yml on michaelellis003/smcx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smcx-1.8.0-py3-none-any.whl.

File metadata

  • Download URL: smcx-1.8.0-py3-none-any.whl
  • Upload date:
  • Size: 67.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for smcx-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8f5b34a9644d20266df94e3c33ebb85c5d20b93b42d9fa95a464246a3910e32
MD5 44a32d8f621ca6adfd44ea0d9d99666f
BLAKE2b-256 71376e1ac7150cdb4c7f911221f325912f1419e79da7d86051224bb506ca42bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for smcx-1.8.0-py3-none-any.whl:

Publisher: release.yml on michaelellis003/smcx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page