replica exchange mcmc

23
Replica exchange MCMC with Stan and R Kentaro Matsuura June 4, 2016 Tokyo.Stan

Upload: -

Post on 21-Apr-2017

3.646 views

Category:

Data & Analytics


0 download

TRANSCRIPT

Page 1: Replica exchange MCMC

Replica exchange MCMC

with Stan and R

Kentaro Matsuura

June 4, 2016

Tokyo.Stan

Page 2: Replica exchange MCMC

Example data

โ€ข N = 50 # number of data points

2

Page 3: Replica exchange MCMC

Model (Assumptions)

โ€ข ๐‘Œ ๐‘› ~ Normal sin ๐›ฝ ๐‘‹ ๐‘› , ๐œŽ๐‘Œ

โ€ข angular rate: ๐›ฝ ~ Normal+ 0, 50

โ€ข noise scale: ๐œŽ๐‘Œ ~ Student_t+ 4, 0, 5

3

๐‘› = 1,โ€ฆ ,๐‘

Page 4: Replica exchange MCMC

Stan Code 4

Page 5: Replica exchange MCMC

R Code 5

Page 6: Replica exchange MCMC

Result | trace plot 6

This chain seems good.

Should I set initial values

around (b, s_y)=(24, 0.3) ?

Page 7: Replica exchange MCMC

By the way

A contour map of log-posterior can be visualized.

Because the number of parameters is just two in this model.

7

For later explanation, I visualized ๐ธ

๐‘‡(โ‰ˆ โˆ’ log-posterior )

๐ธ: Energy, ๐‘‡: Temperature

higher log-posterior lower ๐ธ

๐‘‡previous model is correspond to ๐‘‡ = 1

Page 8: Replica exchange MCMC

Contour map of ๐ธ/๐‘‡ (at ๐‘‡ = 1) 8

Page 9: Replica exchange MCMC

Contour map of ๐ธ/๐‘‡ (at ๐‘‡ = 1) 9

around (24, 0.3)

๐ธ โ‰ˆ 33

around (0.5, 0.3)

๐ธ โ‰ˆ 28

Page 10: Replica exchange MCMC

10

Replica exchange MCMC (also known as parallel tempering)

Setting initial values is generally difficult.

Page 11: Replica exchange MCMC

References

โ€ข Y. Iba, "Extended Ensemble Monte Carlo," Int. J. Mod.

Phys. C, 12, pp.623-652, 2001.

โ€ข Movie by Y. Iba (in Japanese):

ใƒฌใƒ—ใƒชใ‚ซไบคๆ›MCMC่ฌ›็พฉ ๏ผˆไผŠๅบญๅนธไบบ๏ผ‰ ้›ฃๆ˜“ๅบฆโ˜…โ˜…https://www.youtube.com/watch?v=1c7mQIhEqmQ

โ€ข Books (in Japanese)

โ€“ ็ฆๅณถๅญๆฒป (2006) ใ‚ตใ‚คใ‚ณใƒญใตใฃใฆ็ฉๅˆ†ใ™ใ‚‹ๆ–นๆณ• ็ขบ็Ž‡็š„ๆƒ…ๅ ฑๅ‡ฆ็†ใจ็ตฑ่จˆๅŠ›ๅญฆ(SGCใƒฉใ‚คใƒ–ใƒฉใƒช 50) p.60-66.

โ€“ ไผŠๅบญใปใ‹ (2005) ่จˆ็ฎ—็ตฑ่จˆII (็ตฑ่จˆ็ง‘ๅญฆใฎใƒ•ใƒญใƒณใƒ†ใ‚ฃใ‚ข 12) p.74-78

11

Page 12: Replica exchange MCMC

Overview 12

Monte Carlo Step

๐‘‡5

๐‘‡4

๐‘‡3

๐‘‡2

๐‘‡1 = 1

>>>>

๐‘๐‘Ÿ๐‘’๐‘๐‘™๐‘–๐‘๐‘Ž = 5

Page 13: Replica exchange MCMC

Annealing and Heating 13

