簡體   English   中英

boost中的分位數函數(C ++)

[英]Quantile functions in boost (C++)

從文檔提升來看,似乎為正態分布和伽瑪分布提供了分位數函數(逆cdf函數),但我不清楚如何實際使用它們。 有人可以貼一個例子嗎?

分位數計算被實現為自由函數。 這是一個例子:

#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

編輯:由於ADL,在自由函數上不需要名稱空間

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM