search for: kahan_summation_algorithm

Displaying 6 results from an estimated 6 matches for "kahan_summation_algorithm".

2019 Feb 19
4
code for sum function
The algorithm does make a differece. You can use Kahan's summation algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) to reduce the error compared to the naive summation algorithm. E.g., in R code: naiveSum <- function(x) { s <- 0.0 for(xi in x) s <- s + xi s } kahanSum <- function (x) { s <- 0.0 c <- 0.0 # running compensation for lost low-order bits for(xi in x) { y &...
2019 Feb 20
0
code for sum function
...ot a naive sum nor a Kahansum (in all cases), but what algorithm is it using then? Cheers, Rampal On Tue, Feb 19, 2019, 19:08 William Dunlap <wdunlap at tibco.com wrote: > The algorithm does make a differece. You can use Kahan's summation > algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) to > reduce the error compared to the naive summation algorithm. E.g., in R > code: > > naiveSum <- > function(x) { > s <- 0.0 > for(xi in x) s <- s + xi > s > } > kahanSum <- function (x) > { > s <- 0.0 > c <- 0.0 # running...
2019 Feb 19
0
code for sum function
...ng extended-precision registers when available. (Using Kahan's algorithm does come at a computational cost ...) On 2019-02-19 2:08 p.m., William Dunlap via R-devel wrote: > The algorithm does make a differece. You can use Kahan's summation > algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) to > reduce the error compared to the naive summation algorithm. E.g., in R > code: > > naiveSum <- > function(x) { > s <- 0.0 > for(xi in x) s <- s + xi > s > } > kahanSum <- function (x) > { > s <- 0.0 > c <- 0.0 # running...
2019 Feb 20
0
code for sum function
...all cases), but what algorithm is it using then? > > Cheers, Rampal > > > On Tue, Feb 19, 2019, 19:08 William Dunlap <wdunlap at tibco.com wrote: > >> The algorithm does make a differece. You can use Kahan's summation >> algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) to >> reduce the error compared to the naive summation algorithm. E.g., in R >> code: >> >> naiveSum <- >> function(x) { >> s <- 0.0 >> for(xi in x) s <- s + xi >> s >> } >> kahanSum <- function (x) >> { >&g...
2013 Jul 25
2
What algorithm is R using to calculate mean?
I am curious to know what algorithm R's mean function uses. Is there some reference to the numerical properties of this algorithm? I found the following C code in summary.c:do_summary(): case REALSXP: PROTECT(ans = allocVector(REALSXP, 1)); for (i = 0; i < n; i++) s += REAL(x)[i]; s /= n; if(R_FINITE((double)s)) { for (i = 0; i < n; i++) t += (REAL(x)[i] -
2019 Feb 14
5
code for sum function
Hello, I am trying to write FORTRAN code to do the same as some R code I have. I get (small) differences when using the sum function in R. I know there are numerical routines to improve precision, but I have not been able to figure out what algorithm R is using. Does anyone know this? Or where can I find the code for the sum function? Regards, Rampal Etienne