Latin Hypercube Sampling Example

13
Latin Hypercube Sampling Example Jake Blanchard Spring 2010 Uncertainty Analysis for Engineers 1

description

Latin Hypercube Sampling Example. Jake Blanchard Spring 2010. Example. Z=XY X and Y follow exponential distributions  x =1  y =1/2. Step 1. Divide cdfs into even intervals (vertical axis). Step 2. Now sample a number in each section - PowerPoint PPT Presentation

Transcript of Latin Hypercube Sampling Example

Page 1: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 1

Latin Hypercube Sampling ExampleJake BlanchardSpring 2010

Page 2: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 2

ExampleZ=XYX and Y follow exponential

distributionsx=1y=1/2

1

1

mean

eFcdf

efpdfx

x

Page 3: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 3

Step 1Divide cdfs into even intervals

(vertical axis)

0 1 2 3 4 5 6 7 8 9 100

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

x

CD

F -

=

1

Page 4: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 4

Step 2Now sample a number in each

sectionFor example, pick a random

number between 0.8 and 1.0 and use it to get a random value for x

xx=expinv(rx,mux);

Page 5: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 5

Step 3Sort the values (shuffle)nux=xx(randperm(n));

0 1 2 3 4 5 6 7 8 9 100

5

10

15

20

25

xx

yy

0 2 4 6 8 100

5

10

15

20

nux

nyy

Page 6: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 6

An AlternativeInstead of using expinv, we can

generate the inverse ourselvesJust take the CDF and solve for xxx=-mux*log(1-rx);

Page 7: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 7

First Scriptn=10000000; mux=1; muy=2;x=exprnd(mux,n,1);

y=exprnd(muy,n,1);mz=mean(x.*y);error=abs(mz-mux*muy)/mux/

muyd=linspace(0,1,n+1);rx=unifrnd(d,d+1/n);ry=unifrnd(d,d+1/n);xx=expinv(rx,mux);

yy=expinv(ry,muy);nux=xx(randperm(n));

nuy=yy(randperm(n));mz=mean(nux.*nuy);error=abs(mz-mux*muy)/mux/

muy

Page 8: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 8

Alternativen=10000000; mux=1; muy=2;x=exprnd(mux,n,1); y=exprnd(muy,n,1);mz=mean(x.*y);error=abs(mz-mux*muy)/mux/muyd=linspace(0,1,n+1);rx=unifrnd(d,d+1/n);ry=unifrnd(d,d+1/n);xx=-mux*log(1-rx); yy=-muy*log(1-ry);nux=xx(randperm(n));

nuy=yy(randperm(n));mz=mean(nux.*nuy);error=abs(mz-mux*muy)/mux/muy

Page 9: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 9

TestZ=XYX and Y are beta with mean of 1

and 2, respectivelyUse simple Monte CarloThen use LHS without sortingThen use LHS with sortingN=100,000For each case, find mean 100

times and then take standard deviation of results

Page 10: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 10

Case 1

n=100000;ntrials=100;mz=zeros(ntrials,1);for i=1:ntrials x=exprnd(mux,n,1); y=exprnd(muy,n,1); mz(i)=mean(x.*y);endstd(mz)

Page 11: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 11

Case 2d=linspace(0,1,n+1);for i=1:ntrials rx=unifrnd(d,d+1/n); rx=rx(1:end-1); ry=unifrnd(d,d+1/n); ry=ry(1:end-1); x=expinv(rx,mux); y=expinv(ry,muy); mz(i)=mean(x.*y);endstd(mz)

Page 12: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 12

Case 3d=linspace(0,1,n+1);for i=1:ntrials rx=unifrnd(d,d+1/n); rx=rx(1:end-1); ry=unifrnd(d,d+1/n); ry=ry(1:end-1); x=expinv(rx,mux); y=expinv(ry,muy); nux=x(randperm(n)); nuy=y(randperm(n)); mz(i)=mean(nux.*nuy);endstd(mz)

Page 13: Latin Hypercube Sampling Example

Uncertainty Analysis for Engineers 13

ResultsMean(mz) Std(mz)

Case 1 1.9999 0.0098

Case 2 4.0000 0.00029

Case 3 1.9998 0.0064