Day 27: Rejection Sampling
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:
- "Rejection Sampling - VISUALLY EXPLAINED with EXAMPLES!" Kapil Sachdeva https://www.youtube.com/watch?v=si76S7QqxTU
- "Accept-Reject Sampling : Data Science Concepts" ritvikmath https://www.youtube.com/watch?v=OXDqjdVVePY
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.