moment< 2>的含义是什么?在boost :: accumulators中

时间:2013-12-10 15:57:49

标签: 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

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

1 个答案:

答案 0 :(得分:3)

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

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

Boost记录该函数(包括其定义)here。维基百科有关于统计时刻的完整文章here

  

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

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

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