8 ms·
Kalman Filter
- successman 6y agoIt is well
- fcn 6y agoKalman filter for the win
- 6gvONxR4sf7o 6y agoThe tl;dr of a Kalman filter is - you have observations that are normally distributed around a linear function of an unknown state - you have some state update function where the next state is normally distributed around a linear function of the unknown current state - your beliefs about your initial state are normally distributed then a kalman filter will update your beliefs about the state of your system and do as good a job as could be hoped for. There are also simple generalizations that relax some of those assumptions. This is one of those algorithms that anyone working with data should know. It answers the dynamical question of wtf is going on now, given what I’ve seen over time.
- a-dub 6y ago- because linearity, your observations can come from more than one distribution. (multiple sensors of different measurements with linear relationships between them)
- deleted 6y ago[deleted]
- magicalhippo 6y agoSome Kalman filter links I found useful How a Kalman filter works, in pictures https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/ https://www.bzarg.com/p/how-a-kalman-filter-works-in-picture... Derive yourself a Kalman filter https://ngr.yt/blog/kalman/ https://ngr.yt/blog/kalman/ Kalman and Bayesian Filters in Python https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Pyt...
- klintcho 6y agoA lot of great links here, and other top answers. The one series that finally made me grasp kalman filters was https://www.youtube.com/playlist?list=PLX2gX-ftPVXU3oUFNATxGXY90AULiqnWT https://www.youtube.com/playlist?list=PLX2gX-ftPVXU3oUFNATxG... from Michel van Biezen, awesome explanations step by step.
- skzv 6y agoIn many circumstances, particles filters are superior. Two major advantages off the top of my head are the ability to track multi-modal distributions (Kalman filters only track one peak) and apply non-Guassian likelihoods (Kalman filters assume Gaussian noise, while you can weight particles in a particle filter using any kind of distribution). Particle filters do come at a cost of increased memory and processing usage. You need to propagate N particles at each epoch, each of which could have M dimensions of state (position, velocity, orientation, etc). So Kalman filters are likely preferred where memory and compute are at a premium.
- kgarten 6y agoOften alterations of the Kalman filter are a good compromise. E.g. the extended Kalman https://en.m.wikipedia.org/wiki/Extended_Kalman_filter https://en.m.wikipedia.org/wiki/Extended_Kalman_filter As you stated particle filters are computationally expensive. Also I found them more fidgety to configure for my application cases (in activity recognition).
- gugagore 6y agoHave you heard of the "Unscented Kalman Filter"? It goes by UKF. It uses a different approximation scheme than the EKF, which creates a linear approximation of the dynamics, in order to propagate the mean and variance. The UKF computation using "sigma points" resembles a specific part of the particle filter. And why the name? Well the EKF stinks in many applications (it diverges). The UKF is more robust, especially when there is more significant uncertainty.
- The_rationalist 6y agoMicrosoft made chromium inputs use a kalman filter
- dataflow 6y agoDo you have a link to more reading on this?
- The_rationalist 6y agoI don't remember well but I found back this link https://chromium-review.googlesource.com/c/chromium/src/+/1822657 https://chromium-review.googlesource.com/c/chromium/src/+/18...
- ckardat123 6y agoThere's a good description of how to build a trading strategy using a Kalman Filter along with some code examples in Ernest P. Chan's book on algorithmic trading. I think it might be available for free online, although that might have just been something I was able to access through my university. I feel like I owe it a shoutout because that strategy was the foundation for an algorithm that got me and a couple friends a top finish at UChicago's algo trading competition a few years back.
- monocasa 6y agoIf you'd like to read a very applied example of kalman filters, there's this great article about using them to improve wiimote positioning. https://www.gamasutra.com/view/feature/129919/wheres_the_wiimote_using_kalman_.php https://www.gamasutra.com/view/feature/129919/wheres_the_wii...
- repsilat 6y agoOne thing I wonder (maybe not a sensible question, I haven't really thought it through): A Kalman filter update is superficially like a HMM Forward Algorithm step, right? You have some belief, you have a new observation, and you have some new belief after. Are there similar equivalences with other HMM algorithms for different questions? A Viterbi-like algorithm for the most likely path, for example, distinct from the series of Kalman-update argmaxes?
- a-dub 6y agoi've always just thought of kalman filters as continuous time/space equivalents of hmms, replacing multinomials with gaussians. so yeah, you can do things like e-m to learn the parameters of the observation and state update models from data (just like fitting an hmm in the fully observed case), or given state and observation models, and past observations you can predict future state given current state. (what it was made for, where state is the state of your rocket given the physics of motion and all the noisy sensors or whatever, which if you think about it is like a viterbi search for the best fitting path through the continuous state space)
- gugagore 6y agoThe connection you are drawing is not incorrect in my opinion. But perhaps I can clarify. The dynamics model in a KF is a linear system with an input and and output (often denoted u and y respectively). A Hidden Markov Model typically does not have an input. There is an initial state, and then the system transitions "autonomously" (that's a term I'm borrowing from differential equations). An "Markov model" with input is called a Markov Decision Process (MDP). And if the state of the system is not fully observable, then it's a POMDP. So Kalman filters are most analogous to "belief updates" in POMDPs. The KF takes into account the known input to the system.
- xfs 6y agoThese are all unified as different modes of message passing in probabilistic graphical models. Kalman filters are indeed structurally similar to an HMM without the backward message passing step if viewed as a PGM.
- EA 6y agoKalman Filter Simulation: https://www.cs.utexas.edu/~teammco/misc/kalman_filter/ https://www.cs.utexas.edu/~teammco/misc/kalman_filter/
- dang 6y agoIf curious, past submissions/threads: How a Kalman filter works, in pictures - https://news.ycombinator.com/item?id=23943836 https://news.ycombinator.com/item?id=23943836 - July 2020 (27 comments) Corona virus spread prediction using kalman filter - https://news.ycombinator.com/item?id=22578235 https://news.ycombinator.com/item?id=22578235 - March 2020 (2 comments) Kalman Filter Simulation - https://news.ycombinator.com/item?id=21709534 https://news.ycombinator.com/item?id=21709534 - Dec 2019 (1 comment) Derive Yourself a Kalman Filter - https://news.ycombinator.com/item?id=19894776 https://news.ycombinator.com/item?id=19894776 - May 2019 (55 comments) How a Kalman filter works, in pictures (2015) - https://news.ycombinator.com/item?id=17116149 https://news.ycombinator.com/item?id=17116149 - May 2018 (34 comments) Reduce GPS data error on Android with Kalman filter and accelerometer - https://news.ycombinator.com/item?id=16627111 https://news.ycombinator.com/item?id=16627111 - March 2018 (30 comments) Quick explanation of how a Kalman filter works - https://news.ycombinator.com/item?id=16575679 https://news.ycombinator.com/item?id=16575679 - March 2018 (76 comments) Unscented Kalman Filter (UKF) C Library - https://news.ycombinator.com/item?id=15986880 https://news.ycombinator.com/item?id=15986880 - Dec 2017 (2 comments) How a Kalman filter works, in pictures (2015) - https://news.ycombinator.com/item?id=13449229 https://news.ycombinator.com/item?id=13449229 - Jan 2017 (32 comments) How a Kalman filter works, in pictures - https://news.ycombinator.com/item?id=12648724 https://news.ycombinator.com/item?id=12648724 - Oct 2016 (1 comment) Kalman Filter via a Simple and Intuitive Derivation [pdf] - https://news.ycombinator.com/item?id=12648035 https://news.ycombinator.com/item?id=12648035 - Oct 2016 (24 comments) The magic of the Kalman filter, in pictures - https://news.ycombinator.com/item?id=10042050 https://news.ycombinator.com/item?id=10042050 - Aug 2015 (48 comments) Kalman Filter Simulator - https://news.ycombinator.com/item?id=7878474 https://news.ycombinator.com/item?id=7878474 - June 2014 (1 comment) SideCar's Kalman Filter models San Francisco brunch - https://news.ycombinator.com/item?id=7349419 https://news.ycombinator.com/item?id=7349419 - March 2014 (14 comments) How to build an Anti Aircraft Missile: Bayes’ Theorem and the Kalman Filter - https://news.ycombinator.com/item?id=6657301 https://news.ycombinator.com/item?id=6657301 - Nov 2013 (15 comments) Using A Kalman Filter To Make Sense Of Noisy Data - https://news.ycombinator.com/item?id=3950510 https://news.ycombinator.com/item?id=3950510 - May 2012 (18 comments) Poor Man's Explanation of Kalman Filtering [pdf] - https://news.ycombinator.com/item?id=1362597 https://news.ycombinator.com/item?id=1362597 - May 2010 (11 comments) Others?
- bfrog 6y agoI've always wanted to deeply, fundamentally understand a kalman filter, but I usually get lost in the math notation that comes up without the plain language explanation of what that math means.
- jvanderbot 6y agoThe only way is to derive it. The KF maximizes the likelihood of the observations.. You can easily form the optimization problem, "what state x maximizes the likelihood of my observations z". I had a writeup to this effect in my class notes from Prof Roumeliotis' class. I'll see if I can post it, but you could probably derive it following the KF wiki page.
- _Microft 6y agoAsk me a question or two about particular math notations and I will try to answer it. I'll just go ahead and explain indices and summation in the meantime already because these are so super-common that you basically cannot read math things without knowing them. I will denote things LaTeX-like, that is subscript with _ and superscript with ^, if multiple things go in there, they will be enclosed in {}. --- First: indices, usually written as sub-script, are super-common. They might be separated by a comma if there are more than one (but they do not have to be. In that case, you need to check which variables make sense as indices.) Usually variables are just single letters and not superWordyDescriptionsOfThingsBecauseCodeCompletionIsDifficultWithPenAndPaper. Examples: a_i is like a[i] m_{ij} is element at position i, j in matrix M, i.e. ~ M[i][j] --- Summation is also very common, denoted via symbol Σ . That's the upper-case greek letter "sigma". This one will have a few things accompanying it: below it is a variable name and most likely an assignment of a value to it. That's the first value that the variable will take. Above, the last value the variable should have. The expression behind the symbol is evaluated for each of these values and all integers in between and summed up. (It might also appear with just the varaible name below it, in which case it means: sum over all values of the variable). Example: Summing up the squares of all integers from 3 to 6 Σ_{i=3}^6 i^2 (Properly rendered here: https://wikimedia.org/api/rest_v1/media/math/render/svg/a60f7e2cea126d44723cff96cdc6cc57316224d1 https://wikimedia.org/api/rest_v1/media/math/render/svg/a60f... ) Pseudocode for this is: for(i = 3; i <= 6; i++) sum += i^2 --- Multiplication: there is also a similiar one for multiplication that I will include because it is so easily explained when having discussed summation already. It's denoted by the greek upper-case letter Π (Pi) Π works like Σ but the results of the expressions are multiplied instead. Example: Π_{i=3}^6 i^2 = 3^2 * 4^2 * 5^2 * 6^2 Pseudocode: for(i = 3; i <= 6; i++) product *= i^2 This is only meant to help you translate a few formulas into forms you might easier work with. Following a university math course for a single semester or maybe two might get you a long way as well.
- etaioinshrdlu 6y agoI’m pretty sure you can see this in action if you open the maps app on your phone and walk around outside. GPS measurements with uncertainty are periodically combined with accelerometer data to produce a better real time position estimate.
- djmips 6y agoOne of the first practical applications (AFAIK) of the Kalman filter was the in the IMU loop in the Apollo Guidance Computer. https://web.mit.edu/digitalapollo/Documents/Chapter6/hoagprogreport.pdf https://web.mit.edu/digitalapollo/Documents/Chapter6/hoagpro... "These simulations used 36-bit floating point arithmetic, which was adequate for trajectory simulations but marginal for implementing the Riccati equation solution for the measurement updates in the Kalman filter. Performance was not reliable in 36-bit floating point arithmetic, and the Apollo flight computer would have to implement the Kalman filter in 15-bit fixed-point arithmetic. Microprocessors were still a long way off. J.E. Potter was at that time a graduate student in mathematics at MIT, working part time at the Instrumentation Laboratory on the Apollo Project. He took the problem home with him one Friday afternoon and arrived back on Monday with a solution. The trick was to use a Cholesky factor of the covariance matrix as the dependent variable in an equivalent Riccati equation. The solution was brilliant, and the improvement was profound. The approach came to be called square-root filtering, and alternative implementations of square-root filters with better numerical stability were soon discovered." excerpted from: https://www.researchgate.net/profile/Mohinder-Grewal/publication/224138621_Applications_of_Kalman_Filtering_in_Aerospace_1960_to_the_Present_Historical_Perspectives/links/56aa3b4308ae7f592f0f2af7/Applications-of-Kalman-Filtering-in-Aerospace-1960-to-the-Present-Historical-Perspectives.pdf https://www.researchgate.net/profile/Mohinder-Grewal/publica...
- dosshell 6y agoYes, the KF was developt for the Apollo project by Kalman. As input in the update steps they used the IMU and the astronauts had to manually measure angles to specific stars. Almost like old sea travelers!
- abecedarius 6y agoThis makes me wonder if KFs could've been a practical improvement for navigation in the age of sail.
- dmh2000 6y ago"The trick was to use a Cholesky factor of the covariance matrix as the dependent variable in an equivalent Riccati equation. " I'm going to use that as my next pickup line
- adipandas 6y agoMy implementation of kalman filters: https://adipandas.github.io/multi-object-tracker/includeme/apidocuments.html#kalman-filters https://adipandas.github.io/multi-object-tracker/includeme/a...
- ephimetheus 6y agoKaiman filtering is frequently used in high energy physics particle tracking. For inhomogeneous magnetic fields, the transport isn’t linear though, so we pair it with 4th order Runge-Kutta for state and covariant propagation. Works pretty well and is typically faster than the alternatives.
- ur-whale 6y agoIt's worth noting that unlike KF and particle filters, none of the deep learning stuff that's making headlines these days is actually capable of properly modeling / simulating / approximating a dynamic system with a continuous time variable. Most striking in deep learning, is that when all is said and done (i.e. unwrapping the so-called "recurrent" part of a deep net) all you're left with is a dumb function from Rn to Rp. In other words, while the term "recurrent" might fool you into believing it, there isn't any actual feedback loop in deep nets, and they therefore can't properly model something whose output evolves over time. I think there's something to be explored in adding actual feedback into deep nets. The price is of course that the output is not a vector anymore: you must compute feed forward passes until the net "settles" to a fixed point or rather until the desired behavior is observed at the outputs. Backprop also becomes a whole new game in that setting. [EDIT]: but the prize is: your deep net, instead of being an approximation of a function from Rn to Rp, becomes an approximation of something that can transform a function into another function.
- omrjml 6y agoRegarding dynamical systems, Neural ODEs hold promise as they are more analogous to the numerical solvers. I think with any dynamical system, purely data driven approach can be problematic because, as you say, the standard NN architectures are not great for it. You can however add physical constraints, e.g. minimize the Lagrangian as the objective function, to bring stability to these NN emulators.
- pgt 6y agoNeural macros? :)
- sdenton4 6y ago"therefore can't properly model something whose output evolves over time." I dunno, WaveNet seems to work pretty good... It's an autoregressive model, and absolutely responds to it's own output. https://deepmind.com/blog/article/wavenet-generative-model-raw-audio https://deepmind.com/blog/article/wavenet-generative-model-r...
- blueblimp 6y ago
- 082349872349872 6y agoLearning about Kalman Filters' deduced-reckoning-like combination of external observation with internal model gave me an idea about the origin of consciousness: https://news.ycombinator.com/item?id=23475069 https://news.ycombinator.com/item?id=23475069
- djmips 6y agoInteresting thoughts. When looking at your link which links to Shannon-Mind-Reading machine I immediately think of several things. One: branch prediction. The mind-reading machine seems a lot like a branch predictor. Two: I used this type of algorithm for a baseball game I wrote when writing the pitching /batting 'AI'. - In fact I stole it from the Intel hardware manual. Three: Rock Paper Scissors - people who are good at Rock Paper Scissors , I feel, use some type of prediction based on your tendencies and tells. Like the dog you mention... There's more in this deep well but I'll stop there.
- fn1 6y agoHere are two good resources for the Kalman Filter: https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/ https://www.bzarg.com/p/how-a-kalman-filter-works-in-picture... https://www.kalmanfilter.net/default.aspx https://www.kalmanfilter.net/default.aspx
- vzaliva 6y agoMany people do not realize that then they move their mouse cursor around the screen its trajectory is most likely smoothed with Kalman filter.
- em500 6y agoThe Kalman Filter is a beautiful algorithm, probably among the top math algorithms of the 20th century. It gives a very fast solution to a specific optimization problem (optimal estimation of hidden/indirectly observed states in a linear dynamic system). But for practitioners, the computations and derivations are far less relevant than recognising the circumstances where state space / Kalman model are relevant/appropriate, and how to set up such a model (defining the transition and observation matrices of the model). In this sense, the Kalman Filter in time-dynamic prediction/forecasting problems is like gradient descent in ML prediction problems, or the solution to the Normal equations in linear regression or FFT for discrete Fourier transforms. The algorithms are mathematical pieces of art, but the useful practical skills are how to set up your problems so that they're amendable to the solutions. In case of Kalman / state space models, the main things that are estimated are positions of things that move in time, but not (directly) observed. These "things" can be concrete (drones, rockets in space, robots on Mars) or abstract (an idealized compuer cursor/pointer, the water level in a river, inflation or unemployment in macro-economics). When concrete "things" are estimated by traditional engineers and the dynamics are governed by physics, the tool of choice is usually (employer-paid) Matlab. For fuzzier economics and forecasting problems, nowadays there's a very good state space / Kalman Filter implementation in Python statsmodels by Chad Fulton[1], which closely follows the academic works from Harvey, Durbin and Koopman. The challenge in these problems is usually setting up a plausible underlying dynamics model, more so than the estimation/prediction part. Just like in linear regression, finding appropriate features and functional forms are the main practical challenge, not calculating the parameters and actual predictions. [1] http://www.chadfulton.com/fulton_statsmodels_2017/sections/1-introduction.html http://www.chadfulton.com/fulton_statsmodels_2017/sections/1...
- alkonaut 6y agoI made a tiny paper for a masters thesis on KF for recurrent neural network training in 2002. 15 or 20 Neurons (a recurrent layer of a handful of neurons) was massive in terms of the compute time needed to train it. To even get it off the ground we had to rewrite all the matlab into C++. Recurrent networks for modeling dynamic systems where all the rage they but I haven’t really kept track of where the field went. Did the deep learning revolution completely drop recurrent connections?
- mjburgess 6y agoThey became a major phenomenon in NLP (ie., sequences of text strings) -- but have since been less prominent. RNNs are still a significant part of the toolbox, and would be found in several chapters in any applied NN book.
- danans 6y agoLast I heard, KFs are still essential for simultaneous localization and mapping (SLAM) applications.
- oli5679 6y agoCan this be used for rating systems in a game?
- jschveibinz 6y agoA simple way to ease into understanding Kalman filters through experimentation is to implement a simpler alpha-beta prediction filter. Here is the link to the Wikipedia article to get started: https://en.m.wikipedia.org/wiki/Alpha_beta_filter https://en.m.wikipedia.org/wiki/Alpha_beta_filter
- jschveibinz 6y agoAnd here is a link to an easy to read article on using Kalman filtering in a navigation application: https://towardsdatascience.com/kalman-filter-an-algorithm-for-making-sense-from-the-insights-of-various-sensors-fused-together-ddf67597f35e https://towardsdatascience.com/kalman-filter-an-algorithm-fo...
- dataflow 6y agoThe Kálmán filter landed us on the moon. https://www.cs.unc.edu/~welch/kalman/siam_cipra.html https://www.cs.unc.edu/~welch/kalman/siam_cipra.html
- londons_explore 6y agoKalman filters require that observed variables have Gaussian distributions. Frequently this isn't the case. Lots of real world systems have more complex distributions, like for example "which lane of a highway am I in given this GPS position" (it's likely you are in one of the lanes, but possible although unlikely I am between lanes). Particle filters use more computation than kalman filters, but they can deal with arbitrary (and unknown) distributions of variables. Considering very few applications of this kind of system are limited by compute power, a particle filter is almost always better suited. (especially when you have a GPU available, which is a perfect fit for particle filters).
- krapht 6y ago> Considering very few applications of this kind of system are limited by compute power Citation needed. If I went by my own experience, the vast majority of Kalman filters run in compute/power/time-limited environments.
- deleted 6y ago[deleted]
- augstein 6y agoIf you are into TradingView for TA, you might want to give the ‚HMA-Kahlman Trend‘ indicator a try.
- _xerces_ 6y agoWhy is this low effort post so high? There have been lots of interesting articles, visualizations and tutorials on Kalman Filters posted on here over the years. This guy just posts a Wikipedia link with no comments and you all think it is great? Let me try: https://en.wikipedia.org/wiki/Sun https://en.wikipedia.org/wiki/Sun Whoa, the sun apparently is a star!
- PaulHoule 6y agoIf you like building machines that function as animals, this is a basic technique. It is how my digital twin tracks my state. I was thinking about my fitness band at the gym and like yeah it uses... A Kalman Filter? I load HN and there it is.
- np_tedious 6y agoArguably the sun is also a compiler
- srean 6y agoI sense some bitterness in the comment. What makes or doesn't make the front page depends on a lot of things and it will not be the same every time. It will, for example, depend on other competing stories. There is a steady influx of new members. So stories that are old hat may not be so for a large section of HN visitors. Yes, this was a Wikipedia link and Kalman filters has been discussed here many times, that said I found the discussion and commentary quite delightful.
- ngvrnd 6y agoYou know how people always say "it isn't rocket science?" Well, this is rocket science.
- ojstella 6y agoThe Kalman Filter has been one of the toughest concepts for me to grasp over the years. I have looked at many examples related to target tracking, which logically makes sense to me given physical behavior of flying targets. But can anyone provide more applications that make learning the Kalman Filter easy? I recommend the following two articles that helped me get a better working understanding of the Kalman Filter: https://www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/ https://www.bzarg.com/p/how-a-kalman-filter-works-in-picture... https://thekalmanfilter.com/kalman-filter-explained-simply/ https://thekalmanfilter.com/kalman-filter-explained-simply/
- pidtuner 6y agoFor predictions, the Kalman Filter has it's drawbacks. They are clearly visible when you try to use it in conjunction with other algorithms based on state prediction such as Model Predictive Control. The main problem is that the KF does not have integral action. One quick fix is to add a disturbance model to the KF, for example an integating disturbance. But then you have one more tuning parameter (the disturbance model). Which along the other KF tuning parameters increase complexity and becomes more difficult to implement and understand. Personally, I have had more success with other types of filters, which have a similar structure as the KF, but include mechanisms for improved predictions, for example this one: https://folk.ntnu.no/skoge/prost/proceedings/ifac2014/media/files/2032.pdf https://folk.ntnu.no/skoge/prost/proceedings/ifac2014/media/...