Computes log(1 + exp(x))
and log(1 - exp(-x))
accurately.
log1mexp(x)
log1pexp(x)
log1mexp(x)
gives the value of
log1pexp(x)
gives the value of
Computes log(1 + exp(x))
and log(1 - exp(-x))
accurately. An adjustment is made when
Maechler, Martin (2012). Accurately Computing log(1-exp(-|a|)). Assessed from the Rmpfr package.
# NOT RUN {
x <- c(10, 50, 100, 200, 400, 500, 800, 1000, 1e4, 1e5, 1e20, Inf, NA)
log1pexp(x)
log(1 + exp(x)) # Naive; suffers from overflow
log1mexp(x)
log(1 - exp(-x))
y <- -x
log1pexp(y)
log(1 + exp(y)) # Naive; suffers from inaccuracy
# }
Run the code above in your browser using DataLab