std::gamma_distribution
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <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
|
RealType
|
param_type
|
パラメータセットの型、 RandomNumberDistribution を参照してください |
メンバ関数
| 新しい分布を構築します (パブリックメンバ関数) | |
| 分布の内部状態をリセットします (パブリックメンバ関数) | |
生成 | |
| 分布の次の乱数を生成します (パブリックメンバ関数) | |
特性 | |
| 分布のパラメータを返します (パブリックメンバ関数) | |
| 分布のパラメータオブジェクトを取得または設定します (パブリックメンバ関数) | |
| 生成される可能性のある最小値を返します (パブリックメンバ関数) | |
| 生成される可能性のある最大値を返します (パブリックメンバ関数) | |
非メンバ関数
| 2つの分布オブジェクトを比較します (関数) | |
| 乱数分布に対してストリーム入出力を行います (関数テンプレート) |
例
Run this code
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
// alpha=1, beta=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 p : hist) {
std::cout << std::fixed << std::setprecision(1)
<< p.first/2.0 << '-' << (p.first+1)/2.0 <<
' ' << std::string(p.second/200, '*') << '\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
8.0-8.5
8.5-9.0
9.0-9.5
9.5-10.0
10.0-10.5
10.5-11.0
11.0-11.5
11.5-12.0
12.0-12.5
12.5-13.0
13.0-13.5
13.5-14.0
14.0-14.5
15.0-15.5
15.5-16.0
18.0-18.5
18.5-19.0
外部リンク
Weisstein, Eric W. "Gamma Distribution." From MathWorld--A Wolfram Web Resource.