Module Reference

Auto-generated documentation from source code docstrings.

Base Estimator

class tfilterspy.base_estimator.BaseEstimator(name=None)[source]

Bases: object

Base class for all estimators in TFiltersPy.

Provides sklearn-compatible parameter handling, Dask array conversion, and shared methods for all filter implementations.

fit_predict(X)[source]

Fit the filter and return state estimates.

get_params(deep=True)[source]

Get parameters of the estimator (sklearn-compatible).

score(X_true)[source]

Negative MSE between filtered states and ground truth.

Returns a negative value so that higher is better (sklearn convention).

set_params(**params)[source]

Set parameters of the estimator (sklearn-compatible).

static to_dask_array(numpy_array, chunk_size=None)[source]

Convert a NumPy array to a Dask array with specified chunking.

validate_matrices(matrices)[source]

Validate that matrices are NumPy or Dask arrays.

State Estimation

State Estimation submodule containing implementations for: - KalmanFilter (linear Gaussian systems) - ExtendedKalmanFilter (nonlinear, Jacobian-based) - UnscentedKalmanFilter (nonlinear, sigma points) - EnsembleKalmanFilter (high-dimensional, Dask-parallel) - ParticleFilter (nonlinear, non-Gaussian)

class tfilterspy.state_estimation.DaskKalmanFilter(state_transition_matrix, observation_matrix, process_noise_cov, observation_noise_cov, initial_state, initial_covariance, chunk_size=64, estimation_strategy='residual_analysis')[source]

Bases: KalmanFilter

Backward-compatible Kalman Filter wrapper.

Accepts the same constructor signature as the original DaskKalmanFilter and delegates to the new efficient KalmanFilter implementation.

predict()[source]

Return filtered states as a Dask array for backward compatibility.

tfilterspy.state_estimation.DaskNonLinearKalmanFilter

alias of ExtendedKalmanFilter

class tfilterspy.state_estimation.DaskParticleFilter(state_transition, observation_model, process_noise_cov, observation_noise_cov, initial_state, num_particles=1000, use_dask=True, estimation_strategy='residual_analysis')[source]

Bases: ParticleFilter

Backward-compatible Particle Filter wrapper.

Accepts the original DaskParticleFilter constructor signature and delegates to the new ParticleFilter implementation.

class tfilterspy.state_estimation.EnsembleKalmanFilter(f, h, Q, R, x0, P0, n_ensemble=100, use_dask=True)[source]

Bases: BaseEstimator

Ensemble Kalman Filter for high-dimensional state-space models.

Approximates the Kalman filter using a Monte Carlo ensemble of state realizations. Scales to systems with millions of state variables where storing full covariance matrices is infeasible.

Uses Dask for parallel ensemble member propagation when use_dask=True.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable) – State transition function f(x) -> x_next.

  • h (callable) – Observation function h(x) -> z.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

  • n_ensemble (int, optional) – Number of ensemble members (default 100).

  • use_dask (bool, optional) – Use Dask for parallel ensemble computation (default True).

Examples

>>> import numpy as np
>>> from tfilterspy import EnsembleKalmanFilter
>>> def f(x): return x
>>> def h(x): return x[:1]
>>> enkf = EnsembleKalmanFilter(f, h,
...     Q=np.eye(2)*0.1, R=np.eye(1)*0.5,
...     x0=np.zeros(2), P0=np.eye(2), n_ensemble=50)
>>> enkf.fit(np.random.randn(50, 1))
>>> states = enkf.predict()
filter_step(z)[source]

Single-step online EnKF update.

fit(X)[source]

Run the EnKF forward pass.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

class tfilterspy.state_estimation.ExtendedKalmanFilter(f, h, F_jacobian, H_jacobian, Q, R, x0, P0)[source]

Bases: BaseEstimator

Extended Kalman Filter for nonlinear state-space models.

Linearizes the dynamics using first-order Taylor expansion (Jacobians) around the current state estimate at each time step.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable) – State transition function f(x) -> x_next.

  • h (callable) – Observation function h(x) -> z.

  • F_jacobian (callable) – Jacobian of f: F_jacobian(x) -> ndarray (n_state, n_state).

  • H_jacobian (callable) – Jacobian of h: H_jacobian(x) -> ndarray (n_obs, n_state).

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

Examples

