Skip to content
Prev 57082 / 63424 Next

Calculation of e^{z^2/2} for a normal deviate z

Hi All,

Thanks for all your comments which allows me to appreciate more of these in Python and R.

I just came across the matrixStats package,


## EXAMPLE #1
lx <- c(1000.01, 1000.02)
y0 <- log(sum(exp(lx)))
print(y0) ## Inf

y1 <- logSumExp(lx)
print(y1) ## 1000.708

and
[1] 100001000 100002000
[1] 100002000
function (lx, idxs = NULL, na.rm = FALSE, ...)
{
    has_na <- TRUE
    .Call(C_logSumExp, as.numeric(lx), idxs, as.logical(na.rm),
        has_na)
}
<bytecode: 0x20c07a8>
<environment: namespace:matrixStats>

Maybe this is rather close?

Best wishes,


Jing Hua