std:: poisson_distribution
From cppreference.net
|
헤더 파일에 정의됨
<random>
|
||
|
template
<
class
IntType
=
int
>
class poisson_distribution ; |
(C++11부터) | |
음수가 아닌 정수 값 i 를 생성하며, 이산 확률 함수에 따라 분포됩니다:
-
P(i|μ) =
e -μ
·μ i
i!
얻어진 값은 정확히 i 번의 확률적 사건 발생 확률이며, 이때 동일한 조건(동일 시간/공간 구간)에서 기대되는 평균 발생 횟수가 μ 인 경우를 의미합니다.
std::poisson_distribution
는
RandomNumberDistribution
요구 사항을 충족합니다.
목차 |
템플릿 매개변수
| IntType | - | 생성자가 생성하는 결과 타입. 이것이 다음 중 하나가 아닌 경우의 효과는 정의되지 않음: short , int , long , long long , unsigned short , unsigned int , unsigned long , 또는 unsigned long long . |
멤버 타입
| 멤버 타입 | 정의 |
result_type
(C++11)
|
IntType
|
param_type
(C++11)
|
매개변수 집합의 타입, RandomNumberDistribution 참조. |
멤버 함수
|
(C++11)
|
새로운 분포를 생성합니다
(public member function) |
|
(C++11)
|
분포의 내부 상태를 재설정합니다
(public member function) |
생성 |
|
|
(C++11)
|
분포에서 다음 난수를 생성합니다
(public member function) |
특성 |
|
|
(C++11)
|
mean
분포 매개변수를 반환합니다 (사건 발생의 평균 횟수)
(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)
|
두 분포 객체를 비교
(함수) |
|
(C++11)
|
의사 난수 분포에 대한 스트림 입출력 수행
(함수 템플릿) |
예제
이 코드 실행
#include <iomanip> #include <iostream> #include <map> #include <random> #include <string> int main() { std::random_device rd; std::mt19937 gen(rd()); // 어떤 사건이 평균적으로 분당 4회 발생한다면, // 1분 동안 n회 발생하는 경우는 얼마나 자주 있을까? std::poisson_distribution<> d(4); 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 c d
외부 링크
| Weisstein, Eric W. "푸아송 분포." MathWorld — Wolfram 웹 자원에서. |