Inprobability theory andcomputer science, alog probability is simply alogarithm of aprobability.[1] The use of log probabilities means representing probabilities on alogarithmic scale, instead of the standardunit interval.
Since the probabilities ofindependentevents 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 ofinformation theory: the negativeexpected value of the log probabilities is theinformation entropy of an event. Similarly,likelihoods are often transformed to the log scale, and the correspondinglog-likelihood can be interpreted as the degree to which an event supports astatistical 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 asnatural language processing.
Representing probabilities in this way has several practical advantages:
The logarithm function is not defined for zero, so log probabilities can only represent non-zero probabilities. Since the logarithm of a number in interval is negative, often the negative log probabilities are used. In that case the log probabilities in the following formulas would beinverted.
Any base can be selected for the logarithm.
In this section we would name probabilities in logarithmic space and for short:
The product of probabilities corresponds to addition in logarithmic space.
Thesum of probabilities is a bit more involved to compute in logarithmic space, requiring the computation of one exponent and one logarithm.
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 acontinuous approximation of the max function.
The formula above is more accurate than, provided one takes advantage of the asymmetry in the addition formula. should be the larger (least negative) of the two operands. This also produces the correct behavior if one of the operands isfloating-pointnegative infinity, which corresponds to a probability of zero.
The above formula alone will incorrectly produce an indeterminate result in the case where both arguments are. This should be checked for separately to return.
For numerical reasons, one should use a function that computes (log1p) directly.