Metropolis-Hasting Algorithm, Exams of Technology

The Metropolis-Hasting Algorithm, which is used to generate random samples from a probability distribution. It discusses the conditions required for a transition kernel, the candidate-generating densities, theoretical properties, pseudocode, rate of convergence, burn-in, and acceptance ratio. It also provides an example of the algorithm's application to a posterior distribution. suitable for students studying probability theory, statistics, and computational methods.

Typology: Exams

2022/2023

Uploaded on 03/14/2023

deville
deville 🇺🇸

4.7

(23)

390 documents

1 / 54

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Metropolis-Hasting Algorithm
Jes´us Fern´andez-Villaverde
University of Pennsylvania
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36

Partial preview of the text

Download Metropolis-Hasting Algorithm and more Exams Technology in PDF only on Docsity!

Metropolis-Hasting Algorithm

Jes´

us Fern´

andez-Villaverde

University of Pennsylvania

1

Building our McMcOur previous chapter showed that we need to

find a transition Kernel

P^ (

x, A

) such that:

  1. It is time reversible.2. It is irreducible.3. It is aperiodic.4. (Bonus Points) It is Harris-recurrent and Geometrically Ergodic.

2

Metropolis-Hastings Transition KernelLet:

PMH

(x, dy

pMH

(x, y

)^ dy

+^ r

MH

(x)

δx^

(dy

where:

pMH

(x, y

q^ (

x, y

)^ α^

(x, y

α^ (x, y

) = min

(f^

(y)

q^ (y, x

f^ (x

)^ q^ (

x, y

,^1 )

)

and

q^ (

x, y

) is a candidate-generating density that is irreducible and aperi-

odic.

4

Lemma R f^ A^

(y)

dy^

R =

P X

MH

(x, A

)^ f^

(x)

dx.

Proof: We only need to show that

f^ (x

)^ pMH

(x, y

f^ (

y)^ p

MH

(y, x

Assume without loss of generality that:

α^ (x, y

)^ <

α^ (

y, x

Then:

f^ (x

)^ pMH

(x, y

f^ (

x)^ q

(x, y

)^ α^

(x, y

=^ f

(x)

q^ (x, y

) min

(f^

(y)

q^ (y, x

f^ (x

)^ q^ (

x, y

,^1 )

)^ =

f^ (

x)^ p

(x, y

f^ ) (y)

q^ (y, x

f^ (x

)^ q^ (

x, y

=^ f

(y)

q^ (y, x

f^ (

y)^ p

MH

(y, x

5

Symmetric Candidate-Generating Densities^ •

We can take a candidate-generating density

q^ (

x, y

q^ (

x, y

) (for

example a Random walk). Then:

α^ (x, y

) = min

(f^

(y) f (x)

-^ Then, if the jump is “uphill” (

f^ (y

)^ /f

(x)

>^

1)^ ,

we always accept:

α^ (x, y

pMH

(x, y

q^ (

x, y

)^ ⇒

rMH

(x) = 0

-^ If the jump is “downhill” (

f^ (y

)^ /f

(x)

<^

1)^ ,

we accept with nonzero

probability:

α^ (x, y

)^ <

pMH

(x, y

)^ < p

(x, y

)^ ⇒

rMH

(x)

>^

7

Pseudo-Code1. Initialize the algorithm with an arbitrary value

x^0

and

M

  1. Set

j^ = 1.

  1. Generate

∗ x j^ from

³ q xj−

, x 1

´∗ j and

u^ from

U[

,^ 1].

  1. If

u^

≤^ α

³ xj

, x− 1

´∗ j then

xj

∗ x j , if

u >

³ α xj−

, x 1

´∗ j then

xj

xj−

  1. If

j^ ≤

M

then

j^ Ã

j^ + 1 and got to 3.

8

Choosing

q^ (

x, y

) I

-^ A popular choice for

q^ (

x, y

) is a random walk: y^ =

x^ +

ε^ where

ε^ ∼

N^

(0,^

-^ It is known as a

Random-Walk M-H

-^ Random walk satis

fies all conditions of a good transition kernel.

-^ Good default option. •^ How do we determine

Σ? Hessian of distribution of interest.

10

Choosing

q^ (

x, y

) II

-^ Another popular choice is the

Independent M-H.

-^ We just make

q^ (

x, y

g^ (

y)^.

-^ Note similarity with acceptance sampling. •^ However, the independent M-H accepts more often. •^ If

f^ (

x)^ ≤

ag

(x), then the independent M-H will accept at least 1

/a

of the proposals.

11

Example I (

t metropolis.m

-^ We revisit our problem of drawing from a

t^ distribution.

-^ Remember how di

fficult it was to use, for example, a normal distribu-

tion to sample as an envelope? • Basically, because dealing with tails with di

fficult.

-^ Now, we will see that with a Metropolis-Hastings the problem is quitesimple.

13

Example I^ •

Use MH to provide a numerical approximation to

t^ (x,

3), a

t^ distrib-

ution with 3 degrees of freedom, evaluated at

x.

-^ We need to get a random draw

n x

oNjj =^

from

t(3) using the MH.

-^ Implemented in my code

t metropolis.m

14

Output^ •

Output is a random draw

n x

oMjj

-^ With simulation, we can compute CDF:

Φ^ (

t)^ '

1 M

MX i=

δ{x

:x<tii^

(x} )i

-^ Some times, researchers report a smoothed version of the density (forexample with a Kernel estimator). •^ Similarly, we can compute the integral of any function of interest andNumerical errors.

16

Rate of ConvergenceAt which speed does the Chain converge? How long the Chain should run?Three important things to do:^ •

Run a set of di

fferent Chains with di

fferent initial values and compare

within and between Chains variation. • Check serial correlation of the draws. • Make

M

an increasing function of the serial correlation of the draws.

-^ Run

N^

diff

erent chains of length

M

with random initial values and

take the last value of each chain.

17

More on Convergence^ •

Often, convergence takes longer than what you think. • Case of bi-modal distributions. • Play it safe: just let the computer run a few more times. • Use acceleration methos or Rao-Blacwellization

var

(E

(h^

(X

|Y^ )))

≤^

varh

(X

19

One Chain versus Many Chains^ •

Should we use one long chain or many di

fferent chains?

-^ The answer is clear: only one long chain. •^ Fortunately, the old approach of many short chains is disappearing. •^ This does not mean that you should not do many runs while you aretuning your software!

20