Probability distribution vector
A computer can make a choice between different alternatives based on assigned statistical “likelihoods”—relative probabilities assigned to each possible alternative. This is accomplished most easily by storing all of the probabilities in a single vector (array), calculating the sum of all those probabilities, dividing the range (0 to the sum) into “quantiles” (subranges) proportional to the different probabilities, choosing a random number within that range, and determining which quantile the random number falls into.
The article “Probability distribution” describes this process and shows how to accomplish it, both conceptually (in a prose description that could be implemented as a program) and with an example written in Max using the table object. That article also discusses the implications and limitations of making decisions in this way.
First, let’s recap the process we’ll follow, as stated in that article.
- Construct a probability vector.
- Calculate the sum of all probabilities.
- Choose a random (nonnegative) number less than the sum.
- Begin cumulatively adding individual probability values, checking after each addition to see if it has resulted in a value greater than the randomly chosen number.
- When the randomly chosen value has been exceeded, choose the event that corresponds to the most recently added probability.
You can try out the program using the example Max patch shown above.