search for: logsumexp

Displaying 10 results from an estimated 10 matches for "logsumexp".

2011 Feb 16
1
logsumexp function in R
Hi, I was wondering if anyone has implemented a numerically stable function to compute log(sum(exp(x))) ? Thanks! Brian [[alternative HTML version deleted]]
2019 Jun 24
1
Calculation of e^{z^2/2} for a normal deviate z
...l, > 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 >> ly <- lx*100000 >> ly > [1] 100001000 100002000 >> y1 <- logSumExp(ly) >> print(y1) > [1] 100002000 >> logSumExp > function (lx, idxs = NULL, na.rm = FALSE, ...) &gt...
2013 Nov 07
1
R interface to C API Rf_logspace_{add,sub}?
...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...
2019 Jun 24
2
Calculation of e^{z^2/2} for a normal deviate z
...ion, then multiply the result (I'm sure >> this is described/documented somewhere). More generally, there are >> methods for computing sums on the log scale, e.g. >> >> >> https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.misc.logsumexp.html >> >> I don't know where this has been implemented in the R ecosystem, but >> this sort of computation is the basis of the "Brobdingnag" package for >> operating on very large ("Brobdingnagian") and very small >> (&quot...
2019 Jun 24
0
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 > ly <- lx*100000 > ly [1] 100001000 100002000 > y1 <- logSumExp(ly) > print(y1) [1] 100002000 > logSumExp function (lx, idxs = NULL, na.rm = FALSE, ...) { has_na <- TRUE .Call(C_logSumExp, as.numeric(lx), idxs, as.logical(na.rm),...
2019 Jun 23
2
Calculation of e^{z^2/2} for a normal deviate z
...he *largest* of the probabilities, then do the (p/sum(p)) computation, then multiply the result (I'm sure this is described/documented somewhere). More generally, there are methods for computing sums on the log scale, e.g. https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.misc.logsumexp.html I don't know where this has been implemented in the R ecosystem, but this sort of computation is the basis of the "Brobdingnag" package for operating on very large ("Brobdingnagian") and very small ("Lilliputian") numbers. On 2019-06-21 6:58 p.m., jing hua...
2015 Jan 26
0
matrixStats 0.13.1 - Methods that Apply to Rows and Columns of a Matrix (and Vectors)
...code is available on GitHub [https://github.com/HenrikBengtsson/matrixStats]. WHAT DOES IT DO? The matrixStats package provides highly optimized functions for computing common summaries over rows and columns of matrices, e.g.rowQuantiles(). There are also functions that operate on vectors, e.g. logSumExp(). Their implementations strive to minimize both memory usage and processing time. They are often remarkably faster compared to good old apply() solutions. The calculations are mostly implemented in C, which allow us to optimize(*) beyond what is possible to do in plain R. The package installs out-...
2015 Jan 26
0
matrixStats 0.13.1 - Methods that Apply to Rows and Columns of a Matrix (and Vectors)
...code is available on GitHub [https://github.com/HenrikBengtsson/matrixStats]. WHAT DOES IT DO? The matrixStats package provides highly optimized functions for computing common summaries over rows and columns of matrices, e.g.rowQuantiles(). There are also functions that operate on vectors, e.g. logSumExp(). Their implementations strive to minimize both memory usage and processing time. They are often remarkably faster compared to good old apply() solutions. The calculations are mostly implemented in C, which allow us to optimize(*) beyond what is possible to do in plain R. The package installs out-...
2019 Jun 23
0
Calculation of e^{z^2/2} for a normal deviate z
...ties, > then do the (p/sum(p)) computation, then multiply the result (I'm sure > this is described/documented somewhere). More generally, there are > methods for computing sums on the log scale, e.g. > > > https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.misc.logsumexp.html > > I don't know where this has been implemented in the R ecosystem, but > this sort of computation is the basis of the "Brobdingnag" package for > operating on very large ("Brobdingnagian") and very small > ("Lilliputian") numbers. > > &...
2019 Jun 21
4
Calculation of e^{z^2/2} for a normal deviate z
You may want to look into using the log option to qnorm e.g., in round figures: > log(1e-300) [1] -690.7755 > qnorm(-691, log=TRUE) [1] -37.05315 > exp(37^2/2) [1] 1.881797e+297 > exp(-37^2/2) [1] 5.314068e-298 Notice that floating point representation cuts out at 1e+/-308 or so. If you want to go outside that range, you may need explicit manipulation of the log values. qnorm()