Python API reference
All names live under kalman after import kalman. The factories return either
a templated _LinearKalmanFilter_NX_NZ or a runtime _DynLinearKalmanFilter
based on the shape (Dispatch); both expose the same surface.
x, P, F, Q, H, R are read/write properties exchanged as flat
row-major Python lists or 1-D numpy arrays. Methods that take measurements
accept either a flat sequence of length N * NZ or anything numpy.asarray()
will turn into a (N, NZ) or (N,) array.
Module-level helpers
backend() -> str
Returns the short name of the SIMD backend chosen at import time. One of
"avx512", "avx2", "avx", "linux_aarch64_sve", "linux_aarch64_asimd",
"macos_arm64_neon", "loongarch_lasx", "loongarch_lsx",
"powerpc64_vsx", or "generic".
available_backends() -> list[tuple[str, bool, bool]]
Returns [(name, compiled_into_wheel, runtime_available_on_host), ...] for
every backend in the priority list. Useful for "why is generic running when I
expected v4" diagnosis.
version() -> str
Returns the C++ core version string.
supported_dimensions() -> list[int]
Returns the list of dimensions [1..8]. Historical — the runtime fallback now
handles anything.
smooth_with_bands(kf, measurements, *, levels=(0.95,), delta_t=None, measurement_variance=None, eps=1e-15) -> dict
Runs kf.smooth(...) and adds per-step Gaussian confidence bands at each
requested coverage level. See Smoother.
Factories
LinearKalmanFilter(nx, nz, x=None, P=None, F=None, Q=None, H=None, R=None)
Linear Kalman filter x_{t+1} = F x_t + w, z_t = H x_t + v. Returns a
templated class for the 9 kept shapes, otherwise the runtime fallback.
AdaptiveKalmanFilter(nx, nz, x=None, P=None, F=None, Q=None, H=None, R=None, forgetting=None, min_variance=None)
Linear filter with an online R estimate. Same shape API as LinearKalmanFilter
plus forgetting ∈ (0, 1] (smoothing of the running R estimate; lower = more
adaptive) and min_variance (floor for diagonal of R).
ExtendedKalmanFilter(nx, nz, x=None, P=None, Q=None, R=None)
EKF with Python callbacks per step. Always returns the runtime
_DynExtendedKalmanFilter. See Filter catalog.
IteratedExtendedKalmanFilter(nx, nz, x=None, P=None, Q=None, R=None)
EKF with Gauss-Newton refinement in the correction step. Always Dyn.
UnscentedKalmanFilter(nx, nz, x=None, P=None, Q=None, R=None, alpha=1e-3, beta=2.0, kappa=0.0)
UKF with sigma-point propagation. Always Dyn.
EnsembleKalmanFilter(nx, nz, ensemble_size=8, members=None, R=None)
8-member deterministic EnKF. ensemble_size currently fixed at 8. Always Dyn.
LinearKalmanFilterBank(nx, nz, K, x=None, P=None, F=None, Q=None, H=None, R=None)
K independent linear filters sharing F, Q, H with per-symbol x, P,
R. SoA storage internally; properties exchange flat (K, NX)-major layouts.
Returns templated for the 9 kept shapes, runtime fallback otherwise. See
Bank.
RangeBearingEKF2D(dt=1.0, landmark_x=0.0, landmark_y=0.0, x=None, P=None, Q=None, R=None)
Tracking-flavored EKF for [px, py, vx, vy] state and [range, bearing]
measurement against a fixed landmark.
make_scalar_random_walk(initial_value, initial_variance, process_variance, measurement_variance)
Convenience constructor returning a configured LinearKalmanFilter(1, 1).
make_constant_velocity_1d(initial_position, initial_velocity, dt, position_variance, velocity_variance, process_position_variance, process_velocity_variance, measurement_variance)
Convenience constructor returning a configured LinearKalmanFilter(2, 1).
make_constant_acceleration_1d(initial_position, initial_velocity, initial_acceleration, dt, position_variance, velocity_variance, acceleration_variance, process_position_variance, process_velocity_variance, process_acceleration_variance, measurement_variance)
Convenience constructor returning a configured LinearKalmanFilter(3, 1).
LinearKalmanFilter / _DynLinearKalmanFilter
Properties
| Name | Shape | R/W |
|---|---|---|
nx |
int |
read-only |
nz |
int |
read-only |
x |
(nx,) |
r/w |
P |
(nx, nx) |
r/w |
F |
(nx, nx) |
r/w |
Q |
(nx, nx) |
r/w |
H |
(nz, nx) |
r/w |
R |
(nz, nz) |
r/w |
last |
dict-like UpdateStats |
read-only |
Methods
predict(delta_t=None)
Advances x ← F x, P ← F P Fᵀ + Q. If delta_t is set and
nx == 2*nz or nx == 3*nz, runs the kinematic predict that exploits the
shear structure of F (templated path only).
correct(z, eps=1e-15) -> UpdateStatsHandle
Applies one measurement. Returns a lazy stats handle (see below). Raises
nothing on a singular innovation covariance; check stats.ok.
update(z, delta_t=None, measurement_variance=None, eps=1e-15) -> UpdateStatsHandle
predict() + correct(z) in one call. Per-tick delta_t requires
nx == 2*nz or nx == 3*nz. Per-tick measurement_variance accepts a scalar
for nz=1 or a (nz, nz) matrix otherwise.
update_many(measurements, delta_t=None, measurement_variance=None, record_states=False, return_stats=False, eps=1e-15) -> dict
Loops update(z) in C++. Releases the GIL when return_stats=False.
Result keys:
"count": number of ticks processed."ok":Falseif any tick had a singularS."x","P","last": final state, covariance, and last-tick stats."states"(ifrecord_states=True):(N, nx)numpy view, zero-copy on the templated path."stats"(ifreturn_stats=True): list of per-tick stats handles.
On the runtime _DynLinearKalmanFilter, delta_t= and measurement_variance=
raise ValueError — that path doesn't have kinematic specialization yet.
smooth(measurements, delta_t=None, measurement_variance=None, record_covariances=False, eps=1e-15) -> dict
Forward filter pass + backward RTS pass. See Smoother.
smooth_with_bands(measurements, levels=(0.95,), delta_t=None, measurement_variance=None, eps=1e-15) -> dict
smooth(...) plus per-step Gaussian confidence bands at each level.
AdaptiveKalmanFilter / _DynAdaptiveKalmanFilter
Same properties as LinearKalmanFilter, plus:
| Name | Type | R/W |
|---|---|---|
forgetting |
float in (0, 1] |
r/w |
min_variance |
float |
r/w |
kf |
underlying LinearKalmanFilter view |
read-only |
Methods mirror LinearKalmanFilter; the running R estimate updates on each
correct() / update().
ExtendedKalmanFilter / _DynExtendedKalmanFilter
Methods
def predict(transition, jacobian)
def correct(z, measurement, jacobian, eps=1e-15) -> stats
def update(z, transition, transition_jacobian, measurement, measurement_jacobian, eps=1e-15) -> stats
def update_many(measurements, transition, transition_jacobian, measurement, measurement_jacobian, return_stats=False, eps=1e-15) -> dict
Callbacks take a 1-D numpy view of the state and return either a 1-D vector or a 2-D matrix. See Filter catalog for shapes.
IteratedExtendedKalmanFilter / _DynIteratedExtendedKalmanFilter
Same signature as EKF, with extra max_iterations and tolerance arguments on
correct / update / update_many.
UnscentedKalmanFilter / _DynUnscentedKalmanFilter
Two callback styles:
- Per-sample:
predict(transition, jitter=…),correct(z, measurement, jitter=…, eps=…). The library calls the Python callback once per sigma point (so2*nx + 1calls perpredict). - Batched:
predict_batch(transition_batch, jitter=…),correct_batch(z, measurement_batch, jitter=…, eps=…). The callback gets a(2nx+1, nx)numpy view and returns a(2nx+1, nx)(or(2nx+1, nz)) numpy array — one Python call perpredict/correct.
update_many(measurements, transition, measurement, …) and
update_many_batch(measurements, transition_batch, measurement_batch, …) loop
the matching style.
Sigma-point parameters alpha, beta, kappa are read/write properties.
EnsembleKalmanFilter / _DynEnsembleKalmanFilter
ensemble_size is fixed at 8. Properties:
| Name | Shape | R/W |
|---|---|---|
members |
(8, nx) |
r/w |
x |
(nx,) |
read-only |
P |
(nx, nx) |
read-only |
R |
(nz, nz) |
r/w |
last |
stats handle | read-only |
Methods:
def recompute_mean_covariance()
def predict(transition)
def correct_deterministic(z, measurement, eps=1e-15) -> stats
def predict_batch(transition_batch)
def correct_deterministic_batch(z, measurement_batch, eps=1e-15) -> stats
def update_many_batch(measurements, transition_batch, measurement_batch, return_stats=False, eps=1e-15) -> dict
LinearKalmanFilterBank / _DynLinearKalmanFilterBank
K independent linear filters sharing F, Q, H. Per-symbol x, P, R.
See Bank for the full layout and benchmark numbers.
Quick reference:
| Property | Shape | R/W |
|---|---|---|
nx, nz, K |
int |
read-only |
x |
(K, nx) flat |
r/w |
P |
(K, nx, nx) flat |
r/w |
R |
(K, nz, nz) flat |
r/w |
F, Q, H |
shared, same shapes as LinearKalmanFilter |
r/w |
Methods:
def predict(delta_t=None)
def update(z) | def correct(z, eps=1e-15) # Dyn only
def update_many(measurements, delta_t=None, measurement_variance=None, record_states=False, eps=1e-15) -> dict
measurements is shape (N, K, nz) flat. record_states=True returns a
(N, K, nx) numpy view as result["states"].
UpdateStatsHandle (return type of correct, update, kf.last)
Lazy view over the per-call statistics. Accessed by attribute or by dict-style
lookup. Implements __bool__ (the .ok flag) so if not kf.update(z): works.
| Field | Type |
|---|---|
ok |
bool |
nis |
float (normalized innovation squared) |
innovation |
list[float] of length nz |
S |
list[list[float]] (nz × nz) |
K |
list[list[float]] (nx × nz) |
to_dict() |
dict |
The lists are materialized lazily, so stats.ok is a fast attribute read.