MGS 3100 Business Analysis Chapter 9 Monté Carlo What Is? A model/process used to duplicate or mimic the real system Types of Models Physical simulation Computer simulation When to Use (Computer) Models? Problems/systems are too comple to be analyzed mathematically There are random components in the system Benefits of Model It is relatively straightforward and generally easier to understand It can model a wide range of problems and answer what-if types of questions without actually changing or building a real system It is generally cheaper, quicker, and safer to eperiment with than a real system Limitations It can be epensive and time consuming to develop There is no guarantee that it will give optimal or eact solution to the problem 3 Monte Carlo Key element is randomness Assume that some inputs are random variables Modeling randomness by generating random variables from their probability distributions Since some inputs to the model are random, outputs from the model are random too. Modeling Process Develop the basic model that behaves like the real problem, with a special consideration of the random or probabilistic input variables Conduct a series of computer runs (called trials) to learn the behavior of the simulation model Compute the summary (output) statistics and make inferences about the real problem 4
Monte Carlo Eample process is similar to statistical inference process Statistics: start with a population, sampling from the population, and then based on sample information to infer population : start with a basic model to represent real problem, replicating the basic model, and then based on the replication results to help solve real problem The larger the number of trials (sample size), the more reliable will be the simulation result! Basic Model: Profit = f(demand) Input: Relationship: Output: t Demand function f Profit How simulation works: Step 1: basic model development: generate one possible random Demand and find the corresponding Profit Step : basic model replication: generate many possible values of Demand and dfind corresponding Profits Step 3: result summarization: calculate summarized statistics on the Profit such as average, min, ma etc. 5 6 How Works Random Numbers What Do We Need Know for? What variable is to be simulated Is the variable discrete or continuous? The distribution of the variable values it can take on and the probabilities biliti of those values occurring. How to Generate Variables? Step 1: Generate random numbers. Step : Create a rule to map the random numbers to values of the variable desired in the right proportion, and apply the rule. Uniformly distributed between 0 and 1 Each number in [0,1] is equally likely The building blocks of all simulation models Other random variables can be generated from random numbers In Ecel, =RAND() generates random numbers When the formula is copied to other cells, different random numbers are generated Press F9 (recalculate) key or do any change in the spreadsheet, all random numbers will change You can freeze the random numbers by using Copy and dpaste Special Value commands 7 8
Types of Variables in Discrete Take only limited specific values or specific points. Eample: number of defects, answer to T/F questions. Continuous Can take any value (between specific points) Eample: time between machine breakdown, filling volume in a coke s bottling assembly line 9 Generating Random Variables General Two-Step Approach first, generate random numbers (u) second, transform random numbers via CDF to random variables () with desired probability distribution u F() =F -1 (u) Inverse transformation method 10 Eample: p generate discrete r.v. Suppose monthly demand follows the following distribution ib ti Demand () p() 5 0.10 0 0.40 30 0.30 50 0.0 We want to generate 1 random demands (may be for net 1 months). How? Eample: generate discrete r.v. First find CDF: Demand () p() F() 5 0.1 0.1 0 04 0.4 05 0.5 30 0.3 0.8 50 0. 1 The CDF (F()) essentially establishes a rule that maps a demand to a random number range Demand 5 0 30 50 Rand # 0 01 0.1 0.5 08 0.8 1 What is the probability that a random number will be in range [0, 0.1], [0.1, 0.5], [0.5, 0.8], or [0.8, 1]? 11 1
Eample: p generate discrete r.v. That is, we have the following rule: If the random number Then the corresponding falls in demand is 0 0.1 5 0.1 0.5 0 05 0.5 08 0.8 30 0.8 1.0 50 So if we get a random number, say 0.1537, then we know we find a demand of 0 13 Eample: generate discrete r.v. Now if we need to simulate 1 times, what we need to do is to generate 1 random numbers and then follow the rule to get 1 demand levels Replication Random number Demand 1 0.7669 30 0.93813 50 3 0.57897 30 4 0.500 0 5 0.14009 0 6 0.98889 50 7 0.07436 5 8 0.47831 0 9 0.6698 30 10 0.1965 0 11 0.55519 30 1 0.45593 0 14 Manual : 1. Coin Toss. Machine Failures Tossing two coins at one time. If both are heads up, then you win $4, if only one head up, then you win $1, if both are tails, then you lose $6. Simulate this game 5 times. Random Random #of Cumulative Game # 1 # Heads Win Win 1 0.5473 0.6513 3 0.944 0.07360736 0.163 0.1758 4 5 0.385 0.5584 0.8958 0.171 Simulate machine failures for the net 5 months based on the historical data given in the table on the left. Number Frequency of Failures (# of months per month this occurred) Random # 0 36 0.3451 1 0 0.0085 3 0.9853 3 1 0.8788 Total 60 0.5694 Number of Failures 15 16
3. Coke Weight Cans from a Coke production line follow the following distribution regarding g their weights. Simulate the process on the net page and find what percentage of cans are at or above 1 oz. Weight Percentage Cumulative Percentage 11.8 oz. or less 11.9 oz. 10% 0% 10% 30% 1.0 oz. 1.1 oz. 1. oz. or more 40% 0% 10% 70% 90% 100% 17 3. Coke Weight Random Can # # Weight 1 oz.? 1 0.7457 0.099 3 0.7477 4 0.0497 5 0.958 6 0.3816 7 0.5874 8 0.8700 9 0.9336 10 0.668 18 Generating Random Variables In Ecel Generating Discrete r.v. with Ecel Use VLOOKUP function Generating Continuous r.v. with Ecel Uniform between a and b: = a+(b-a)*rand() Normal with mean μ and standard deviation σ = NORMINV(RAND(), μ, σ) Eponential with mean μ: = - μ*ln(rand()) Using Ecel s Features in Tools Data Analysis Random Number Generation Generating Discrete rv r.v. in Ecel First, find cumulative distribution of the r.v. Second, generate random numbers by =RAND() Finally, use VLOOKUP function (Note: the nd and 3 rd steps can be combined as one step) 19 0
An Eample A B C D E F G 1 Generating discrete random variables with VLOOKUP function 3 Random number range Demand 4 0 0.1 5 5 0.1 0.5 0 6 0.5 0.8 30 7 0.8 1 50 8 9 Random number Outcome 10 0.47444547 0 The range A4:C7 has been range- 11 0.71318343 30 named TABLE 1 0.844783096 50 13 0.86109451 50 14 0.434684 0 15 0.3073877 0 16 0.017091017091 5 17 18 with Spreadsheet Coin Toss Newsboy Problem - Walton s Bookstore Capital Budgeting (tetbook pp. 167-174) A B C D E F G 9 Random number Outcome 10 =RAND() =VLOOKUP(A10,TABLE,3) 11 =RAND() =VLOOKUP(A11,TABLE,3) 1 =RAND() =VLOOKUP(A1,TABLE,3) 13 =RAND() =VLOOKUP(A13,TABLE,3) 14 =RAND() =VLOOKUP(A14,TABLE,3) 15 =RAND() =VLOOKUP(A15,TABLE,3) 16 =RAND() =VLOOKUP(A16,TABLE,3) 17 18 *** TABLE in VLOOKUP is the range name for cell range A4:C7 The second column in the TABLE range (A4:C7) is not necessary. Without it (only two columns in the TABLE range), the VLOOKUP function will be VLOOKUP(A10,TABLE,) 1 Queuing (Waiting Line) Model Appendi Random Variable & Probability bilit Distribution A Quick Review Random Variable (r.v.) A variable that has many possible values, but eactly which one it will take is unknown Discrete r.v. vs. Continuous r.v. Probability Distribution Mathematical mechanism used to characterize the probabilistic bili pattern/behavior of a random variable Two types of probability distribution: probability density function (pdf) and cumulative distribution function (CDF) 3 Probability Distributions probability density function for discrete r.v. A list of all possible values of a discrete r.v.,x,and their associated probabilities, p() P(X = ), where is a particular value the r.v. X may take. Eample: X = # of cars sold per day in a car shop p() p() 03 0.3 0 0.10 1 0.0 0.30 0. 3 0.0 0.1 4 0.10 5 010 0.10 1.00 0 1 3 4 5 4
Probability Distributions Probability Distributions probability density function for continuous r.v. For continuous r.v., a pdf itself is not a probability. Rather, any area under the curve pdf curve is the probability Eample: X = The eact fluid content of a 1-ounce coke randomly selected from the production line f() P(a X b) f() a b 5 Cumulative Distribution Function (CDF) CDF (or F()) is the cumulative form of the pdf For any r.v. X, F() = P(X ) Eample: X = # of cars sold per day p() F()=P(X ) 0 010 0.10 010 0.10 1 0.0 0.30 0.30 0.60 3 00 0.0 080 0.80 4 0.10 0.90 5 0.10 1.00 1.00 pdf CDF 6 Useful Discrete Distributions Useful Discrete Distributions The Binomial Distribution Used to model the number of successes in a series of independent eperiments, each of which has only two possible outcomes: success and failure Eamples: the number of workers absent in a department of 10 employees on any day; the number of American-made cars in a parking lot of 30 spaces; the number of defective items in a sample of 10 n n pmf: P ( X = ) = p (1 p ), = 0,1,,,...,, n where n = number of trials, p = prob. of success X = number of successes in n trials The Poisson Distribution Used to model the number of events that occur in certain amount of time or space Eamples: the number of people arriving at a bank during lunch hour; the number of misspelled words on a page of your tetbook λ pmf: e λ P ( X = ) =, = 0,1,,...! where λ = average number of occurrences, e =.7188 X = number of occurrences 7 8
Useful Continuous Distributions Uniform Distribution between 0 and 1 Any value in the range [0, 1] is equally likely pdf: f() = 1, if 0 1 = 0, if < 0 or > 1 CDF: F() =, if 0 1 = 0, if < 0 or > 1 Useful Continuous Distributions Normal Distribution The most important probability distribution in Statistics ti ti and other applications Symmetric around the mean and bell shaped pdf: f ( ) = 1 ) / e σ, < < πσ If X N(μ, σ ), then Z=(X - μ)/σ N(0, 1) f() Uniform pdf F() Uniform CDF f() pdf 1 1 CDF 0 1 0 1 9 μ 30 Useful Continuous Distributions Triangular Distribution The pdf has a triangular shape Used when we only know the minimum, maimum and most likely values of a r.v., but no other information Useful Continuous Distributions Eponential Distribution Useful for modeling the time between two successive random events Eamples in queuing systems: inter-arrival times of customers, service times f() a - minimum b - most likely c -maimum f() f ) = 1 e μ μ (, μ: mean a b c 31 3