Wednesday, March 24, 2010

Kalman Filter in Python

The attached Kalman filter code is based on Python example found in book Kalman and Bayesian Filters in Python by Labbe. 

11 comments:

  1. Hi.. i was looking at the kalman filter code.. I was looking to use kalman filters to predict the next data point from a dataset, given n data points.. Is it possible to extend your code to do that?

    ReplyDelete
  2. Sure it is possible. Train the filter with n points, than "push" the filter to n+1 using the transition equations, one for hidden state x at n+1, the other for observation y at n+1.

    ReplyDelete
    Replies
    1. I'm getting some errors while doin this.. So i train it by initializing mu to my n-point array right?

      And then how do I push my filter to n+1?

      Delete
  3. The __main__ does it already. k.update trains with each data point. For pushing to n+1, look at the two main eqns of kalman filtering, one is time transition (for n+1) the other is observation (y_{n+1}). Once you have a \mu and a covariance, just apply the transition on x_n getting you a x_{n+1}

    ReplyDelete
  4. merhaba ,
    kalman filtreyi python'dak bir yazılıma adapte etmeye çalışıyorum ama başarılı olamadım.
    accx.plot( pos=(t, words[3]) )
    accy.plot( pos=(t, words[4]) )
    accz.plot( pos=(t, words[5]) )şeklinde 3 ayrı eksen için ivme bilgilerini çizdiriyorum. Altına birde bunların kalman filtresinden geçmiş şeklini çizdirmem gerekiyor fakat uyguladıklarım olmadı.
    Yardımcı olabilir misiniz ? oguzgora@yahoo.com

    ReplyDelete
    Replies
    1. Suradaki pdf belgeye de bir bakin

      https://github.com/burakbayramli/classnotes/tree/master/app-math-tr/filter

      her veri noktasini filtreye teker teker update ile gecmek lazim. kalman.py icinde bir __main__ var, orada ornegi gosteriliyor.

      Delete
  5. Hi,
    Your dropbox link is dead - if you still have the code is it at-all possible to repost it or send it directly to me please? I was looking to see your Kalman filter code from the above article in Python, since I'm been trying to port our Java implementation to Python, and it would really help.
    Thanks!
    Sam

    ReplyDelete