Random Variables Generation
Total Page:16
File Type:pdf, Size:1020Kb
Random Variables Generation Revised version of the slides based on the book Discrete-Event Simulation: a first course L.L. Leemis & S.K. Park Section(s) 6.1, 6.2, 7.1, 7.2 c 2006 Pearson Ed., Inc. 0-13-142917-5 Discrete-Event Simulation Random Variables Generation 1/80 Introduction Monte Carlo Simulators differ from Trace Driven simulators because of the use of Random Number Generators to represent the variability that affects the behaviors of real systems. Uniformly distributed random variables are the most elementary representations that we can use in Monte Carlo simulation, but are not enough to capture the complexity of real systems. We must thus devise methods for generating instances (variates) of arbitrary random variables Properly using uniform random numbers, it is possible to obtain this result. In the sequel we will first recall some basic properties of Discrete and Continuous random variables and then we will discuss several methods to obtain their variates Discrete-Event Simulation Random Variables Generation 2/80 Basic Probability Concepts Empirical Probability, derives from performing an experiment many times n and counting the number of occurrences na of an event A The relative frequency of occurrence of event is na/n The frequency theory of probability asserts thatA the relative frequency converges as n → ∞ n Pr( )= lim a A n→∞ n Axiomatic Probability is a formal, set-theoretic approach Mathematically construct the sample space and calculate the number of events A The two are complementary! Discrete-Event Simulation Random Variables Generation 3/80 Example Roll two dice and observe the up faces (1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (2, 1) (2, 2) (2, 3) (2, 4) (2, 5) (2, 6) (3, 1) (3, 2) (3, 3) (3, 4) (3, 5) (3, 6) (4, 1) (4, 2) (4, 3) (4, 4) (4, 5) (4, 6) (5, 1) (5, 2) (5, 3) (5, 4) (5, 5) (5, 6) (6, 1) (6, 2) (6, 3) (6, 4) (6, 5) (6, 6) If the two up faces are summed, an integer-valued random variable, say X, is defined with possible values 2 through 12 sum, x : 2 3 4 5 6 7 8 9101112 1 2 3 4 5 6 5 4 3 2 1 Pr(X = x) : 36 36 36 36 36 36 36 36 36 36 36 Pr(X = 7) could be estimated by replicating the experiment many times and calculating the relative frequency of occurrence of 7’s Discrete-Event Simulation Random Variables Generation 4/80 Discrete Random Variables A random variable X is discrete if and only if its set of possible values is finite or, at most, countably infinite X A discrete random variable X is uniquely determined by Its set of possible values Its probability distributionX function (pdf): A real-valued function f ( ) defined for each x as the probability that X has the· value x ∈ X f (x)= Pr(X = x) By definition, f (x)=1 x X Discrete-Event Simulation Random Variables Generation 5/80 Examples Example 1 X is Equilikely (Discrete Uniform dist.) (a, b) = b a + 1 and each possible value is equally likely |X | − 1 f (x)= x = a, a + 1,..., b b a + 1 − Example 2 Roll two fair dice If X is the sum of the two up faces, = x x = 2, 3,..., 12 X { | } From example 2.3.1, 6 7 x f (x)= − | − | x = 2, 3,..., 12 36 or alternatively x 1 − 2 x = 7 36 ≤ ≤ f (x)= 13 x − 8 x = 12 36 ≤ ≤ Discrete-Event Simulation Random Variables Generation 6/80 Examples (cont) Example 3 Toss a coin until the first tail occurs Assume the coin has p as its probability of a head If X is the number of heads, = x x = 0, 1, 2, ... and the X { | } pdf is f (x)= px (1 p) x = 0, 1, 2, ... − X is Geometric(p) and the set of possible values is infinite Verify that x f (x) = 1: P ∞ f (x)= px (1 p) = (1 p)(1+p+p2+p3+p4+ ) = 1 x x − − · · · X X=0 Discrete-Event Simulation Random Variables Generation 7/80 Cumulative Distribution Function The cumulative distribution function(cdf) of X is the real-valued function F ( ) for each x as · ∈X F (x)= Pr(X x)= f (t) ≤ ≤ tXx If X is Equilikely(a, b) then the cdf is x F (x)= 1/(b − a +1)=(x −a+1)/(b −a+1) x = a, a+1,..., b t=a X If X is Geometric(p) then the cdf is x F (x)= pt (1−p)=(1−p)(1+p+· · ·+px ) = 1−px+1 x = 0, 1, 2, ... t=0 X Discrete-Event Simulation Random Variables Generation 8/80 Example No simple equation for F ( ) for sum of two dice · is small enough to tabulate the cdf |X | 0.2 1.0 f(x) 0.1 F (x) 0.5 0.0 0.0 2 4 6 8 1012 2 4 6 8 1012 x x Discrete-Event Simulation Random Variables Generation 9/80 Relationship Between cdfs and pdfs A cdf can be generated from its corresponding pdf by recursion For example, = x x = a, a +1, ..., b X { | } F (a) = f (a) F (x) = F (x 1) + f (x) x = a +1, a +2, ..., b − A pdf can be generated from its corresponding cdf by subtraction f (a) = F (a) f (x) = F (x) F (x 1) x = a + 1, a + 2, ..., b − − A discrete random variable can be defined by specifying either its pdf or its cdf Discrete-Event Simulation Random Variables Generation 10/80 Other cdf Properties A cdf is strictly monotone increasing: if x1 < x2, then F (x1) < F (x2) The cdf values are bounded between 0.0 and 1.0 Monotonicity of F ( ) is the basis to generate discrete random · variates as we will see soon Discrete-Event Simulation Random Variables Generation 11/80 Mean and Standard Deviation The mean µ of the discrete random variable X is µ = xf (x) x X The variance of X is σ2 = (x µ)2f (x) or σ2 = x 2f (x) µ2 x − x ! − X X The corresponding standard deviation σ is σ = (x µ)2f (x) or σ = x 2f (x) µ2 v s x − u x ! − X u X t Discrete-Event Simulation Random Variables Generation 12/80 Examples If X is Equilikely(a, b) then the mean and standard deviation are b b a−1 x 1 • µ = = x − x b − a + 1 b − a + 1 x=a " x=1 x=1 # X X X 1 b(b + 1) (a − 1)a b2 − b − a2 + a a + b = − = = b − a + 1 2 2 2(b − a + 1) 2 b b b a−1 (x − µ)2 x 2 1 • σ2 = = − µ2 = x 2 − x 2 − µ2 b − a + 1 b − a + 1 b − a + 1 x=a x=a " x=1 x=1 # X X X X 1 b(b + 1)(2b + 1) (a − 1)a(2a − 1) = − − µ2 b − a + 1 6 6 2 (b − a + 1) − 1 ∗ = ( ) 12 35 When X is Equilikely(1, 6), µ = 3.5 and σ = 12 ∼= 1.708 q (*)recall that the sum of the squares of the first n natural numbers is n(n + 1)(2n + 1) S2 = n 6 Discrete-Event Simulation Random Variables Generation 13/80 Roll two fair dice: average If X is the sum of two dice then 12 12 6 7 x µ = xf (x)= x − | − | x x 36 X=2 X=2 6 6 7+ x 6 7 + 7 = [x + (14 x)] − + 7 − | | x − 36 36 X=2 6 x 1 7 7 6 7 = 14 − + = (x 1) + x 36 6 18 x − 6 X=2 X=2 7 4 7 7 4 7 = (2 + k 1) + = (1 + k)+ 18 − 6 18 6 kX=0 kX=0 7 4 (4 + 1) 7 7 21 = 5+ ∗ + = 10 + = 18 2 6 18 18 70 21 7 18 = + = ∗ = 7 18 18 18 Discrete-Event Simulation Random Variables Generation 14/80 Roll two fair dice: alternative derivations 12 7 x 1 12 13 x µ = xf (x)= x − + x − x x 36 x 36 X=2 X=2 X=8 6 x 1 6 2 y 1 = x − + 7 + (14 y) − x 36 36 y − 36 X=2 X=6 where y = 14 x. With this substitution it is easy to see that − 6 x 1 7 6 x 1 7 µ = [x + (14 x)] − + = 14 − + x − 36 6 x 36 6 X=2 X=2 7 6 7 7 4 7 = (x 1) + = (2 + k 1) + 18 x − 6 18 − 6 X=2 kX=0 7 4 7 7 4 (4 + 1) 7 = (1 + k)+ = 5+ ∗ + 18 6 18 2 6 kX=0 7 21 70 21 7 18 = 10 + = + = ∗ = 7 18 18 18 18 18 Discrete-Event Simulation Random Variables Generation 15/80 Roll two fair dice: variance If X is the sum of two dice then 12 σ2 = (x µ)2f (x)=35/6=5.813 − x=2 X Standard Deviation σ = 35/6 ∼= 2.415 p Discrete-Event Simulation Random Variables Generation 16/80 Another Example If X is Geometric(p) then the mean and standard deviation are ∞ ∞ p µ = xf (x)= xpx (1 p)= = x x − · · · 1 p X=0 X=1 − ∞ ∞ 2 2 2 2 2 x p σ = x f (x) µ = x p (1 p) 2 x ! − x − ! − (1 p) X=0 X=1 − . p σ2 = (1 p)2 − √p σ = (1 p) − Discrete-Event Simulation Random Variables Generation 17/80 Expected Value The mean of a random variable is also known as the expected value The expected value of the discrete random variable X is E[X]= xf (x)= µ x X Expected value refers to the expected average of a large sample x , x ,..., xn corresponding to X:x ¯ E[X]= µ as 1 2 → n .