std::negative_binomial_distribution
From cppreference.com
| ヘッダー <random> で定義 |
||
| template< class IntType = int > class negative_binomial_distribution; |
(C++11以降) | |
成功確率pの独立な「はい」か「いいえ」かの試行(各成功確率p)を繰り返したときに、ちょうどk回の成功が発生する前に起こる失敗の回数iを生成します。
- P(i|k,p) =⎛
⎜
⎝k + i − 1
i⎞
⎟
⎠ · pk
· (1 − p)i
この値は、ちょうどk回の成功が発生する前に、独立な「はい」か「いいえ」かの試行(各成功確率p)の系列で起こった失敗の回数を表します。
std::negative_binomial_distribution は RandomNumberDistribution の要件を満たします。
目次 |
[edit] テンプレートパラメータ
| IntType | - | ジェネレータによって生成される結果の型。これが short、int、long、long long、unsigned short、unsigned int、unsigned long、または unsigned long long のいずれでもない場合、その効果は未定義です。 |
[edit] メンバ型
| メンバ型 | 定義 |
result_type (C++11) |
IntType |
param_type (C++11) |
パラメータセットの型。RandomNumberDistribution を参照してください。 |
[edit] メンバ関数
| (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) |
[edit] 非メンバ関数
| (C++11)(C++11)(C++20で削除) |
2つの分布オブジェクトを比較します。 (function) |
| (C++11) |
疑似乱数分布のストリーム入出力を実行 (関数テンプレート) |
[edit] 例
このコードを実行
#include <iomanip> #include <iostream> #include <map> #include <random> #include <string> int main() { std::random_device rd; std::mt19937 gen(rd()); // Pat goes door-to-door selling cookies // At each house, there's a 75% chance that she sells one box // how many times will she be turned away before selling 5 boxes? std::negative_binomial_distribution<> d(5, 0.75); std::map<int, int> hist; for (int n = 0; n != 10000; ++n) ++hist[d(gen)]; for (auto [x, y] : hist) std::cout << std::hex << x << ' ' << std::string(y / 100, '*') << '\n'; }
実行結果の例
0 *********************** 1 ***************************** 2 ********************** 3 ************* 4 ****** 5 *** 6 * 7 8 9 a b
[edit] 外部リンク
| Weisstein, Eric W. "Negative Binomial Distribution." From MathWorld — A Wolfram Web Resource. |