【问题标题】:What is the meaning of moment<2> in boost::accumulatorsboost::accumulators 中的 moment<2> 是什么意思
【发布时间】:2013-12-10 15:57:48
【问题描述】:

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

#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

此外,我怎样才能从方差方面得到样本与平均值的距离?

【问题讨论】:

    标签: c++ boost statistics


    【解决方案1】:

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

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

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

    此外,我怎样才能从方差方面得到样本与平均值的距离?

    我猜你希望距离是标准差的倍数:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-17
      • 2014-05-08
      • 2011-12-03
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多