randomPoisson¶
Generates pseudorandom numbers from a Poisson distribution.
Synopsis¶
randomPoisson (nRandom, theta)
Required Arguments¶
- int
nRandom(Input) - Number of random numbers to generate.
- float
theta(Input) - Mean of the Poisson distribution. The argument
thetamust be positive.
Return Value¶
randomPoisson returns a vector of length nRandom containing the
random Poisson deviates.
Description¶
The function randomPoisson generates pseudorandom numbers from a Poisson
distribution with positive mean theta. The probability function (with θ
= theta) is
If theta is less than 15, randomPoisson uses an inverse CDF method;
otherwise, the PTPE method of Schmeiser and Kachitvichyanukul (1981) (see
also Schmeiser 1983) is used. The PTPE method uses a composition of four
regions, a triangle, a parallelogram, and two negative exponentials. In each
region except the triangle, acceptance/rejection is used. The execution time
of the method is essentially insensitive to the mean of the Poisson.
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, randomPoisson is used to generate five pseudorandom
deviates from a Poisson distribution with mean equal to 0.5.
from numpy import *
from pyimsl.math.randomPoisson import randomPoisson
from pyimsl.math.randomSeedSet import randomSeedSet
from pyimsl.math.writeMatrix import writeMatrix
randomSeedSet(123457)
theta = 0.5
r = randomPoisson(5, theta)
writeMatrix("Poisson(0.5) random deviates", r)
Output¶
Poisson(0.5) random deviates
1 2 3 4 5
2 0 1 0 1