HenrikBengtsson/matrixStats

Feature request: `log_inv_ logit` and/or `log1p`

wds15 opened this issue · 0 comments

wds15 commented

I happen to use on a few of my programs a specialised function called log_inv_logit which is arithmetically equal to log(inv_logit(x)).

For numerical stability reasons the function is defined as:

log_inv_logit <- function(mat) {
    idx <- mat < 0
    mat[idx] <- mat[idx] - log1p(exp(mat[idx]))
    mat[!idx] <- -1*log1p(exp(-mat[!idx]))
    mat
}

The log1p function would also be great to have on its own in the usual vector/row/col flavour: log1p(x) = log(1 + x)

Other than that: Great package! matrixStats made with it's logSumExp calls EMs coded in R 3x-6x faster in a package of mine.