Log probability should not be confused with log odds.
(-inf,0]
[0,1]
Since the probabilities of independent events multiply, and logarithms convert multiplication to addition, log probabilities of independent events add. Log probabilities are thus practical for computations, and have an intuitive interpretation in terms of information theory: the negative expected value of the log probabilities is the information entropy of an event. Similarly, likelihoods are often transformed to the log scale, and the corresponding log-likelihood can be interpreted as the degree to which an event supports a statistical model. The log probability is widely used in implementations of computations with probability, and is studied as a concept in its own right in some applications of information theory, such as natural language processing.
Representing probabilities in this way has several practical advantages:
-((x-mx)/\sigma
2+C | |
m) |
C2\exp\left(-((x-mx)/\sigma
2\right) | |
m) |
The logarithm function is not defined for zero, so log probabilities can only represent non-zero probabilities. Since the logarithm of a number in
(0,1)
Any base can be selected for the logarithm.
See also: Log semiring.
In this section we would name probabilities in logarithmic space
x'
y'
x'=log(x)\inR
y'=log(y)\inR
The product of probabilities
x ⋅ y
log(x ⋅ y)=log(x)+log(y)=x'+y'.
x+y
However, in many applications a multiplication of probabilities (giving the probability of all independent events occurring) is used more often than their addition (giving the probability of at least one of mutually exclusive events occurring). Additionally, the cost of computing the addition can be avoided in some situations by simply using the highest probability as an approximation. Since probabilities are non-negative this gives a lower bound. This approximation is used in reverse to get a continuous approximation of the max function.
\begin{align} &log(x+y)\\ ={}&log(x+x ⋅ y/x)\\ ={}&log(x+x ⋅ \exp(log(y/x)))\\ ={}&log(x ⋅ (1+\exp(log(y)-log(x))))\\ ={}&log(x)+log(1+\exp(log(y)-log(x)))\\ ={}&x'+log\left(1+\exp\left(y'-x'\right)\right) \end{align}
The formula above is more accurate than
log\left(ex'+ey'\right)
{x'}
-infty+log\left(1+\exp\left(y'-(-infty)\right)\right)=-infty+infty
x'+log\left(1+\exp\left(-infty-x'\right)\right)=x'+0
The above formula alone will incorrectly produce an indeterminate result in the case where both arguments are
-infty
-infty
For numerical reasons, one should use a function that computes
log(1+x)