>>> import numpy as np
>>> from tfilterspy import ExtendedKalmanFilter
>>> def f(x): return x  # identity dynamics
>>> def h(x): return x[:1]  # observe first state only
>>> def Fj(x): return np.eye(2)
>>> def Hj(x): return np.array([[1.0, 0.0]])
>>> ekf = ExtendedKalmanFilter(f, h, Fj, Hj,
...     Q=np.eye(2)*0.1, R=np.eye(1)*0.5,
...     x0=np.zeros(2), P0=np.eye(2))
>>> ekf.fit(np.random.randn(50, 1))
>>> states = ekf.predict()
filter_step(z)[source]

Single-step online EKF update.

fit(X)[source]

Run the EKF forward pass on measurements.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

smooth()[source]

RTS smoother for EKF (re-linearizes at filtered states).

Returns:

  • smoothed_states (ndarray, shape (n_timesteps, n_state))

  • smoothed_covs (ndarray, shape (n_timesteps, n_state, n_state))

class tfilterspy.state_estimation.KalmanFilter(F, H, Q, R, x0, P0, store_covariances=True)[source]

Bases: BaseEstimator

Kalman Filter for linear Gaussian state-space models.

Efficient numpy core with optional Dask support for batch processing. Implements the full sklearn-compatible API: fit / predict / score.

State-space model:

x_{k+1} = F @ x_k + w_k,    w_k ~ N(0, Q)
z_k     = H @ x_k + v_k,     v_k ~ N(0, R)
Parameters:
  • F (ndarray, shape (n_state, n_state)) – State transition matrix.

  • H (ndarray, shape (n_obs, n_state)) – Observation matrix mapping state to measurement space.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

  • store_covariances (bool, optional) – If True (default), stores full covariance history. Set to False to save memory on very long time series (disables smooth()).

Examples

>>> import numpy as np
>>> from tfilterspy import KalmanFilter
>>> F = np.eye(2); H = np.eye(2)
>>> Q = np.eye(2) * 0.1; R = np.eye(2) * 0.5
>>> kf = KalmanFilter(F, H, Q, R, np.zeros(2), np.eye(2))
>>> kf.fit(np.random.randn(100, 2))
>>> states = kf.predict()
>>> smoothed, _ = kf.smooth()
filter_step(z)[source]

Single-step online filtering.

Parameters:

z (ndarray, shape (n_obs,)) – Single measurement vector.

Returns:

  • x (ndarray, shape (n_state,)) – Updated state estimate.

  • P (ndarray, shape (n_state, n_state)) – Updated covariance.

fit(X)[source]

Run the Kalman filter forward pass on measurements.

Parameters:

X (ndarray or dask.array, shape (n_timesteps, n_obs)) – Measurement sequence. 1-D arrays are reshaped to (n, 1).

Return type:

self

forecast(n_steps)[source]

Forecast future states beyond the observed data.

Parameters:

n_steps (int) – Number of steps to forecast.

Returns:

  • forecasted_states (ndarray, shape (n_steps, n_state))

  • forecasted_covs (ndarray, shape (n_steps, n_state, n_state))

predict()[source]

Return filtered state estimates.

Returns:

filtered_states

Return type:

ndarray, shape (n_timesteps, n_state)

run_filter(measurements)[source]

Legacy method. Use fit() + predict() instead.

smooth()[source]

Rauch-Tung-Striebel (RTS) backward smoothing pass.

Requires store_covariances=True (the default).

Returns:

  • smoothed_states (ndarray, shape (n_timesteps, n_state))

  • smoothed_covs (ndarray, shape (n_timesteps, n_state, n_state))

class tfilterspy.state_estimation.ParticleFilter(f, h, Q, R, x0, n_particles=1000, resample_threshold=0.5, use_dask=False)[source]

Bases: BaseEstimator

Sequential Importance Resampling (SIR) Particle Filter.

Represents the posterior distribution using a set of weighted particles. Handles nonlinear, non-Gaussian state-space models where Kalman-based approaches fail.

Supports both callable and matrix-based transition/observation models. When matrices are provided, particle propagation is vectorized for speed.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable or ndarray) – State transition. If callable: f(x) -> x_next. If ndarray (n_state, n_state): linear transition matrix.

  • h (callable or ndarray) – Observation model. If callable: h(x) -> z. If ndarray (n_obs, n_state): linear observation matrix.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • n_particles (int, optional) – Number of particles (default 1000).

  • resample_threshold (float, optional) – ESS ratio below which resampling triggers (default 0.5).

  • use_dask (bool, optional) – Parallelize particle propagation with Dask (default False).

Examples

