search for: kahansum

Displaying 5 results from an estimated 5 matches for "kahansum".

2019 Feb 19
4
code for sum function
...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 <- xi - c t <- s + y # low-order bits of y may be lost here c <- (t - s) - y s <- t } s } > rSum <- vapply(c(1:20,10^(2:7)), functio...
2019 Feb 20
0
code for sum function
Dear Will, This is exactly what I find. My point is thus that the sum function in R is not 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...
2019 Feb 20
0
code for sum function
...the sum: n%/%3 + (n%%3)/3. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Feb 20, 2019 at 2:45 PM Rampal Etienne <rampaletienne at gmail.com> wrote: > Dear Will, > > This is exactly what I find. > My point is thus that the sum function in R is not 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/...
2019 Feb 19
0
code for sum function
...;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 <- xi - c > t <- s + y # low-order bits of y may be lost here > c <- (t - s) - y > s <- t > } > s &...
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