Coder Social home page Coder Social logo

rlabbe / filterpy Goto Github PK

View Code? Open in Web Editor NEW
3.2K 77.0 612.0 1.1 MB

Python Kalman filtering and optimal estimation library. Implements Kalman filter, particle filter, Extended Kalman filter, Unscented Kalman filter, g-h (alpha-beta), least squares, H Infinity, smoothers, and more. Has companion book 'Kalman and Bayesian Filters in Python'.

License: MIT License

Python 99.77% Shell 0.13% Batchfile 0.09%

filterpy's Introduction

FilterPy - Kalman filters and other optimal and non-optimal estimation filters in Python.

https://readthedocs.org/projects/pip/badge/?version=latest&style=flat

NOTE: Imminent drop of support of Python 2.7, 3.4. See section below for details.

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 I am developing in conjunction with my book Kalman and Bayesian Filter in Python, which you can read/download at https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/

My aim is largely pedalogical - I opt 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, I find it somewhat clearer to write a small set of equations using linear algebra, but numpy's overhead on small matrices makes it run slower than writing each equation out by hand. Furthermore, books such Zarchan present the written out form, not the linear algebra form. It is hard for me to choose which presentation is 'clearer' - it depends on the audience. In that case I usually opt for the faster implementation.

I use NumPy and SciPy for all of the computations. I have experimented with Numba and it yields impressive speed ups with minimal costs, but I am not convinced that I want to add that requirement to my project. It is still on my list of things to figure out, however.

Sphinx generated documentation lives at http://filterpy.readthedocs.org/. Generation is triggered by git when I do a check in, so this will always be bleeding edge development version - it will often be ahead of the released version.

Plan for dropping Python 2.7 support

I haven't finalized my decision on this, but NumPy is dropping Python 2.7 support in December 2018. I will certainly drop Python 2.7 support by then; I will probably do it much sooner.

At the moment FilterPy is on version 1.x. I plan to fork the project to version 2.0, and support only Python 3.5+. The 1.x version will still be available, but I will not support it. If I add something amazing to 2.0 and someone really begs, I might backport it; more likely I would accept a pull request with the feature backported to 1.x. But to be honest I don't forsee this happening.

Why 3.5+, and not 3.4+? 3.5 introduced the matrix multiply symbol, and I want my code to take advantage of it. Plus, to be honest, I'm being selfish. I don't want to spend my life supporting this package, and moving as far into the present as possible means a few extra years before the Python version I choose becomes hopelessly dated and a liability. I recognize this makes people running the default Python in their linux distribution more painful. All I can say is I did not decide to do the Python 3 fork, and I don't have the time to support the bifurcation any longer.

I am making edits to the package now in support of my book; once those are done I'll probably create the 2.0 branch. I'm contemplating a SLAM addition to the book, and am not sure if I will do this in 3.5+ only or not.

Installation

The most general installation is just to use pip, which should come with any modern Python distribution.

pip install filterpy

If you prefer to download the source yourself

cd <directory you want to install to>
git clone http://github.com/rlabbe/filterpy
python setup.py install

If you use Anaconda, you can install from the conda-forge channel. You will need to add the conda-forge channel if you haven't already done so:

::
conda config --add channels conda-forge

and then install with:

::
conda install filterpy

And, if you want to install from the bleeding edge git version

pip install git+https://github.com/rlabbe/filterpy.git

Note: I make no guarantees that everything works if you install from here. I'm the only developer, and so I don't worry about dev/release branches and the like. Unless I fix a bug for you and tell you to get this version because I haven't made a new release yet, I strongly advise not installing from git.

Basic use

Full documentation is at https://filterpy.readthedocs.io/en/latest/

First, import the filters and helper functions.

import numpy as np
from filterpy.kalman import KalmanFilter
from filterpy.common import Q_discrete_white_noise

Now, create the filter

my_filter = KalmanFilter(dim_x=2, dim_z=1)

Initialize the filter's matrices.

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

Finally, run the filter.

