API Reference
All filters inherit from BaseEstimator and share a common interface.
+-----------------+
| BaseEstimator |
|-----------------|
| fit(X) |
| predict() |
| score(X_true) |
| fit_predict(X) |
| get_params() |
| set_params() |
+--------+--------+
|
+------------------+-------------------+
| | |
+-------v-------+ +------v--------+ +-------v--------+
| KalmanFilter | | EKF/UKF/EnKF | | ParticleFilter |
| smooth() | | (callables) | | ESS monitoring |
| forecast() | | | | systematic |
+---------------+ +---------------+ | resampling |
+----------------+
KalmanFilter
from tfilterspy import KalmanFilter
kf = KalmanFilter(F, H, Q, R, x0, P0, store_covariances=True)
Constructor parameters:
Parameter |
Description |
|---|---|
|
State transition matrix |
|
Observation matrix |
|
Process noise covariance |
|
Observation noise covariance |
|
Initial state estimate |
|
Initial state covariance |
|
If |
Additional methods:
Method |
Description |
|---|---|
|
RTS backward smoother. Returns |
|
Predict |
|
Log-likelihood of the data (computed during |
ExtendedKalmanFilter
from tfilterspy import ExtendedKalmanFilter
ekf = ExtendedKalmanFilter(
f=transition_fn, h=observation_fn,
F_jacobian=F_jac_fn, H_jacobian=H_jac_fn,
Q=Q, R=R, x0=x0, P0=P0,
)
Constructor parameters:
Parameter |
Description |
|---|---|
|
State transition function |
|
Observation function |
|
Jacobian of f: |
|
Jacobian of h: |
|
Same as KalmanFilter |
Additional methods: smooth() (RTS smoother), log_likelihood_
UnscentedKalmanFilter
from tfilterspy import UnscentedKalmanFilter
ukf = UnscentedKalmanFilter(
f=transition_fn, h=observation_fn,
Q=Q, R=R, x0=x0, P0=P0,
alpha=1e-3, beta=2.0, kappa=0.0,
)
Sigma point parameters:
Parameter |
Description |
|---|---|
|
Spread of sigma points around the mean (default: 1e-3) |
|
Prior knowledge of distribution; 2.0 is optimal for Gaussian |
|
Secondary scaling parameter (default: 0.0) |
No Jacobians required – just provide f(x) and h(x).
EnsembleKalmanFilter
from tfilterspy import EnsembleKalmanFilter
enkf = EnsembleKalmanFilter(
f=transition_fn, h=observation_fn,
Q=Q, R=R, x0=x0,
n_ensemble=100,
use_dask=True,
)
Constructor parameters:
Parameter |
Description |
|---|---|
|
Number of ensemble members (default: 50) |
|
Enable Dask parallel propagation (default: False) |
Scales to high-dimensional state spaces where storing full covariance matrices is infeasible.
ParticleFilter
from tfilterspy import ParticleFilter
pf = ParticleFilter(
f=transition_fn, h=observation_fn,
Q=Q, R=R, x0=x0,
n_particles=1000,
resample_threshold=0.5,
use_dask=False,
)
Constructor parameters:
Parameter |
Description |
|---|---|
|
State transition. If ndarray, used as linear matrix (vectorized). |
|
Observation model. If ndarray, used as linear matrix (vectorized). |
|
Number of particles (default: 1000) |
|
Resample when ESS drops below this fraction of |
|
Dask parallel particle propagation |
Attributes after fit:
Attribute |
Description |
|---|---|
|
ESS at each time step (monitors particle degeneracy) |
|
Log-likelihood of the data |
Backward Compatibility
The legacy class names still work:
from tfilterspy import DaskKalmanFilter # wraps KalmanFilter
from tfilterspy import DaskParticleFilter # wraps ParticleFilter
These accept the old constructor argument names and map them to the new API.
New code should use KalmanFilter and ParticleFilter directly.