![]() |
Home | Libraries | People | FAQ | More |
在一些建模軟件中,我們需要一個特定位置(location)和圖度(scale)的分佈:通常這等價於一個特殊的均值(specific mean)和標準差,雖然對於大多數的分佈來說,這些屬性,位置(location),尺度參數之間的關係是非平凡的(non-trivial). 參見http://www.itl.nist.gov/div898/handbook/eda/section3/eda364.htm 瞭解更多信息.
顯而易見的處理方式是使用一個適配器模板( adapter template):
template <class Dist> class scaled_distribution { scaled_distribution( const Dist dist, typename Dist::value_type location, typename Dist::value_type scale = 0); };
然而這個模板會有一系列重載的非成員訪問函數(accessor function).
添加一個虛擬化(virtualises)實際分佈類型的對象將會是一件相當平凡的(trivial)事情,因此就可以容納「任何」滿足分佈的概念要求的對象。:
template <class RealType> class any_distribution { public: template <class Distribution> any_distribution(const Distribution& d); }; // 獲取潛在的分佈的cdf: template <class RealType> RealType cdf(const any_distribution<RealType>& d, RealType x); // 等等....
這樣一個類將會使得編寫可以處理任何分佈類型的非模板代碼變得更容易。雖然還不清楚是否有一個引起興趣的(compelling)使用案例。擬合良度(goodness of fit)的可能性檢驗(Possibly tests)或許提供了這樣一個使用案例:這需要更多的調查。
高級檢驗大體上對應於數學假設檢驗 包,並且可以相當容易地添加到這個類庫中 ,例如:
template <class InputIterator> typename std::iterator_traits<InputIterator>::value_type test_equal_mean( InputIterator a, InputIterator b, typename std::iterator_traits<InputIterator>::value_type expected_mean);
返回序列 [a,b)中的數據具有expected_mean均值(mean)的概率。
Eric Niebler's 累中器框架 - 也處於編寫進展之中 - 提供了從實驗數據中計算各種統計屬性的方法。 在以後時間裡有一個將統計實驗與這個框架集成的機會。:
// 定義一個累加器, 所有的用於計算這些檢驗的要求的統計都自動計算: accumulator_set<double, features<tag::test_expected_mean> > acc(expected_mean=4); // 將我們的數據傳遞給這個累加器: acc = std::for_each(mydata.begin(), mydata.end(), acc); // 獲取返回值: double p = probability(acc);