while True:
    my_filter.predict()
    my_filter.update(get_some_measurement())

    # do something with the output
    x = my_filter.x
    do_something_amazing(x)

Sorry, that is the extent of the documentation here. However, the library is broken up into subdirectories: gh, kalman, memory, leastsq, and so on. Each subdirectory contains python files relating to that form of filter. The functions and methods contain pretty good docstrings on use.

My book https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/ uses this library, and is the place to go if you are trying to learn about Kalman filtering and/or this library. These two are not exactly in sync - my normal development cycle is to add files here, test them, figure out how to present them pedalogically, then write the appropriate section or chapter in the book. So there is code here that is not discussed yet in the book.

Requirements

This library uses NumPy, SciPy, Matplotlib, and Python.

I haven't extensively tested backwards compatibility - I use the Anaconda distribution, and so I am on Python 3.6 and 2.7.14, along with whatever version of NumPy, SciPy, and matplotlib they provide. But I am using pretty basic Python - numpy.array, maybe a list comprehension in my tests.

I import from __future__ to ensure the code works in Python 2 and 3.

Testing

All tests are written to work with py.test. Just type py.test at the command line.

As explained above, the tests are not robust. I'm still at the stage where visual plots are the best way to see how things are working. Apologies, but I think it is a sound choice for development. It is easy for a filter to perform within theoretical limits (which we can write a non-visual test for) yet be 'off' in some way. The code itself contains tests in the form of asserts and properties that ensure that arrays are of the proper dimension, etc.

References

I use three main texts as my refererence, though I do own the majority of the Kalman filtering literature. First is Paul Zarchan's 'Fundamentals of Kalman Filtering: A Practical Approach'. I think it by far the best Kalman filtering book out there if you are interested in practical applications more than writing a thesis. The second book I use is Eli Brookner's 'Tracking and Kalman Filtering Made Easy'. This is an astonishingly good book; its first chapter is actually readable by the layperson! Brookner starts from the g-h filter, and shows how all other filters - the Kalman filter, least squares, fading memory, etc., all derive from the g-h filter. It greatly simplifies many aspects of analysis and/or intuitive understanding of your problem. In contrast, Zarchan starts from least squares, and then moves on to Kalman filtering. I find that he downplays the predict-update aspect of the algorithms, but he has a wealth of worked examples and comparisons between different methods. I think both viewpoints are needed, and so I can't imagine discarding one book. Brookner also focuses on issues that are ignored in other books - track initialization, detecting and discarding noise, tracking multiple objects, an so on.

I said three books. I also like and use Bar-Shalom's Estimation with Applications to Tracking and Navigation. Much more mathematical than the previous two books, I would not recommend it as a first text unless you already have a background in control theory or optimal estimation. Once you have that experience, this book is a gem. Every sentence is crystal clear, his language is precise, but each abstract mathematical statement is followed with something like "and this means...".

License

https://anaconda.org/rlabbe/filterpy/badges/license.svg:target:https://anaconda.org/rlabbe/filterpy

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.TION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

filterpy's People

Contributors

ateraz avatar ernstklrb avatar frolswe avatar gjacquenot avatar haditab avatar hajapy avatar icaven avatar igorinov avatar jasonmhead avatar jbradt avatar jonathanjfshaw avatar jpcms avatar kinodim avatar lucasb-eyer avatar mahmoudalmasri avatar msabramo avatar nh2 avatar paulolimac avatar pavelmk avatar phlogistique avatar prokhozhijj avatar rlabbe avatar sauravrt avatar slayoo avatar thatch avatar timhutton avatar veeresht avatar voutcn avatar zolabar avatar zougloub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

filterpy's Issues

Enhancement - check all matrices and sample y input in KalmanFilter.test_matrix_dimensions()

Currently it looks like test_matrix_dimensions only checks x, P, and Q. The docs indicate it checks the size of everything, which is misleading since it doesn't check F, H, R, or a sample input. I would prefer it to check all of those in such a way that the state of the filter is not altered. Running down mismatched sizes is one of my least favorite things to debug and it could be streamlined.

