2

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 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.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Dylan Klomparens
  • 2,853
  • 7
  • 35
  • 52

2 Answers2

2

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.

K-ballo
  • 80,396
  • 20
  • 159
  • 169
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;
sihadas
  • 11
  • 3