![]() |
Home | Libraries | People | FAQ | More |
如果一個統計分佈是離散的,那麼隨機變量的值只能是整數-當計算分位點時,
這給我們留下了一個問題-我們或者忽略分佈的離散性並返回一個浮點數,
或者我們可以將結果捨入為一個整數。就像實際發生的那樣,
計算整數值要比計算浮點值要快很多,所以,返回整數值有明顯的優點,
但是我們需要確定如何對結果進行捨入。discrete_quantile 策略定義了分位點函數如何工作,以及結果如何進行捨入。
enum discrete_quantile_policy_type { real, integer_round_outwards, // 缺省
integer_round_inwards, integer_round_down, integer_round_up, integer_round_nearest }; template <discrete_quantile_policy_type> struct discrete_quantile;
discrete_quantile
可以接收的值具有以下含義:
忽略分佈的離散性並返回浮點結果。例如:
#include <boost/math/distributions/negative_binomial.hpp> using namespace boost::math; using namespace boost::math::policies; typedef negative_binomial_distribution< double, policy<discrete_quantile<integer_round_inwards> > > dist_type; // 下分位點: double x = quantile(dist_type(20, 0.3), 0.05); // 上分位點: double y = quantile(complement(dist_type(20, 0.3), 0.05));
結果為x =
27.3898 且 y
= 68.1584.
這是缺省的策略:返回一個整數值使得:
這通常是最安全的捨入策略,因為它保證單側(one-sided)或雙側區間(two-sided)至少包含要求的覆蓋範圍。例如:
#include <boost/math/distributions/negative_binomial.hpp> using namespace boost::math; // 下分位點向下捨入: double x = quantile(negative_binomial(20, 0.3), 0.05); // 上分位點向上捨入: double y = quantile(complement(negative_binomial(20, 0.3), 0.05));
結果為x =
27 ( 27.3898向下捨入) 且 y =
69 (68.1584向上捨入)。
隨機變量x和y定義為滿足:
cdf(negative_binomial(20), x) <= 0.05 cdf(negative_binomial(20), y) >= 0.95
換句話說,我們可以保證在中間區域至少有90%的覆蓋,並且在每個尾部範圍內的覆蓋不超過5%。
這是integer_round_outwards對立面: 返回一個整數值,使得滿足:
例如:
#include <boost/math/distributions/negative_binomial.hpp> using namespace boost::math; using namespace boost::math::policies; typedef negative_binomial_distribution< double, policy<discrete_quantile<integer_round_inwards> > > dist_type; // 下分位點向上捨入: double x = quantile(dist_type(20, 0.3), 0.05); // 上分位點向下捨入: double y = quantile(complement(dist_type(20, 0.3), 0.05));
結果為x =
28 ( 27.3898向上捨入) 且 y =
68 (68.1584向下捨入)。
隨機變量x和y定義為滿足:
cdf(negative_binomial(20), x) >= 0.05 cdf(negative_binomial(20), y) <= 0.95
換句話說,我們可以保證在中間區域不超過有90%的覆蓋,並且在每個尾部範圍內的覆蓋不少於5%。
不管是上分位點還是下分位點,永遠向下捨入為一個整數。
不管是上分位點還是下分位點,永遠向上捨入為一個整數。
永遠將結果捨入為最接近的的整數值,不管是上分位點還是下分位點。這會在平均情況下產生要求的覆蓋範圍,但對於特殊的例子可能導致明顯的或多或少的與要求的差別。例如:
#include <boost/math/distributions/negative_binomial.hpp> using namespace boost::math; using namespace boost::math::policies; typedef negative_binomial_distribution< double, policy<discrete_quantile<integer_round_nearest> > > dist_type; // 下分位點向上捨入: double x = quantile(dist_type(20, 0.3), 0.05); // 上分位點向下捨入: double y = quantile(complement(dist_type(20, 0.3), 0.05));
結果為x =
27 (由27.3898捨入) 而 y = 68 (由 68.1584捨入)。