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.1

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.1
File Size Uploaded Provenance Actions
ode_filters-0.8.1.tar.gz 892.2 kB Without provenance Details for ode_filters-0.8.1.tar.gz

Built distribution (wheel)

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

Total release size: 1.0 MB

Release files / ode_filters-0.8.1.tar.gz

Download URL ode_filters-0.8.1.tar.gz
Size 892.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0c9ede31e063ce996cd6fe2076d34276934403f8335ae81b983ac2b0a0afa3eb
BLAKE2b-256 checksum
How to use checksums
d87b65d25b9d3362641b5686aa15dc4f8afa82803fec272c625f191064e48951
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.1-py3-none-any.whl

Download URL ode_filters-0.8.1-py3-none-any.whl
Size 117.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
046de4c324d6016488299f1dc30af5755b5d4814fdc649bd0168f1e45d2b6cef
BLAKE2b-256 checksum
How to use checksums
f72a9f10b3bc2c00682e5d664408458e542fce92d2bd1fa1c06f185de4986812
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.1

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