我完成了这个例子,但我不明白数学运算 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/