Said slightly differently, in order to fully check the size of inputs, you need to run it, but in order to run it you need to have (mostly) correct inputs, which results in some awkward circular logic.

I think the signature could be test_matrix_dimensions(sample_input=None), where if sample_input is supplied it is additionally checked. That would not change the previous api.

Thank you

Improve UKF documentation

If you look at the UKF.py file and read the comments it is impossible to figure out how to use the class. At a minimum, add a reference to my KF book, and add an example or two.

Covariance matrix not positive definite

For some reason, the covariance matrix in my system gets entries that are not positive definite.
Do you have any ideas on what may be causing this issue?

Thanks in advance!

Kalman filter G and u problems

  1. the predict() method takes in an optional parameter u instead of using KalmanFilter.u variable. There is no way to get the object's u to be used. This can be worked around if you are calling predict, but batch_filter will always ignore KalmanFilter.u.
  2. I have constrained G to be of a certain size depending on the dim_u parameter. However it is perfectly legal for G to be a scalar such as 1. The constraint should not be that G or u be of a specific size, but only that Gu is of the same size as the state vector. There is no reasonable way to constrain that in the setters, so let it go and accept that there will be an exception thrown in predict() if the user got it wrong.

Install behind proxy

I am trying to install filterpy behind a proxy. The security team will not allow it through the proxy. Any help is appreciated.

Using UKF for sensor fusion

Hi,

I'd like to use filterpy's UKF for sensor fusion. However I have two different measurement sources with different sizes, how can I setup the filter to make this work?

Thanks,
Carlos

How to use batch_filter, and rts_smoother for multiple sensors with different sampling rates

Thanks for this amazing library coupled with your very informative book. I am really grateful that you spent so much time making this great.

In you book you have an example of creating a filter that could handle measurements from two sensors with different sampling frequencies. The solution there was to create different R and H matrices depending on which sensor we have at a particular time.

My question is how we can do this but using the batch_filter, and rts_smoother functions? Is that already implemented in filterPy and I just missed that, or do you have a recommended way to implement this myself.

Thanks so much.

Best,

Brad

EKF predict, parameter u not used

In
https://github.com/rlabbe/filterpy/blob/7c3a683104e07d42f73e9a739a07549389cd67bf/filterpy/kalman/EKF.py

the predict function takes a parameter u
it fails to pass this forward to the predict_x function.

Starting on line 161:

 def predict(self, u=0):
      """ Predict next position.
      **Parameters**
      u : np.array
      Optional control vector. If non-zero, it is multiplied by B
      to create the control input into the system.
      """
      self.predict_x()
      self._P = dot3(self._F, self._P, self._F.T) + self._Q

Should read:

 def predict(self, u=0):
      """ Predict next position.
      **Parameters**
      u : np.array
      Optional control vector. If non-zero, it is multiplied by B
      to create the control input into the system.
      """
      self.predict_x(u)
      self._P = dot3(self._F, self._P, self._F.T) + self._Q

The use of u has not come up in the book, yet (to my knowledge).
(But when it does, this could be a confusing bug).

I could submit a pull request for this, but it seems a bit much for a single character change.

Implement CDKF

The central difference KF is a nice, alternative implementation of a sigma point filter that doesn't get enough love. It really needs to be part of the library.

invalid docstring for rts_smoother

The rts_smoother functions states that that F and Q are optional. They are not. Apparently docstring was taken from the class method,where they are optional.

Unit testing needs a lot of work

I mostly use graphs to 'eyeball' how things are working. Tthere are well known performance bounds, such as Cramer-Rao, for these filters. I need to think through what I want re unit testing and turn it into a PR. FilterPy also probably needs supporting functions - if I can turn a Cramer-Rao into a stand alone function it should be part of the general library, for example.

There are better bounds than Cramer-Rao, but they can be a bear to compute. Section 2.7 of Challa covers this to some extent.

