使用空的 Boost 累加器

发布于 2024-12-09 15:53:43 字数 354 浏览 0 评论 0 原文

我很好奇,从这段代码片段中获得的平均值是多少?累加器应为空。

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

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

当我测试它时,平均值不为零。有什么方法可以告诉我平均值是针对空数据集得出的吗?为什么“平均值”的结果值不为零?

我正在查看累加器库的文档,但无法找到这个问题的答案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞旧 2024-12-16 15:53:43

任何值都是空值集的有效平均值。即 x * 0 = 0 对于任何 x 都成立。

您可以将 count 功能添加到您的 accumulator_set 中,并查询它以查看其是否为 0。

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.

哎呦我呸! 2024-12-16 15:53:43

您不需要添加 count 功能,因为 mean 累加器基于来自

count 和 sum 累加器href="https://www.boost.org/doc/libs/1_55_0/doc/html/accumulators/user_s_guide.html" rel="nofollow noreferrer">Boost 用户指南

平均值取决于总和和计数累加器...平均累加器的结果仅仅是总和累加器的结果除以计数累加器的结果。

所以你只需要验证计数是否大于 0:

bool isEmpty = boost::accumulators::count(Accumulator) == 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文