๐‘‡โ„Ž๐‘–๐‘”โ„Ž

๐‘‡๐‘š๐‘–๐‘‘๐‘‘๐‘™๐‘’

๐‘‡1 = 1

Page 14: Replica exchange MCMC

Sampling from joint distribution

โ€ข Theoretically, Replica exchange MCMC

does sampling from the following joint

distribution:

๐‘ ๐œฝ1, โ€ฆ , ๐œฝ๐‘‡๐‘_๐‘Ÿ๐‘’๐‘๐‘™๐‘–๐‘๐‘Ž =

๐‘Ÿ=1

๐‘_๐‘Ÿ๐‘’๐‘๐‘™๐‘–๐‘๐‘Ž

๐‘ ๐œฝ๐‘Ÿ|๐‘‡ = ๐‘‡๐‘Ÿ

where ๐‘ ๐œฝ๐‘Ÿ|๐‘‡ = ๐‘‡๐‘Ÿ โˆ exp โˆ’๐ธ ๐œฝ๐‘Ÿ

๐‘‡๐‘Ÿ

14

Page 15: Replica exchange MCMC

Exchange probability of replicas

๐‘ = min 1,exp โˆ’๐ธ๐‘Ÿโ€ฒ๐‘‡๐‘Ÿโˆ’๐ธ๐‘Ÿ๐‘‡๐‘Ÿโ€ฒ

exp โˆ’๐ธ๐‘Ÿ๐‘‡๐‘Ÿโˆ’๐ธ๐‘Ÿโ€ฒ๐‘‡๐‘Ÿโ€ฒ

= min 1, exp ๐ธ๐‘Ÿ โˆ’ ๐ธ๐‘Ÿโ€ฒ ร—1

๐‘‡๐‘Ÿโˆ’1

๐‘‡๐‘Ÿโ€ฒ

15

Page 16: Replica exchange MCMC

Pseudo Code 16

set T of replicas: T = (1, T2, T3, ..., TN_replica)set initial values: x = (x0, x0, ..., x0)

for e in 1, ..., N_exchangefor r in 1, ..., N_replica

short sampling started from x[r] at each T[r]endsave MCMC samples at T = 1

exchange replicas if p < unif(0,1)

for r in 1, ..., N_replicaupdate x[r]

endend

Page 17: Replica exchange MCMC

Stan Code 17

Page 18: Replica exchange MCMC

R Code and Settings

โ€ข R Code:

โ€ข ๐‘๐‘Ÿ๐‘’๐‘๐‘™๐‘–๐‘๐‘Ž = 10

โ€ข ๐‘๐‘’๐‘ฅ๐‘โ„Ž๐‘Ž๐‘›๐‘”๐‘’ = 100

โ€ข ๐‘‡ = 1, 1.54, โ€ฆ , 32.37, 50

โ€ข ๐‘ฅ0 = ๐‘, ๐œŽ๐‘ฆ 0= 24. 2, 0.4

โ€ข iter=70 and warmup=50 each short sampling

(i.e. 20 MCMC samples)

18

๐‘๐‘Ÿ๐‘’๐‘๐‘™๐‘–๐‘๐‘Ž needs โ‰ˆ ๐‘

geometric progression

deep local minimum โ˜ 

https://gist.github.com/MatsuuraKentaro/bccf13af3ba52c9d6c379c0032725b91

Page 19: Replica exchange MCMC

Result | Exchanges of replicas 19

Page 20: Replica exchange MCMC

Result | ๐ธ (Energy) 20

Page 21: Replica exchange MCMC

Result | ๐ธ (Energy) 21

Page 22: Replica exchange MCMC

Result | trace plot (at ๐‘‡ = 1) 22

Page 23: Replica exchange MCMC

Discussion

โ€ข Can I re-use warmup result in Stan?

i.e. step size &

diagonal elements of inverse mass matrix

โ€ข How to set iter and warmup of each short

sampling?

warmup=50 is usually too short as total sampling.

But, total warmup is 50*100 in this case.

Does it make sense?

23