This is part of the course “Probability Theory and Statistics for Programmers”.
In the practical application of probability theory, one often has to meet with problems in which the same or similar experiments are repeated many times. As a result of each experiment, some event may or may not occur, and we are not interested in the result of each individual experiment, but in the total number of occurrences of the event as a result of a series of experiments. Depend on the type of events you will use different approaches to find the probability.
Probability of repetitive experiments (independent events)
We have n experiments. In every experiment, the event can occur or not with probabilities p and q = 1-p. We should find probability Pm,n —the probability of event A occurring m times in n experiments. We can represent this event as a sum of all possible combinations of products of events. A number of such combinations can be calculated using combinatorics formula:
The probability of each such combination, by the multiplication theorem for independent events, is:
Now we can construct the formula:
Probability of repetitive (dependent experiments)
When we have dependent experiments different approach needed. The event that event A will appear m times during n experiments still will be represented as a sum of products of events. A Number of combinations also will be the same, but combinations will not have the same probability. Since independent events have a number of different probabilities. In order to find such a probability, we use a magic function. The probability that an event A in n independent experiments will appear exactly m times is equal to the coefficient
in the expression for the generating function:
It seems like magic, but it actually works, if you look at the example below you will find that coefficients represent a sum of products of events:
Now we can write code for this. At first, we create the list of list of products of events for each coefficient. In each iteration number of total products will be increased in two times, since we need to multiply existing products on corresponding q and p.
Reach the next level of focus and productivity with increaser.org.