Skip to main content

ODE Filters

PyPI Python CI Docs Coverage

ode_filters fits ODE models to data and accounts for the numerical error of the solver. It is a probabilistic ODE solver: it returns a Gaussian distribution over the solution instead of a single trajectory, and the spread of this distribution estimates the numerical error. The ODE enters as information about the solution, in the same way as data. One square-root Kalman filter therefore conditions on the ODE, on noisy measurements, on conservation laws and on an unknown input that drives the system. The result is a likelihood of the data that includes the numerical error and is differentiable in every parameter of the model. The library is written in JAX, so fits can be compiled, batched and differentiated.

Features

  • Inference from data: a differentiable marginal likelihood for any parameter of the ODE or the prior; fit_scipy (L-BFGS-B), fit (Optax), NumPyro and BlackJAX
  • Hidden inputs: joint state-input priors recover an unknown force driving the system, with information criteria for what the data say about it
  • Evidence for hyperparameters: the sequential data evidence and the conditional evidence given the ODE (Fenrir, Dalton)
  • Outputs: smoothed marginals, joint posterior samples, dense output, observation predictives, innovation diagnostics (NIS, whitened residuals)
  • The ODE as information: first- and second-order ODEs, conservation laws, black-box and transformed operators, data at any time (between the grid nodes as data-only nodes)
  • Pluggable linearization: EK0, EK1, IEKF and statistical linearization, plus the IEKS and IPLS smoothers
  • Priors: integrated Wiener, Matern, integrated Ornstein-Uhlenbeck and joint priors, plain or preconditioned
  • Calibrated uncertainty: online and post-hoc diffusion calibration; fixed grids of any spacing and adaptive steps
  • Pure JAX, square-root form: jit, vmap and grad through every solver; numerically stable QR-based filtering and smoothing

Installation

Install the latest release from PyPI:

pip install ode-filters
pip install "ode-filters[inference]"  # with Optax, SciPy, NumPyro and BlackJAX

Or install from source with the development tools (tests, linting, type checking):

git clone https://github.com/paufisch/ode_filters.git
cd ode_filters
uv sync --group dev

With pip 25.1 or newer, pip install -e . --group dev does the same.

Quick example

Estimate the growth rate of the logistic ODE from noisy data:

import jax
import jax.numpy as np

from ode_filters import (
    IWP,
    InferenceProblem,
    Measurement,
    ODEInformation,
    PositiveReal,
    fit_scipy,
    marginal_loglik,
    taylor_mode_initialization,
)

jax.config.update("jax_enable_x64", True)

# Noisy observations of the logistic ODE x' = r x (1 - x), x(0) = 0.1
ts = np.linspace(0.0, 10.0, 101)
x = 1.0 / (1.0 + 9.0 * np.exp(-0.8 * ts[1:]))
y = x + 0.02 * jax.random.normal(jax.random.PRNGKey(0), x.shape)

prior = IWP(q=2, d=1)
data = [Measurement(np.eye(1), y[:, None], ts[1:], noise=0.02**2)]


# The ODE, as a function of the unknown rate r
def build(theta):
    def vf(x, *, t):
        return theta["r"] * x * (1.0 - x)

    m_0, P_0_sqr = taylor_mode_initialization(vf, np.array([0.1]), q=2)
    return m_0, P_0_sqr, ODEInformation(vf, prior.E0, prior.E1)


# Maximize the likelihood of the data, numerical error included
problem = InferenceProblem(build=build, prior=prior, ts=ts)
theta, _ = fit_scipy(
    lambda th: -marginal_loglik(th, data, model=problem), {"r": PositiveReal(0.3)}
)
print(f"r = {theta['r'].unwrap():.3f}  (true: 0.8)")
# r = 0.793  (true: 0.8)

Solving an ODE without data is the same filter without the data:

from ode_filters import gaussian_filter, rts_smoother

vf = lambda x, *, t: 0.8 * x * (1.0 - x)
m_0, P_0_sqr = taylor_mode_initialization(vf, np.array([0.1]), q=2)
result = gaussian_filter(m_0, P_0_sqr, prior, ODEInformation(vf, prior.E0, prior.E1), ts)
posterior = rts_smoother(result)  # posterior.m, posterior.std: mean and error estimate

To upgrade from 0.7, follow the migration guide.

Package Structure

ode_filters/
├── priors/           # Gauss-Markov priors (IWP, Matern, IOUP, joint)
├── information/      # ODE information, conservation laws, data observations
├── linearization/    # Taylor and statistical linearization, frozen surrogates
├── calibration/      # Diffusion (sigma^2) calibration policies and rescaling
├── filters/          # Filters, smoothers, the iterated smoother, step control
├── inference/        # Marginal likelihoods and parameter fitting
└── gaussian/         # Square-root Gaussian types and algebra

Documentation

Full documentation is available at paufisch.github.io/ode_filters.

Development

Run the test suite:

uv run pytest --cov=ode_filters --cov-report=term-missing

Build documentation locally:

uv run --group docs mkdocs serve

License

MIT License. See LICENSE for details.

Metadata

Release files for ode-filters 0.8.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 ode-filters 0.8.2
File Size Uploaded Provenance Actions
ode_filters-0.8.2.tar.gz 895.2 kB Without provenance Details for ode_filters-0.8.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ode-filters 0.8.2
File Interpreter ABI Platform Actions
ode_filters-0.8.2-py3-none-any.whl Python 3 none any Details for ode_filters-0.8.2-py3-none-any.whl

Total release size: 1.0 MB

Release files / ode_filters-0.8.2.tar.gz

Download URL ode_filters-0.8.2.tar.gz
Size 895.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1db481a78f543a6525810ea47626ba2e0b92a757530b6137039a3fb7860b71e5
BLAKE2b-256 checksum
How to use checksums
6c30540e476c8ca491bc4fdc3bfddce4c8f3f73d380579352ac0a8e9e9e4f534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ode_filters-0.8.2-py3-none-any.whl

Download URL ode_filters-0.8.2-py3-none-any.whl
Size 118.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fa036e539cdf5b07cef29b5b0e64e58c81b4b1d43a6a7f6e5a85d6d303e55ad
BLAKE2b-256 checksum
How to use checksums
9f6727272abbbd80119dffa4a8fbc574b4ce2a177e964ca05f15cb0b3e006ba3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ode-filters 0.8.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.

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.

Release history Release notifications | RSS feed

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