log_of_sum_of_exp_x.Rd
Function to compute the log of the sum of exponent of a set of log-values.
log_of_sum_of_exp_x(x, na.rm = FALSE)
A numeric vector of log-values.
Logical; if TRUE
removes NA
values.
The log of the sum of the exponentiated values of x
.
It is often useful to take the log of very small or large values (e.g., likelihoods). Working with log-values makes exponentiation, multiplication, and division easier. However, addition and subtraction become harder.
Assume a = log(a.)
and b = log(b.)
. The identity
log(a. + b.) = a + log(1 + exp(b - a))
allows us to compute
the log of the sum of the exponentiated values of a and b. This can
be further extended to a series of log-values
x = {x[1], x[2], ..., x[n]}
as
x[1] + log( 1 + exp(x[2] - x[1]) + ... + exp(x[n] - x[1]) )
.
http://bayesfactor.blogspot.com/2016/05/numerical-pitfalls-in-computing-variance.html
https://stackoverflow.com/questions/65233445/how-to-calculate-sums-in-log-space-without-underflow