Monte Carlo Simulation Monte Carlo Simulation - UF · PDF fileLatin hypyp p gercube sampling X...
Transcript of Monte Carlo Simulation Monte Carlo Simulation - UF · PDF fileLatin hypyp p gercube sampling X...
Monte Carlo Simulation A7G
6VQ
PP
N2A
.jpg
How do we generate the statistics of a function of a random
Monte Carlo Simulation
pics
.hoo
bly.
com
/full/
AA
How do we generate the statistics of a function of a random variable?– Why is the method called “Monte Carlo?” S
OU
RC
E: h
ttp://
p
How do we use the uniform random number generator to generate other distributions?
A th di t ib ti di tl il bl i tl b?– Are other distributions directly available in matlab?
How do we accelerate the brute force approach?Probability distributions and moments– Probability distributions and moments
Web links: htt // i k l /li k/ t l th d hthttp://www.riskglossary.com/link/monte_carlo_method.htmhttp://physics.gac.edu/~huber/envision/instruct/montecar.htm
Basic Monte Carlo
iles/
0410
2210
4413
s.jp
g
• Given a random variable X and a function h(X):
E: w.s
z-w
hole
sale
.com
/upl
oadF
i
sample X: [x1,x2,…,xn];Calculate [h(x1),h(x2),…,h(xn)]; use to approximate statistics of h.
SO
UR
CE
http
://w
ww
• Example: X is U[0,1]. Use MCS to find mean of X2
x=rand(10); y=x.^2; %generates 10x10 random matrix( ) y gsumy=sum(y)/10sumy =0.4017 0.5279 0.1367 0.3501 0.3072 0.3362 0.3855 0.3646 0.5033 0.2666sum(sumy)/10 ans =0 3580sum(sumy)/10 ans =0.3580
• What is the true mean
SOURCE: http://schools.sd68.bc.ca/ed611/akerley/question.jpg
Basic Monte Carlo• Given a random variable X and a function h(X): sample
X: [x1,x2,…,xn]; Calculate [h(x1),h(x2),…,h(xn)]; use to [ 1, 2, , n]; [ ( 1), ( 2), , ( n)];approximate statistics of h.
• Example: X is U[0,1]. Use MCS to find mean of X2
x=rand(10); y=x.^2; %generates 10x10 random matrixsumy=sum(y)/10sumy =0 4017 0 5279 0 1367 0 3501 0 3072sumy =0.4017 0.5279 0.1367 0.3501 0.3072
0.3362 0.3855 0.3646 0.5033 0.2666sum(sumy)/10 ans =0.3580( y)• What is the true mean SOURCE:
http://schools.sd68.bc.ca/ed611/akerley/question.jpg
Obtaining distributionsObtaining distributions
• Histogram: y=randn(100 1); hist(y)Histogram: y=randn(100,1); hist(y)25
15
20
10
15
0
5
-3 -2 -1 0 1 2 30
Cumulative density functionCumulative density function• Cdfplot(y)p (y)
0 8
0.9
1Empirical CDF
0.6
0.7
0.8
)
0.3
0.4
0.5
F(x
-3 -2 -1 0 1 2 3 40
0.1
0.2
3 2 1 0 1 2 3 4x
Experimental CDFExperimental CDF
• [f x]=ecdf(y); f’[f,x]=ecdf(y); fColumns 1 through 8
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700Columns 9 through 16Columns 9 through 16
0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500
• x‘Columns 1 through 8
-2.2529 -2.2529 -2.1763 -2.1746 -1.9539 -1.9068 -1.6354 -1.5729Columns 9 through 16
1 4127 1 2568 1 2203 1 2158 1 1957 1 1684 1 1645 1 0954-1.4127 -1.2568 -1.2203 -1.2158 -1.1957 -1.1684 -1.1645 -1.0954
Columns 89 through 960.9940 1.0437 1.0945 1.1654 1.2020 1.2750 1.5081 1.5338
Columns 97 through 1011.5908 1.7909 1.8918 2.4124 2.7335
Histogram of averageg g• x=rand(100); y=sum(x)/100; hist(y)
30
35
20
25
15
20
5
10
0.42 0.44 0.46 0.48 0.5 0.52 0.54 0.56 0.580
Histogram of average• x=rand(1000); y=sum(x)/1000; hist(y)
140
100
120
80
100
40
60
0 46 0 47 0 48 0 49 0 5 0 51 0 52 0 530
20
0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53
What is the law of large numbers?
Distribution of x2Distribution of x
x=rand(10000,1);( , );x2=x.^2;hist(x2,20)
2500
1500
2000
1000
1500
500
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
Other distributions• Other distributions available in matlab• For example, Weibul distributionFor example, Weibul distribution
/1( )bx ab bf x ba x e
600
( )0
f x ba x efor x
400
500
300r=wblrnd(1,1,1000);hist(r,20)
100
200
0 2 4 6 8 10 12 140
Correlated Variables
For normal distrib tion can se Matlab’s m nrnd• For normal distribution can use Matlab’s mvnrnd• R = MVNRND(MU,SIGMA) returns an n-by-d
matrix R of random vectors chosen from thematrix R of random vectors chosen from the multivariate normal distribution with mean vector MU, and covariance matrix SIGMA. MU is anMU, and covariance matrix SIGMA. MU is an n-by-d matrix, and MVNRND generates each row of R using the corresponding row of MU. SIGMA is a d-by-d symmetric positive semi-definite matrix
Examplepmu = [2 3];sigma = [1 1 5; 1 5 3];sigma = [1 1.5; 1.5 3];r = mvnrnd(mu,sigma,20);plot(r(:,1),r(:,2),'+') 4.5
5
plot(r(:,1),r(:,2), )
3.5
4
2
2.5
3
1
1.5
0 0.5 1 1.5 2 2.5 3 3.50
0.5
Latin hypercube samplingyp p g
X = lhsnorm(mu,SIGMA,n) generates a latinX lhsnorm(mu,SIGMA,n) generates a latin hypercube sample X of size n from the multivariate normal distribution with mean vector mu and covariance matrix SIGMA. X is similar to a random sample from the
lti i t l di t ib ti b t thmultivariate normal distribution, but the marginal distribution of each column is adjusted so that its sample marginaladjusted so that its sample marginal distribution is close to its theoretical normal distributionnormal distribution.
Comparing MCS to LHS
mu = [2 2];sigma = [1 0; 0 3];sigma [1 0; 0 3];r = lhsnorm(mu,sigma,20);sum(r)/20
r = mvnrnd(mu,sigma,20);sum(r)/20
2 3327 2 2184( )
ans = 1.9732 2.0259
5
6
4
5
ans =2.3327 2.2184
2
3
4
2
3
-1
0
1
-1
0
1
0.5 1 1.5 2 2.5 3 3.5 4 4.5-2
0 0.5 1 1.5 2 2.5 3 3.5 4-2
Evaluating probabilities of failureEvaluating probabilities of failure
• Failure is defined in terms of a limit stateFailure is defined in terms of a limit state function that must satisfy g(r)>0, where r is a vector of random variables. /fP m N
• Probability of failure is estimated as the ratio of number of negative g’s, m, to total MC sample
f
size, N• The accuracy of the estimate is poor unless N
i h l h 1/Pis much larger than 1/Pf
• For small Pf
(1 )
1
f ff
f
P PP
NP
1f
f
PP m
Separable Monte CarloSeparable Monte Carlo
• Usually limit state function is written inUsually limit state function is written in terms of response vs. capacity g=C(r)-R(r)>0g C(r) R(r)>0
• Failure typically corresponds to structures with extremely low capacity or extremelywith extremely low capacity or extremely high response but not bothC t k d t f th t i bl• Can take advantage of that in separable MC
Reading assignmentg gSDM paper by Ben Smarslok
Source: www.library.veryhelpful.co.uk/ Page11.htm
problems1. Derive formula for the standard
deviation of estimate of Pfdeviation of estimate of Pf
2. Use MCS to calculate the probability of failure when astructure is designed with 50% safety factor
Source: Smithsonian InstitutionNumber: 2004-57325
structure is designed with 50% safety factor and both stress and failure stress have a normal distribution with 10% COV.normal distribution with 10% COV.
3. Calculate the exact value of the answer to Problem 2 (that is without MCS).