Draws samples from a probability mass function defined by an array of discrete probabilities.
indices = pmfdraw(p) indices = pmfdraw(p, n)
Array defining a probability mass function
Number of draws to make (defaults to the length of
Random draws corresponding to indicies of
We'll create a 3-element probability distribution, where the first element occurs 25% of the time, the second element occurs 40% of the time, and the third element occurs 35% of the time.
p = [0.25 0.4 0.35];
We can make 1000 random draws from this distribution. Approximately 25% will be 1, 40% will be 2, and 35% will be 3.
indices = pmfdraw(p, 1000);
Let's see how we did:
sum(indices == 1)/1000 sum(indices == 2)/1000 sum(indices == 3)/1000
ans = 0.2490 ans = 0.4030 ans = 0.3480
Particle filters use discrete probabilities as "weights" for each particle, so that particles that produce predictions of the observation that are consistent with the true measurement end up with a higher probability. These most-likely particles are more likely to be selected during resampling, resulting in a clustering of particles near high-probability areas of the state space. This function is useful to randomly draw the particles to select according to their individual "probabilities".