Pregunta

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.

¿Fue útil?

Solución

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.

Otros consejos

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;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top