namespace std {
template <class RealType = double>
class student_t_distribution;
}
概要
student_t_distribution
は、連続確率分布の一種である、ステューデントのt分布を生成する。以下の確率密度関数に基いて、浮動小数点数の乱数を生成する:
$$ p(x \mid n) = \frac{1}{\sqrt{n \pi}} \cdot \frac{\Gamma((n+1)/2)}{\Gamma(n/2)} \cdot \left( 1 + \frac{x^2}{n} \right) ^ {-(n+1)/2} $$
この確率密度関数において、nは自由度を意味する。
以下のような用途に使用できる:
- 母集団の性質(平均、分散)を推定する
テンプレートパラメータは、以下を意味する:
RealType
: 成功する実数型。
メンバ関数
構築・リセット
名前 | 説明 | 対応バージョン |
---|---|---|
(constructor) |
コンストラクタ | C++11 |
~student_t_distribution() = default; |
デストラクタ | C++11 |
reset |
状態をリセットする | C++11 |
生成
名前 | 説明 | 対応バージョン |
---|---|---|
operator() |
乱数を生成する | C++11 |
プロパティ
名前 | 説明 | 対応バージョン |
---|---|---|
n |
分布の自由度を取得する | C++11 |
param |
分布のパラメータを取得/設定する | C++11 |
min |
生成し得る値の下限を取得する | C++11 |
max |
生成し得る値の上限を取得する | C++11 |
メンバ型
型 | 説明 | 対応バージョン |
---|---|---|
result_type |
乱数生成結果の実数型。RealType |
C++11 |
param_type |
分布パラメータの型。未規定。 | C++11 |
非メンバ関数
名前 | 説明 | 対応バージョン |
---|---|---|
operator== |
等値比較 | C++11 |
operator!= |
非等値比較 | C++11 |
operator<< |
ストリームへの出力 | C++11 |
operator>> |
ストリームからの入力 | C++11 |
例
#include <random>
#include <fstream>
int main()
{
std::random_device seed_gen;
std::default_random_engine engine(seed_gen());
// 自由度1.0で分布させる
std::student_t_distribution<> dist(1.0);
std::ofstream file("student_t_distribution.tsv");
for (std::size_t n = 0; n < 256; ++n) {
// t分布で乱数を生成する
double result = dist(engine);
file << result << "\n";
}
}
出力
このプログラムによってある時に得られた結果(student_t_distribution.tsv)を図示する。
バージョン
言語
- C++11
処理系
- Clang:
- GCC: 4.6.1 ✅
- ICC:
- Visual C++: