Boost logo

Boost :

Subject: Re: [boost] Interest in algorithm for arithmetic mean of integers
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2015-09-04 17:59:18


On Fri, Sep 4, 2015 at 11:20 AM, Matt Calabrese <rivorus_at_[hidden]> wrote:
>
> //////////
> auto result = mean(std::begin(range), std::end(range));
> //////////
>
> At the moment I do not have an implementation that works piecemeal as is
> akin to Boost.Accumulators, however since the implementation of the
> algorithm really is simply a call to std::accumulate, it should be very
> simple to expose such a form, and I imagine that it would be especially
> useful. Some further details on how the state is manipulated with each
> iteration:
>

I also do not support weighted averages yet, but it should be possible. In
that case, I imagine that integral weights could be specified with the
precondition of the algorithm being that the sum of the weights needs to be
<= std::numeric_limits<difference_type>::max(). With such a precondition, I
believe it's possible to produce an exact result using the same mixed
number type that was described earlier.

-- 
-Matt Calabrese

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk