200 likes | 465 Views
An Introduction to R Pseudo Random Number Generation (PRNG). Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University. Pseudo Random Number Generator (PRNG).
E N D
An Introduction to RPseudo Random Number Generation (PRNG) Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University
Pseudo Random Number Generator (PRNG) • Computer simulation of random variables is the task of using computers to generate many random numbers that are independent and identically distributed. It is also known as random number generation (RNG). • In fact, these computer-generated random numbers form a deterministicsequence, and the same list of numbers will be cycled over and over again. This cycle can be made to be so long that the lack of true independence is unimportant.
Therefore, such computer codes are often termed pseudo-random number generators (PRNG). • There exist mathematical transformation methods to obtain other distributions from uniform variates. For this reason, most PRNGs found in software libraries produce uniform random numbers in the unit interval (0, 1).
Linear Congruential Generator • Generation of random samples of various probability densities is based random samples of the uniform density U[0,1). Therefore, the algorithm of generating random numbers of U[0,1) is essential. This can be achieved by the Linear Congruential Generator (LCG) described below.
Let a sequence of numbers xn be defined by modulo m where a, c, and m are given positive integers. The above equation means that is divided by m and the remainder is taken as the value of . The quantity is then taken as an approximation to the value of a U[0,1) random variable. When c = 0, the algorithm is also called a pure multiplicative generator.
A guideline for selection of a and m (c =0) is that m be chosen to be a large prime number that can be fitted to the computer word size. For a 32-bit word computer, m = and a = result in desired properties. • For small computers without a random number generator, the following a, c, and m are found to be satisfactory when the LCG algorithm is used: and
PROBABILITY INTEGRAL TRANSFORMATION • The PIT method is based on the property that a random variable X with CDF can be transformed into a random variable U with uniform distribution over the interval (0,1) by defining • Conversely, if U is uniformly distributed over the interval (0,1), then has cumulative distribution function .
Demonstration of the Probability Integration Transformation through stochastic simulation
For random variables whose cumulative distribution function cannot be expressed by a close form the probability integral transformation technique cannot be used for generating random numbers of these random variables. • The normal distribution is one such random variable.
The Acceptance/Rejection Method • This method uses an auxiliary density for generation of random quantities from another distribution. This method is particularly useful for generating random numbers of random variables whose cumulative distribution functions cannot be expressed in closed form.
Suppose that we want to generate random numbers of a random variable X with density f(X). • An auxiliary density g(X) which we know how to generate random samples is identified and cg(X) is everywhere no less than f(X) for some constant c, i.e.,
cg(X) f(X) X
Generate a random number x of density g(X), • Generate a random number u from the density U[0,cg(x)), • Reject x if u > f(x); otherwise, x is accepted as a random number form f(X), • Repeat the above steps until the desired number of random numbers are obtained.