首页 > 代码库 > Stats - Probability
Stats - Probability
There are a lot of controversy about the definition of probability, so we just start with the uncontroversial parts. In general we can say that the probability is a value between 0 and 1 that is intended to be a quantitative measure corresponding to the qualitative notion that some things are more likely than others.
The "things" we assign probability to are called events. If E represents an event, then P(E) denotes the probability that E will happen.
Rules of probability
There are some rules describe the related probabilities of different events. Probably the best known of these rules is:P(AB) = P(A)P(B)
Where P(AB) means the probability that events A and B both occur.This formula is easy to remember; the only thing is it is not always true. It only applies if A and B areindependent which means that I we know A occured, it doesn‘t change the probability of B, and vice versa.
When A and B are not independent, it is often useful to compute he Conditional Probability, P(A |B) which is the probability of A given that we know B occured:
P(A | B) = P(AB) / P(B)
From which we can derive the following formula:
P(AB) = P(B) * P(A | B)
We can think of the previous formula as "The chance of both things happening is the chance that first one happens, and then the second one happens given the first". Also the order doens‘t matter, so we can also write it like:
P(AB) = P(A) * P(B | A)
This formula holds whether A and B are independent or not. Because if they are independent, P(B | A) = P(B) which is the same with the first rule.
If two events are mutual exclusive which means only one of them can happen, the conditional probabilities are 0:
P(B | A) = P(A | B) = 0
In this case it is easy to compute the probability of either event:
P(A + B) = P(A) + P(B)
But we should keep in mind that it only work if the events are mutual exclusive. In general the formula should be:
P(A + B) = P(A) + P(B) - P(AB)