TFilterPy.utils package¶
Submodules¶
TFilterPy.utils.optimisation_utils module¶
- class TFilterPy.utils.optimisation_utils.ParameterEstimator(estimation_strategy: str = 'residual_analysis')[source]¶
Bases:
BaseEstimatorA class for estimating Kalman Filter parameters, such as process noise covariance (Q) and observation noise covariance (R), using different estimation methods.
Parameter estimation is crucial for optimal performance of Kalman Filters, particularly in dynamic systems where noise characteristics are unknown or change over time.
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.
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
- Returns:
Q (da.Array, shape (n_features, n_features)) – Estimated process noise covariance matrix.
R (da.Array, shape (n_features, n_features)) – Estimated observation noise covariance matrix.
Notes
Innovations (differences between predictions and observations) are used to update Q and R adaptively.
A smoothing factor (alpha) determines the influence of recent measurements.
- estimate_with_cross_validation(measurements: Array, k_folds: int = 5) tuple[source]¶
Estimate Q and R using k-fold cross-validation.
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
k_folds (int, optional) – Number of folds to split the data for cross-validation. Default is 5.
- Returns:
best_Q (da.Array, shape (n_features, n_features)) – Best estimated process noise covariance matrix.
best_R (da.Array, shape (n_features, n_features)) – Best estimated observation noise covariance matrix.
Notes
The data is split into k-folds. The model is trained on k-1 folds and validated on the remaining fold.
The fold with the lowest validation error determines the best Q and R estimates.
- estimate_with_mle(measurements: Array, max_iterations: int = 5) tuple[source]¶
Estimate Q and R using Maximum Likelihood Estimation (MLE).
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
max_iterations (int, optional) – Number of iterations to refine the estimates. Default is 5.
- Returns:
Q (da.Array, shape (n_features, n_features)) – Estimated process noise covariance matrix.
R (da.Array, shape (n_features, n_features)) – Estimated observation noise covariance matrix.
Notes
MLE iteratively adjusts Q and R by maximizing the likelihood of the observed measurements.
The process is repeated for max_iterations to converge towards optimal estimates.
- estimate_with_residual_analysis(measurements: Array) tuple[source]¶
Estimate process (Q) and observation (R) noise covariances using residual analysis.
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
- Returns:
Q (da.Array, shape (n_features, n_features)) – Estimated process noise covariance matrix.
R (da.Array, shape (n_features, n_features)) – Estimated observation noise covariance matrix.
Notes
Residual analysis involves analyzing the discrepancies between measurements and predictions.
Q is derived from the covariance of the residuals, while R is scaled based on residual variance.
Module contents¶
Utility functions for parameter estimation and optimization.
- class TFilterPy.utils.ParameterEstimator(estimation_strategy: str = 'residual_analysis')[source]¶
Bases:
BaseEstimatorA class for estimating Kalman Filter parameters, such as process noise covariance (Q) and observation noise covariance (R), using different estimation methods.
Parameter estimation is crucial for optimal performance of Kalman Filters, particularly in dynamic systems where noise characteristics are unknown or change over time.
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.
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
- Returns:
Q (da.Array, shape (n_features, n_features)) – Estimated process noise covariance matrix.
R (da.Array, shape (n_features, n_features)) – Estimated observation noise covariance matrix.
Notes
Innovations (differences between predictions and observations) are used to update Q and R adaptively.
A smoothing factor (alpha) determines the influence of recent measurements.
- estimate_with_cross_validation(measurements: Array, k_folds: int = 5) tuple[source]¶
Estimate Q and R using k-fold cross-validation.
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
k_folds (int, optional) – Number of folds to split the data for cross-validation. Default is 5.
- Returns:
best_Q (da.Array, shape (n_features, n_features)) – Best estimated process noise covariance matrix.
best_R (da.Array, shape (n_features, n_features)) – Best estimated observation noise covariance matrix.
Notes
The data is split into k-folds. The model is trained on k-1 folds and validated on the remaining fold.
The fold with the lowest validation error determines the best Q and R estimates.
- estimate_with_mle(measurements: Array, max_iterations: int = 5) tuple[source]¶
Estimate Q and R using Maximum Likelihood Estimation (MLE).
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
max_iterations (int, optional) – Number of iterations to refine the estimates. Default is 5.
- Returns:
Q (da.Array, shape (n_features, n_features)) – Estimated process noise covariance matrix.
R (da.Array, shape (n_features, n_features)) – Estimated observation noise covariance matrix.
Notes
MLE iteratively adjusts Q and R by maximizing the likelihood of the observed measurements.
The process is repeated for max_iterations to converge towards optimal estimates.
- estimate_with_residual_analysis(measurements: Array) tuple[source]¶
Estimate process (Q) and observation (R) noise covariances using residual analysis.
- Parameters:
measurements (da.Array, shape (n_timesteps, n_features)) – Observed measurements over time.
- Returns:
Q (da.Array, shape (n_features, n_features)) – Estimated process noise covariance matrix.
R (da.Array, shape (n_features, n_features)) – Estimated observation noise covariance matrix.
Notes
Residual analysis involves analyzing the discrepancies between measurements and predictions.
Q is derived from the covariance of the residuals, while R is scaled based on residual variance.