This document is published at www.agner.org/random, Feb. 2008, as part of a software package.



Similar documents
2WB05 Simulation Lecture 8: Generating random variables

Probability Calculator

Notes on Continuous Random Variables

Chapter 3: DISCRETE RANDOM VARIABLES AND PROBABILITY DISTRIBUTIONS. Part 3: Discrete Uniform Distribution Binomial Distribution

Chapter 3 RANDOM VARIATE GENERATION

Joint Exam 1/P Sample Exam 1

STT315 Chapter 4 Random Variables & Probability Distributions KM. Chapter 4.5, 6, 8 Probability Distributions for Continuous Random Variables

Probability and Statistics Prof. Dr. Somesh Kumar Department of Mathematics Indian Institute of Technology, Kharagpur

Department of Mathematics, Indian Institute of Technology, Kharagpur Assignment 2-3, Probability and Statistics, March Due:-March 25, 2015.

Lecture 5 : The Poisson Distribution

The Monty Python Method for Generating Gamma Variables

CHAPTER 6: Continuous Uniform Distribution: 6.1. Definition: The density function of the continuous random variable X on the interval [A, B] is.

General Sampling Methods

Probability density function : An arbitrary continuous random variable X is similarly described by its probability density function f x = f X

Statistics I for QBIC. Contents and Objectives. Chapters 1 7. Revised: August 2013

EMPIRICAL FREQUENCY DISTRIBUTION

1 Sufficient statistics

PROBABILITY AND SAMPLING DISTRIBUTIONS

Normal distribution. ) 2 /2σ. 2π σ

Algebra I Vocabulary Cards

Institute of Actuaries of India Subject CT3 Probability and Mathematical Statistics

Tests for Two Proportions

STRUTS: Statistical Rules of Thumb. Seattle, WA

Math 461 Fall 2006 Test 2 Solutions

Non-Inferiority Tests for Two Means using Differences

STAT 360 Probability and Statistics. Fall 2012

A logistic approximation to the cumulative normal distribution

Exploratory Data Analysis

Math 431 An Introduction to Probability. Final Exam Solutions

Statistical Process Control (SPC) Training Guide

Aachen Summer Simulation Seminar 2014

UNIT I: RANDOM VARIABLES PART- A -TWO MARKS

Random variables, probability distributions, binomial random variable

Random Variate Generation (Part 3)

Permutation Tests for Comparing Two Populations

Errata and updates for ASM Exam C/Exam 4 Manual (Sixteenth Edition) sorted by page

WHERE DOES THE 10% CONDITION COME FROM?

Quantitative Methods for Finance

5. Continuous Random Variables

Introduction to the Monte Carlo method

PROPERTIES OF THE SAMPLE CORRELATION OF THE BIVARIATE LOGNORMAL DISTRIBUTION

Stochastic Processes and Queueing Theory used in Cloud Computer Performance Simulations

Example: Credit card default, we may be more interested in predicting the probabilty of a default than classifying individuals as default or not.

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

MATH 10: Elementary Statistics and Probability Chapter 5: Continuous Random Variables

5.1 Identifying the Target Parameter

Beta Distribution. Paul Johnson and Matt Beverlin June 10, 2013

Math 425 (Fall 08) Solutions Midterm 2 November 6, 2008

Manhattan Center for Science and Math High School Mathematics Department Curriculum

1) Write the following as an algebraic expression using x as the variable: Triple a number subtracted from the number

Chapter 5. Random variables

Chapter 4 Lecture Notes

096 Professional Readiness Examination (Mathematics)

MULTIVARIATE PROBABILITY DISTRIBUTIONS

Principle of Data Reduction

Algebra Unpacked Content For the new Common Core standards that will be effective in all North Carolina schools in the school year.

Cloud Storage and Online Bin Packing

INSURANCE RISK THEORY (Problems)

3. Monte Carlo Simulations. Math6911 S08, HM Zhu

1.1 Introduction, and Review of Probability Theory Random Variable, Range, Types of Random Variables CDF, PDF, Quantiles...

Sums of Independent Random Variables

Stats on the TI 83 and TI 84 Calculator

Confidence Intervals for the Difference Between Two Means

Probability and Statistics Vocabulary List (Definitions for Middle School Teachers)

