TOC

Day 27: Rejection Sampling

Repo for Day 27

Getting a selection from a set that is weighted proportionally is central to doing genetic algorithms. One solution is to create an array that contains proportional numbers of the values, but that may mean creating and destroying an large array several times.

Both in Shiffman's videos and in a couple of other places the "Rejection Sampling" algorithm is mentioned. I wanted to make sure I understood it.

This non-looping sketch creates 10k shapes, based on weights determined at the beginning at each run.

Nice video on the topic:

Compare to Inverse Transform Sampling

(smrinoff, inverse cumulative distribution function) Videos from same channels as above - https://www.youtube.com/watch?v=d_KiCqW3DTs - https://www.youtube.com/watch?v=9ixzzPQWuAY

Hover the mouse over a sketch to make it run.

  1. 01-rejection-sampling