Monte Carlo - milidiu/inf2981/aulas/13_acceptance... A Agulha de Buffon Georges-Louis Leclerc –...

Post on 02-Feb-2019

224 views 0 download

Transcript of Monte Carlo - milidiu/inf2981/aulas/13_acceptance... A Agulha de Buffon Georges-Louis Leclerc –...

Ruy Luiz Milidiú

Monte Carlo

Monte Carlo

Monte Carlo

Monte Carlo

A Agulha de Buffon

Georges-Louis Leclerc – Conde de Buffon, 1777

Elementos

uma agulha

um piso

Experimento

Lançar a agulha ao piso

A agulha

O piso

Lançamento

Lançamento

Lançamento

Lançamento

Contagens

Lançamentos 8

Cortes 5

Estimativa de

cortes

slançamento.2

Estimativa de

2.3

5

8.2

Corte

d

sin21

sin21d

Accept–reject

sin21d

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

Accept–reject

sin21d

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

accept

Accept–reject

sin21d

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

accept

Accept–reject

sin21d

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

accept

Accept–reject

sin21d

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

accept

21cossinaccept

21

21

021

21

021

d

P

Accept–reject

2

slançamento

cortes

2accept

P

cortes

slançamento.2

Accepted values

?accept P

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

Accepted values

cos1accept21 P

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

Accepted values

sinaccept21f

0

0.1

0.2

0.3

0.4

0.5

0 0.5 1 1.5 2 2.5 3

U(0,) D U(0,½)

cos1accept

sinaccept

accept

2accept

sinD,accept

sinDaccept

21

0 21

0

sin

0

0

sin

0

2

2

21

21

21

21

P

duuP

dudvP

dudvP

PP

PP

u

u

y = ½

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

0 0.5 1 1.5 2 2.5 3

accept

y = 2.x.( - x)/

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

0 0.5 1 1.5 2 2.5 3

accept

Accept–reject

032.2

021

0

2

021

32

2

2

cosaccept

.

sinaccept

P

d

dP

3accept P

ACEITA

MAIS

y = 2.x.( - x)/2

yyyg

yyyg

dvvv

.

.

3.

3

2

2

6

3

2

0

2

yyyyG 023 3213

G(y) = (3y2 – 2y3)/3

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 0.5 1 1.5 2 2.5 3

The Cubic formula

a

cr

a

adbcpq

a

bp

dcybyay

3

6

3

3

0

2

3

23

pprqqprqqy 3 3223 322

Inverse Transformation

032

023

323

321

1

3

uyy

yyyu

yGu

uGy

1221221

2

3 23 2 uuuuuuy

G D U(0,(/3).g())

0 21

0

sin

23

3

0 0

3

sin

23

sinaccept

3accept

,accept

sin

23

duuduugP

duugdvP

UPP

ug

u

g

ug

u

cos1accept21 P

sinaccept21DPP

G D U(0,1)

0 21

0

sin

23

3

0 0

3

sin

23

sinaccept

3accept

,accept

sin

23

duuduugP

duugdvP

UPP

ug

u

g

ug

u

cos1accept21 P

gUPP

sin

23accept

Acceptance – Rejection

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

0 0.5 1 1.5 2 2.5 3

accept

y = g(x)

y = f(x)

X G D U(0,1)

00

1

0 0

1

1

accept

accept

,accept

1

duufduugMxXP

duugdvMxXP

UxXPxXP

ug

uf

M

M

Xg

Xf

M

ug

uf

M

xFxXP accept

Xg

Xf

MUxXPxXP 1accept

X G U U(0,1)

MM

xg

xf

M

Xg

Xf

M

dxxfP

dxxgP

dxxgxXUPP

11

1

1

accept

.accept

.accept

M

P 1accept

Xg

Xf

MUPP 1accept

Acceptance – Rejection

while ( TRUE )

gerar X com distribuição G

gerar U uniforme em [0,1]

if U ≤ f(X)/M.g(X)

return (X)

Want to generate X with density f(x)

The proposal density g(x) is easier to generate

X N(0,1)

0

0.2

0.4

0.6

0.8

1

1.2

1.4

-6 -4 -2 0 2 4 6

X N(0,1)

0

0.2

0.4

0.6

0.8

1

1.2

1.4

-6 -4 -2 0 2 4 6

M

212

21

2

21

2

21

2max2

2

2

max

max

eeM

eM

e

eM

xx

xx

x

x

eM 2

X N(0,1)

0

0.2

0.4

0.6

0.8

1

1.2

1.4

-6 -4 -2 0 2 4 6

X meia N(0,1)

0

0.2

0.4

0.6

0.8

1

1.2

1.4

-6 -4 -2 0 2 4 6

Acceptance – Rejection

while ( TRUE )

gerar X com distribuição G

gerar U uniforme em [0,1]

if U ≤ f(X)/M.g(X)

return (X)

f(x)/M.g(x)

212

21

2

21

.

. 2

2

xx

xe

x

exgM

xf

e

e

xgM

xf

221 1

.

xe

xgM

xf

X meia N(0,1)

while ( TRUE )

gerar X com distribuição G

gerar U uniforme em [0,1]

if U ≤ e-0.5(X-1)²

return (X)

X N(0,1)

while ( TRUE )

gerar X com distribuição exp(1)

gerar U uniforme em [0,1]

if U ≤ e-0.5(X-1)² break

gerar U uniforme em [0,1]

if U ≤ 0.5 then

return (X)

else return (–X)