>>> import numpy as np
>>> from tfilterspy import ParticleFilter
>>> F = np.eye(2)
>>> H = np.eye(2)
>>> pf = ParticleFilter(F, H, Q=np.eye(2)*0.1, R=np.eye(2)*0.5,
...     x0=np.zeros(2), n_particles=500)
>>> pf.fit(np.random.randn(100, 2))
>>> states = pf.predict()
filter_step(z)[source]

Single-step online particle filter update.

Parameters:

z (ndarray, shape (n_obs,)) – Single measurement.

Returns:

state – Weighted mean state estimate.

Return type:

ndarray, shape (n_state,)

fit(X)[source]

Run the particle filter on measurements.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

class tfilterspy.state_estimation.UnscentedKalmanFilter(f, h, Q, R, x0, P0, alpha=0.001, beta=2.0, kappa=0.0)[source]

Bases: BaseEstimator

Unscented Kalman Filter for nonlinear state-space models.

Uses the unscented transform with sigma points to propagate mean and covariance through nonlinear functions — no Jacobians required.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable) – State transition function f(x) -> x_next.

  • h (callable) – Observation function h(x) -> z.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

  • alpha (float, optional) – Spread of sigma points around the mean (default 1e-3).

  • beta (float, optional) – Prior distribution parameter; 2 is optimal for Gaussian (default 2.0).

  • kappa (float, optional) – Secondary scaling parameter (default 0).

Examples

>>> import numpy as np
>>> from tfilterspy import UnscentedKalmanFilter
>>> def f(x): return x
>>> def h(x): return x[:1]
>>> ukf = UnscentedKalmanFilter(f, h,
...     Q=np.eye(2)*0.1, R=np.eye(1)*0.5,
...     x0=np.zeros(2), P0=np.eye(2))
>>> ukf.fit(np.random.randn(50, 1))
>>> states = ukf.predict()
filter_step(z)[source]

Single-step online UKF update.

fit(X)[source]

Run the UKF forward pass.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

Kalman Filter

class tfilterspy.state_estimation.linear_filters.DaskKalmanFilter(state_transition_matrix, observation_matrix, process_noise_cov, observation_noise_cov, initial_state, initial_covariance, chunk_size=64, estimation_strategy='residual_analysis')[source]

Bases: KalmanFilter

Backward-compatible Kalman Filter wrapper.

Accepts the same constructor signature as the original DaskKalmanFilter and delegates to the new efficient KalmanFilter implementation.

predict()[source]

Return filtered states as a Dask array for backward compatibility.

class tfilterspy.state_estimation.linear_filters.KalmanFilter(F, H, Q, R, x0, P0, store_covariances=True)[source]

Bases: BaseEstimator

Kalman Filter for linear Gaussian state-space models.

Efficient numpy core with optional Dask support for batch processing. Implements the full sklearn-compatible API: fit / predict / score.

State-space model:

x_{k+1} = F @ x_k + w_k,    w_k ~ N(0, Q)
z_k     = H @ x_k + v_k,     v_k ~ N(0, R)
Parameters:
  • F (ndarray, shape (n_state, n_state)) – State transition matrix.

  • H (ndarray, shape (n_obs, n_state)) – Observation matrix mapping state to measurement space.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

  • store_covariances (bool, optional) – If True (default), stores full covariance history. Set to False to save memory on very long time series (disables smooth()).

Examples

>>> import numpy as np
>>> from tfilterspy import KalmanFilter
>>> F = np.eye(2); H = np.eye(2)
>>> Q = np.eye(2) * 0.1; R = np.eye(2) * 0.5
>>> kf = KalmanFilter(F, H, Q, R, np.zeros(2), np.eye(2))
>>> kf.fit(np.random.randn(100, 2))
>>> states = kf.predict()
>>> smoothed, _ = kf.smooth()
filter_step(z)[source]

Single-step online filtering.

Parameters:

z (ndarray, shape (n_obs,)) – Single measurement vector.

Returns:

  • x (ndarray, shape (n_state,)) – Updated state estimate.

  • P (ndarray, shape (n_state, n_state)) – Updated covariance.

fit(X)[source]

Run the Kalman filter forward pass on measurements.

Parameters:

X (ndarray or dask.array, shape (n_timesteps, n_obs)) – Measurement sequence. 1-D arrays are reshaped to (n, 1).

Return type:

self

forecast(n_steps)[source]

Forecast future states beyond the observed data.

Parameters:

n_steps (int) – Number of steps to forecast.

Returns:

  • forecasted_states (ndarray, shape (n_steps, n_state))

  • forecasted_covs (ndarray, shape (n_steps, n_state, n_state))

