質問

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

役に立ちましたか?

解決

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.

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top