Registry / ai-ml / filterpy

filterpy

JSON →
library1.4.5pypypi✓ verified 25d ago

FilterPy is a Python library for Kalman filtering and optimal estimation, including Kalman Filters, Extended Kalman Filters, and Unscented Kalman Filters. It provides a robust and well-documented framework for state estimation. The current version is 1.4.5, which has been stable since 2017, indicating a very mature but not actively developed codebase.

pip install filterpy
INSTALL
IMPORT
SIG · FILTERPY
F
filterpy
ai-mlpythonv1.4.5
Install
12.5s avg
Import
2521ms
Disk
324MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 2.590s · 321.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 12.5s · import 2.452s · 309MB
324MB installed
● package 324MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

KalmanFilter
from filterpy.kalman import KalmanFilter
ExtendedKalmanFilter
from filterpy.kalman import ExtendedKalmanFilter
UnscentedKalmanFilter
from filterpy.kalman import UnscentedKalmanFilter
Q_discrete_white_noise
from filterpy.common import Q_discrete_white_noise
A helper function for common process noise covariance matrices.

Initializes a simple 1D Kalman Filter to track position and velocity based on position measurements. It demonstrates the setup of the KalmanFilter object, defining its core matrices (F, H, P, R, Q), and iterating through measurements using `predict()` and `update()`.

import numpy as np from filterpy.kalman import KalmanFilter # Create a KalmanFilter object kf = KalmanFilter(dim_x=2, dim_z=1) # Initialize state vector x (position, velocity) kf.x = np.array([[0.], [0.]]) # State transition matrix F kf.F = np.array([[1., 1.], [0., 1.]]) # Measurement function H kf.H = np.array([[1., 0.]]) # State covariance matrix P kf.P *= 1000. # Measurement noise covariance R kf.R = 5 # Measurement noise # Process noise covariance Q kf.Q = np.diag([0.01, 0.01]) # Simple process noise # Simulate some measurements z = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # Run the filter estimates = [] for measurement in z: kf.predict() kf.update(measurement) estimates.append(kf.x.T[0].tolist()) # print(estimates) # Expected output for first few: [[...], [...]]
Debug
Known issues
gotchaIncorrect matrix dimensions or initialization for state vector (x), covariance matrices (P, Q, R) are very common. This leads to `ValueError` during matrix operations or, more subtly, poor filter performance and divergence. Ensure `dim_x`, `dim_z` match your matrix shapes.
fix
Carefully review the documentation for each matrix's required dimensions. Use `np.array` with correct shapes (e.g., `[[value]]` for 1D vectors). Ensure initial `P` is large enough to reflect uncertainty, and `Q`, `R` reflect expected noise levels.
affects: All versions
gotchaDefining the process noise covariance matrix (Q) is often challenging and misunderstood. An inappropriate `Q` can lead to filter divergence or sluggish response. While the library provides `Q_discrete_white_noise`, users often use overly simplistic or incorrect `Q` matrices.
fix
Consult `filterpy`'s documentation on 'Choosing Q and R' and 'System Modeling'. Start with `Q_discrete_white_noise` for common scenarios and tune it based on system dynamics and expected process variation. Remember `Q` should reflect uncertainty added by the system model per time step.
affects: All versions
gotchaFilterPy version 1.4.5 has not been updated since 2017. While functional and stable, it is not actively maintained. This means no new features, bug fixes for new Python versions/dependencies, or performance improvements are expected. Users should be aware of this for long-term project planning.
fix
Factor in the lack of ongoing maintenance when integrating into new projects or using with very recent Python versions. Test thoroughly for compatibility with your environment. Consider alternative libraries if active development, modern features, or specific performance optimizations are critical.
affects: 1.4.5+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'filterpy'
The `filterpy` library is not installed in the current Python environment, or its installation failed due to compatibility issues with newer `setuptools` versions.
fix
Install `filterpy` using pip: `pip install filterpy`. If this fails with `subprocess-exited-with-error`, try installing a known working fork: `pip install git+https://github.com/rodjjo/filterpy.git` or `python_embeded\python.exe -m pip install git+https://github.com/rodjjo/filterpy.git` for embedded environments.
LinAlgError: 1-th leading minor of the array is not positive definite
This error often occurs when the covariance matrix (P or Q) in a Kalman filter becomes non-positive definite, which can happen due to numerical instability, incorrect model parameters, or an overly aggressive update step.
fix
Review your filter's process noise covariance (Q) and measurement noise covariance (R) matrices, ensuring they are correctly defined and positive definite. Increasing the process noise or adjusting the filter's update logic can sometimes help stabilize the covariance matrix.
ValueError: operands could not be broadcast together with shapes (X) (Y)
This is a common NumPy error indicating a mismatch in array dimensions during mathematical operations within the filter, often when trying to add or multiply matrices of incompatible sizes (e.g., state vector `x` and measurement `z`, or state transition matrix `F` and state covariance `P`).
fix
Carefully check the dimensions of all matrices and vectors involved in your Kalman filter equations (e.g., `x`, `P`, `F`, `H`, `Q`, `R`, `z`). Ensure they align according to the filter's mathematical requirements, especially when initializing the filter or performing predictions and updates.
Upgrade
Version history
1.4.5latest on PyPI · released Oct 10, 2018
Audit
Dependencies
numpyrequiredEssential for numerical operations and matrix algebra.
scipyrequiredRequired for certain advanced scientific computing functions, though primarily relies on NumPy.
Agent activity
34 hits · last 30 days
node
32
OpenAI (training)
1
Resources