jtosey/particle_filter_demo — comment on commit ba3a5df3f6d6c70d52d78bea962a7c6fcbd6232f
File:  line 0
By jtosey:

No, that won't work, because the points aren't equally weighted. The array represents a PDF. Suppose the particle array had four points, with the following normalized points:

[ 0.9, 0.025, 0.05, 0.025 ]

The distribution array would then have the following accumulated weights:

[ 0.9, 0.925, 0.975, 1 ]

If you pick a randomized number using a uniform distribution, if that number is 0 <= X <= 0.9, we want to return the first particle. Suppose you get the random number 0.7 from a uniform random number generator. Using the bisect algorithm, it will say that this is closest to the 0.9 particle, and return index 0. I then take index 0 and return the 0th particle from the first array.

If we just used a random uniform lookup instead, it wouldn't return a weighted response - it would return each particle with a 25% probability.