#10 monte carlo simulation systems 303 - fall 2000 instructor: peter m. hahn [email protected]
Post on 21-Dec-2015
216 views
TRANSCRIPT
MONTE CARLO SIMULATION
• Based upon the generation of random numbers• Used for solving stochastic (or deterministic)
problems where the passage of time plays no substantive role
• Widely used to solve certain problems in statistics that are not analytically tractable
• Specifically used for determining the critical values for the Kolmogorov-Smirnov test
• We will describe the concept, determine the number of random number samples required and give several examples
MODELING ALTERNATIVES
-Prob. Theory -Monte Carlo -Queuing Theory -Discrete Event-Diff. Eqns. Simulation -Markov Chains or Continuous etc. etc. Simulation
MONTE CARLO SIMULATION
• Consider the problem of evaluating a definite integral
where for simplicity r(x) ≥ 0 on [a,b], r(x) is bounded above by y = c and an analytical solution is not possible for r(x)
• The graph of r bounds a region R within the rectangle defined by x=a, x=b, y=0 and y=c
• We present a method for determining A
r(x)dxa
b
A
MONTE CARLO SIMULATION
y =r(x)
c
a b
y
x
R
METHOD FOR ESTIMATING A
• A is simply the area of region R
• Select point (x,y) at random in rectangle abc
• With probability p, (x,y) will satisfy y ≤ r(x)
• If we can determine p, then it is clear that
• The Monte Carlo method involves estimating p by generating statistically independent points (xi,yi) from the uniform distribution of points on the rectangle abc
pc(b a) A
METHOD FOR ESTIMATING A
• The pdf of points (xi,yi) is given by
• Actually, we can do the same by generating
fX,Y (x, y) 1
c(b a) a x b,0 y c
0 otherwise
fX (x) 1
(b a) a xb
0 otherwise
and fY (y) 1c
0 y c
0 otherwise
METHOD FOR ESTIMATING A• We have N samples (x1,y1), (x2,y2),…, (xN,yN)
• An estimate of p is the fraction of points in R
• How well approximates p depends on N
• The larger N the better the estimate
Let I(x,y) 1 if (x, y)R
0 otherwise
Then an estimate of p is
ˆ p 1N
I(x, y)i1
N
Number of sample points in R
N
ˆ p
BIASEDNESS OF ESTIMATOR OF p?
• If is an unbiased estimator, its variance is a measure of how good an estimate it is
• is indeed an unbiased estimator
ˆ p
E[ ˆ p ]1
NE I xi , yi
i1
N
1N
1c(b a)
dxdy
R
i1
N
1N
1c(b a)
N dxdy
R
Area of R
c(b a)p
ˆ p
HOW GOOD IS OUR ESTIMATOR?• The variance of is computed as followsˆ p 2 ˆ p E ˆ p 2 E ˆ p 2 E ˆ p 2 p2
E1
N 2 I xi , yi I x j , y j j1
N
i1
N
p2
E1
N 2 I x i , yi 2i1
N
1
N 2 I x i , yi I x j , y j j1
N
ij
N
p2
Np
N 2 N N 1 p2
N 2 p2 Np N 2 p2 Np2 N 2 p2
N 2
1N
p(1 p) pqN
CHEBYCHEV’S INEQUALITY (A BOUND)
X is an arbitrary RV with mean , mean -square X2
and variance X2 . The pdf of X is unknown.
X2 x 2 fX (x)dx
x 2 fX (x)dx
x 2 fX (x)dx
x
P X X2
2
Replacing X with X
P X X2
2
P X 1 X
2
2
CHEBYCHEV’S INEQUALITY (A BOUND)
-
A
B
P X A X
2
2 A *
But, B 1 A
Now B1 A *
P X 1 X2
2
SAMPLES REQUIRED FOR p ESTIMATE
P ˆ p p 1 2 ˆ p 2 1
pqN 2
Thus, if we wish
P ˆ p p 1 where , small, N has to be
N pq 2
It is necessary that p where < 1 so that
N 1 p
2 p
For 0.5, 0.01 and p 0.1, N 0.9
0.01 0.25 0.1 3600
SAMPLES REQUIRED FOR p ESTIMATE
• But, we really don’t know p at the start• What if p = 0.1 and we guess 0.3?
• A third try will give us the required N=3600
We calculate N 0.7
(0.01)(0.25)(0.3)934
Since ( ˆ p ) pq
N
0.1 0.9 934
0.01
The value of ˆ p we get should be within 0.03 of 0.1
So if ˆ p 0.13 a new N 0.87
(0.01)(0.25)(0.13)2677
MONTE CARLO SIMULATION
• Monte Carlo is commonly used today to determine outcomes of complex processes
• The process is represented by steps or equations in a general purpose computer
• The computer model is then exercised in a fashion similar to the real process to estimate the desired probabilities
• Often Monte Carlo is used for determining probability of rare but important events
• The rarer the event, the longer the simulation
AMMUNITION DEPOT EXAMPLE
• Bombers attempting to destroy a depot of odd shape fly over it in the E-W direction
• The pdf of bomb impact is two-dimensional Gaussian centered around the aim point with E-W = 600m and N-S = 300m
• The problem is to determine the percentage of bombs that hit the depot
• This example is hand simulated in Section 2.3 of B,C,N&N
AMMUNITION DEPOT EXAMPLE
AMMUNITION DEPOT EXAMPLE
AMMUNITION DEPOT EXAMPLE• The aiming point is considered the (0,0)
point of the following distribution
• X and Y values can be computer-generated with the ‘direct transformation technique’
• Assuming p = 3/7, = 0.01 and = 0.5
fX,Y (x, y) fX (x)fY (y) 1
2X Y
e 1
2x 2
X2 y2
Y2
where X 600m and Y 300m
N 1 p 2 p
0.57
0.01 0.25 0.429 532.4
DIRECT TRANSFORMATION
MONTE CARLO SIMULATION
• Suppose we can express the desired system measure as the RV X=g(Y1,…,Yk,Z1,…,Zm) where the Y’s represent random inputs and the Z’s represent control variables.
• Using Monte Carlo we can estimate E[h(X)] or P(x1<h(X)<x2). h(.) a real fn or constant.
• We generate Y1,…,Yk using their statistical distributions and a random number generator
• We read in Z1,…,Zm from a data file or key these in manually
MONTE CARLO ALGORITHM
N=number of simulation iterations
i=1, H = 0, P =0 (Initialize)
Read in Z1,…,Zm
Do while (i ≤ N) {Generate Y1i,…,Yki
Xi=g(Y1i,…,Yki,Z1,…,Zm)
H = H + h(Xi) where h(Xi) can be equal to Xi
If (x1<h(Xi)<x2 ) P = P + 1}
E[h(X)] = H/N
P(x1<h(X)<x2) = P/N
MONTE CARLO SIMULATION• Good practice - collect cumulative variance for
averages and Chebychev bounds for probabilities in order to revise number of samples N, if needed
• For either we need the cumulative sample mean:
After the n - th sample the sample mean is
X (n)1
nXi
i1
n
We add a sample Xn1
X (n 1) 1
n 1nX (n) Xn1
CUMULATIVE SAMPLE VARIANCE
After the n - th sample the cumulative sample variance is ˜ S 2 (n)
We add a sample Xn1
˜ S 2 (n 1) 1n
n 1 ˜ S 2 (n) Xn1 X (n 1) 2 Thus,
˜ S 2 (1) 0
˜ S 2 (2) 0 X2 X (2) 2
˜ S 2 (3)12
˜ S 2 (2) X3 X (3) 2 ˜ S 2 (4)
1
32 ˜ S 2 (3) X4 X (4) 2 etc.,
COMPUTER PRODUCTION EXAMPLE
• How many computers P to produce? WhereD = Market demand ~ 200 + exp(0.02)
L = Total labor cost 100+P
M= Total material cost 10+3P
I = Income per computer ~ N(5,1)
• We wish to maximize profit g(P) = I·min{D,P} - L - M
• For HW#10 conduct a Monte Carlo simulation to estimate E[g(250)]. Assume N=10,000 provides an accurate estimate