MMAE Filter Bank

needs documentation....

Example

from filterpy.kalman import MMAEFilterBank

pos, zs = generate_data(120, noise_factor=0.2)
z_xs = zs[:, 0]
t = np.arange(0, len(z_xs) * dt, dt)

dt = 0.1
filters = [make_cv_filter(dt), make_ca_filter(dt)]
H_cv = np.array([[1., 0, 0],
                 [0., 1, 0]])

H_ca = np.array([[1., 0., 0.],
                 [0., 1., 0.],
                 [0., 0., 1.]])


bank = MMAEFilterBank(filters, (0.5, 0.5), dim_x=3, H=(H_cv, H_ca))

xs, probs = [], []
for z in z_xs:
    bank.predict()
    bank.update(z)
    xs.append(bank.x[0])
    probs.append(bank.p[0])

plt.subplot(121)
plt.plot(xs)
plt.subplot(122)
plt.plot(probs)

Copyright 2015 Roger R Labbe Jr.

FilterPy library. http://github.com/rlabbe/filterpy

Documentation at: https://filterpy.readthedocs.org

Supporting book at: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python

This is licensed under an MIT license. See the readme.MD file for more information.

class filterpy.kalman.MMAEFilterBank(filters, p, dim_x, H=None)[source]

Implements the fixed Multiple Model Adaptive Estimator (MMAE). This is a bank of independent Kalman filters. This estimator computes the likelihood that each filter is the correct one, and blends their state estimates weighted by their likelihood to produce the state estimate.

References

Zarchan and Musoff. “Fundamentals of Kalman filtering: A Practical Approach.” AIAA, third edition.

Examples

..code:

ca = make_ca_filter(dt, noise_factor=0.6) cv = make_ca_filter(dt, noise_factor=0.6) cv.F[:,2] = 0 # remove acceleration term cv.P[2,2] = 0 cv.Q[2,2] = 0

filters = [cv, ca] bank = MMAEFilterBank(filters, p=(0.5, 0.5), dim_x=3)

for z in zs:
bank.predict() bank.update(z)
__init__(filters, p, dim_x, H=None)[source]

Creates an fixed MMAE Estimator.

Parameters:

filters : list of Kalman filters

List of Kalman filters.

p : list-like of floats

Initial probability that each filter is the correct one. In general you’d probably set each element to 1./len(p).

dim_x : float

number of random variables in the state X

H :

x

The estimated state of the bank of filters.

P

Estimated covariance of the bank of filters.

predict(u=0)[source]

Predict next position using the Kalman filter state propagation equations for each filter in the bank.

Parameters:

u : np.array

Optional control vector. If non-zero, it is multiplied by B to create the control input into the system.

update(z, R=None, H=None)[source]

Add a new measurement (z) to the Kalman filter. If z is None, nothing is changed.

Parameters:

z : np.array

measurement for this update.

R : np.array, scalar, or None

Optionally provide R to override the measurement noise for this one call, otherwise self.R will be used.

H : np.array, or None

Optionally provide H to override the measurement function for this one call, otherwise self.H will be used.