Skip to main content

Optimized Kalman Filter

Get an optimized Kalman Filter from data of system-states and observations.

This package implements the paper The Fragility of Noise Estimation in Kalman Filter: Optimization Can Handle Model-Misspecification, by Greenberg, Mannor and Yannay.

Installation: pip install Optimized-Kalman-Filter

Usage example: example.ipynb.

The standard KF (tuned by noise-estimation) vs. the Optimized KF, in the test data of the simple-lidar example problem: errors summary (left) and a sample of models predictions against the actual target (right) (images from example.ipynb)

Background: the Kalman Filter

The Kalman Filter (KF) is a popular algorithm for filtering problems such as state estimation, smoothing, tracking and navigation. For example, consider tracking a plane using noisy measurements (observations) from a radar. Every time-step, we try to predict the motion of the plane, then receive a new measurement from the radar and update our belief accordingly.

An illustration of a single step of the Kalman Filter: predict the next state (black arrow); receive a new observation (green ellipse); update your belief about the state (mixing the two right ellipses) (image by Ido Greenberg)
A diagram of the Kalman Filter algorithm (image by Ido Greenberg)

To tune the KF, one has to determine the parameters representing the measurement (observation) noise and the motion-prediction noise, expressed as covariance matrices R and Q. Given a dataset of measurements {z_t} (e.g. from the radar), tuning these parameters may be a difficult task, and has been studied for many decades. However, given data of both measurements {z_t} and true-states {x_t} (e.g. true plane locations), the parameters R,Q are usually estimated from the data as the sample covariance matrices of the noise.

When to use this package

When you want to build a Kalman Filter for your problem, and you have a training dataset with sequences of both states {x_t} and observations {z_t}.

Why to use

Tuning the KF parameters through noise estimation (as explained above) yields optimal model predictions - under the KF assumptions. However, as shown in the paper, whenever the assumptions do not hold, optimization of the parameters may lead to more accurate predictions. Since most practical problems do not satisfy the assumptions, and since assumptions violations are often not noticed at all by the user, optimization of the parameters is a good practice whenever a corresponding dataset is available.

How to use

Installation: pip install Optimized-Kalman-Filter

Import: import okf

Usage example: example.ipynb.

Data

The data consists of 2 lists of length n, where n is the number of trajectories in the data:

  1. X[i] = a numpy array of type double and shape (n_time_steps(trajectory i), state_dimension).
  2. Z[i] = a numpy array of type double and shape (n_time_steps(trajectory i), observation_dimension).

For example, if a state is 4-dimensional (e.g. (x,y,vx,vy)) and an observation is 2-dimensional (e.g. (x,y)), and the i'th trajectory has 30 time-steps, then X[i].shape is (30,4) and Z[i].shape is (30,2).

Below we assume that Xtrain, Ztrain, Xtest, Ztest correspond to train and test datasets of the format specified above.

KF configuration

The configuration of the KF has to be specified as a dict model_args containing the following entries:

  • dim_x: the number of entries in a state
  • dim_z: the number of entries in an observation
  • init_z2x: a function that receives the first observation and returns the first state-estimate
  • F: the dynamics model: a pytorch tensor of type double and shape (dim_x, dim_x)
  • H: the observation model: a pytorch tensor of type double and shape (dim_z, dim_x); or a function that returns such a tensor given the estimated state and the current observation
  • loss_fun: function(predicted_x, true_x) used as loss for training and evaluation

See an example here.

Train and test

import okf
model = okf.OKF(**model_args)  # set optimize=False for the standard KF baseline
okf.train(model, Ztrain, Xtrain)
loss = okf.test_model(model, Ztest, Xtest, loss_fun=model_args['loss_fun'])

Analysis

See example.ipynb.

Metadata

Release files for Optimized-Kalman-Filter 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Optimized-Kalman-Filter 0.0.4
File Size Uploaded
Optimized Kalman Filter-0.0.4.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Optimized-Kalman-Filter 0.0.4
File Interpreter ABI Platform
Optimized_Kalman_Filter-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 36.6 kB

Release files / Optimized Kalman Filter-0.0.4.tar.gz

Download URL Optimized Kalman Filter-0.0.4.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
907bdd13096ebd66785b921c94824f0775d31de5a98ce1f88bdf30f16c06f6b1
BLAKE2b-256 checksum
How to use checksums
4dc8e287c47f58b0c51d97ea8403e5efd66c44fa2a27ec289665702d8027f67b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release files / Optimized_Kalman_Filter-0.0.4-py3-none-any.whl

Download URL Optimized_Kalman_Filter-0.0.4-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e960743689e4e4a5729d4c2937129f03d58de1f3a8b53c87ac9192b691937f4
BLAKE2b-256 checksum
How to use checksums
3246e4df59289a08005430a4f7dde2693410740df421644b5b985fa2500365b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release history Release notifications | RSS feed

0.0.9

1 release file

0.0.8

1 release file

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page