Probability theory: Repetitive experiments

This is part of the course “Probability Theory and Statistics for Programmers”.

Image for post
Image for post
Probability Theory 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.

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:

Image for post
Image for post
combination

The probability of each such combination, by the multiplication theorem for independent events, is:

Image for post
Image for post
probability of combination

Now we can construct the formula:

Image for post
Image for post
probability of repetitive experiments(repetitive events)

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

Image for post
Image for post

in the expression for the generating function:

Image for post
Image for post

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:

Image for post
Image for post

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.

Image for post
Image for post

Next part ->

Reach the next level of focus and productivity with increaser.org.

Image for post
Image for post
Increaser

Written by

Software engineer, creator of increaser.org. More at geekrodion.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store