You are on page 1of 49

Simulation Methods

Simulation
Methods

R.M. Montaril, MSECE

Chapter Outline
Generating, transformation, and
testing of pseudorandom numbers. Outline

Pseudorandom
Numbers

Monte Carlo Method Monte Carlo


Method

Stochastic Models Stochastic


Models

Marcov Method Marcov Method


Random Numbers
Numbers are based on random phenomena, others on
deterministic recurrence procedures.

Initially, manual methods were used, including such


techniques as coin flipping, dice rolling, card shuffling,
and roulette wheels.

It was believed that only mechanical (or electronic)


devices could yield truly random numbers.

These methods were too slow for general use, and


moreover, sequences generated by them could not be
reproduced.

Shortly following the advent of the computer it became


possible to obtain random numbers with its aid.
Random Numbers Generation
(RNG)
is a computational or physical device
designed to generate a sequence of
numbers or symbols that lack any
pattern, i.e. appear random.
Generation Methods
Physical Methods.
The earliest methods for generating random
numbers dice, coin flipping, roulette wheels
are still used today, mainly in games and
gambling as they tend to be too slow for most
applications in statistics and cryptography.
Computational Methods.
Based from Pseudo-random number generators.

Generation from a probability distribution.


Generate a random number based on distribution
functions.
Random Number Generations
One method of generating random
numbers on a digital computer consists of
preparing a table and storing it in the
memory of the computer.
In 1955 the RAND Corporation published
a well known table of a million random
digits that may be used in forming such a
table.
The advantage of this method is
reproducibility; its disadvantage is its lack
of speed and the risk of exhausting the
table.
Pseudorandom number
generation
Also known as a deterministic random bit generator
(DRBG)

An algorithm for generating a sequence of numbers


that approximates the properties of random numbers.

The sequence is not truly random in that it is


completely determined by a relatively small set of
initial values, called the PRNG's state.

Algorithms that can automatically create long runs of


numbers with good random properties but eventually
the sequence repeats (or the memory usage grows
without bound). The string of values generated by such
algorithms is generally determined by a fixed number
called a seed.
Random Seed
Also known as seed state, or just seed.

a number (or vector) used to initialize a pseudorandom number generator.

The choice of a good random seed is crucial in the field of computer security.
When a secret encryption key is pseudo randomly generated, having the seed
will allow one to obtain the key.

If the same random seed is deliberately shared, it becomes a secret key, so


two or more systems using matching pseudorandom number algorithms and
matching seeds can generate matching sequences of non-repeating numbers
which can be used to synchronize remote systems, such as GPS satellites and
receivers.

Random seeds are often generated from the state of the computer system
(such as the time), a cryptographically secure pseudorandom number
generator or from a hardware random number generator.
1951 by Berkeley professor D. H. Lehmer, a
pioneer in computing and,
especially, computational number theory:

A random sequence is a vague notion


in which each term is unpredictable to
the uninitiated and whose digits pass a
certain number of tests traditional with
statisticians ...
Uniform Distribution
Lehmer also invented the multiplicative
congruential algorithm, which is the
basis for many of the random number
generators in use today.
Lehmer's generators involve three
integer parameters, a, c, and m, and an
initial value, x0, called the seed.
A sequence of integers is defined by:
Uniform Distribution
The operation mod m means take the
remainder after division by m. For
example, with a = 13, c = 0, m = 31, and
x0 = 1, the sequence begins with:

The first 30 terms in the sequence are a


permutation of the integers from 1 to 30
and then the sequence repeats itself. It
has a period equal to m - 1.
Uniform Distribution
If a pseudorandom integer sequence with
values between 0 and m is scaled by dividing
by m, the result is floating-point numbers
uniformly distributed in the interval [0,1].
Our simple example begins with:

There is only a finite number of values, 30 in


this case. The smallest value is 1/31; the
largest is 30/31. Each one is equally
probable in a long run of the sequence.
Uniform Distribution
In the 1960s, the Scientific Subroutine
Package (SSP) on IBM mainframe computers
included a random number generator named
RND or RANDU. It was a multiplicative
congruential with parameters a = 65539, c=
0, and m = 231.

With a 32-bit integer word size, arithmetic


mod 231 can be done quickly.

Furthermore, because a = 216+3, the


multiplication by a can be done with a shift
and an addition.
Uniform Distribution
In MATLAB, each 64-bit Floating
number has a resolution of
called eps .

32-bit Floating number has a


resolution of half on one eps, called
one ulp, (Unit in the last place).
Normal Distribution
Almost all algorithms for generating
normally distributed random numbers are
based on transformations of uniform
distributions.

The probability density function, or pdf, of


the normal distribution is the bell-shaped
curve.

where c is a normalizing constant that we


can ignore.
Normal Distribution
Monte Carlo Method
A class of computational algorithms that rely on
repeated random sampling to compute their results.

It is a technique that involves using random


numbers and probability to solve problems.

These methods are most suited to calculation by a


computer and tend to be used when it is unfeasible
or impossible to compute an exact result with a
deterministic algorithm.
Computer Simulation
It has to do with using computer
models to imitate real life or make
predictions.

When you create a model with a


spreadsheet like Excel, you have a
certain number of input parameters
and a few equations that use those
inputs to give you a set of outputs (or
response variables).
Monte Carlo Simulations
It is a method for iteratively evaluating a
deterministic model using sets of random
numbers as inputs.

This method is often used when the model


is complex, nonlinear, or involves more
than just a couple uncertain parameters.

A simulation can typically involve over


10,000 evaluations of the model, a task
which in the past was only practical using
super computers.
Why Monte Carlo???
- Whats in a Name??
The term Monte Carlo Method was coined by Stanislaw Ulam in
1946.

Ulam later contacted John von Neumann to work on him.

Physicists at Los Alamos Scientific Laboratory were


investigating radiation shielding and the distance that neutrons
would likely travel through various materials.

John von Neumann and Stanislaw Ulam suggested that the


problem be solved by modeling the experiment on a computer
using chance. Being secret, their work required a code name.

Von Neumann chose the name "Monte Carlo". The name is a


reference to the Monte Carlo Casino in Monaco where Ulam's
uncle would borrow money to gamble.
Applications of Monte Carlo Simulation
Physical Science
Engineering
Applied Statistics
Design and Visuals
Finance and Business
Telecommunications
Games
Model Map of Monte Carlo
Uncertainty Propagation
the goal is to determine how random variation, lack
of knowledge, or error affects the sensitivity,
performance, or reliability of the system that is
being modeled.

Monte Carlo simulation is categorized as a


sampling method because the inputs are
randomly generated from probability distributions
to simulate the process of sampling from an actual
population.

The data generated from the simulation can be


represented as probability distributions (or
histograms) or converted to error bars, reliability
predictions, tolerance zones, and confidence
intervals
Stochastic Uncertainty
Propagation
- Basic Principle of Monte Carlo Method
Five Steps of Monte Carlo Simulation
Step 1: Create a parametric model, y = f(x1, x2, ..., xq).

Step 2: Generate a set of random inputs, xi1, xi2, ..., xiq.

Step 3: Evaluate the model and store the results as yi.

Step 4: Repeat steps 2 and 3 for i = 1 to n.

Step 5: Analyze the results using histograms,


summary statistics, confidence intervals, etc.
Example- Sales Forcasting
Company RMM wants to know how
profitable it will be to market their
new gadget, realizing there are many
uncertainties associated with market
size, expenses, and revenue.

The Method: Use a Monte Carlo


Simulation to estimate profit and
evaluate risk.
Step 1: Create the Model
Profit = Income Expenses

Income comes solely from the number of


sales (S) multiplied by the profit per sale (P)
resulting from an individual purchase of a
gadget, so Income = S*P.

The profit per sale takes into account the sale


price, the initial cost to manufacturer or
purchase the product wholesale, and other
transaction fees (credit cards, shipping, etc.).

the P may fluctuate between $47 and $53


Step 1: Create the Model
Leave the number of sales as one of
the primary variables, but for this
example, Company RMM generates
sales through purchasing leads.

The number of sales per month is the


number of leads per month (L)
multiplied by the conversion rate
(R) (the percentage of leads that result
in sales).

So our final equation for Income:

Income = L*R*P
Step 1: Create the Model
Consider the Expenses to be a combination of
fixed overhead (H) plus the total cost of the
leads.

For this model, the cost of a single lead (C)


varies between $0.20 and $0.80.

Based upon some market research, Company


RMM expects the number of leads per month (L)
to vary between 1200 and 1800.

Our final model for Company RMM's sales


forecast is:
Profit = L*R*P - (H + L*C)
Step 1: Create the Model
Profit = L*R*P - (H + L*C)
Y = Profits
X1 = L
X2 = C
X3 = R
X4 = P
Step2: Generating Random Inputs
Use a Uniform Distribution to represent the
four uncertain parameters.

Use "Min" and "Max" to indicate the uncertainty


