# 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)

  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.

  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 Measurement matrix
  Attributes:
    x numpy.array(dim_x, 1)

      Current state estimate. Any call to update() or predict() updates this variable.

    P numpy.array(dim_x, dim_x)

      Current state covariance matrix. Any call to update() or predict() updates this variable.

    x_prior numpy.array(dim_x, 1)

      Prior (predicted) state estimate. The *_prior and *_post attributes are for convienence; they store the prior and posterior of the current epoch. Read Only.

    P_prior numpy.array(dim_x, dim_x)

      Prior (predicted) state covariance matrix. Read Only.

    x_post numpy.array(dim_x, 1)

      Posterior (updated) state estimate. Read Only.

    P_post numpy.array(dim_x, dim_x)

      Posterior (updated) state covariance matrix. Read Only.

    z ndarray

      Last measurement used in update(). Read only.

    filters list of Kalman filters

      List of Kalman filters.

  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)

  Also, see my book Kalman and Bayesian Filters in Python https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python

  __init__(filters, p, dim_x, H=None)
  predict(u=0)

    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)

    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.