Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Summing two boost::accumulator_set instances

I have recently discovered the excellent library boost::accumulators, and I would like to use it to replace some of my code that accumulates statistics.

One thing I cannot find in the documentation is the ability to sum two accumulator sets, as in operator+=

Example:

using namespace boost::accumulators;
typedef accumulator_set<double, features<tag::variance> > AccumSet;

class Foo {
    AccumSet acc;
public:
    Foo& operator+=(const Foo& that) {
        this->acc += that.acc; // error! no such operator
        return *this;
    }
    double GetVariance() { return variance(acc); }
};

How can I achieve this using the available API? I don't know if this can be implemented for all the types of accumulators in the library (maybe not for tail), but it sure can be for important things, like count, sum, mean, moment, covariance, etc

like image 489
killogre Avatar asked May 13 '12 11:05

killogre


2 Answers

Unfortunately, this feature is not provided by Boost.Accumulators, probably because combining would only work for some statistics.

There is a ticket on the Boost tracker asking for such a combine function.

like image 133
Luc Touraille Avatar answered Nov 15 '22 23:11

Luc Touraille


There is no appropriate and available operator+= for adding two accumulator_set<> objects.

like image 39
beniekg Avatar answered Nov 15 '22 21:11

beniekg