in L, C, R, and P. To generate a random
number between "Min" and "Max.
= min + RAND()*(max-min)
Step 3 and Step 4
Run n=5000 evaluations of our model.
This is a fairly low number when it comes to
Monte Carlo simulation, and you will see why
once we begin to analyze the results.

Using Excel Spreadsheet to Generate Random


Numbers.
Step 5. Creating a Histogram
Analyze the results. We will start off by
creating a histogram.
Step 5. Creating a Histogram

It looks like profit will be positive, most of the time.


The uncertainty is quite large, varying between -1000
to 3400.
The distribution does not look like a perfect Normal
distribution.
There doesn't appear to be outliers, truncation,
multiple modes, etc.
Stochastic Models
One that involves probability or randomness .

A stochastic model is a tool for estimating


probability distributions of potential outcomes by
allowing for random variation in one or more inputs
over time.

The random variation is usually based on


fluctuations observed in historical data for a selected
period using standard time-series techniques.

Distributions of potential outcomes are derived from


a large number of simulations (stochastic
projections) which reflect the random variation in
the input(s).
Example- The Hinge
An assembly of 4 parts that make up a hinge, with a
pin or bolt through the centers of the parts. Looking
at the figure below, if A + B + C is greater than
D, we're going to have a hard time putting this thing
together.
Example- The Hinge
Let's say we have a million of each of
the different parts, and we randomly
select the parts we need in order to
assemble the hinge.

No two parts are going to be


exactly the same size!

But, if we have an idea of the range of


sizes for each part, then we can
simulate the selection and assembly
of the parts mathematically.
Example- The Hinge
Creation of an assembly from a random set of parts.

If you ever get a negative clearance, then that means


the combination of the parts you have selected will be
too large to fit within dimension D.
Marcov Models
Markov processes are stochastic
processes whose futures are
conditionally independent of their
pasts given their present values

Marov Property
to predict future states, we only
need to know the present one.
Marcov Chains
DTMC
Discrete-time Markov chains (DTMCs),
admit probabilistic choice, in the sense that
one can specify the probability of making a
transition from one state to another.

CTMC
Continuous-time Markov chains (CTMCs),
frequently used in performance analysis,
which model continuous real time and
probabilistic choice: one can specify the rate
of making a transition from one state to
another
Discrete Time Marcov Chains
Such chains are called time-homogeneous. The
probabilities. Which are called the (one-step)
transition probabilities of state . The distribution
of State is called the initial distribution of the
Markov chain.
There is an array called the (one-step)
transition matrix of States .
Marcov Simulation System
Example
An excellent discussion of these
models can be found in
Sonnenberg and Beck's 1993
article "Markov Models in
Medical Decision Making: A
practical guide" (in Medical
Decision Making, 13:322-338).
States
For simplicity, we will assume three states:

Controlled diabetes
End-stage renal disease (ESRD)
Death
Transition Probabilities
Imagine that, each year, patients with controlled
diabetes have an 85% chance of staying in that state,
a 10% chance of moving to the ESRD state, and a 5%
chance of dying. This is obviously a simplification,
and it's possible to build Markov models that allow
(for example) a chance of death that increases over
time (background mortality).

Let's further imagine that, each year, patients with


ESRD have a 70% chance of continuing in the ESRD
state and a 30% chance of dying.

Patients who have died have a 100% chance of


staying dead. Death is thus an "absorbing state" -- a
state which, once entered, can not be left.
Utilities
Imagine that the utility for living
with controlled diabetes is 0.95, the
utility for ESRD is 0.30, and the
utility of death is, by definition, 0.0.
Thinking about the Model
Here are some questions to try to answer about the
model. Make your best estimate. Imagine that we
begin with 10,000 patients with controlled diabetes.
In one year, how many patients will still have
controlled diabetes? How many will have ESRD? How
many will have died?

How much utility per patient will have been


experienced during that year? Remember that each
diabetes patient experiences a utility of 0.95 for the
year, each ESRD patient experiences a utility of 0.30
for the year, and dead people experience no utility.
Thinking about the Model
In 10 years, how many patients do you estimate will be in each state?

Future health is often considered to be less valuable than immediate


health. This is handled in some models by discounting future utility by
some constant rate. For example, if we use a 3% discount rate, the utility
of being in any particular state for a year is worth only 97% next year of
what it was worth this year, and 94% (= 97% * 97%) in the second year of
what it was worth this year. Imagine that after 20 years, without
discounting, our patients have experienced an average of 6.3 utility units
per patient during those 10 years. How much would you guess they
would have experienced if we were discounting the utilities by 3% per
year?

How many years will it take before all of the patients are dead?
End of Discusssion

You might also like