It occurs to me that I don't test things like immutability of things like self.F. What if I force an exception - are things in a standard state? Etc. All pameter inputs need to be tested. And so on.

Anyway, it is time to think through a solid testing plan, set some reasonable standards for what tests must be done for any functionality, and then execute on at least some of it.

This is important - this was designed largely as a pedagogical tool, but Ph.D students are using it in their research, some companies are using it for there work - there are real-world consequences to bugs.

2 D measurements, 3 D state

first, thanks $1M for such an incredible book and set of tools - I had despaired of using Kalman filtering until I discovered them. Second, I am a lapsed C programmer, last active 10 years ago, and have been recently learning Python so as to use this library. Sorry if my inexperience is the cause of my issue.

I am trying to implement the following KF: dim x = 3 (pos, vel, acc), dim z = 2 (pos, acc) - (PS- tried to attach file but it failed):

x dim 3- spot, vel and acc,

z dim = 2, spot and acc

f = KalmanFilter (dim_x=3, dim_z=2)
f.x = np.array([[1.58], # init position
[0.01], # init velocity
[0.0]]) # init acceleration
f.F = np.array([[1.,1., 0.5], # 1, delta T, delta T^2/2 timestep = 1
[0.,1., 1.], # 0, 1, delta T
[0.,0., 1.]]) # 0, 0, 1
f.H = np.array([[1.,0., 0.], # dim_z by dim_x, i.e. 2 x 3
[0.,0., 1.]]) # measure position, and acc, but not vel
f.P = np.array([[1.,0., 0.], # covariance dim_x dim_x, i.e. 3 x 3
[0.,1., 0.],
[0.,0., 1.]])
f.R = np.array([[1.,0.], # measurement noise dim_z dim_z, i.e 2 x 2
[0.,1.]])
f.B = 0 # no control inputs
f.Q = Q_discrete_white_noise(dim=3, dt=1, var=0.5)

my measurements are stored in a .csv file as follows:
pos1, acc1,
pos 2, acc2,
etc

it actually runs for one cycle, then gives a dimensional error. the first estimate is quite incorrect
Thanks for any guidance

Problem while implementing Kalman Filter

Hi, I have created a dictionary of Kalman Filters. I'm having an issue in the update function.
AssertionError: shape of z should be (), but it is (1,)
I have a 1D Kalman Filter, here it is the declaration.

K = KalmanFilter (dim_x=1, dim_z=1)
#State space model used
K.F= np.array([1.])
 #Initial State
K.x=np.array([-60.])                          
#Measurement Matrix                         
K.H=np.array([1.])
#Covariance Matrix
K.P=np.array([10.])
#Process Noise          
K.Q=np.array([20.])                              
#Measurement Noise
K.R=np.array([0.002])
#Add KF to the dictionary when a new UUID is detected
KF_dict.update({data:K})

Hope you can help me, thanks.

Typo in discretization.py

Hello,

There is a typo in function Q_continuous_white_noise, line 82 of file discretization.py. The term (dt**4)/3 should instead read (dt**3)/3.

Refactor unit tests for UKF

I've made a few changes to the UKF code that changed the API; the tests no longer run. Fix the tests and (of course) make sure the UKF is still producing correct results.

rts smoother

First of all, thank you for sharing such great work, in which i learnt a lot from it!

so, in kalman_filter.py file, line 374, i saw that you have
P[k] += dot3(K[k], P[k+1]-P_pred, K[k].T)

however, from Simon's book p294, equation (9.138), there's actually a minus sign. Thus i'm suspecting that line 374 should actually be
P[k] -= dot3(K[k], P[k+1]-P_pred, K[k].T)

Can you please verify?

UKF.batch_filter doesn't use all parameters

residual and UT are not used. This needs to be either expanded to include all options, or just do the default implementation - there is little value in this function anyway since you can just call predict and update yourself.

multivariate_gaussian incorrect if covariance not np.array

