名前空間
変種
操作

std::piecewise_linear_distribution

提供: cppreference.com
< cpp‎ | numeric‎ | random
 
 
 
擬似乱数生成
一様ランダムビットジェネレータ
エンジンとエンジンアダプタ
非決定的なジェネレータ
分布
一様分布
ベルヌーイ分布
ポアソン分布
正規分布
標本分布
piecewise_linear_distribution
(C++11)
シードシーケンス
(C++11)
C のライブラリ
 
 
ヘッダ <random> で定義
template< class RealType = double >
class piecewise_linear_distribution;
(C++11以上)

std::piecewise_linear_distribution は、いくつかの部分区間 [b
i
, b
i+1
)
それぞれの線形確率密度関数に従って分布する、ランダムな浮動小数点数を生成します。 分布は各区間の境界の確率密度がちょうどあらかじめ定義された値 p
i
となるようになります。

任意の b
i
≤x<b
i+1
について、確率密度は p
i
b
i+1
-x
b
i+1
-b
i
+ p
i+1
x-b
i
b
i+1
-b
i
になります。 ただし区間の境界 p
k
における確率密度は w
k
/S
として計算されます。 ただし S はすべての
1
2
(w
k
+w
k+1
)(b
k+1
−b
k
)
の合計です。

区間の境界 b
i
の集合および境界における重み w
i
の集合がこの分布のパラメータです。

std::piecewise_linear_distributionRandomNumberDistribution の要件をすべて満たします。

目次

[編集] テンプレート引数

RealType - ジェネレータが生成する結果の型。 floatdouble または long double のいずれかでない場合、効果は未定義です


[編集] メンバ型

メンバ型 定義
result_type RealType
param_type パラメータセットの型、 RandomNumberDistribution を参照してください

[編集] メンバ関数

新しい分布を構築します
(パブリックメンバ関数) [edit]
分布の内部状態をリセットします
(パブリックメンバ関数) [edit]
生成
分布の次の乱数を生成します
(パブリックメンバ関数) [edit]
特性
分布のパラメータを返します
(パブリックメンバ関数) [edit]
分布のパラメータオブジェクトを取得または設定します
(パブリックメンバ関数) [edit]
生成される可能性のある最小値を返します
(パブリックメンバ関数) [edit]
生成される可能性のある最大値を返します
(パブリックメンバ関数) [edit]

[編集] 非メンバ関数

2つの分布オブジェクトを比較します
(関数) [edit]
乱数分布に対してストリーム入出力を行います
(関数テンプレート) [edit]

[編集]

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
 
int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    // increase the probability from 0 to 5
    // remain flat from 5 to 10
    // decrease from 10 to 15 at the same rate
    std::vector<double> i{0, 5, 10, 15};
    std::vector<double> w{0, 1,   1, 0};
    std::piecewise_linear_distribution<> d(i.begin(), i.end(), w.begin());
 
    std::map<int, int> hist;
    for(int n=0; n<10000; ++n) {
        ++hist[d(gen)];
    }
    for(auto p : hist) {
        std::cout << std::setw(2) << std::setfill('0') << p.first << ' '
            << std::string(p.second/100,'*') << '\n';
    }
}

出力例:

00 *
01 ***
02 ****
03 ******
04 *********
05 *********
06 *********
07 **********
08 *********
09 **********
10 *********
11 *******
12 ****
13 ***
14 *