predict()[source]

Return filtered state estimates.

Returns:

filtered_states

Return type:

ndarray, shape (n_timesteps, n_state)

run_filter(measurements)[source]

Legacy method. Use fit() + predict() instead.

smooth()[source]

Rauch-Tung-Striebel (RTS) backward smoothing pass.

Requires store_covariances=True (the default).

Returns:

  • smoothed_states (ndarray, shape (n_timesteps, n_state))

  • smoothed_covs (ndarray, shape (n_timesteps, n_state, n_state))

Extended Kalman Filter

class tfilterspy.state_estimation.extended_kalman.ExtendedKalmanFilter(f, h, F_jacobian, H_jacobian, Q, R, x0, P0)[source]

Bases: BaseEstimator

Extended Kalman Filter for nonlinear state-space models.

Linearizes the dynamics using first-order Taylor expansion (Jacobians) around the current state estimate at each time step.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable) – State transition function f(x) -> x_next.

  • h (callable) – Observation function h(x) -> z.

  • F_jacobian (callable) – Jacobian of f: F_jacobian(x) -> ndarray (n_state, n_state).

  • H_jacobian (callable) – Jacobian of h: H_jacobian(x) -> ndarray (n_obs, n_state).

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

Examples

>>> import numpy as np
>>> from tfilterspy import ExtendedKalmanFilter
>>> def f(x): return x  # identity dynamics
>>> def h(x): return x[:1]  # observe first state only
>>> def Fj(x): return np.eye(2)
>>> def Hj(x): return np.array([[1.0, 0.0]])
>>> ekf = ExtendedKalmanFilter(f, h, Fj, Hj,
...     Q=np.eye(2)*0.1, R=np.eye(1)*0.5,
...     x0=np.zeros(2), P0=np.eye(2))
>>> ekf.fit(np.random.randn(50, 1))
>>> states = ekf.predict()
filter_step(z)[source]

Single-step online EKF update.

fit(X)[source]

Run the EKF forward pass on measurements.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

smooth()[source]

RTS smoother for EKF (re-linearizes at filtered states).

Returns:

  • smoothed_states (ndarray, shape (n_timesteps, n_state))

  • smoothed_covs (ndarray, shape (n_timesteps, n_state, n_state))

Unscented Kalman Filter

class tfilterspy.state_estimation.unscented_kalman.UnscentedKalmanFilter(f, h, Q, R, x0, P0, alpha=0.001, beta=2.0, kappa=0.0)[source]

Bases: BaseEstimator

Unscented Kalman Filter for nonlinear state-space models.

Uses the unscented transform with sigma points to propagate mean and covariance through nonlinear functions — no Jacobians required.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable) – State transition function f(x) -> x_next.

  • h (callable) – Observation function h(x) -> z.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

  • alpha (float, optional) – Spread of sigma points around the mean (default 1e-3).

  • beta (float, optional) – Prior distribution parameter; 2 is optimal for Gaussian (default 2.0).

  • kappa (float, optional) – Secondary scaling parameter (default 0).

Examples

>>> import numpy as np
>>> from tfilterspy import UnscentedKalmanFilter
>>> def f(x): return x
>>> def h(x): return x[:1]
>>> ukf = UnscentedKalmanFilter(f, h,
...     Q=np.eye(2)*0.1, R=np.eye(1)*0.5,
...     x0=np.zeros(2), P0=np.eye(2))
>>> ukf.fit(np.random.randn(50, 1))
>>> states = ukf.predict()
filter_step(z)[source]

Single-step online UKF update.

fit(X)[source]

Run the UKF forward pass.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

Ensemble Kalman Filter

class tfilterspy.state_estimation.ensemble_kalman.EnsembleKalmanFilter(f, h, Q, R, x0, P0, n_ensemble=100, use_dask=True)[source]

Bases: BaseEstimator

Ensemble Kalman Filter for high-dimensional state-space models.

Approximates the Kalman filter using a Monte Carlo ensemble of state realizations. Scales to systems with millions of state variables where storing full covariance matrices is infeasible.

Uses Dask for parallel ensemble member propagation when use_dask=True.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable) – State transition function f(x) -> x_next.

  • h (callable) – Observation function h(x) -> z.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • P0 (ndarray, shape (n_state, n_state)) – Initial state covariance.

  • n_ensemble (int, optional) – Number of ensemble members (default 100).

  • use_dask (bool, optional) – Use Dask for parallel ensemble computation (default True).

Examples

