开发者

Using empty Boost accumulators

I am curious, what average is obtained from this code snippet? The accumulator is intended to be empty.

boost::accumulators::accumulator_set<
    int,
    boost::accumulators::features<boost::accumulators::tag::mean>
> Accumulator;

int Mean = boost::accumulators::mean(Accumulator);

The average is non-zero when I test it. Is there开发者_如何学Python some way I can tell that the average was taken for an empty data set? Why is the resulting value for "Mean" non-zero?

I was looking around in the documentation for the accumulator library, but was unable to find an answer to this question.


Any value would be a valid mean for an empty set of values. That is x * 0 = 0 holds for any x.

You could add a count feature to your accumulator_set and query it to see if its 0.


You don't need to add count feature since mean accumulator is based on count and sum accumulators

from boost User's Guide:

mean depends on the sum and count accumulators ... The result of the mean accumulator is merely the result of the sum accumulator divided by the result of the count accumulator.

so you just need to validate that count is bigger then 0:

bool isEmpty = boost::accumulators::count(Accumulator) == 0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