Is there an R-language interface to the R API C-language functions 
Rf_logspace_add()
and Rf_logspace_sub()?   I don't see one but I may not looking under the
right name.

Various packages have functions which do that same sort
of thing (log(exp(x)+exp(y)) and log(exp(x)-exp(y)) without unnecessary
floating point errors).  They have names like
    matrixStats::logSumExp(lx, na.rm=FALSE, ...) (the ... is ignored by the 
function)
    sna::logSub(x,y), logSum(x), logMean(x)
    BTYD::addLogs(loga, logb) and subLogs(loga, logb)
Googling for logSumExp (the Python name) indicates that many know this as "LSE"
(the "Log-Sum-Exp trick").

I've seen several instances in R-help recently where user code could be
made more accurate if these were available.  They can be written in pure
R code, but would be slower because they would require something like
pmin() and pmax() to work.  I think they belong in the same package as log1p()
and expm1().  I think the add and subtraction versions are the most useful
and the sum version would be very nice to have.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to