naginterfaces.library.rand.dist_​gamma

naginterfaces.library.rand.dist_gamma(n, a, b, statecomm)[source]

dist_gamma generates a vector of pseudorandom numbers taken from a gamma distribution with parameters and .

For full information please refer to the NAG Library document for g05sj

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g05/g05sjf.html

Parameters
nint

, the number of pseudorandom numbers to be generated.

afloat

, the parameter of the gamma distribution.

bfloat

, the parameter of the gamma distribution.

statecommdict, RNG communication object, modified in place

RNG communication structure.

This argument must have been initialized by a prior call to init_repeat() or init_nonrepeat().

Returns
xfloat, ndarray, shape

The pseudorandom numbers from the specified gamma distribution.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, [‘state’] vector has been corrupted or not initialized.

Warns
NagAlgorithmicWarning
(errno )

On entry, .

For very small shape parameter values, variates are approximate.

Notes

The gamma distribution has PDF (probability density function)

One of three algorithms is used to generate the variates depending upon the value of :

  1. if , a switching algorithm described by Dagpunar (1988) (called G6) is used. The target distributions are and , where , and the switching parameter, , is taken as . This is similar to Ahrens and Dieter’s GS algorithm (see Ahrens and Dieter (1974)) in which ;

  2. if , the gamma distribution reduces to the exponential distribution and the method based on the logarithmic transformation of a uniform random variate is used;

  3. if , the algorithm given by Best (1978) is used. This is based on using a Student’s -distribution with two degrees of freedom as the target distribution in an envelope rejection method.

One of the initialization functions init_repeat() (for a repeatable sequence if computed sequentially) or init_nonrepeat() (for a non-repeatable sequence) must be called prior to the first call to dist_gamma.

References

Ahrens, J H and Dieter, U, 1974, Computer methods for sampling from gamma, beta, Poisson and binomial distributions, Computing (12), 223–46

Best, D J, 1978, Letter to the Editor, Appl. Statist. (27), 181

Dagpunar, J, 1988, Principles of Random Variate Generation, Oxford University Press

Hastings, N A J and Peacock, J B, 1975, Statistical Distributions, Butterworth