2013-03-05 3 views
6

데이터 벡터가 있고 데이터 세트의 첨도를 찾고 싶습니다. 내가 부스트와 함께 그렇게하고 싶어 여기에 지금까지 (하지 컴파일 가능한)가 무엇 :부스트가있는 데이터 세트에 대한 첨도 찾기

#include <boost/math/distributions.hpp> 
using namespace std; 

int main() 
{ 
    vector<double> a; 
    a.push_back(-1); 
    a.push_back(0); 
    a.push_back(1); 

    cout << "Kurtosis:"<< kurtosis(a) << endl; 
    return 0; 
} 

하지 않는 이유는이 작품? 내 컴파일러가 내게 오류를 준다 : "[...] \ main.cpp | 28 | 오류 : 'kurtosis'가이 범위에서 선언되지 않았습니다."

#include <boost/accumulators/statistics/kurtosis.hpp> 

당신이 직선 vector 작동하지 않습니다 참조대로 않았더라도, 당신이 아마하고 싶은 것은 accumulator_set을 사용하고 : 당신이 kurtosis의 헤더가 포함되지 않은 하나

+3

컴파일이 안되면 컴파일러 오류 – mathematician1975

+1

을 게시하십시오.이 함수는 다른 네임 스페이스에 있으므로'boost :: some :: namespace :: kurtosis (a)'를 사용해야합니다. 'some :: namespace'를 실제 네임 스페이스로 바꾸십시오. –

+1

면책 조항 : 내가 말하는 것에 대해 절대적으로 문제 도메인에 대해 충분히 알지 못합니다. 내 생각 엔 의 알고리즘은 [매개 변수화 된 사전 정의 된 배포본] (http://www.boost.org/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref)에서만 작동합니다. /dists.html). 데이터 세트를 사용하는 대안은 [Boost.Accumulators] (http://www.boost.org/libs/accumulators) 일 수 있습니다. [여기] (http://liveworkspace.org/code/2cDjQ9$0)가 그 예입니다. –

답변

1

더 많은 헤더도 있습니다. 여기

accumulator_set를 사용하여 최소한의 예이며,이 문제를 해결하기위한 두 가지 방법을 도시한다 : 여기

#include <boost/math/distributions.hpp> 
#include <boost/accumulators/accumulators.hpp> 
#include <boost/accumulators/statistics/stats.hpp> 
#include <boost/accumulators/statistics/mean.hpp> 
#include <boost/accumulators/statistics/variance.hpp> 
#include <boost/accumulators/statistics/kurtosis.hpp> 
#include <iostream> 
#include <vector> 

using namespace boost::accumulators; 

int main() 
{ 
    accumulator_set<double, stats<tag::mean, tag::kurtosis > > acc; 
    accumulator_set<double, stats<tag::mean, tag::kurtosis > > acc2; 

    acc(2) ; 
    acc(3) ; 
    acc(4) ; 

    std::cout << mean(acc) << " " << kurtosis(acc) << std::endl ; 

    std::vector<double> v1 ; 

    v1.push_back(2); 
    v1.push_back(3); 
    v1.push_back(4); 

    acc2 = std::for_each(v1.begin(), v1.end(), acc2) ; 

    std::cout << mean(acc2) << " " << kurtosis(acc2) << std::endl ; 
} 

하면 Accumulators FrameworkUser's Guide에 대한 링크이다. 이 가이드에는 몇 가지 좋은 예가 있습니다.

이 이전 thread은 사용할 수있는 방법을 찾지 못했지만 전혀 작동하지는 못했지만 vector을 사용했습니다.

관련 문제