Particle Filter in F#

Since my last blog post, I’ve been reading the Probabilistic Robotics book. I coded up a Kalman Filter in C++ (

It’s been a while since I’d coded up any F#, so I converted a particle filter over from Python. The code is from the online MOOC Artificial Intelligence for Robotics from Udacity.

The idea is to perform robot localisation, by creating a set of particles randomly over the entire state space. On a noisy sensor reading, the probability of that sensor reading having being made for each particle is calculated. Then, all particles undergo a weighted resampling (weighted by the measurement probability).

In this example, the sensor reading is the distance to four beacons at a known position in space. The same algorithm is used in Simultaneous Location and Mapping (SLAM) applications, where the sensor readings could be sonar, radar, visual etc.

The F# code is nice and compact at only 94 lines. The project is available at

1 thought on “Particle Filter in F#”

Leave a Reply

Your email address will not be published. Required fields are marked *