logAdd {mBPCR} | R Documentation |
Function to compute the logarithm of a sum of small numbers, avoiding overflow.
logAdd(x)
x |
array or matrix containing the logarithm of the terms of the sum. If |
If x
is an array, the function returns log(sum_i(e^x[i])), otherwise it returns an array containing the results by column.
x <- log(c(0.0001, 0.0003, 0.000006)) y <- logAdd(x) ##verification that the computation is correct z <- sum(c(0.0001, 0.0003, 0.000006)) z exp(y)