Boost logo

Boost Users :

Subject: Re: [Boost-users] [accumulators] Kahan algorithmic variants of sum_impl, mean_impl?
From: Eric Niebler (eric_at_[hidden])
Date: 2011-09-30 13:49:12


On 9/30/2011 7:28 AM, Rhys Ulerich wrote:
>>From a look at boost::accumulators::impl::sum_impl [1] it appears a
> straightforward, fast 'sum += value' is used to accumulate the running
> sum. That can fall prey to numerical errors if the sum is large and
> the value is small. A slower but more precise summation is possible
> using the Kahan summation algorithm [2].
>
> Has anyone implemented a Kahan-based variant for either sum_impl or
> mean_impl [3]?

sum_kahan:
http://www.boost.org/doc/libs/1_47_0/doc/html/accumulators/reference.html#header.boost.accumulators.statistics.sum_kahan_hpp

You can get a kahan mean by putting both sum_kahan and mean in the
accumulator set, since sum_kahan satisfies the sum dependency.

sum_kahan is new in 1.47, thanks for Gaetano Mendola and Simon West.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net