Baixe Simulation - Sheldon Ross - Academic Press 4 ed. 2006 e outras Notas de estudo em PDF para Cultura, somente na Docsity!
Simulation Fourth Edition Vi Bar Simulation Fourth Edition Sheldon M. Ross Epstein Department of Industrial and Systems Engineering University of Southern California AMSTERDAM « BOSTON » HEIDELBERG + LONDON NEW YORK « OXFORD » PARIS » SAN DIEGO SAN FRANCISCO « SINGAPORE « SYDNEY « TOKYO Academis Press is an imprint of Elsevier vi Contents 3 Random Numbers 41 Introduction 41 3.1 Pseudorandom Number Generation 41 3,2 Using Random Numbers to Evaluate Integrals 42 Exercises * 46 References 48 4 Generating Discrete Random Variables 49 4.1 The Inverse Transform Method 49 4.2 Generating a Poisson Random Variable 55 4.3 Generating Binomial Random Variables 57 44 The Acceptance-Rejection Technique 58 4.5 The Composition Approach 60 4.6 Generating Random Vectors 61 Exercises 62 5 Generating Continuvous Random Variables 67 Introduction 67 5.1 The Inverse Transform Algorithm 67 5.2 The Rejection Method 71 5.3 The Polar Method for Generating Normal Random Variables 78 5.4 Generating a Poisson Process 82 5.5 Generating a Nonhomogeneous Poisson Process 83 Exercises 87 References 91 6 The Discrete Event Simulation Approach 93 Introduction 93 6.1 Simulation via Discrete Events 93 6.2 A Single-Server Queneing System 94 6.3 A Queueing System with Two Servers in Series 97 64 A Queueing System with Two Parallel Servers 99 6.5 An Inventory Model 102 6.6 An Insurance Risk Model 103 6.7 A Repair Problem 105 6.8 Exercising a Stock Option 108 6.9 Verification of the Simulation Model 110 Exercises 111 References 115 Contents 7 Statistical Analysis of Simulated Data 117 Introduction 117 7.1 The Sample Mean and Sample Variance 117 7.2 Interval Estimates of a Population Mean 123 7.3 The Bootstrapping Technique for Estimating Mean Square Errors 126 Exercises 133 References 135 8 Variance Reduction Techniques 137 Introduction 137 8.1 The Use of Antithetic Variables 139 8.2 The Use of Control Variates 147 8.3 Variance Reduction by Conditioning 154 Estimating the Expected Number of Renewals by Time + 164 84 Stratifed Sampling 166 8.5 Applications of Stratified Sampling 175 Analyzing Systems Having Poisson Arrivais 176 Computing Multidimensional Integrals of Monotone Functions 180 Compound Random Vectors 182 84 importance Sampling 184 8.7 VUsing Common Random Numbers 197 8.8 Evaluating an Exotic Option 198 8.9 Estimating Functions of Random Permutations and Random Subsets 203 Random Permutations 203 Random Subsets 206 8.10 Appendix: Verification of Antithetic Variable Approach When Estimating the Expected Value of Monotone Functions 207 Exercises 209 References 217 9 Statistical Validation Techniques 219 Introduction 219 9.1 Goodness of Fit Tests 219 The Chi-Square Goodness of Fit Test for Discrete Data 220 The Kolmogorov—Smimov Test for Continuous Data 222 9.2 Goodness of Fit Tests When Some Parameters Are Unspecified 227 vii viii Contents The Discrete Data Case 227 The Continuous Data Case 230 9.3 The Two-Sample Problem 230 9.4 Validating the Assumption of a Nonhomogeneous Poisson Process 237 Exercises 241 References 244 10 Markov Chain Monte Carlo Methods 245 Introduction 245 10.1 Markov Chains 245 10.2 The Hastings-Metropolis Algoritim 248 10.3 The Gibbs Sampler 251 104 Simulated Annealing 262 10.5 The Sampling Enportance Resampling Algorithm 264 Exercises 269 References 272 11 Some Additional Topics 273 Introduction 273 11.1 The Alias Method for Generating Discrete Random Variables 273 11.2 Simulating a Two-Dimensional Poisson Process 277 11,3 Simulation Applications of an Identity for Sums of Bernoulti Random Variables 280 11.4 Estimating the Distribution and the Mean of the First Passage Time of a Markov Chain 285 11.5 Conpling from the Past 289 Exercises 291 References 293 Index 294 Preface Overview In formulating a stochastic model to describe a real phenomenon, it used to be that one compromised between choosing a model that is a realistic replica of the actual. situation and choosing one whose mathematical analysis is tractable. That is, there did not seem to be any payoff ir choosing a model that faithfully conformed to the phenomenon under study if it were not possible to mathematically analyze that model, Similar considerations have led to the concentration on asymptotic or steady-state results as opposed to the more useful ones on transient time. However, the relatively recent advent of fast and inexpensive computational power has opened up another approach-—namely, to try to model the phenomenon as faithfully as possible and then to rely on a simulation study to analyze it. In this text we show how to analyze a model by use of a simulation study. Tn particular, we first show how a compater can be utilized to generate random (more precisely, pseudorandom) numbers, and then how these random numbers can be used to generate the values of random variables from arbitrary distribu- . tions. Using the concept of discrete events we show how to use random variables to generate the behavior of a stochastic model over time. By continualiy gener- ating the behavior of the system we show how to obtain estimators of desired quantities of interest. The statistical questions of when to stop a simulation and what confidence to place in the resulting estimators are considered. A variety of ways in which one can improve on the usual simulation estimators are presented. In addition, we show how to use simulation to determine whether the stochastic model chosen is consistent with a set of actual data. New to This Edition New exercises in most chapters. New results on generating a sequence of Bemoulli random variabies (Example 4e). xii Preface of this chain, has become widely used in recent years. These Markov chain Monte Carlo methods are explored in Chapter 10. We start, in Section 10.2, by introducing and presenting some of the properties of Markov chains. A general technique for generating a Markov chain having a limiting distribution that is specified up to a multiplicative constant, known as the Hastings-Metropolis algorithm, is presented in Section 10.3, and an application to generating a randoro element of a large “combinatorial” set is given. The most widely used version of the Hastings-Metropolis algorithm is known as the Gibbs sampler, and this is presented in Section 10,4, Examples are discussed relating to such problems as generating random points in a region subject to a constraint that no pair of points are within a fixed distance of each other, to analyzing product form queueing networks, to analyzing a hierarchical Bayesian statistical model for predicting the numbers of home runs that will be hit by certain baseball players, and to simulating a multinomial vector conditional on the event that all outcomes occur at least once. An application of the methods of this chapter to deterministic optimization problems, called simulated annealing, is presented in Section 10.5, and an example concerning the traveling salesman problem is presented. The final section of Chapter 10 deals with the sampling importance resampling algorithm, which is a generalizatior of the acceptance-rejection technique of Chapters 4 and 5. The use of this algorithm in Bayesian statistics is indicated. Chapter 11 deals with some additional topics in simulation. In Section 11.1 we leam of the alias method which, at the cost of some setup time, is a very efficient way to generate discrete random variables. Section 11.2 is concerned with simulating a two- dimensional Poisson process. In Section 11.3 we present an identity conceming the covariance of the sum of dependent Bernoulti random variables and show how its use can result in estimators of small probabitities having very low variances. Applications relating to estimating the reliability of a system, which appears to be more efficient that any other known estimator of a small systero reliability, and to estimating the probability that a specified pattem occurs by some fixed time, are given. Section 11.4 presents an efficient technique to employ simulation to estimate first passage time means and distributions of a Markov chain. An application to computing the tail probabilities of a bivariate normal random variable is given. Section 11.5 presents the coupling from the past approach to simulating a random variable whose distribution is that of the stationary distribution of a specified Markov chain. Thanks We are indebted to Yontha Ath (California State University, Long Beach) David Buder (Oregon State University), Matt Carlton (California Polytechnic State University), James Daniel (University of Texas, Austin), William Frye (Ball State University), Mark Glickman (Boston University), Ckuanshu Ji (University of North Carolina), Yonghee Kim-Park (California State University, Long Beach), Preface xiii Donald E. Miller (St. Mary's College), Krzysztof Ostaszewski (Illinois State University), Bernardo Pagnocelli, Erol Pekôz (Boston University), Yuval Peres (University of California, Berkeley), and Esther Portnoy (University of Illinois, Urbana-Champaign) for their many helpfai comments. We would like to thank those text reviewers who wish to remain anonymous. Introduction Consider the foliowing situation faced by a pharmacist who is thinking cf setting up a small pharmacy where he will fill prescriptions. He plans on opening up at 9 AM. every weekday and expects that, on average, there will be about 32 prescriptions called in daily before 5 P.M. His experience indicates that the time that it will take him to fill a prescription, once he begins working on it, is a random quantity having a mean and standard deviation of 10 and 4 minntes, respectively. He plans on accepting no new prescriptions after 5 P.m., although he will remain in the shop past this time if necessary to fill alt the prescriptions ordered that day. Given this scenario the pharmacist is probably, among other things, interested in the answers to the following questions: E 1. What is the average time that he will depart his store at night? 2. What proportion of days will he still be working at 5:30 p.M.? 3. What is the average time it will take bim to fill a prescription (taking into account that he cannot begin working on a newly arrived prescription until ali earlier arriving ones have been filled)? 4. What proportion of prescriptions will be filled within 30 minutes? . H'he changes his policy on accepting all prescriptions between 9 A.M. and 5 PM., but rather only accepts new ones when there are fewer than five prescriptions still needing to be filled, how many prescriptions, on average, will be lost? 6. How would tbe conditions of limiting orders affect the answers to questions 1 through 4? u En order to employ mathematics to analyze this situation and answer the questions, we first construct a probability model. To do this it is necessary to make some reasonabiy accurate assumptions concerning the preceding scenario. For instance, we must make some assumptions about the probabilistic mechanism 1 4 1 Introduction service time, and the departure time of customer n. Suppose there is a single server and that the system is initially empty of customers, (a) With D, = 0, argue that for n > O D,—S,=Maximum (A4,,D,.;) (b) Determine the corresponding recursion formula when there are two servers. (o) Determine the corresponding recursion formula when there are k servers. (d) Vie a computer program to determine the departure times as a function of the arrival and service times and use if to check i r your answers in parts (a) and (b) of Exercise 1. ? Elements of Probability 2.1 Sample Space and Events Consider an experiment whose outcome is not known in advance. Let S, called the sample space of the experiment, denote the set of all possible outcomes. For example, if the experiment consisis of the running of a race among the seven horses numbered 1 through 7, then S = (all orderings of (1,2,3,4,5,6,N) The outcome (3, 4, £, 7, 6, 5, 2) means, for example, that the nuraber 3 horse came in first, the number 4 horse came in second, and so on. Any subset A of the sample space is known as an event. That is, an event is a set consisting of possible outcomes of the experiment. H the outcome of the experiment is contained in A, we say that A has occurred. For example, in the above, if A = (ali outcomes in S starting with 5) then A is the event that the number 5 horse comes in first. For any two events 4 and B we define the new event AU B, calied the union of A and B, to consist of all outcomes that are either in 4 or B or in both 4 and B. Simiarty, we define the event AB, called the intersection of À and B, to consist of all outcomes that are in both A and B. That is, the event AUB occurs if either A or B occurs, whereas the event AB occurs if both A and B occur. We can also define unions and intersections of more than two events. In particular, the union of the events A,,..., Ay-—designated by Us. A;— is defined to consist of ail outcomes that are in any of the A,. Similarly, the intersection of the events 5 ó 2 Elements of Probabiliry Ai: -.. A—designated by A,A,..- A, —is defined to consist of all outcomes that are in all of the A,. For any event A we define the event Aº, referred to as the complement of 4, to consist of all outcomes in the sample space S that are not in 4. That is, Aº occurs if and only if A does not. Since the outcome of the experiment must lie in the sample space S, it follows that Sº does not contain any outcomes and thus cannot occur. We call S* the null set and designate it by g. If AB = 6 so that À and B camot both occur (since there are no outcomes that are in both 4 and B), we say that A and B are mutually exclusive. 2.2. Axioms of Probability Suppose that for each event A of an experiment having sample space S there is a number, denoted by P(A) and called the probability of the event A, which is in accord with the foliowing three axioms: Axiom | 0<7(A4)<1 Axiom2 AMS9)=1 Axiom 3 For any sequence of mutually exclusive evenis Ay Ao, e(Ua) Dra) noi, d=1 = . Thus, Axiom 1 states that the probability that the outcome of the experiment les within A is some number between O and 1; Axiom 2 states that with probability 1 this outcome is a member of the sample space; and Axiom 3 states that for any set of mutually exclusive events, the probability that at least one of these events occurs is equal to the sum of their respective probabilities. These three axioras can be used to prove a variety of results about probabilities. For instance, since A and Aº are always mutually exclusive, and since AUA'=S, we have from Axioms 2 and 3 that 1=PMS)=P(AUAS) = P(A)+-P(4º) or equivalently P(A) =1- P(A) In words, the probability that an event does not occur is 1 minns the probability that it does. 2.3 Conditional Probability and Independence 7 2.3 Conditional Probability and Independence Consider an experiment that consists of flipping a coin twice, noting each time whether the result was heads or tails. The sample space of this experiment can be taken to be the following set of four outcomes: S=((H,H), (HT), (T,H),(T,T)) where (H, T) means, for example, that the first flip lands heads and the second tails. Suppose now that each of the four possible outcomes is equally fikely to occur and thus has probability Ea Suppose further that we observe that the first flip lands on heads. Then, given this information, what is the probability that both flips land on heads? To calculate this probability we reason as fol- lows: Given that the initial flip lauds heads, there can be at most two possible outcomes of our experiment, namely, (EL, H) or (H, 1). In addition, as each of these outcomes originally bad the same probability of occurring, they should still have equal probabilities. That is, given that the first flip lands heads, the (conditional) probability of each of the outcomes (H, H) and (H, T) is 1, whercas the (conditional) probability of the other two outcomes is 0. Hence the desired probability is à. * we let 4 and B denote, respectively, the event that both flips land on heads and the event that the first flip lands on heads, then the probability obtained above is called the conditional probability of A given that B has occurred and is denoted by P(AIB) A general formula for P(A|B) that is valid for all experiments and events A and B can be obtained in the same manner as given previously. Namely, if the event B occurs, then in order for A to occur it is necessary that the actual oceurrence be a point in both A and B; that is, it must be in AB. Now since we know that B has occurred, it follows that B becomes our new sample space and hence the probability that the event AB occurs will equal the probability of AB relative to the probability of B. That is, P(AB) P(AÍ|B) = —— ID) = "6 The determination of the probability that some event 4 occurs is often simpli- fied by considerihg a second event B and then determining both the conditionai probability of 4 given that B occurs and the conditional probability of A given that B does not occur. To do this, note first that A = ABUAB 10 2 Elements of Probability H X is a discrete random variable that takes on one of the possible values XX». then, since X must take on one of these values, we have Epa) =1 = Example 2a Suppose that X takes on one of the values 1, 2,0r 3. If MD=5 MD=5 then, since p(1) + p(2) + p(3) = 1, it follows that p(3) = = a Whereas a discrete random variable assumes at most a countable set of possible values, we often have to consider random variables whose set of possible values isan interval We say that the random variable X is a continuous random variable if there is a nonnegative function f(x) defined for all real numbers x and having the property that for any set C of real numbers P(XEC)= L Fo) dx (2.1) The function f is called the probability density function of the random variable X. The relationship between the cumulative distribution F(:) and the probability density f(.) is expressed by Fa) = P(X e (-oo,al)= [ fts)dz Differentiating both sides yields EF(a) = fo) That is, the density is the derivative of the cumulative distribution function. A somewhat more intuitive interpretation of the density function may be obtained from Equation (2.1) as follows: Ple-jstcass)=[Croarmerça) when € is small In other words, the probability that X will be contained in an interval of length e around the point a is approximately ef(a). From this, we see that f(a) is a measure oí how likely it is that the random variable will be near a. EE many experiments we are interested not only in probability distribution functions of individual random variables, but also in the relationships between 2.5 Expectation un two or more of them. In order to specify the relationship between two random variables, we define the joint cumulative probability distribution function of X and Y by Mep=PX
(ax+b)p() xp(x) +b>. pls) =aElX]+b Since the proof in the continuous case is similar, the result is established. [a] 16 2 Elements of Probability Proof From Equation (2.3) it follows that we need to show that E[XY] = EIX]EIY. Now in the discrete case, ERM=DsoPlX= sr =2) 4 =5 5 xyPlX==)P(Y =3,) by independence FR =P =D aP(X =x) j i = [MEX] Since a similar argument hoids in the continuous case, the result is proved. O The correlation between two random variables X and Y, denoted as Cor(X, Y), is defined by Corr(x, 4) = — CD) Tar0O Var(P) 2.7 Chebyshev's Inequality and the Laws of Large Numbers We start with a result known as Markov”s inequality. Proposition Markov's Inequality 1 X rakes on only nomnegative values, then for any value « > O EM PlX>aj<-— a Proof Define the random variable Y by y= a, ifX xa “lo EX 0, it easily follows that XY Taking expectations of the preceding inequality yields EX] > EM =aP[X > 0) and the result is proved. [E 2.7 Chebyshev's Inequality and the Laws of Lorge Numbers 17 As a corollary we have Chebyshev"s inequality, which states that the probability that a random variable differs from its mean by more than k of its standard deviations is bounded by 1/k2, where the standard deviation of a random variable is defined to be the square root of its variance. Corollory Chebyshev's nequality 1X isa random variable having mean ps and variance 02, then for any value k > 0, 1 PIX-niz ko) ss Proof Since (X—)?/o? is a nonnegative random variable whose mean is A 02 we obtain from Maskov"s inequality that E-n? lol P [E 2ki< The result now follows since the inequality (X — p)?/0? > K2 is equivalent to ihe inequality |X — pu] > ko. o We now use Chebyshev's ineguality to prove the weak law of large numbers, which states that the probability that the average of the first x terms of a sequence of independent and identically distributed random variables differs from its mean by more than e goes to O as n goes to infinity. Theorem The Weak Law of Large Numbers Lei X,X,... be . a sequence of independent and identically distributed random variables having mean |. Then, for any e > 0, "| Proof We give a proof under the additional assumption that the random variables X, have a finite variance o?. Now s[Bttã, n E n [-d-0 asn-> 00 | emas eua and a 1 12 var (Ft) = [Varão ++ Var(x,)]= n n n 18 2 Elements of Probahility where the above equation makes use of the fact that the variance of the sum of independent random variables is-equal to the sum of their variances. Hence, from Chebyshev's inequality, it follows. that for any positive k Pp Mtek n ko i <— mjJTR Hence, for any e > 0, by letting k be such tbat ko/./h = e, that is, by letting k=né/o?, we see that "À which establishes the result. o n Att X | | q? ATO ul>el< A generalization of the weak law is the strong law of large numbers, which states that, with probability 1, tim Bt aca a That is, with certainty, the long-run average of a sequence of independent and identically distributed random variables will converge to its mean. 2.8 Some Discrete Random Variables There are certain types of random variables that frequentiy appear in applications. ln this section we survey some of the discrete ones. Binomial Random Variables Suppose that n independent trials, each of which results in a “success” with probability p, are to be performed. If X represents the number of successes that occur in the » trials, then X is said to be a binomial random variable with parameters (7, p). Its probability mass function is given by P=Plx=j= (3) PG, i=0L...n (2.5) where is the binomial coefficient, equal to the number of different subsets of i elements that can be chosen from a set of n elements. 2.8 Some Discrete Random Variables 19 The validity of Equation (2.5) can be seen by first noting that the probability of any particular sequence of outcomes that results in i successes and n—i failures is, by the assumed independence of trials, p'(L — p)"-'. Equation (2.5) then follows since there are (5) different seguences of the n outcomes that result in i successes and n— í failures-— which can be seen by noting that there are (5) different choices of the i trials that result in successes. A binomial (1, p) random variable is called a Bernou!li random variable. Since a binomial (n, p) random variable X represents the number of successes in n independent trials, each of which results in a success with probability p, we can represent it as follows: X=5X, (2.6) ia where xe 1 ifthe ith trial is a success io otherwise Now ElX]=PlX=1)=p Var(X,) = E[X7] — EX]? =p>p'=p(l-p) where the above equation uses the fact that X2 =X, (since 0? =0Q and 12= 1). Hence the representation (2.6) yields that, for a binomial (x, p) random variable X, m= 5 alxi=np i=l Var(X) => Var(X;) since the X, are independent i=l =np(l-p) The following recursive formula expressing pj in terms of p, is useful when computing the binomial probabilities: nt ; + MED men" ar = nn, = MED am pi do mpg DP 0 To =toi po Spot” 22 2 Elements of Probability Summing over m yields that PM =n=DPM=n,M=m) m e DD o ata MUS é a! Le ml » = gro AY o nt Similariy, E P(a = ma = esto QUAD ml! thus verifying that N, and N, are indeed independent Poisson random variables with respective means Ap and A(1 =p). The preceding result generalizes when each of the Poisson number of events is independently one of the types 1,...,r, with respective probabilities Pros Pr Dia p= 1 With N, equal to the number of the events that are type ti=1,...,r, tis similarly shown that N,,.... N, are independent Poisson random variables, with respective means ElMi= Ap, Geometric Random Variables Consider independent trials, each of which is a success with probability p. E X represents the number of the first trial that is a success, then PXen=pd-pr!, n>1 (270 which is easily obtained by noting that in order for the first success to occur on the nth trial, the first 2 — 1 must all be failures and the nth a success. Equation (2.7) now follows because the trials are independent. A random variable whose probability mass function is given by (2.7) is said to be a geometric random variable with parameter p. The mean of the geometric is obtained as follows: ema Bolt py! = 4 2.8 Some Discrete Random Variables 23 wbere the above equation made use of the algebraic identity, for 0 < x < 1, - date d 1 1 nl uy L = E — dx (Ex ) dx (5) 1-3 It is also not difficult to show that Var(X) = 1 The Negative Binomial Random Variable X we let X denote the number of trials needed to amass a total of 7 successes when each trial is independently a success with probability p, then X is said to be a negative binomial, sometimes called a Pascal, random variable with parameters »p and r. The probability mass function of such a random variable is given by the following: Plx=n)= (: T 1) PG, nzr (2.8) To see why Equation (2.8) is valid note that im order for it to take exactly n trials to amass r successes, the first à — 1 trials must result in exactly r— 1 successes—and the probability of this is (17/) p'(1— p)'"—and then the ath trial must be a success-—and the probability of this is p. Kwelet X,i==1,...,r, denote the number of trials needed after the (i— I)st success to obtain the ith success, then it is easy to see that they are independent geometric random variables with common parameter p. Since x=Dx Ei we see that HJ=S EX i=1 Var(1) =) Var(x) = i=1 where the preceding made use of the corresponding results for geometric random variables. 24 2 Elements of Probability Hypergeometric Random Variables Consider an urn containing N 4 M balis, of which N are Hght colored and M are dark colored. If a sample of size n is randomly chosen [in the sense that each of the (“5H subsets of size n is equally likely to be chosen] then X, the number of light colored balls selected, has probability mass function () ( - ) iJhn-i PMX=ij= f À NAM n A random variable X whose probability mass function is given by the preceding equation is called a hypergeometric random variable. Suppose that the x balls are chosen segquentially. If we let X=- 1 ifthe ith selection is light “jo otherwise X=5X, (2.9) and so HD etel= where the above equation uses the fact that, by symmetry, the ith selection is equally likely to be any of the N+M balls, and so EX] = P(X = 1I|= NHNAM). Since the X, are not independent (why not?), the utiization of the represen- tation (2.9) to compute Var(X) involves covariance terms. The end product can be shown to yield the resuit nNM n—1 Ve = rag (WERE) 2.9 Continuous Random Variables Y this section we consider certain types of continuous random variables. 2.9 Continuous Random Variables 25 Uniformly Distributed Random Variables A random variable X is said.to be uniformiy distributed over the interval (a,b),a < b, if its probability density function is given by fa