# Bayesian Filters - Kalman filters and other optimal and non-optimal estimation filters in Python
<p align="center">
<img width="100%" alt="Kalman Filter Illustration" src="https://github.com/user-attachments/assets/90b0b305-3128-4806-a72c-a061d01a854b" />
</p>
For people new to Kalman filters, they're well explained here https://www.youtube.com/watch?v=IFeCIbljreY (credit for the above image)
[](https://pypi.org/project/bayesian-filters/)
[](https://georgepearse.github.io/bayesian_filters)
> **Note**: This is a personal fork of the original FilterPy library (now renamed to Bayesian Filters). The original project can be found at https://github.com/rlabbe/filterpy
>
> Maintained by George Pearse, Lead MLE at [Visia](https://www.visia.ai/)
This library provides Kalman filtering and various related optimal and non-optimal filtering software written in Python. It contains Kalman filters, Extended Kalman filters, Unscented Kalman filters, Kalman smoothers, Least Squares filters, fading memory filters, g-h filters, discrete Bayes, and more.
This is code originally developed in conjunction with the book [Kalman and Bayesian Filter in Python](https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/).
## Design Philosophy
The original author's aim is largely pedagogical - opting for clear code that matches the equations in the relevant texts on a 1-to-1 basis, even when that has a performance cost. There are places where this tradeoff is unclear - for example, writing a small set of equations using linear algebra may be clearer, but NumPy's overhead on small matrices makes it run slower than writing each equation out by hand.
All computations use NumPy and SciPy.
## Documentation
Documentation is available at https://georgepearse.github.io/bayesian_filters
## Installation
```bash
uv pip install bayesian-filters
```
## Basic Usage
Full documentation is at https://georgepearse.github.io/bayesian_filters
### Import the filters
```python
import numpy as np
import bayesian_filters as bf
# Or import specific modules
from bayesian_filters.kalman import KalmanFilter
from bayesian_filters.common import Q_discrete_white_noise
```
### Create the filter
```python
my_filter = KalmanFilter(dim_x=2, dim_z=1)
```
### Initialize the filter's matrices
```python
my_filter.x = np.array([[2.],
[0.]]) # initial state (location and velocity)
my_filter.F = np.array([[1.,1.],
[0.,1.]]) # state transition matrix
my_filter.H = np.array([[1.,0.]]) # Measurement function
my_filter.P *= 1000. # covariance matrix
my_filter.R = 5 # state uncertainty
my_filter.Q = Q_discrete_white_noise(dim=2, dt=0.1, var=0.1) # process uncertainty
```
### Run the filter
```python
while True:
my_filter.predict()
my_filter.update(get_some_measurement())
# do something with the output
x = my_filter.x
do_something_amazing(x)
```
## Library Structure
The library is broken up into subdirectories:
- `gh` - g-h filters
- `kalman` - Kalman filters (KF, EKF, UKF, etc.)
- `memory` - fading memory filters
- `leastsq` - least squares filters
- `discrete_bayes` - discrete Bayes filters
- `stats` - statistical functions
- `common` - common helper functions
Each subdirectory contains Python files relating to that form of filter. The functions and methods contain comprehensive docstrings.
The book [Kalman and Bayesian Filters in Python](https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/) uses this library and is the best place to learn about Kalman filtering and/or this library.
## Requirements
This library requires:
- Python 3.9+
- NumPy
- SciPy
- Matplotlib
## Testing
All tests are written to work with pytest. Just run:
```bash
pytest
```
The tests include both unit tests and visual verification. Visual plots are often the best way to see how filters are working, as it's easy for a filter to perform within theoretical limits yet be 'off' in some way.
## References
### Books
The original author uses three main reference texts:
1. **Paul Zarchan's 'Fundamentals of Kalman Filtering: A Practical Approach'** - Excellent for practical applications rather than theoretical thesis work.
2. **Eli Brookner's 'Tracking and Kalman Filtering Made Easy'** - An astonishingly good book with its first chapter readable by laypeople. Brookner starts from the g-h filter and shows how all other filters derive from it, including Kalman filters, least squares, and fading memory filters. Also focuses on practical issues like track initialization, noise detection, and tracking multiple objects.
3. **Bar-Shalom's 'Estimation with Applications to Tracking and Navigation'** - More mathematical than the previous two. Recommended after gaining some background in control theory or optimal estimation. Every sentence is crystal clear with precise language, and abstract mathematical statements are followed with practical explanations.
### Online Resources
- **[Kalman Filter Background](https://kalmanfilter.net/background.html)** - Comprehensive background and theory on Kalman filtering
## License
[](https://github.com/GeorgePearse/bayesian_filters/blob/master/LICENSE)
The MIT License (MIT)
Copyright (c) 2015 Roger R. Labbe Jr
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Raw data
{
"_id": null,
"home_page": null,
"name": "bayesian-filters",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "Bayesian, Kalman, estimation, filtering, filters, optimal, tracking",
"author": null,
"author_email": "Roger Labbe <rlabbejr@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e4/20/da275a7f24f0cdec09d2e91298a0ec7420c7e17bf7c8d25e34ad2a7073f3/bayesian_filters-1.4.5.tar.gz",
"platform": null,
"description": "# Bayesian Filters - Kalman filters and other optimal and non-optimal estimation filters in Python\n\n<p align=\"center\">\n <img width=\"100%\" alt=\"Kalman Filter Illustration\" src=\"https://github.com/user-attachments/assets/90b0b305-3128-4806-a72c-a061d01a854b\" />\n</p>\n\nFor people new to Kalman filters, they're well explained here https://www.youtube.com/watch?v=IFeCIbljreY (credit for the above image)\n\n[](https://pypi.org/project/bayesian-filters/)\n[](https://georgepearse.github.io/bayesian_filters)\n\n> **Note**: This is a personal fork of the original FilterPy library (now renamed to Bayesian Filters). The original project can be found at https://github.com/rlabbe/filterpy\n>\n> Maintained by George Pearse, Lead MLE at [Visia](https://www.visia.ai/)\n\nThis library provides Kalman filtering and various related optimal and non-optimal filtering software written in Python. It contains Kalman filters, Extended Kalman filters, Unscented Kalman filters, Kalman smoothers, Least Squares filters, fading memory filters, g-h filters, discrete Bayes, and more.\n\nThis is code originally developed in conjunction with the book [Kalman and Bayesian Filter in Python](https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/).\n\n## Design Philosophy\n\nThe original author's aim is largely pedagogical - opting for clear code that matches the equations in the relevant texts on a 1-to-1 basis, even when that has a performance cost. There are places where this tradeoff is unclear - for example, writing a small set of equations using linear algebra may be clearer, but NumPy's overhead on small matrices makes it run slower than writing each equation out by hand.\n\nAll computations use NumPy and SciPy.\n\n## Documentation\n\nDocumentation is available at https://georgepearse.github.io/bayesian_filters\n\n## Installation\n\n```bash\nuv pip install bayesian-filters\n```\n\n\n## Basic Usage\n\nFull documentation is at https://georgepearse.github.io/bayesian_filters\n\n### Import the filters\n\n```python\nimport numpy as np\nimport bayesian_filters as bf\n\n# Or import specific modules\nfrom bayesian_filters.kalman import KalmanFilter\nfrom bayesian_filters.common import Q_discrete_white_noise\n```\n\n### Create the filter\n\n```python\nmy_filter = KalmanFilter(dim_x=2, dim_z=1)\n```\n\n### Initialize the filter's matrices\n\n```python\nmy_filter.x = np.array([[2.],\n [0.]]) # initial state (location and velocity)\n\nmy_filter.F = np.array([[1.,1.],\n [0.,1.]]) # state transition matrix\n\nmy_filter.H = np.array([[1.,0.]]) # Measurement function\nmy_filter.P *= 1000. # covariance matrix\nmy_filter.R = 5 # state uncertainty\nmy_filter.Q = Q_discrete_white_noise(dim=2, dt=0.1, var=0.1) # process uncertainty\n```\n\n### Run the filter\n\n```python\nwhile True:\n my_filter.predict()\n my_filter.update(get_some_measurement())\n\n # do something with the output\n x = my_filter.x\n do_something_amazing(x)\n```\n\n## Library Structure\n\nThe library is broken up into subdirectories:\n- `gh` - g-h filters\n- `kalman` - Kalman filters (KF, EKF, UKF, etc.)\n- `memory` - fading memory filters\n- `leastsq` - least squares filters\n- `discrete_bayes` - discrete Bayes filters\n- `stats` - statistical functions\n- `common` - common helper functions\n\nEach subdirectory contains Python files relating to that form of filter. The functions and methods contain comprehensive docstrings.\n\nThe book [Kalman and Bayesian Filters in Python](https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/) uses this library and is the best place to learn about Kalman filtering and/or this library.\n\n## Requirements\n\nThis library requires:\n- Python 3.9+\n- NumPy\n- SciPy\n- Matplotlib\n\n## Testing\n\nAll tests are written to work with pytest. Just run:\n\n```bash\npytest\n```\n\nThe tests include both unit tests and visual verification. Visual plots are often the best way to see how filters are working, as it's easy for a filter to perform within theoretical limits yet be 'off' in some way.\n\n## References\n\n### Books\n\nThe original author uses three main reference texts:\n\n1. **Paul Zarchan's 'Fundamentals of Kalman Filtering: A Practical Approach'** - Excellent for practical applications rather than theoretical thesis work.\n\n2. **Eli Brookner's 'Tracking and Kalman Filtering Made Easy'** - An astonishingly good book with its first chapter readable by laypeople. Brookner starts from the g-h filter and shows how all other filters derive from it, including Kalman filters, least squares, and fading memory filters. Also focuses on practical issues like track initialization, noise detection, and tracking multiple objects.\n\n3. **Bar-Shalom's 'Estimation with Applications to Tracking and Navigation'** - More mathematical than the previous two. Recommended after gaining some background in control theory or optimal estimation. Every sentence is crystal clear with precise language, and abstract mathematical statements are followed with practical explanations.\n\n### Online Resources\n\n- **[Kalman Filter Background](https://kalmanfilter.net/background.html)** - Comprehensive background and theory on Kalman filtering\n\n## License\n\n[](https://github.com/GeorgePearse/bayesian_filters/blob/master/LICENSE)\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Roger R. Labbe Jr\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Kalman filtering and optimal estimation library",
"version": "1.4.5",
"project_urls": {
"Documentation": "https://georgepearse.github.io/bayesian_filters",
"Homepage": "https://github.com/GeorgePearse/bayesian_filters",
"Original Project": "https://github.com/rlabbe/filterpy",
"Repository": "https://github.com/GeorgePearse/bayesian_filters"
},
"split_keywords": [
"bayesian",
" kalman",
" estimation",
" filtering",
" filters",
" optimal",
" tracking"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a6feb02bddcd0dd427cd96843946e51ecd81e4edfc37d3fcbd729dabfbe1bff6",
"md5": "dcf2397a402abb85a44aa5a46bd62898",
"sha256": "6d9a6e019ad5166a4a12e95220a6dad1a9bd96b1a97ca4b7d363e061a7d8d1fb"
},
"downloads": -1,
"filename": "bayesian_filters-1.4.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dcf2397a402abb85a44aa5a46bd62898",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 168713,
"upload_time": "2025-10-20T18:29:34",
"upload_time_iso_8601": "2025-10-20T18:29:34.670750Z",
"url": "https://files.pythonhosted.org/packages/a6/fe/b02bddcd0dd427cd96843946e51ecd81e4edfc37d3fcbd729dabfbe1bff6/bayesian_filters-1.4.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e420da275a7f24f0cdec09d2e91298a0ec7420c7e17bf7c8d25e34ad2a7073f3",
"md5": "8a1f0784f210cc28570790d415968d66",
"sha256": "93266955ed7ab08fb1180976d39861c5585bebce0cc6e32ed1eebf1c9f19cb0a"
},
"downloads": -1,
"filename": "bayesian_filters-1.4.5.tar.gz",
"has_sig": false,
"md5_digest": "8a1f0784f210cc28570790d415968d66",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 147539,
"upload_time": "2025-10-20T18:29:36",
"upload_time_iso_8601": "2025-10-20T18:29:36.150195Z",
"url": "https://files.pythonhosted.org/packages/e4/20/da275a7f24f0cdec09d2e91298a0ec7420c7e17bf7c8d25e34ad2a7073f3/bayesian_filters-1.4.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-20 18:29:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GeorgePearse",
"github_project": "bayesian_filters",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": []
},
{
"name": "scipy",
"specs": []
}
],
"lcname": "bayesian-filters"
}