
Last chance! 50% off unlimited learning
Sale ends in
log(1 + exp(x))
accurately.log1pexp(x)
log1p
does
not handle these.log(1 + exp(x))
.log(1 + exp(x))
accurately.
An adjustment is made when x
is positive and large in value.log1p
,
exp
.x <- c(10, 50, 100, 200, 400, 500, 800, 1000, 1e4, 1e5, 1e20, Inf)
log1pexp(x)
log(1 + exp(x)) # Naive; suffers from overflow
x <- -c(10, 50, 100, 200, 400, 500, 800, 1000, 1e4, 1e5, 1e20, Inf)
log1pexp(x)
log(1 + exp(x)) # Naive; suffers from inaccuracy
Run the code above in your browser using DataLab