stats.multivariate_gaussian(x,mu,cov) silently gives the wrong value if cov is, e.g., a list of lists instead of a numpy array. The failure occurs during the call to _to_cov where the covariance should be checking whether x is a scalar, but is instead checking whether it is not an np.array.

This problem demonstrates itself in the 05-Multivariate-Gaussians chapter of your book, where putting in a non-diagonal covariance for the 3-d plot gives an orthogonal rather than slanted gaussian. Changing the covariance list-of-lists to an np.array fixes the problem.

Example:

import numpy as np
from filterpy import stats
from scipy.stats import multivariate_normal
np.set_printoptions(precision=3)
mean=(0,0)

cov=[[1,.5],[.5,1]]
print("For list and np.array covariances:")
for covariance in (cov,np.asarray(cov)):
    a = [[stats.multivariate_gaussian((i,j),mean,covariance)
          for i in (-1,0,1)]
         for j in (-1,0,1)]
    print(np.asarray(a))
    print()

Gives two different results for the datatypes of the covariance:

For list and np.array covariances:
[[ 0.059  0.097  0.059]
 [ 0.097  0.159  0.097]
 [ 0.059  0.097  0.059]]

[[ 0.094  0.094  0.025]
 [ 0.094  0.184  0.094]
 [ 0.025  0.094  0.094]]

No posterior estimator for IMMEstimator?

Hi,
After carefully reading your source code for IMMEstimator class in filterpy.kalman, my understanding is that after running the update() function,
self.x = \hat{x_{k+1|k}}, that is, the prediction(prior estimate) for time k+1 at time t. This is also the case for each individual filter.
I wonder what if i want to get \hat{x_{k|k}}, i.e., the posterior estimate of x, as well as P, at time k ?

off-by-one error for Fs/Qs index in kalman_filter.rts_smoother

The key update equations in the current implementation is

        P_pred = dot3(Fs[k], P[k], Fs[k].T) + Qs[k]

        K[k]  = dot3(P[k], Fs[k].T, linalg.inv(P_pred))
        x[k] += dot (K[k], x[k+1] - dot(Fs[k], x[k]))
        P[k] += dot3 (K[k], P[k+1] - P_pred, K[k].T)

I am using this in a situation where the Fs is time varying and I noticed that the smoother results is much worse than filtering. Eyeballing the results of the filter and smoother, it looks like an off-by-one problem in the Fs.

Comparing with the equations in Wikipedia https://en.wikipedia.org/wiki/Kalman_filter#Rauch.E2.80.93Tung.E2.80.93Striebel the correct implementation should use Fs[k+1] and Qs[k+1]

        P_pred = dot3(Fs[k+1], P[k], Fs[k+1].T) + Qs[k+1]

        K[k]  = dot3(P[k], Fs[k+1].T, linalg.inv(P_pred))
        x[k] += dot (K[k], x[k+1] - dot(Fs[k+1], x[k]))
        P[k] += dot3 (K[k], P[k+1] - P_pred, K[k].T)

To compute P_pred based on P[k] we should be using Fs[k+1] and Qs[k+1], similar for X_pred should be computed from x[k] using Fs[k+1].

Kalman .update throwing type error with 'allow_singular' argument with scipy 0.14

Hello,

I am working with python 2.7 on Windows 64 bit. I have scipy 0.14, filterpy 0.14, and numpy 1.11.1 installed.

As expected, in 0.14 Scipy, there is no 'allow_singular' keyword.

https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.multivariate_normal.html

TypeError Traceback (most recent call last)
in ()
88 filt_AngularVelocity.append(kalman['ang'].predict)
89 print image_center[-1][0]
---> 90 kalman['x'].update(float(image_center[-1][0]))
91 kalman['y'].update(float(image_center[-1][1]))
92 kalman['ang'].update(AngularVelocity[-1])

C:\Python27\lib\site-packages\filterpy\kalman\kalman_filter.pyc in update(self, z, R, H)
203 flatz = np.asarray(z).flatten()
204 self.log_likelihood = multivariate_normal.logpdf(
--> 205 flatz, mean, cov=S, allow_singular=True)
206
207

