randomBeta¶
Generates pseudorandom numbers from a beta distribution.
Synopsis¶
randomBeta (nRandom, pin, qin)
Required Arguments¶
- int
nRandom
(Input) - Number of random numbers to generate.
- float
pin
(Input) - First beta distribution parameter. Argument
pin
must be positive. - float
qin
(Input) - Second beta distribution parameter. Argument
qin
must be positive.
Return Value¶
randomBeta
returns a vector of length nRandom
containing the
random standard beta deviates.
Description¶
The function randomBeta
generates pseudorandom numbers from a beta
distribution with parameters pin
and qin
, both of which must be
positive. With p = pin
and q = qin
, the probability density
function is
where Γ(⋅) is the gamma function.
The algorithm used depends on the values of p and q. Except for the
trivial cases of \(p=1\) or \(q=1\), in which the inverse CDF method
is used, all of the methods use acceptance/rejection. If p and q are both
less than 1, the method of Jöhnk (1964) is used. If either p or q is less
than 1 and the other is greater than 1, the method of Atkinson (1979) is
used. If both p and q are greater than 1, algorithm BB of Cheng (1978),
which requires very little setup time, is used if nRandom
is less than 4;
and algorithm B4PE of Schmeiser and Babu (1980) is used if nRandom
is
greater than or equal to 4. Note that for p and q both greater than 1,
calling randomBeta
in a loop getting less than 4 variates on each call
will not yield the same set of deviates as calling randomBeta
once and
getting all the deviates at once.
The values returned in r
are less than 1.0 and greater than ɛ where ɛ is
the smallest positive number such that 1.0 − ɛ is less than 1.0.
The function randomSeedSet
can be used to initialize the seed of the
random number generator. The function randomOption
can be used to select
the form of the generator.
Example¶
In this example, randomBeta
is used to generate five pseudorandom beta
(3, 2) variates.
from numpy import *
from pyimsl.math.randomBeta import randomBeta
from pyimsl.math.randomSeedSet import randomSeedSet
from pyimsl.math.writeMatrix import writeMatrix
randomSeedSet(123457)
pin = 3.0
qin = 2.0
r = randomBeta(5, pin, qin)
writeMatrix("Beta (3,2) random deviates", r)
Output¶
Beta (3,2) random deviates
1 2 3 4 5
0.2814 0.9483 0.3984 0.3103 0.8296