2013-12-10 81 views
0

我通過這個例子工作,但是我沒有得到什麼數學運算boost :: accumulators :: moment < 2>是。什麼是瞬間<2>在boost :: accumulators中的含義

#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

此外,我怎麼能得到平均的樣本的距離方差的條款?

回答

3

n th moment是期望值X^n;第二個時刻是預期值X^2。它是密切相關的方差:

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

加速文檔的功能(包括其定義)here。維基百科有關統計時刻的相當詳盡的文章here

此外,我怎樣才能從方差的平均值得到樣本的距離?

我想你想的距離爲標準差的倍數:

distance = (sample - mean)/sqrt(variance) 
相關問題