std:: gamma_distribution
From cppreference.net
|
定義先ヘッダ
<random>
|
||
|
template
<
class
RealType
=
double
>
class gamma_distribution ; |
(C++11以降) | |
正の浮動小数点のランダム値を生成します。 x 、確率密度関数に従って分布します:
-
P(x|α,β) =
· x α-1e -x/β
β α
· Γ(α)
ここで α は 形状 パラメータ、 β は 尺度 パラメータとして知られています。形状パラメータは文字 k で、尺度パラメータは文字 θ で表されることもあります。
浮動小数点の α に対して、得られる値は α 個の独立した指数分布確率変数の和であり、各変数の平均は β です。
std::gamma_distribution
は
RandomNumberDistribution
の要件を満たす。
目次 |
テンプレートパラメータ
| RealType | - | ジェネレータによって生成される結果の型。これが float 、 double 、または long double のいずれでもない場合、効果は未定義です。 |
メンバー型
| メンバー型 | 定義 |
result_type
(C++11)
|
RealType |
param_type
(C++11)
|
パラメータセットの型、 RandomNumberDistribution を参照。 |
メンバー関数
|
(C++11)
|
新しい分布を構築する
(public member function) |
|
(C++11)
|
分布の内部状態をリセットする
(public member function) |
生成 |
|
|
(C++11)
|
分布における次の乱数を生成する
(public member function) |
特性 |
|
|
(C++11)
|
分布パラメータを返す
(public member function) |
|
(C++11)
|
分布パラメータオブジェクトを取得または設定する
(public member function) |
|
(C++11)
|
生成され得る最小値を返す
(public member function) |
|
(C++11)
|
生成され得る最大値を返す
(public member function) |
非メンバー関数
|
(C++11)
(C++11)
(removed in C++20)
|
2つの分布オブジェクトを比較する
(関数) |
|
(C++11)
|
擬似乱数分布に対するストリーム入出力を実行する
(関数テンプレート) |
例
このコードを実行
#include <iomanip> #include <iostream> #include <map> #include <random> #include <string> int main() { std::random_device rd; std::mt19937 gen(rd()); // アルファ=1、ベータ=2のガンマ分布は // 指数分布に近似します std::gamma_distribution<> d(1, 2); std::map<int, int> hist; for (int n = 0; n != 10000; ++n) ++hist[2 * d(gen)]; for (auto const& [x, y] : hist) if (y / 100.0 > 0.5) std::cout << std::fixed << std::setprecision(1) << x / 2.0 << '-' << (x + 1) / 2.0 << ' ' << std::string(y / 100, '*') << '\n'; }
出力例:
0.0-0.5 ********************** 0.5-1.0 **************** 1.0-1.5 ************* 1.5-2.0 ********** 2.0-2.5 ******** 2.5-3.0 ****** 3.0-3.5 ***** 3.5-4.0 **** 4.0-4.5 *** 4.5-5.0 ** 5.0-5.5 ** 5.5-6.0 * 6.0-6.5 * 6.5-7.0 7.0-7.5 7.5-8.0
外部リンク
| Weisstein, Eric W. "Gamma Distribution." From MathWorld — A Wolfram Web Resource. |
| Weisstein, Eric W. "ガンマ分布" MathWorld — Wolfram Webリソースより |