Namespaces
Variants

std:: gamma_distribution

From cppreference.net
헤더 파일에 정의됨 <random>
template < class RealType = double >
class gamma_distribution ;
(C++11 이후)

양의 부동 소수점 값을 무작위로 생성합니다. x , 확률 밀도 함수에 따라 분포됩니다:

P(x|α,β) =
e -x/β
β α
· Γ(α)
· x α-1

여기서 α 형태 매개변수로 알려져 있고 β 척도 매개변수로 알려져 있습니다. 형태 매개변수는 때때로 문자 k 로 표기되며, 척도 매개변수는 때때로 문자 θ 로 표기됩니다.

부동 소수점 α 의 경우, 얻어진 값은 각각 평균이 β 인 지수 분포를 따르는 독립 확률 변수 α 개의 합입니다.

std::gamma_distribution RandomNumberDistribution 요구 사항을 충족합니다.

목차

템플릿 매개변수

RealType - 생성기에 의해 생성되는 결과 타입. 이것이 다음 중 하나가 아닌 경우의 효과는 정의되지 않음: float , double , 또는 long double .

멤버 타입

멤버 타입 정의
result_type (C++11) RealType
param_type (C++11) 매개변수 집합의 타입, RandomNumberDistribution 참조.

멤버 함수

새로운 분포를 생성합니다
(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)
두 분포 객체를 비교함
(함수)
의사 난수 분포에 대한 스트림 입출력을 수행함
(함수 템플릿)

예제

#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.