c++ - boost::accumulators 中的 moment<2> 是什么意思

标签 c++ boost statistics

我完成了这个例子,但我不明白数学运算 boost::accumulators::moment<2> 是什么。

#include <iostream>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/moment.hpp>
using namespace boost::accumulators;

int main()
{
    // Define an accumulator set for calculating the mean and the
    // 2nd moment ...
    accumulator_set<double, stats<tag::mean, tag::moment<2> > > acc;

    // push in some data ...
    acc(1.2);
    acc(2.3);
    acc(3.4);
    acc(4.5);

    // Display the results ...
    std::cout << "Mean:   " << mean(acc) << std::endl;
    std::cout << "Moment: " << accumulators::moment<2>(acc) << std::endl;

    return 0;
}

示例可在此处找到:http://www.boost.org/doc/libs/1_53_0/doc/html/accumulators/user_s_guide.html

此外,我如何根据方差获得样本与均值的距离?

最佳答案

第n时刻是X^n的期望值;第二个时刻是 X^2 的期望值。它与方差密切相关:

variance = E((X-mean)^2)
         = E(X^2) - mean^2

Boost 记录函数(包括它的定义)here .维基百科有一篇关于统计矩的文章相当详尽here .

Furthermore, how can i get the distance of a sample from mean in terms of the variance?

我猜你想要距离作为标准偏差的倍数:

distance = (sample - mean) / sqrt(variance)

关于c++ - boost::accumulators 中的 moment<2> 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20499116/

相关文章:

C++ 原始类型安全

c++ - 如何忽略某些套接字请求

c++ - 与 shell 脚本不同,批处理文件不可执行吗?

statistics - 确定最小样本数以实现 99% 的准确度

r - 如果落在 R 中另一个数据集中的两个变量定义的范围内,则从一个数据集中获取变量值

mysql - 如果它通过类似的方法mysql,则计算行数

c++ - 使用 enable_if 选择类构造函数

c++ - header 和源类文件不起作用

c++ - boost 日志 - 使用severity_channel_logger进行格式化

c++ - 使用 Boost Asio 建立 SSL 连接