Study Guide for the Final Exam

MATH4427 Notebook 2 Spring MATH4427 Notebook Definitions and Examples Performance Measures for Estimators...

An Introduction to Basic Statistics and Probability

Introduction to Mobile Robotics Bayes Filter Particle Filter and Monte Carlo Localization

Chapter 14 Managing Operational Risks with Bayesian Networks

Internet Dial-Up Traffic Modelling

Word Length and Frequency Distributions in Different Text Genres

4. Continuous Random Variables, the Pareto and Normal Distributions

Chapter 4. Probability and Probability Distributions

CONTINGENCY TABLES ARE NOT ALL THE SAME David C. Howell University of Vermont

6.4 Normal Distribution

Maximum Likelihood Estimation

Queuing Theory. Long Term Averages. Assumptions. Interesting Values. Queuing Model

Algebra Academic Content Standards Grade Eight and Grade Nine Ohio. Grade Eight. Number, Number Sense and Operations Standard

Some special discrete probability distributions

Linear Threshold Units

Standard Deviation Estimator

Business Statistics. Successful completion of Introductory and/or Intermediate Algebra courses is recommended before taking Business Statistics.

AP STATISTICS 2010 SCORING GUIDELINES

individualdifferences

Density Curve. A density curve is the graph of a continuous probability distribution. It must satisfy the following properties:

Estimating the Degree of Activity of jumps in High Frequency Financial Data. joint with Yacine Aït-Sahalia

Fairfield Public Schools

Common Core Unit Summary Grades 6 to 8

Linda K. Muthén Bengt Muthén. Copyright 2008 Muthén & Muthén Table Of Contents

Statistical Functions in Excel

Two-Sample T-Tests Assuming Equal Variance (Enter Means)

Lecture 8. Confidence intervals and the central limit theorem

The normal approximation to the binomial

ST 371 (IV): Discrete Random Variables

Traffic Behavior Analysis with Poisson Sampling on High-speed Network 1

Statistics 100A Homework 7 Solutions

6.4 Logarithmic Equations and Inequalities

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.436J/15.085J Fall 2008 Lecture 14 10/27/2008 MOMENT GENERATING FUNCTIONS

39.2. The Normal Approximation to the Binomial Distribution. Introduction. Prerequisites. Learning Outcomes

Transcription:

Sampling methods by Agner Fog This document is published at www.agner.org/random, Feb. 008, as part of a software package. Introduction A C++ class library of non-uniform random number generators is available from www.agner.org/random. The distributions include normal, poisson, binomial, hypergeometric, Fisher's noncentral hypergeometric and Wallenius' noncentral hypergeometric distributions as well as multivariate versions of these distributions. This document describes the various methods used for generating variates with some of these distributions. The reader is referred to the file distrib.pdf for a definition of these distributions and to the file nchyp.pdf (Fog 004) for theory of Fisher's and Wallenius' noncentral hypergeometric distributions. Two characteristics are important when selecting the optimal variate generation method, the set-up time and the execution time (Stadlober 1989). The set-up time is the computer time used by the non-random part of the calculations, which only depends on the parameters. The execution time is the time spent on the rest of the calculations, which involves random factors. The set-up time is unimportant if the generator is called repeatedly with the same parameters because the results of these calculations can be saved and re-used. The set-up time is important, however, if the parameters often change. Some of the generators are provided in two different versions, one with a short set-up time, which is optimal when parameters often change, and one with a long set-up time but a short execution time, which is optimal when the generator is called repeatedly with the same parameters. The former generators are implemented in the C++ classes StochasticLib, while the latter are implemented in StochasticLib. Generators for Fisher's and Wallenius' noncentral hypergeometric distributions are implemented in StochasticLib3. Some of the functions in this library are adapted from the Win-rand package by Ernst Stadlober. See www.cis.tugraz.at/stat/stadl/random.html. The Win-rand package also contains many other distributions than the ones supplied here, and a graphic interface to show the distribution curves. Inversion method Assume that we want to generate a variate with the frequency function f(x). The distribution function is F( x) = x f( t) dt (1) 0 for a continuous distribution, or x F( x) = f( j) () j = 0 for a discrete distribution. If u is a variate with the uniform distribution u ~ uniform(0,1), then a variate with the desired distribution can be generated by applying the inverse distribution function to u: x = F 1 ( u) (3)