TypeError: logpdf() got an unexpected keyword argument 'allow_singular'

Sphinx doesn't use NumPy's docstrings

I use NumPy's documentation standard, but Sphinx does not support it by default. There is a package numpydoc which is supposed to add hooks to support it. I installed it with PIP but saw no change. Haven't had a chance to investigate.

To be clear, things like

Parameters

does not render properly in the documentation.

UKF and scaled UKF are not consistent with each other

Different methods are implemented (e.g. scaled does not implement batch_filter), different parameterizations, and so on. They should be made as consistent as possible.

Once that is done, the documentation should make it clear that the scaled version is the preferred implementation as it incorporates all of the most recent research on the algorithm. UnscentedKalmanFilter is mostly for pedagogical purposes.

conda install issue

I am on a Mac version 10.11.6 . This is the output of running your conda command:

Phil@MacBook-Pro~/anaconda/envs $ conda install -c rabbi filterpy
Fetching package metadata: ......
Solving package specifications: .
Error:  Package missing in current osx-64 channels: 
  - filterpy

You can search for this package on anaconda.org with

    anaconda search -t condo filterpy

Problems with PIP

I put this here so other people can find it.
I, like I suspect many other people uploaded the Anaconda distribution of Python as the easiest option to read the book. I already had a version of Python. I am running Windows 7.
All went well and everything worked until I tried to install filterpy on to my original Python setup.
Of course PIP was now “pointing” at the Anaconda version and despite Googling and asking a question on Stackoverflow I still do not know how this works and how you change it.
I had a rather old version of 2.7 so I decided to upgrade it (to 2.7.10) so I knew for certain that it had PIP installed. That worked but now I could not get at the notebook by typing “ipython notebook” as it now looks at the 2.7.10 version for what it needs.
My next great idea to sort this was to try and use pip2.7 and pip3.4 by reloading Anaconda but installing 3.4 rather than the 2.7 version that is the default. Pip2.7 works but there does not seem to be a version pip3.4 or at least I keep getting a response that the command is not recognized.
You might think that the pip would point to the latest installed version ie the Anaconda but for some unknown reason it still pointed to the 2.7.10 version. I therefore could not install filterpy in the Anaconda version.
The solution to all this is that I found that in the Anaconda folder there is an Anaconda Command Prompt which I got to from the Start Menu. Working in that pip works and finds the Anaconda version of Python and you can do ipython notebook although I now find the simplest way to start is to use the Anaconda graphical start up, choose ipython and navigate to the directory. Typing in that long directory name is a pain.
Why do I keep two versions of Python? Eell partly because I am an old foggy and have not yet got used to programming with iPython but also because my robot has a small Rpi in charge and I want to have a version the same as is on that.

Tests not distributed with pip install

I don't know if this contravenes any standard practice, but I would like it if you do 'pip install filterpy' that all of the unit tests get installed as well. They are extremely useful to use as examples/references.

AttributeError: 'int' object has no attribute 'T'

I'm trying to get started implementing a Kalman Filter using filterpy, using code from the readme:

kf = KalmanFilter(dim_x=2, dim_z=1)
kf.x = np.array([[x],[0.]])       # initial state (location and velocity)
kf.F = np.array([[1.,1.], [0.,1.]])    # state transition matrix
kf.H = np.array([[1.,0.]])    # Measurement function
kf.P *= 1000.                 # covariance matrix
kf.R = 5                      # state uncertainty
kf.Q = Q_discrete_white_noise(2, dt, .1) # process uncertainty

Then later

kf.predict()
kf.update(x)

Then I get this error when invoking predict:

Traceback (most recent call last):
  File "drone/test_predict.py", line 102, in <module>
    main()
  File "drone/test_predict.py", line 73, in main
    kf.predict()
  File "/Users/alex/.virtualenvs/ddc/lib/python2.7/site-packages/filterpy/kalman/kalman_filter.py", line 416, in predict
    self._P = self._alpha_sq * dot3(F, self._P, F.T) + Q
