This repository features a simple Kalman filter and RTS smoother (KFS) implementation in Rust by using the ndarray library.
By simple, I mean that this implementation is almost a direct translation of my past Python implementations of KFS, and I tried to keep the syntax here readable for Python/Matlab/Julia users. It on ther other hand means that this implementation would be a good starting example for you, if you are familar with Python/Matlab/Julia and is interesting to learn Rust.
The installation guidance of Rust can be found at this official website.
After you have Rust installed, open a terminal and run
git clone [email protected]:spdes/kalman-rust.git
cd kalman-rust
cargo run
If succeeded, you will see a figure generated as in the above.
If failed, it is very likely that you need to have openblas
or Intel MKL
configured in your system and change the feature
of ndarray-linalg
in ./Cargo.toml
accordingly.
Welcome to the cult!
Implementing Kalman filter and RTS smoother is a good exercise to practise a new language, as they involves basic linear algebras, such as matrix algebras and solving linear systems. In light of this, I have an article explaining the codes here line-by-line. This article is readable even if you have no experience using Rust.
As a disclaimer, in case that you want to sue me for luring you to learn Rust, please be aware that I do not promise (nor I see any evidence) that Rust would be a main-stream language for scientific computing (especially machine learning) in the future. Furthermore, the learning curve of Rust is very steep. I learnt Rust purely out of hobby and its name 1.
In folder ./benchmarks
you may find a few benchmark files written in Rust, Numpy, Jax, Matlab, and Julia to compare their performance on running Kalman filtering and smoothing.
In short, the most important result is that the Rust implementation is evidently faster than others when the state dimension is large (on my working computer), and there is still a room to optimise it further!
You could find detailed results and explanations in this article.
GPL v3 or later.
Zheng Zhao, [email protected]
Footnotes
-
Python: "the only good snake is a dead snake". ↩