This method requires that F -1 is easy to calculate. Inversion by chop down search from 0 When f(x) is a discrete function (x integer) then (3) can be calculated by successively adding f(0) + f(1) +... + f(x) until the sum exceeds u. Each f(x) is computed from the previous one according to a recursion formula: Poisson: L = f( x 1) (4) x Binomial: n x + 1 p = f( x 1) (5) x 1 p Hypergeometric: ( m x + 1)( n x + 1) = f( x 1), L = N m n (6) x( L + x) Fisher's noncentral hypergeometric: ( m x + 1)( n x + 1) = f( x 1) ω, L = N m n (7) x( L + x) Since division is slow, this method can be speeded up by multiplying u with the denominator in the recursion formula instead of dividing f(x) with the denominator. We then have to check for overflow unless the parameters are limited to safe intervals. The computation time is proportional to the mean of x. Therefore this method is used only when the mean is low. This method is used for the poisson and binomial distributions in StochasticLib when the mean is below a certain threshold. Chop down search from the mode This is very similar to the method above. f(x) values are added consecutively until the sum exceeds u. The difference is that the x values are taken in a different order. Rather than starting at x = 0 we start at the mode M, and take f(m) + f(m-1) + f(m+1) + f(m-) + f(m+) +... until the sum exceeds u. The advantage of this method is that the search is likely to end earlier when we take the most probable x-values first. The disadvantage is that the set-up time is higher. This method is used when the mean is low for hypergeometric in StochasticLib and also for poisson and binomial in StochasticLib.

Rejection method The principle of the rejection method is that the frequency function f(x) is approximated by another distribution function h(x) which is easier to calculate, and then a correction is made by randomly accepting x values with a probability p( x ) =, and rejecting x values with k h( x) probability 1-p(x). The constant k is chosen so that k h( x) for all values of x. Whenever an x value is rejected, the procedure starts over again with a new x. The accepted x values have the distribution f(x) because the acceptance probability p(x) is proportional to f(x) / h(x). x values with distribution h(x) are generated by simple inversion from a random number u with uniform distribution: x = H -1 (u), where H is the integral of h and H -1 is the inverse of H. Acceptance/rejection is done on the basis of a second random number v with uniform distribution. x is accepted if v < p(x) and rejected if v p(x). The rejection method can be improved by quick acceptance and quick rejection schemes. Quick acceptance is based on a minorizing function fa ( x), and quick rejection is based on a majorizing function fr ( x). These can be simple linear functions or other functions that are easy to calculate. The acceptance condition can be written as vkh(x) < f(x). The timeconsuming calculation of f(x) is avoided by quick acceptance when vkh(x) < f a (x) and quick rejection when vk h( x) fr ( x). Only when vkh(x) is between these two values do we need to calculate f(x) in the final acceptance/rejection decision. The advantage of the rejection method is that the calculation time does not grow with x. It is therefore used when the variance is so large that the chop-down search would be more time consuming. The disadvantage of the rejection method is that it is difficult to find a good hat function h(x) which is easy to calculate and at the same time approximates f(x) so good that the rejection rate will be low. A bad hat function will lead to a high rejection rate and hence a long execution time. Various improvements of the rejection method are applied, as explained below. Patchwork rejection method (Stadlober & Zechner 1998). This variation of the rejection method uses a simple hat function, which has a large uniform section in the center and exponential tails. The area under the curve of the frequency function f(x) is cut into pieces which are rotated and rearranged geometrically like a jigsaw puzzle to fill as much of the area under the hat function as possible. A point under the curve of the hat function is generated on the basis of the two uniform random numbers u and v. It is then determined whether this point falls on a piece of our jigsaw puzzle or in the rejection area between the pieces. If the point falls on a rearranged piece then the transformations of the rearrangement are undone in order to find the corresponding x. Quick acceptance and quick rejection areas are used. The advantage of this method is that the rejection rate is low. The disadvantage is that the setup time is quite high because it takes a lot of calculations to determine where the borders of each piece are. Hence, this method is only advantageous if the function is called many times with the same parameters. The patchwork rejection method is used for the poisson, binomial and hypergeometric functions in StochasticLib when the mean is high.