>>> import numpy as np
>>> from tfilterspy import EnsembleKalmanFilter
>>> def f(x): return x
>>> def h(x): return x[:1]
>>> enkf = EnsembleKalmanFilter(f, h,
...     Q=np.eye(2)*0.1, R=np.eye(1)*0.5,
...     x0=np.zeros(2), P0=np.eye(2), n_ensemble=50)
>>> enkf.fit(np.random.randn(50, 1))
>>> states = enkf.predict()
filter_step(z)[source]

Single-step online EnKF update.

fit(X)[source]

Run the EnKF forward pass.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

Particle Filter

class tfilterspy.state_estimation.particle_filters.DaskParticleFilter(state_transition, observation_model, process_noise_cov, observation_noise_cov, initial_state, num_particles=1000, use_dask=True, estimation_strategy='residual_analysis')[source]

Bases: ParticleFilter

Backward-compatible Particle Filter wrapper.

Accepts the original DaskParticleFilter constructor signature and delegates to the new ParticleFilter implementation.

class tfilterspy.state_estimation.particle_filters.ParticleFilter(f, h, Q, R, x0, n_particles=1000, resample_threshold=0.5, use_dask=False)[source]

Bases: BaseEstimator

Sequential Importance Resampling (SIR) Particle Filter.

Represents the posterior distribution using a set of weighted particles. Handles nonlinear, non-Gaussian state-space models where Kalman-based approaches fail.

Supports both callable and matrix-based transition/observation models. When matrices are provided, particle propagation is vectorized for speed.

State-space model:

x_{k+1} = f(x_k) + w_k,    w_k ~ N(0, Q)
z_k     = h(x_k) + v_k,     v_k ~ N(0, R)
Parameters:
  • f (callable or ndarray) – State transition. If callable: f(x) -> x_next. If ndarray (n_state, n_state): linear transition matrix.

  • h (callable or ndarray) – Observation model. If callable: h(x) -> z. If ndarray (n_obs, n_state): linear observation matrix.

  • Q (ndarray, shape (n_state, n_state)) – Process noise covariance.

  • R (ndarray, shape (n_obs, n_obs)) – Observation noise covariance.

  • x0 (ndarray, shape (n_state,)) – Initial state estimate.

  • n_particles (int, optional) – Number of particles (default 1000).

  • resample_threshold (float, optional) – ESS ratio below which resampling triggers (default 0.5).

  • use_dask (bool, optional) – Parallelize particle propagation with Dask (default False).

Examples

>>> import numpy as np
>>> from tfilterspy import ParticleFilter
>>> F = np.eye(2)
>>> H = np.eye(2)
>>> pf = ParticleFilter(F, H, Q=np.eye(2)*0.1, R=np.eye(2)*0.5,
...     x0=np.zeros(2), n_particles=500)
>>> pf.fit(np.random.randn(100, 2))
>>> states = pf.predict()
filter_step(z)[source]

Single-step online particle filter update.

Parameters:

z (ndarray, shape (n_obs,)) – Single measurement.

Returns:

state – Weighted mean state estimate.

Return type:

ndarray, shape (n_state,)

fit(X)[source]

Run the particle filter on measurements.

Parameters:

X (ndarray, shape (n_timesteps, n_obs))

Return type:

self

predict()[source]

Return filtered state estimates.

Utilities

class tfilterspy.utils.optimisation_utils.ParameterEstimator(estimation_strategy: str = 'residual_analysis')[source]

Bases: BaseEstimator

A class for estimating Kalman Filter parameters, such as process noise covariance (Q) and observation noise covariance (R), using different estimation methods.

Estimation strategies include: - Residual Analysis - Maximum Likelihood Estimation (MLE) - Cross-Validation - Adaptive Filtering

References: - Welch, G., & Bishop, G. (1995). An Introduction to the Kalman Filter. - Haykin, S. (2001). Kalman Filtering and Neural Networks.

estimate_parameters(measurements: Array)[source]

Estimate the parameters Q and R using the specified estimation strategy.

estimate_with_adaptive_filtering(measurements: Array) tuple[source]

Estimate Q and R adaptively based on innovations over time.

estimate_with_cross_validation(measurements: Array, k_folds: int = 5) tuple[source]

Estimate Q and R using k-fold cross-validation.

estimate_with_mle(measurements: Array, max_iterations: int = 5) tuple[source]

Estimate Q and R using Maximum Likelihood Estimation (MLE).

estimate_with_residual_analysis(measurements: Array) tuple[source]

Estimate process (Q) and observation (R) noise covariances using residual analysis.