AttributeError: 'int' object has no attribute 'T'

Fixed lag smoother not correct

I don't believe the formulation of the fixed lag smoother is correct. I implemented the equations in Dan Simon's book and the performance is much better.

It needs to be tested and then checked in. It doesn't save the smoothed results so that has to be fixed. And then the batch version has to be corrected as well.

To the reader: I don't think the current implementation will break, it is just far from optimal. Still, you may want to steer clear for now.

MerweScaledSigmaPoints weights do not sum to 1, documentation says it should

For example:

import numpy as np
from filterpy.kalman import MerweScaledSigmaPoints as SigmaPoints

sigma_points = SigmaPoints(n=9, alpha=0.001, beta=2, kappa=-6)
Wm, Wc = sigma_points.weights()
print np.sum(Wm)
print np.sum(Wc)

Which returns

1.0000000005238689
3.9999990007490851

While Wm is small enough to be rounding error, Wc seems to go against notes in the documentation. Now, I'm not saying MerweScaledSigmaPoints is set wrong -- as far as I can tell all the equations are right. However, the book and documentation both say that Wc "must sum to 1".

So what's the deal?

kalman filter P update

in file kalman_filter.py, line 174-176, you implemented the following ...
174 # P = (I-KH)P(I-KH)' + KRK'
175 I_KH = self._I - dot(K, H)
176 self._P = dot3(I_KH, P, I_KH.T) + dot3(K, R, K.T)

this is mathematically correct, yet line 176 could be further reduced to ...
self._P = dot(I_KH, P)

because (cf. Simon's book p128, eq 5.16)
P = (I-KH)P(I-KH)' + KRK' = (I-KH)P

No example for use of EKF

Hi,

I wanted to use your EKF for a project of my own, but I cannot figure out how to set the variables and matrices, because there is no example provided.

EKF update equation

Hi,

I'm using your library to work on a research project. When I used EKF, I found that the equation for updating P (covariance matrix) is not as same as it should be. I'm wondering if there is a specific reason to do that which updates P with R. Here is the code used in this both update() and predict_update().
I_KH = self._I - dot(K, H)
self._P = dot3(I_KH, P, I_KH.T) + dot3(K, R, K.T)
However, according to the theory of EKF. It should be like this.
self._p = dot(I_KH, P)
Please let me know if I'm wrong. Thx!
picture1

UKF Different Updates

Is there an example of a filter taking in different measurements at different times? Does the library support this feature? It seems that the UKF in particular does not support this. It would improve the usefulness of the library.

Wrong weights used in UnscentedKalmanFilter.rts_smoother

Hi Roger,

First of all, thanks for the book and filterpy. Both are awesome!

I believe I found a bug in the rts_smoother method of UnscentedKalmanFilter.
In the code you use mean weights for both mean and covariance which is obviously wrong.

On line 519 of UKF.py
Pb += self.Wm[i] * outer(y, y)
should be
Pb += self.Wc[i] * outer(y, y)

Similarly, on line 527
Pxb += self.Wm[i] * outer(z, y)
should be replaced with
Pxb += self.Wc[i] * outer(z, y)

See this paper for more details https://users.aalto.fi/~ssarkka/pub/uks-preprint.pdf
The bug is not obvious as in many applications the weights are close.

Regards,
Roman

Particle Filters

In the particle filter notebook - code block 10 i.e the update function, you're getting rid of the prior every time by filling the weights with 1. Is this on purpose or have I misunderstood something?

Comments for filterpy.stats.multivariate_multiply()

In the method signature, comments for parameter c1 and c2 currently say they are the means of the respective Gaussian. Should they not be covariance instead?

Happy to start a PR if that's the case.

Thanks.

UKF does not support missing data as 'None'

In the doc string to UnscentedKalmanFilter.batch_filter, it states to represent missing data as None. However, this fails in the update step with a type multiply error; there appears to be no code to handle this case. In the standard KalmanFilter.update, there is a simple return statement if z is None.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.