Ratio-of-uniforms rejection method (Stadlober 1989, 1990). Let u and v be two independent random numbers with uniform distribution in the intervals 0 < u 1, and 1 v 1. Do the transformation x = sv u + a, y = u. The rectangle in the (u,v) plane is transformed into a hat function y = h(x) in the (x,y) plane. All (x,y) points will fall under the hat curve y = h(x) which is uniform in the center and falls like x - in the tails. h(x) is a useful hat function for the rejection method. The acceptance condition is v < f(x)/k. s and a are chosen so that k h( x) for all x, where 1 for a s x a + s h( x ) = s elsewhere (8) ( x a) The advantage of this method is that the calculations are simple and fast, and the rejection rate is reasonable. Quick acceptance and quick rejection areas can be applied. For discrete distributions, f(x) is replaced by f( x. ) The following values are used for the hat parameters for the poisson, binomial and hypergeometric distributions a = µ +, and (9) 1 s = σ + 1 ( + ) s1, 3 3 s 1 = (10) where µ is the mean and σ is the variance of the distribution (Ahrens & Dieter 1989). These values are reasonably close to the optimal values. It is possible to calculate the optimal values for a and s (Stadlober 1989, 1990), but this adds to the set-up time with only a marginal improvement in execution time. The optimal value of k is of course the maximum of f(x): k = f(m), where M is the mode. This method is used for the poisson, binomial and hypergeometric distributions in StochasticLib. Box-Muller transformation A special transformation method is used for the normal distribution (Devroye 1986). 1. Generate two independent uniform variates u and v in the interval [-1,1]. Set z = u +v. 3. If z 1 then reject and go to step 1 4. Set w = log z z 5. x 1 = uw and x = vw are independent variates with distribution normal(0,1) Conditional method for multivariate distributions The conditional method for sampling from a multivariate distribution is the method where x 1 is sampled first from the marginal distribution, then x is sampled according to the conditional

distribution of x given x 1, and so forth (Johnson 1987). This method is useful for sampling from the multivariate binomial (multinomial) and the multivariate hypergeometric distributions, because the marginal and conditional distributions are all univariate binomial, respectively hypergeometric, distributions. Fisher's and Wallenius' noncentral hypergeometric distributions Methods for the univariate and multivariate Fisher's and Wallenius' noncentral hypergeometric distributions are described in detail in the file nchyp.pdf and in (Fog 004, 008). These methods are implemented in the C++ class StochasticLib3. References Ahrens, J H & Dieter, U (1989): A convenient sampling method with bounded computation times for Poisson distributions. American Journal of Mathematical and Management Sciences, pp. 1-13. Devroye, Luc (1986): Non-uniform random variate generation. New York: Springer. Fog, Agner (004): The noncentral hypergeometric probability distributions. www.agner.org/random/theory. Fog, Agner (008): Sampling Methods for Wallenius' and Fisher's Noncentral Hypergeometric Distributions. Communications in Statistics - Simulation and Computation. vol. 37, no., pp. 41-57. Johnson, Mark E (1987): Multivariate Statistical Simulation. New York: Wiley & Sons. Levin, Bruce (1984): Simple improvements on Cornfield's approximation to the mean of a noncentral hypergeometric random variable. Biometrika, vol. 71, no. 3. pp. 630-63. Liao, Jason G; Rosen, Ori (00): Fast and Stable Algorithms for Computing and Sampling from the Noncentral Hypergeometric Distribution. The American Statistician, vol. 55, no. 4, pp. 366-369. Stadlober, Ernst (1989): Sampling from poisson, binomial and hypergeometric distributions: Ratio of uniforms as a simple and fast alternative. Berichte der mathematisch-statistischen Sektion in der Forschungsgesellschaft Joanneum, no. 303, Graz. Stadlober, Ernst (1990): The ratio of uniforms approach for generating discrete random variates. Journal of Computational and Applied Mathematics, vol. 31, no. 1, 1990, pp. 181-189. Stadlober, Ernst & Zechner, Heinz (1999): The Patchwork Rejection Technique for Sampling from Unimodal Distributions. ACM Transactions on Modeling and Computer Simulation, Vol. 9, No. 1, pp. 59-80.