Skip to main content

An implementation of the Kalman Filter, Kalman Smoother, and EM algorithm in Python

Project description

Welcome to pykalman

The dead-simple Kalman Filter, Kalman Smoother, and EM library for Python.

pykalman is a Python library for Kalman filtering and smoothing, providing efficient algorithms for state estimation in time series. It includes tools for linear dynamical systems, parameter estimation, and sequential data modeling. The library supports the Kalman Filter, Unscented Kalman Filter, and EM algorithm for parameter learning.

Originally created by Daniel Duckworth (@duckworthd).

:rocket: Version 0.11.2 out now! Check out the release notes here.

Documentation · Tutorials
Open Source BSD 3-clause
Community !discord !LinkedI
Code !pypi !python-versions !black
Downloads PyPI - Downloads PyPI - Downloads Downloads

:speech_balloon: Where to ask questions

Questions and feedback are extremely welcome! We strongly believe in the value of sharing help publicly, as it allows a wider audience to benefit from it.

Type Platforms
:bug: Bug Reports GitHub Issue Tracker
:sparkles: Feature Requests & Ideas GitHub Issue Tracker
:woman_technologist: Usage Questions Stack Overflow
:speech_balloon: General Discussion Discord
:factory: Contribution & Development dev-chat channel · Discord
:globe_with_meridians: Meet-ups and collaboration sessions Discord - Fridays 13 UTC, dev/meet-ups channel

:hourglass_flowing_sand: Install pykalman

  • Operating system: macOS X · Linux · Windows 8.1 or higher
  • Python version: Python 3.10, 3.11, 3.12, 3.13, and 3.14
  • Package managers: pip

For a quick installation::

pip install pykalman

Alternatively, you can setup from source:

pip install .

:zap: Usage

from pykalman import KalmanFilter
import numpy as np
kf = KalmanFilter(transition_matrices = [[1, 1], [0, 1]], observation_matrices = [[0.1, 0.5], [-0.3, 0.0]])
measurements = np.asarray([[1,0], [0,0], [0,1]])  # 3 observations
kf = kf.em(measurements, n_iter=5)
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurements)

Also included is support for missing measurements:

from numpy import ma
measurements = ma.asarray(measurements)
measurements[1] = ma.masked   # measurement at timestep 1 is unobserved
kf = kf.em(measurements, n_iter=5)
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurements)

And for the non-linear dynamics via the UnscentedKalmanFilter:

from pykalman import UnscentedKalmanFilter
ukf = UnscentedKalmanFilter(lambda x, w: x + np.sin(w), lambda x, v: x + v, transition_covariance=0.1)
(filtered_state_means, filtered_state_covariances) = ukf.filter([0, 1, 2])
(smoothed_state_means, smoothed_state_covariances) = ukf.smooth([0, 1, 2])

And for online state estimation:

for t in range(1, 3):
    filtered_state_means[t], filtered_state_covariances[t] = \
            kf.filter_update(filtered_state_means[t-1], filtered_state_covariances[t-1], measurements[t])

And for numerically robust "square root" filters

from pykalman.sqrt import CholeskyKalmanFilter, AdditiveUnscentedKalmanFilter
kf = CholeskyKalmanFilter(transition_matrices = [[1, 1], [0, 1]], observation_matrices = [[0.1, 0.5], [-0.3, 0.0]])
ukf = AdditiveUnscentedKalmanFilter(lambda x, w: x + np.sin(w), lambda x, v: x + v, observation_covariance=0.1)

Examples

Examples of all of pykalman's functionality can be found here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pykalman-0.11.2.tar.gz (244.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykalman-0.11.2-py2.py3-none-any.whl (252.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pykalman-0.11.2.tar.gz.

File metadata

  • Download URL: pykalman-0.11.2.tar.gz
  • Upload date:
  • Size: 244.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pykalman-0.11.2.tar.gz
Algorithm Hash digest
SHA256 70c22bb074376f7aa1304c4c2f4c61feb22bafd4ab992d340da9340b5a028674
MD5 5b2cbf7fa644e4a2f75e87f46fe30bb3
BLAKE2b-256 ae5e2c4a3dc86f5d9bc80ef48a79197b57c6b03aefa021aa685da1a8b1478492

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykalman-0.11.2.tar.gz:

Publisher: release.yml on pykalman/pykalman

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pykalman-0.11.2-py2.py3-none-any.whl.

File metadata

  • Download URL: pykalman-0.11.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 252.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pykalman-0.11.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 00dcc0c88b93a8ab6100295501e7f440350b872d558b41d0deff2fcaf827a553
MD5 203c907b98277db1c1a5a255a606dc19
BLAKE2b-256 6e4dbd6608cb7b1d2832e4270bb36c7394efa6ea1c8243a3b9ee53726a6cffe0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykalman-0.11.2-py2.py3-none-any.whl:

Publisher: release.yml on pykalman/pykalman

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page