2011-04-06 5 views
10

설명서 향상은 일반 및 감마 분포 모두에 대해 quantile 함수 (역함수 cdf 함수)를 제공하는 것으로 보이지만 실제로는 어떻게 사용할 수 있습니까? 누군가 예를 붙여 주시겠습니까?부스트 (Q ++)에서 Quantile 함수

+0

[이 페이지 (http://www.boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/math_toolkit/dist/stat_tut/weg/normal_example/normal_misc.html)에는 정규 분포의 분위수를 계산하는 예제가 들어 있습니다. 그것은 매우 직설적 인 것처럼 보입니다. 이 방법이 효과가 있습니까? –

답변

8

양분 계산은 자유 함수로 구현됩니다.

#include <boost/math/distributions/normal.hpp> 

boost::math::normal dist(0.0, 1.0); 

// 95% of distribution is below q: 
double q = quantile(dist, 0.95); 

또한 (오른쪽에서 분위수) 보수를 얻을 수 있습니다 사용 : 예를 들면 다음과 같습니다이다

// 95% of distribution is above qc: 
double qc = quantile(complement(dist, 0.05)); 

이와 유사한 가공 한 예는 여기에 있습니다 :

http://www.boost.org/doc/libs/1_46_1/libs/math/doc/sf_and_dist/html/math_toolkit/dist/stat_tut/weg.html

편집 : 덕분에 무료 함수에 대한 네임 스페이스가 필요하지 않습니다.

+0

'normal'과'normal_distribution' 클래스가 모두있는 이유는 무엇입니까? 이것은 나를 혼란스럽게 만들었습니다. – Grzenio

+0

정상적인 것은'normal_distribution '의 typedef라고 생각합니다. – Inverse

3

QuantCorner에 실행 가능한 예제가 있습니다.

// Édouard Tallent @ TaGoMa.Tech 
// September 2012 

#include<boost/math/distributions.hpp> 
#include<iostream> 
using std::cout; 
using std::endl; 

double inverseNormal(double prob, double mean, double sd){ 
     boost::math::normal_distribution<>myNormal (mean, sd); 
     return quantile(myNormal, prob); 
} 

int main (int, char*[]) 
{ 
     try 
     {     
       double myProb = 0.1; // the 10% quantile 
       double myMean = 0.07; // a 7% mean 
       double myVol = 0.14; // a 14% volatility 

     cout << inverseNormal(myProb, myMean, myVol) << endl; 
     } 

       catch(std::exception& e) 
     { 
       cout << "Error message: " << e.what() << endl; 
     } 
return 0; 
}