SlideShare a Scribd company logo
1 of 55
Download to read offline
Julia Tokyo #2 
Julias»‚ 
Hamiltonian Monte Carlo 
(NUTSâ–) 
,‡ W+ (Kenta Sato) 
@bicycle1885 
1 / 55
²òÅòÃ 
ß…Ãu 
Ýê²Ô×7áòŪêì] (MCMC) 
Metropolis-Hastings 
Hamiltonian Monte Carlo (HMC) 
No-U-Turn Sampler (NUTS) 
JuliasžT—MCMCа–· 
2 / 55
_ŸvÑÇzkzP¼se 
MCMCw”—´òÖéò¯žÕè®Û®¸wck[vP 
Stanvuz´òÖè–zqvž£fkP 
JuliasžT—´òÖè–ž—–kP 
3 / 55
¶ 
ÔzZÖ|MCMCß9{
zw÷˜— _se 
D»0wrÃvø{?cvPsAaP 
Æ?w{Qz¶žorPŠeX|š“’T«PXN— 
WŽc˜ŠgŸ 
izÔ{izÝs®,crPkl]—tˆW–Še 
4 / 55
ß…Ãu / а–·Ãu 
5 / 55
ß…Ãu 
,‡ W+ 
Twitter/GitHub: @bicycle1885 
}: rRRȂȗ 
š: Bioinformatics 
JuliaÉ: ñz|›xW 
¾Yv{§: Julia / Haskell 
”[žR{§: Python / R 
6 / 55
HaskellŽ”™c[V,PcŠe 
²Haskellw”— Ê€ íÖì¯èÞò¯³z™ëÒä–žcŠc 
k} 
7 / 55
а–·Ãu 
DocOpt.jl - https://github.com/docopt/DocOpt.jl 
×êÖຖ·žÐ–¸c|²ÝòÈè£òÂDzЖ¸že— 
RandomForests.jl - 
https://github.com/bicycle1885/RandomForests.jl 
A†»?¡ê³é¹ßRandom ForestzJuliaö 
GeneOntology.jl - https://github.com/bicycle1885/GeneOntology.jl 
f»zGene OntologyzÖê¬ÂÇžö®cr— 
8 / 55
Ýê²Ô×7áòŪêì] 
(MCMC) 
9 / 55
MCMC]t{ 
1	Y
 
{›ft—˜k|±
Ú W•z´òÖêžÝê²Ô×7žJ 
Pr¤—´òÖéò¯]z~tp} 
¤•˜k´òÖêß9{
Úz?–
Œvuö“v–ž4‘e— 
zwž›˜—} 
Ýê²Ô×7t{|xWzæAz‹sÕzæAz±
ÚXEŠ—± 
f z_tžPR} 
1	9U
Y  9  Y
2
 9U  YU
  1	9U
Y  9U  YU
 
Y Y 5	Y Y
 
_ztY|æA W• „·¤e—±ž t„Y|·¤± 
t‚} 
10 / 55
Ýê²Ô×7z. 
·¤± 5	Y Y
  1	9U
Y  9U  Y
 
11 / 55
ccPMCMC 
	Y
 
ö0z±
Ú W•´òÖéò¯e—w{|·¤±Xºka 
v]˜|v•vP[õXN—} 

ÚzÓ/[: 
§ê³–È[: 
	Y
  D 5	Y Y
	Y
EY 
1	U
	Y
 ³ 	Y
 BT U ³ 7
 GPSBOZ 1	
	Y
 
©´òÖè–X_˜•žºketPR_tzÚvu{à{cvP 
(sYvP)} 
12 / 55
ûÕpósz´òÖéò¯{ÕcP 
Q	Y
 Q	Y
 
±Ã_D iz”cLBÃ_D XN—te—} 
ûÕpósz´òÖéò¯zÕca 
ýP¥°{|óÖz`[´ówK¯crP— 
Q	Y
 
cWci˜Xu_W{´òÖéò¯¼w{
W•vP 
2pzƒ 
1. izÝW•ýP[„ýP[„t‹ 
2. ýPt_™žfp]k•i_W•9Pt_™„{NŠ–íWvP 
➠ MCMC{Šawiz”Rvƒžt— 
13 / 55
Metropolis­Hastings 
Night View with Tokyo Tower Special Lightup (Shibakouen, Tokyo, Japan) by t-mizo is licensed under CC BY 2.0 
14 / 55
Metropolis­Hastings 
MCMC´òÖéò¯z~tps|Ž
ÚtPR´òÖéò¯ckP 

Út{*z
ÚW•°BFž–cc| P–v•izFž*v 
c|iRsv]˜|izÝwtuŠ—} 
R	ú 
 
°BFžfe—Ž
Ú {özvPcL
Úvu|´ò 
Öéò¯ceP
Úwe—} 
ú 	ú 	N

 
	ú 	N

  NJO
 
 Q	ú
R		N
  ú
 
°BF {’Az± s*va˜—: 
Q		N

R	ú 	N

 
Q	
 Q	
 
__s| {´òÖéò¯ckP
Ú z”cLBÃ_D 
15 / 55
Metropolis­Hastings 
z¡ê³é¹ß 
”cLB±
ÚD W•´òÖéò¯e— 
1. |æA žE| we— 
2. Ž
Ú W•kvF žt— 
3. ± s ž´òÖêtcr*vc|iRsv]˜| 
@qe— 
4. *va˜kÝ{ tc|@qa˜kÝ{ 
te— 
5. tcr|2~4ž z´òÖêX¤•˜—Šs– 
4e 
Q	
 
	
 N ±  
R	ú 	N

 ú 
	ú 	N

 ú 
	N
± ú 
	N
± 	N
 
N ± N
. 
16 / 55
Ž
Ú{cL
Ú( randn) 
# p: (unnormalized) probability density function 
# θ₀: initial state 
# M: number of samples 
# ϵ: step size 
function metropolis(p::Function, θ₀::Vector{Float64}, M::Int, ϵ::Float64) 
d = length(θ₀) 
# allocate samples' holder 
samples = Array(typeof(θ₀), M) 
# set the current state to the initial state 
θ = θ₀ 
for m in 1:M 
# generate a candidate sample from 
# the proposal distribution (normal distribution) 
θ̃ = randn(d) * ϵ + θ 
if rand()  min(1.0, p(θ̃) / p(θ)) 
# accept the proposal 
θ = θ̃ 
end 
samples[m] = θ 
print_sample(θ) 
end 
samples 
end 
metropolis.jl 
17 / 55
cc 
2/Dz/DwözN—cL
Ú 
# mean 
μ = [0.0, 0.0] 
# covariance matrix 
Σ = [1.0 0.8; 
0.8 1.0] 
# precision matrix 
Λ = inv(Σ) 
# unnormalized multivariate normal distribution 
normal = x - exp(-0.5 * ((x - μ)' * Λ * (x - μ))[1]) 
|–x₀|´òÖêDM|¸ÅÂÖüϵž®cr´òÖéò¯ 
samples = metropolis(normal, x₀, M, ϵ) 
18 / 55
HQ ­created 
with Gadfly.jl 
-4 -2 0 2 4 
x 
Iteration 
500 
400 
300 
200 
100 
1 
4 
2 
0 
-2 
-4 
y 
Metropolis (ϵ = 1.0) 
19 / 55
HQ ­created 
with Gadfly.jl 
-3 -2 -1 0 1 
x 
Iteration 
500 
400 
300 
200 
100 
1 
0.5 
0.0 
-0.5 
-1.0 
-1.5 
-2.0 
y 
Metropolis (ϵ = 0.1) 
-3 -2 -1 0 1 2 
x 
Iteration 
500 
400 
300 
200 
100 
1 
3 
2 
1 
0 
-1 
-2 
-3 
y 
Metropolis (ϵ = 0.5) 
-4 -2 0 2 4 
x 
Iteration 
500 
400 
300 
200 
100 
1 
4 
2 
0 
-2 
-4 
y 
Metropolis (ϵ = 1.0) 
-3 -2 -1 0 1 2 3 
x 
Iteration 
500 
400 
300 
200 
100 
1 
3 
2 
1 
0 
-1 
-2 
-3 
y 
Metropolis (ϵ = 2.0) 
20 / 55
Metropolis­Hastings 
zþUF 
1. @qzÇë–È©Ô 
1 
¸ÅÂÖ´£¹ z–s|@qt[ÿzÇë–È©ÔXN— 
2. èò¿ß¥¨–® 
´òÖêzÊXèò¿ß¥¨–®že— 
21 / 55
þU1: @qzÇë–È©Ô 
±
Úz–XK¯cr—z{`[´ól]} 
1 
1 
¸ÅÂÖ´£¹ R ➠ RY[”]—X|@qXÖX— 
¸ÅÂÖ´£¹ Ÿ ➠ @q{WT•˜—X|NŠ–”]vP 
MCMCW•v—…[¬€v´òÖꞤ—w{¸ÅÂÖ´£¹žRY 
[ckPX|@qXÖX—k´òÖéò¯zµXu[v—Çë 
–È©ÔXN—} 
1 
Õp(´òÖéò¯e—/D)w”orÐèà–¾ z P–X£v 
–|ۏXÕcP} 
22 / 55
þU2: èò¿ß¥¨–® 
Metropolis-HastingsW•¤•˜k´òÖêÊ{|èò¿ß¥¨–®ž 
crP— 
ú 	N
 
Ž
ÚXÜe—°BF {|xWz– W•‹r[0 
X¤”ck–W•ewûorYrcŠR_tXN— 
	N
 
èò¿ß¥¨–®s{(VVŠWw{or)`ûxDz[$w‡º 
ck—|cWvP 
óž…W•…ŠsU—zwWv–`ûxDX«Pwv— 
23 / 55
Hamiltonian Mote Carlo (HMC) 
Hamiltonian circuit on a small rhombicosidodecahedron by fdecomite is licensed under CC BY 2.0 
24 / 55
Hamiltonian Monte Carlo 
Hamiltonian Monte Carlo](HMC){|ÎÞêÇò¦»(Hamiltonian 
dynamics)žpwæŽa˜kMCMC]z~tp} 
±Ã_Dz¶žqJe— (|Œ0v±
Ú{sYvP) 
ószŠ¨z唞ðor´òÖꞤ— 
)zMCMCz¡ê³é¹ßt‡¶cr|öz vP P´òÖ 
êX¤•˜— 
_z]žPagkNo-U-Turn Sampler (NUTS){StantPR 
Ø£¹4zkzÖì¯èÞò¯{§wöa˜rP— 
25 / 55
Boltzmann
Ú 
Y 	Y
 1	Y
 
æA z§Ìê­– t±
Ú {Õz”Rw×Ô]• 
˜—} 
 
; 
1	Y
  FYQ 	+	Y

 
; 
__s| {±
ÚzcLBDsN—} 
_˜žuwžT||±
Úz§Ìê­–X4‘sY—} 
	Y
  + MPH 1	Y
 + MPH ; 
26 / 55
ÎÞêÇò¦» 
 S 
Š¨z唞æT—} žŠ¨z”ŸØ®Çê| žå”£Ø®Çê 
tckÔzŠ¨z唞E—ÎÞêÇò[ ä: 
EJ 
EU 
ESJ 
EU 
 ) 
SJ 
 + 
) 
J 
)	
 S
 6	
 
__s|ÎÞêÇÊ¡ò {ÜÅò¶âê§Ìê­– t 
唧Ìê­– z÷tcraa˜—} 
,	S
 
)	
 S
  6
,	S
 
27 / 55
´òÖéò¯„z%J 
/D 
”ŸØ®Çê : ´òÖéò¯ckP±/D 
唣خÇê : å”zBˆ0v/D 
§Ìê­– 
ÜÅò¶âê§Ìê­– : Boltzmann
Úž2w 
唧Ìê­– : 2|v唧Ìê­–w 
”ŸØ®Çêt唣خÇêz•Ô
Ú { 
”–’Az”Rw
wsY—} 
 
S 
6	
 
,	S
 
Q	
 S
 
)	
 S
  6
,	S
 
Q	
 S
  FYQ +)	
 S
  FYQ +6	
 FYQ 	+,	S

 
 
; 
 
; 
28 / 55
HMCz*?± 
Üa˜k°BFwe—*?±{’Az”Rwv—} 
	  
  NJO ú 
 FYQ 	)	
 S
 + )	ú
 S
ú
 
) )	
 S
 + )	ú
 S
ú   
   
võ0w{| z–{Ó/vzs ’T«f 
*va˜— ( ) {flX|²òÓä–¾sD–0wÎÞêÇò[ 
 äž|ŒBcrw[t«f¨1XPfe—kxö0w{@q{ 
ȓsvP} 
29 / 55
Leapfrog|ŒB 
ÎÞêÇò[ ä{w}0ww[z{ÕcPzs|D–
žíR} 
i_s{|Leapfrog|ŒBtPR’AzÒäžpWR} 
SJ 	U
1
 
J 	U
1
 
SJ 	U
1
 
 SJ	U
 + 
1 
 
6		U

 
J 
 J	U
1SJ	U
1
 
 SJ	U
1
 + 
1 
 
6		U
1

 
J 
30 / 55
vhLeapfrog|ŒBvzW 
Q	
 S
 )	
 S
 
•Ô
Ú žÓ/we—kw{| z9žÓ/w 
cv]˜|v•vP 
cWc|Euler]vus{(h_zuažÏÁcrŽ)9X/Bc 
rcŠRzs| Q	
 S
 
XÓ/wv•vP 
Leapfrog|ŒBs{|3pzÒä{i˜j˜¹	(shear 
mapping)vzs|i˜j˜2JcrŽ9X/BcvP 
VerticalShear m=1.25 by RobHar - Own work using Inkscape. Licensed under Public domain via Wikimedia Commons - 
http://commons.wikimedia.org/wiki/File:VerticalShear_m%3D1.25.svg#mediaviewer/File:VerticalShear_m%3D1.25.svg 
31 / 55
HMCw”—´òÖéò¯¡ê³é¹ß 
1. |æA žE| we— 
2. 唣žcL
ÚvuW•´òÖéò¯e— 
3. W•¸ÅÂÖ´£¹ sLeapfrog|ŒBw”—Òž x 
–4c| ž¤— 
4. ± s*vc|iRsv] 
˜|@qe— 
5. *va˜kÝ{ tc|@qa˜kÝ{ 
te— 
6. tcr|2~5ž z´òÖêX¤•˜—Šs– 
4e 
	
 N ±  
	N
 1 - 
ú 
NJO 
 FYQ 	)	
 S
 + )	ú
 S
ú
 
	N
± ú 
	N
± 	N
 
N ± N
. 
32 / 55
# U : potential energy function 
# ∇U : gradient of the potential energy function 
# θ₀ : initial state 
# M : number of samples 
# ϵ : step size 
# L : number of steps 
function hmc(U::Function, ∇U::Function, θ₀::Vector{Float64}, M::Int, ϵ::Float64, L::Int) 
d = length(θ₀) 
# allocate sampels' holder 
samples = Array(typeof(θ₀), M) 
# set the current sate to the initail state 
θ = θ₀ 
for m in 1:M 
# sample momentum variable 
p = randn(d) 
H = U(θ) + p ⋅ p / 2 
θ̃ = θ 
for l in 1:L 
p -= ϵ / 2 * ∇U(θ̃) # half step in momentum variable 
θ̃ += ϵ * p # full step in location variable 
p -= ϵ / 2 * ∇U(θ̃) # half step in momentum variable again 
end 
H̃ = U(θ̃) + p ⋅ p / 2 
if randn()  min(1.0, exp(H - H̃)) 
# accept the proposal 
θ = θ̃ 
end 
samples[m] = θ 
print_sample(θ) 
end 
samples 
end 
hmc.jl 
33 / 55
HQ ­created 
with Gadfly.jl 
-4 -2 0 2 4 
x 
Iteration 
500 
400 
300 
200 
100 
1 
4 
2 
0 
-2 
-4 
y 
HMC (ϵ = 0.1, L = 10) 
-   34 / 55
HQ ­created 
with Gadfly.jl 
-2 -1 0 1 
x 
Iteration 
500 
400 
300 
200 
100 
1 
1 
0 
-1 
-2 
y 
HMC (ϵ = 0.01, L = 10) 
-4 -2 0 2 4 
x 
Iteration 
500 
400 
300 
200 
100 
1 
3 
2 
1 
0 
-1 
-2 
-3 
y 
HMC (ϵ = 0.05, L = 10) 
-4 -2 0 2 4 
x 
Iteration 
500 
400 
300 
200 
100 
1 
4 
2 
0 
-2 
-4 
y 
HMC (ϵ = 0.1, L = 10) 
-4 -2 0 2 4 
x 
Iteration 
500 
400 
300 
200 
100 
1 
4 
2 
0 
-2 
-4 
y 
HMC (ϵ = 0.5, L = 10) 
-   
35 / 55
HQ ­created 
with Gadfly.jl 
-0.3 -0.2 -0.1 0.0 0.1 
x 
Iteration 
500 
400 
300 
200 
100 
1 
0.1 
0.0 
-0.1 
-0.2 
-0.3 
y 
HMC (ϵ = 0.01, L = 1) 
-1.0 -0.5 0.0 0.5 
x 
Iteration 
500 
400 
300 
200 
100 
1 
0.5 
0.0 
-0.5 
-1.0 
-1.5 
y 
HMC (ϵ = 0.05, L = 1) 
-2 -1 0 1 
x 
Iteration 
500 
400 
300 
200 
100 
1 
1 
0 
-1 
-2 
y 
HMC (ϵ = 0.1, L = 1) 
-4 -2 0 2 4 
x 
Iteration 
500 
400 
300 
200 
100 
1 
3 
2 
1 
0 
-1 
-2 
-3 
y 
HMC (ϵ = 0.5, L = 1) 
-   
36 / 55

More Related Content

What's hot

Rで階層ベイズモデル
Rで階層ベイズモデルRで階層ベイズモデル
Rで階層ベイズモデルYohei Sato
 
マルコフ連鎖モンテカルロ法入門-1
マルコフ連鎖モンテカルロ法入門-1マルコフ連鎖モンテカルロ法入門-1
マルコフ連鎖モンテカルロ法入門-1Nagi Teramo
 
負の二項分布について
負の二項分布について負の二項分布について
負の二項分布についてHiroshi Shimizu
 
ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介Naoki Hayashi
 
変分ベイズ法の説明
変分ベイズ法の説明変分ベイズ法の説明
変分ベイズ法の説明Haruka Ozaki
 
順序データでもベイズモデリング
順序データでもベイズモデリング順序データでもベイズモデリング
順序データでもベイズモデリング. .
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデルHiroshi Shimizu
 
15分でわかる(範囲の)ベイズ統計学
15分でわかる(範囲の)ベイズ統計学15分でわかる(範囲の)ベイズ統計学
15分でわかる(範囲の)ベイズ統計学Ken'ichi Matsui
 
StanとRでベイズ統計モデリング 11章 離散値をとるパラメータ
StanとRでベイズ統計モデリング 11章 離散値をとるパラメータStanとRでベイズ統計モデリング 11章 離散値をとるパラメータ
StanとRでベイズ統計モデリング 11章 離散値をとるパラメータMiki Katsuragi
 
あなたの心にBridgeSampling
あなたの心にBridgeSamplingあなたの心にBridgeSampling
あなたの心にBridgeSamplingdaiki hojo
 
ベイズ統計入門
ベイズ統計入門ベイズ統計入門
ベイズ統計入門Miyoshi Yuya
 
機械学習による統計的実験計画(ベイズ最適化を中心に)
機械学習による統計的実験計画(ベイズ最適化を中心に)機械学習による統計的実験計画(ベイズ最適化を中心に)
機械学習による統計的実験計画(ベイズ最適化を中心に)Kota Matsui
 
基礎からのベイズ統計学第5章
基礎からのベイズ統計学第5章基礎からのベイズ統計学第5章
基礎からのベイズ統計学第5章hiro5585
 
Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Hiroshi Shimizu
 
数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツ数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツShuyo Nakatani
 
MCMCサンプルの使い方 ~見る・決める・探す・発生させる~
MCMCサンプルの使い方 ~見る・決める・探す・発生させる~MCMCサンプルの使い方 ~見る・決める・探す・発生させる~
MCMCサンプルの使い方 ~見る・決める・探す・発生させる~. .
 
2 6.ゼロ切断・過剰モデル
2 6.ゼロ切断・過剰モデル2 6.ゼロ切断・過剰モデル
2 6.ゼロ切断・過剰モデルlogics-of-blue
 
心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズ心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズHiroshi Shimizu
 
ようやく分かった!最尤推定とベイズ推定
ようやく分かった!最尤推定とベイズ推定ようやく分かった!最尤推定とベイズ推定
ようやく分かった!最尤推定とベイズ推定Akira Masuda
 

What's hot (20)

Rで階層ベイズモデル
Rで階層ベイズモデルRで階層ベイズモデル
Rで階層ベイズモデル
 
階層ベイズとWAIC
階層ベイズとWAIC階層ベイズとWAIC
階層ベイズとWAIC
 
マルコフ連鎖モンテカルロ法入門-1
マルコフ連鎖モンテカルロ法入門-1マルコフ連鎖モンテカルロ法入門-1
マルコフ連鎖モンテカルロ法入門-1
 
負の二項分布について
負の二項分布について負の二項分布について
負の二項分布について
 
ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介
 
変分ベイズ法の説明
変分ベイズ法の説明変分ベイズ法の説明
変分ベイズ法の説明
 
順序データでもベイズモデリング
順序データでもベイズモデリング順序データでもベイズモデリング
順序データでもベイズモデリング
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデル
 
15分でわかる(範囲の)ベイズ統計学
15分でわかる(範囲の)ベイズ統計学15分でわかる(範囲の)ベイズ統計学
15分でわかる(範囲の)ベイズ統計学
 
StanとRでベイズ統計モデリング 11章 離散値をとるパラメータ
StanとRでベイズ統計モデリング 11章 離散値をとるパラメータStanとRでベイズ統計モデリング 11章 離散値をとるパラメータ
StanとRでベイズ統計モデリング 11章 離散値をとるパラメータ
 
あなたの心にBridgeSampling
あなたの心にBridgeSamplingあなたの心にBridgeSampling
あなたの心にBridgeSampling
 
ベイズ統計入門
ベイズ統計入門ベイズ統計入門
ベイズ統計入門
 
機械学習による統計的実験計画(ベイズ最適化を中心に)
機械学習による統計的実験計画(ベイズ最適化を中心に)機械学習による統計的実験計画(ベイズ最適化を中心に)
機械学習による統計的実験計画(ベイズ最適化を中心に)
 
基礎からのベイズ統計学第5章
基礎からのベイズ統計学第5章基礎からのベイズ統計学第5章
基礎からのベイズ統計学第5章
 
Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説
 
数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツ数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツ
 
MCMCサンプルの使い方 ~見る・決める・探す・発生させる~
MCMCサンプルの使い方 ~見る・決める・探す・発生させる~MCMCサンプルの使い方 ~見る・決める・探す・発生させる~
MCMCサンプルの使い方 ~見る・決める・探す・発生させる~
 
2 6.ゼロ切断・過剰モデル
2 6.ゼロ切断・過剰モデル2 6.ゼロ切断・過剰モデル
2 6.ゼロ切断・過剰モデル
 
心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズ心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズ
 
ようやく分かった!最尤推定とベイズ推定
ようやく分かった!最尤推定とベイズ推定ようやく分かった!最尤推定とベイズ推定
ようやく分かった!最尤推定とベイズ推定
 

Similar to Julia Tokyo #2 Hamiltonian Monte Carlo (NUTS

5.5 to 5.7 Review.pdf
5.5 to 5.7 Review.pdf5.5 to 5.7 Review.pdf
5.5 to 5.7 Review.pdfLomasAlg1
 
Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理niratama
 
67243- cooling and heating & calculation
67243- cooling and heating  & calculation67243- cooling and heating  & calculation
67243- cooling and heating & calculationA.M. ATIQULLAH
 
Module 3 example 15
Module 3 example 15Module 3 example 15
Module 3 example 15ccooking
 
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)SAJJAD KHUDHUR ABBAS
 
Risk assessment of a hydroelectric dam with parallel
Risk assessment of a hydroelectric dam with parallelRisk assessment of a hydroelectric dam with parallel
Risk assessment of a hydroelectric dam with paralleleSAT Publishing House
 
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING
Episode 40 :  DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYINGEpisode 40 :  DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYINGSAJJAD KHUDHUR ABBAS
 
Part 3 Residuals.pdf
Part 3 Residuals.pdfPart 3 Residuals.pdf
Part 3 Residuals.pdfSajawalNawaz5
 
Solutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfSolutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfWaleedHussain30
 
Pembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan Tanah
Pembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan TanahPembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan Tanah
Pembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan TanahChristopherAbhistaAr
 
TC74VCX244FT PSpice Model (Free SPICE Model)
TC74VCX244FT PSpice Model (Free SPICE Model)TC74VCX244FT PSpice Model (Free SPICE Model)
TC74VCX244FT PSpice Model (Free SPICE Model)Tsuyoshi Horigome
 
vibration of machines and structures
vibration of machines and structuresvibration of machines and structures
vibration of machines and structuresAniruddhsinh Barad
 
Mathematical Modelling of Electrical/Mechanical modellinng in MATLAB
Mathematical Modelling of Electrical/Mechanical modellinng in MATLABMathematical Modelling of Electrical/Mechanical modellinng in MATLAB
Mathematical Modelling of Electrical/Mechanical modellinng in MATLABCOMSATS Abbottabad
 
kintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプルkintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプルYudai Shibuya
 
Time and size covariate generalization of growth curves and their extension t...
Time and size covariate generalization of growth curves and their extension t...Time and size covariate generalization of growth curves and their extension t...
Time and size covariate generalization of growth curves and their extension t...bimchk
 
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...Jhonatan Minchán
 

Similar to Julia Tokyo #2 Hamiltonian Monte Carlo (NUTS (20)

5.5 to 5.7 Review.pdf
5.5 to 5.7 Review.pdf5.5 to 5.7 Review.pdf
5.5 to 5.7 Review.pdf
 
Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理
 
67243- cooling and heating & calculation
67243- cooling and heating  & calculation67243- cooling and heating  & calculation
67243- cooling and heating & calculation
 
Examen final
Examen finalExamen final
Examen final
 
HIDRAULICA DE CANALES
HIDRAULICA DE CANALESHIDRAULICA DE CANALES
HIDRAULICA DE CANALES
 
Module 3 example 15
Module 3 example 15Module 3 example 15
Module 3 example 15
 
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING (Part 2)
 
Risk assessment of a hydroelectric dam with parallel
Risk assessment of a hydroelectric dam with parallelRisk assessment of a hydroelectric dam with parallel
Risk assessment of a hydroelectric dam with parallel
 
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING
Episode 40 :  DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYINGEpisode 40 :  DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING
Episode 40 : DESIGN EXAMPLE – DILUTE PHASE PNEUMATIC CONVEYING
 
Cholesky sqrt venka
Cholesky sqrt venkaCholesky sqrt venka
Cholesky sqrt venka
 
Part 3 Residuals.pdf
Part 3 Residuals.pdfPart 3 Residuals.pdf
Part 3 Residuals.pdf
 
Solutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdfSolutions_Manual_to_accompany_Applied_Nu.pdf
Solutions_Manual_to_accompany_Applied_Nu.pdf
 
Pembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan Tanah
Pembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan TanahPembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan Tanah
Pembahasan Soal Teknik Fondasi Telapak dan Dinding Penahan Tanah
 
TC74VCX244FT PSpice Model (Free SPICE Model)
TC74VCX244FT PSpice Model (Free SPICE Model)TC74VCX244FT PSpice Model (Free SPICE Model)
TC74VCX244FT PSpice Model (Free SPICE Model)
 
vibration of machines and structures
vibration of machines and structuresvibration of machines and structures
vibration of machines and structures
 
project designa.docx
project designa.docxproject designa.docx
project designa.docx
 
Mathematical Modelling of Electrical/Mechanical modellinng in MATLAB
Mathematical Modelling of Electrical/Mechanical modellinng in MATLABMathematical Modelling of Electrical/Mechanical modellinng in MATLAB
Mathematical Modelling of Electrical/Mechanical modellinng in MATLAB
 
kintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプルkintone university 03-1. AD+カスタマイズ入門第6版 サンプル
kintone university 03-1. AD+カスタマイズ入門第6版 サンプル
 
Time and size covariate generalization of growth curves and their extension t...
Time and size covariate generalization of growth curves and their extension t...Time and size covariate generalization of growth curves and their extension t...
Time and size covariate generalization of growth curves and their extension t...
 
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
 

More from Kenta Sato

Julia最新情報 2015
Julia最新情報 2015Julia最新情報 2015
Julia最新情報 2015Kenta Sato
 
Introduction to Julia for bioinformacis
Introduction to Julia for bioinformacisIntroduction to Julia for bioinformacis
Introduction to Julia for bioinformacisKenta Sato
 
Juliaのパッケージをつくろう!
Juliaのパッケージをつくろう!Juliaのパッケージをつくろう!
Juliaのパッケージをつくろう!Kenta Sato
 
Julia - Easier, Better, Faster, Stronger
Julia - Easier, Better, Faster, StrongerJulia - Easier, Better, Faster, Stronger
Julia - Easier, Better, Faster, StrongerKenta Sato
 
実践! D3.jsで可視化入門
実践! D3.jsで可視化入門実践! D3.jsで可視化入門
実践! D3.jsで可視化入門Kenta Sato
 
モナドがいっぱい!
モナドがいっぱい!モナドがいっぱい!
モナドがいっぱい!Kenta Sato
 

More from Kenta Sato (6)

Julia最新情報 2015
Julia最新情報 2015Julia最新情報 2015
Julia最新情報 2015
 
Introduction to Julia for bioinformacis
Introduction to Julia for bioinformacisIntroduction to Julia for bioinformacis
Introduction to Julia for bioinformacis
 
Juliaのパッケージをつくろう!
Juliaのパッケージをつくろう!Juliaのパッケージをつくろう!
Juliaのパッケージをつくろう!
 
Julia - Easier, Better, Faster, Stronger
Julia - Easier, Better, Faster, StrongerJulia - Easier, Better, Faster, Stronger
Julia - Easier, Better, Faster, Stronger
 
実践! D3.jsで可視化入門
実践! D3.jsで可視化入門実践! D3.jsで可視化入門
実践! D3.jsで可視化入門
 
モナドがいっぱい!
モナドがいっぱい!モナドがいっぱい!
モナドがいっぱい!
 

Recently uploaded

An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESNarmatha D
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 

Recently uploaded (20)

An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Industrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIESIndustrial Safety Unit-I SAFETY TERMINOLOGIES
Industrial Safety Unit-I SAFETY TERMINOLOGIES
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 

Julia Tokyo #2 Hamiltonian Monte Carlo (NUTS

  • 1. Julia Tokyo #2 Julias»‚ Hamiltonian Monte Carlo (NUTSâ–) ,‡ W+ (Kenta Sato) @bicycle1885 1 / 55
  • 2. ²òÅòà ߅Ãu Ýê²Ô×7áòŪêì] (MCMC) Metropolis-Hastings Hamiltonian Monte Carlo (HMC) No-U-Turn Sampler (NUTS) JuliasžT—MCMCа–· 2 / 55
  • 5. zw÷˜— _se D»0wrÃvø{?cvPsAaP Æ?w{Qz¶žorPŠeX|š“’T«PXN— WŽc˜ŠgŸ izÔ{izÝs®,crPkl]—tˆW–Še 4 / 55
  • 7. ß…Ãu ,‡ W+ Twitter/GitHub: @bicycle1885 }: rRR»Ç»ó š: Bioinformatics JuliaÉ: ñz|›xW ¾Yv{§: Julia / Haskell ”[žR{§: Python / R 6 / 55
  • 8. HaskellŽ”™c[V,PcŠe ²Haskellw”— Ê€ íÖì¯èÞò¯³z™ëÒä–žcŠc k} 7 / 55
  • 9. а–·Ãu DocOpt.jl - https://github.com/docopt/DocOpt.jl ×êÖຖ·žÐ–¸c|²ÝòÈè£òÂDzЖ¸že— RandomForests.jl - https://github.com/bicycle1885/RandomForests.jl A†»?¡ê³é¹ßRandom ForestzJuliaö GeneOntology.jl - https://github.com/bicycle1885/GeneOntology.jl f»zGene OntologyzÖê¬ÂÇžö®cr— 8 / 55
  • 11. MCMC]t{ 1 Y {›ft—˜k|± Ú W•z´òÖêžÝê²Ô×7žJ Pr¤—´òÖéò¯]z~tp} ¤•˜k´òÖêß9{ Úz?– Œvuö“v–ž4‘e— zwž›˜—} Ýê²Ô×7t{|xWzæAz‹sÕzæAz± ÚXEŠ—± f z_tžPR} 1 9U
  • 12. Y 9 Y 2 9U YU 1 9U
  • 13. Y 9U YU Y Y 5 Y Y _ztY|æA W• „·¤e—±ž t„Y|·¤± t‚} 10 / 55
  • 15. Y 9U Y 11 / 55
  • 16. ccPMCMC Y ö0z± Ú W•´òÖéò¯e—w{|·¤±Xºka v]˜|v•vP[õXN—} ÚzÓ/[: §ê³–È[: Y D 5 Y Y Y EY 1 U Y ³ Y BT U ³ 7 GPSBOZ 1 Y ©´òÖè–X_˜•žºketPR_tzÚvu{à{cvP (sYvP)} 12 / 55
  • 17. ûÕpósz´òÖéò¯{ÕcP Q Y Q Y ±Ã_D iz”cLBÃ_D XN—te—} ûÕpósz´òÖéò¯zÕca ýP¥°{|óÖz`[´ówK¯crP— Q Y cWci˜Xu_W{´òÖéò¯¼w{ W•vP 2pzƒ 1. izÝW•ýP[„ýP[„t‹ 2. ýPt_™žfp]k•i_W•9Pt_™„{NŠ–íWvP ➠ MCMC{Šawiz”Rvƒžt— 13 / 55
  • 18. Metropolis­Hastings Night View with Tokyo Tower Special Lightup (Shibakouen, Tokyo, Japan) by t-mizo is licensed under CC BY 2.0 14 / 55
  • 19. Metropolis­Hastings MCMC´òÖéò¯z~tps|Ž ÚtPR´òÖéò¯ckP Út{*z ÚW•°BFž–cc| P–v•izFž*v c|iRsv]˜|izÝwtuŠ—} R ú °BFžfe—Ž Ú {özvPcL Úvu|´ò Öéò¯ceP Úwe—} ú ú N ú N NJO Q ú R N ú °BF {’Az± s*va˜—: Q N R ú N Q Q __s| {´òÖéò¯ckP Ú z”cLBÃ_D 15 / 55
  • 20. Metropolis­Hastings z¡ê³é¹ß ”cLB± ÚD W•´òÖéò¯e— 1. |æA žE| we— 2. Ž Ú W•kvF žt— 3. ± s ž´òÖêtcr*vc|iRsv]˜| @qe— 4. *va˜kÝ{ tc|@qa˜kÝ{ te— 5. tcr|2~4ž z´òÖêX¤•˜—Šs– 4e Q N ± R ú N ú ú N ú N
  • 22. ± N N ± N
  • 23. . 16 / 55
  • 24. Ž Ú{cL Ú( randn) # p: (unnormalized) probability density function # θ₀: initial state # M: number of samples # ϵ: step size function metropolis(p::Function, θ₀::Vector{Float64}, M::Int, ϵ::Float64) d = length(θ₀) # allocate samples' holder samples = Array(typeof(θ₀), M) # set the current state to the initial state θ = θ₀ for m in 1:M # generate a candidate sample from # the proposal distribution (normal distribution) θ̃ = randn(d) * ϵ + θ if rand() min(1.0, p(θ̃) / p(θ)) # accept the proposal θ = θ̃ end samples[m] = θ print_sample(θ) end samples end metropolis.jl 17 / 55
  • 25. cc 2/Dz/DwözN—cL Ú # mean μ = [0.0, 0.0] # covariance matrix Σ = [1.0 0.8; 0.8 1.0] # precision matrix Λ = inv(Σ) # unnormalized multivariate normal distribution normal = x - exp(-0.5 * ((x - μ)' * Λ * (x - μ))[1]) |–x₀|´òÖêDM|¸ÅÂÖüϵž®cr´òÖéò¯ samples = metropolis(normal, x₀, M, ϵ) 18 / 55
  • 26. HQ ­created with Gadfly.jl -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y Metropolis (ϵ = 1.0) 19 / 55
  • 27. HQ ­created with Gadfly.jl -3 -2 -1 0 1 x Iteration 500 400 300 200 100 1 0.5 0.0 -0.5 -1.0 -1.5 -2.0 y Metropolis (ϵ = 0.1) -3 -2 -1 0 1 2 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y Metropolis (ϵ = 0.5) -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y Metropolis (ϵ = 1.0) -3 -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y Metropolis (ϵ = 2.0) 20 / 55
  • 28. Metropolis­Hastings zþUF 1. @qzÇë–È©Ô 1 ¸ÅÂÖ´£¹ z–s|@qt[ÿzÇë–È©ÔXN— 2. èò¿ß¥¨–® ´òÖêzÊXèò¿ß¥¨–®že— 21 / 55
  • 29. þU1: @qzÇë–È©Ô ± Úz–XK¯cr—z{`[´ól]} 1 1 ¸ÅÂÖ´£¹ R ➠ RY[”]—X|@qXÖX— ¸ÅÂÖ´£¹ Ÿ ➠ @q{WT•˜—X|NŠ–”]vP MCMCW•v—…[¬€v´òÖꞤ—w{¸ÅÂÖ´£¹žRY [ckPX|@qXÖX—k´òÖéò¯zµXu[v—Çë –È©ÔXN—} 1 Õp(´òÖéò¯e—/D)w”orÐèà–¾ z P–X£v –|ۏXÕcP} 22 / 55
  • 30. þU2: èò¿ß¥¨–® Metropolis-HastingsW•¤•˜k´òÖêÊ{|èò¿ß¥¨–®ž crP— ú N Ž ÚXÜe—°BF {|xWz– W•‹r[0 X¤”ck–W•ewûorYrcŠR_tXN— N èò¿ß¥¨–®s{(VVŠWw{or)`ûxDz[$w‡º ck—|cWvP óž…W•…ŠsU—zwWv–`ûxDX«Pwv— 23 / 55
  • 31. Hamiltonian Mote Carlo (HMC) Hamiltonian circuit on a small rhombicosidodecahedron by fdecomite is licensed under CC BY 2.0 24 / 55
  • 32. Hamiltonian Monte Carlo Hamiltonian Monte Carlo](HMC){|ÎÞêÇò¦»(Hamiltonian dynamics)žpwæŽa˜kMCMC]z~tp} ±Ã_Dz¶žqJe— (|Œ0v± Ú{sYvP) ószŠ¨z唞ðor´òÖꞤ— )zMCMCz¡ê³é¹ßt‡¶cr|öz vP P´òÖ êX¤•˜— _z]žPagkNo-U-Turn Sampler (NUTS){StantPR Ø£¹4zkzÖì¯èÞò¯{§wöa˜rP— 25 / 55
  • 33. Boltzmann Ú Y Y 1 Y æA z§Ìê­– t± Ú {Õz”Rw×Ô]• ˜—} ; 1 Y FYQ + Y ; __s| {± ÚzcLBDsN—} _˜žuwžT||± Úz§Ìê­–X4‘sY—} Y + MPH 1 Y + MPH ; 26 / 55
  • 34. ÎÞêÇò¦» S Š¨z唞æT—} žŠ¨z”ŸØ®Çê| žå”£Ø®Çê tckÔzŠ¨z唞E—ÎÞêÇò[ ä: EJ EU ESJ EU ) SJ + ) J ) S 6 __s|ÎÞêÇÊ¡ò {ÜÅò¶âê§Ìê­– t 唧Ìê­– z÷tcraa˜—} , S ) S 6
  • 35. , S 27 / 55
  • 36. ´òÖéò¯„z%J /D ”ŸØ®Çê : ´òÖéò¯ckP±/D 唣خÇê : å”zBˆ0v/D §Ìê­– ÜÅò¶âê§Ìê­– : Boltzmann Úž2w 唧Ìê­– : 2|v唧Ìê­–w ”ŸØ®Çêt唣خÇêz•Ô Ú { ”–’Az”Rw wsY—} S 6 , S Q S ) S 6
  • 37. , S Q S FYQ +) S FYQ +6 FYQ +, S ; ; 28 / 55
  • 38. HMCz*?± Üa˜k°BFwe—*?±{’Az”Rwv—} NJO ú FYQ ) S + ) ú S ú ) ) S + ) ú S ú võ0w{| z–{Ó/vzs ’T«f *va˜— ( ) {flX|²òÓä–¾sD–0wÎÞêÇò[ äž|ŒBcrw[t«f¨1XPfe—kxö0w{@q{ »ìsvP} 29 / 55
  • 39. Leapfrog|ŒB ÎÞêÇò[ ä{w}0ww[z{ÕcPzs|D– žíR} i_s{|Leapfrog|ŒBtPR’AzÒäžpWR} SJ U
  • 40. 1 J U
  • 42. 1 SJ U + 1 6 U J J U
  • 43. 1SJ U
  • 45. 1 + 1 6 U
  • 46. 1 J 30 / 55
  • 47. vhLeapfrog|ŒBvzW Q S ) S •Ô Ú žÓ/we—kw{| z9žÓ/w cv]˜|v•vP cWc|Euler]vus{(h_zuažÏÁcrŽ)9X/Bc rcŠRzs| Q S XÓ/wv•vP Leapfrog|ŒBs{|3pzÒä{i˜j˜¹ (shear mapping)vzs|i˜j˜2JcrŽ9X/BcvP VerticalShear m=1.25 by RobHar - Own work using Inkscape. Licensed under Public domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:VerticalShear_m%3D1.25.svg#mediaviewer/File:VerticalShear_m%3D1.25.svg 31 / 55
  • 48. HMCw”—´òÖéò¯¡ê³é¹ß 1. |æA žE| we— 2. 唣žcL ÚvuW•´òÖéò¯e— 3. W•¸ÅÂÖ´£¹ sLeapfrog|ŒBw”—Òž x –4c| ž¤— 4. ± s*vc|iRsv] ˜|@qe— 5. *va˜kÝ{ tc|@qa˜kÝ{ te— 6. tcr|2~5ž z´òÖêX¤•˜—Šs– 4e N ± N 1 - ú NJO FYQ ) S + ) ú S ú N
  • 50. ± N N ± N
  • 51. . 32 / 55
  • 52. # U : potential energy function # ∇U : gradient of the potential energy function # θ₀ : initial state # M : number of samples # ϵ : step size # L : number of steps function hmc(U::Function, ∇U::Function, θ₀::Vector{Float64}, M::Int, ϵ::Float64, L::Int) d = length(θ₀) # allocate sampels' holder samples = Array(typeof(θ₀), M) # set the current sate to the initail state θ = θ₀ for m in 1:M # sample momentum variable p = randn(d) H = U(θ) + p ⋅ p / 2 θ̃ = θ for l in 1:L p -= ϵ / 2 * ∇U(θ̃) # half step in momentum variable θ̃ += ϵ * p # full step in location variable p -= ϵ / 2 * ∇U(θ̃) # half step in momentum variable again end H̃ = U(θ̃) + p ⋅ p / 2 if randn() min(1.0, exp(H - H̃)) # accept the proposal θ = θ̃ end samples[m] = θ print_sample(θ) end samples end hmc.jl 33 / 55
  • 53. HQ ­created with Gadfly.jl -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y HMC (ϵ = 0.1, L = 10) - 34 / 55
  • 54. HQ ­created with Gadfly.jl -2 -1 0 1 x Iteration 500 400 300 200 100 1 1 0 -1 -2 y HMC (ϵ = 0.01, L = 10) -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y HMC (ϵ = 0.05, L = 10) -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y HMC (ϵ = 0.1, L = 10) -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y HMC (ϵ = 0.5, L = 10) - 35 / 55
  • 55. HQ ­created with Gadfly.jl -0.3 -0.2 -0.1 0.0 0.1 x Iteration 500 400 300 200 100 1 0.1 0.0 -0.1 -0.2 -0.3 y HMC (ϵ = 0.01, L = 1) -1.0 -0.5 0.0 0.5 x Iteration 500 400 300 200 100 1 0.5 0.0 -0.5 -1.0 -1.5 y HMC (ϵ = 0.05, L = 1) -2 -1 0 1 x Iteration 500 400 300 200 100 1 1 0 -1 -2 y HMC (ϵ = 0.1, L = 1) -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y HMC (ϵ = 0.5, L = 1) - 36 / 55
  • 56. HQ ­created with Gadfly.jl -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y HMC (ϵ = 0.01, L = 50) -3 -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y HMC (ϵ = 0.05, L = 50) -4 -2 0 2 4 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y HMC (ϵ = 0.1, L = 50) -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 y HMC (ϵ = 0.5, L = 50) - 37 / 55
  • 57. HMCXwEck_t §Ìê­–z¶áQžžR_ts|Iÿwvok_t: 1 ¸ÅÂÖ´£¹ žP Ÿa[t˜|Leapfrogz ¨1XŸa [v–|@qž[WT•˜— Š¨X - ¸ÅÂÖ×crÍ•Ww¤”e—k|èò¿ß¥¨ –®t‡…r[Šs”]— @qžWTpp¼z”Ÿ”–[Šs”[_tXsY—”Rwv –|¤•˜—´òÖêX”–¬€v´òÖêwßqPk} 38 / 55
  • 58. HMCzÕca HMCzqF{|唞ۏe—2pzÐèà–¾ ¸ÅÂÖ´£¹ ¸ÅÂÖD 1 - z–Xm“Ru P–wa˜rP—tPR_tw•#crP—} Úzæw”orm“Ru P–X/›—k|_˜•z–žuŸ v ÚwŽRŠ[P[”R6e—z{ÓIÿ} 39 / 55
  • 59. 1 - t zÛ^ž«T—tuRv—W 1 ¸ÅÂÖ´£¹ : XŸaeZ— ➠ Š¨XNŠ–”WvP XRYeZ— ➠ leapfrog|ŒBXìeZr@qXÖX— 1 1 1 - žŸa[e—t žRY[cvPtP]vPk|4‘²¸ÇŽW W—} - ¸ÅÂÖD : XŸaeZ— ➠ èò¿ß¥¨–®žcrcŠR XRYeZ— ➠ Š¨XÂY4e (U¾–ò) - - ➠ ß”0wÐèà–¾žÛckP 40 / 55
  • 60. No­U­Turn Sampler (NUTS) No Turning Back by Pak Gwei is licensed under CC BY-NC-SA 2.0 41 / 55
  • 61. No­U­Turn Sampler HMC{¸ÅÂÖ´£¹ 1 t¸ÅÂÖD - z2pzÐèà–¾wÑ÷l okX| No-U-Turn Sampler (NUTS)s{_˜•zÐèà–¾(§w )žRŠP_tۏcr[˜—} zۏ ➠ ´òÖéò¯¼zdual averagingw”–?2B zۏ ➠ ´òÖéò¯¯zŠ¨z}cP唞ccrµŠ— - 1 - ÑÇXsÐèà–¾zÀä–Êò¯e—_tv[?2vHMC´òÖ è–t•d[•õz P´òÖêX¤•˜—”RwvorP—} 42 / 55
  • 62. ±¿seXNUTSz¡ê³é¹ßse (Hoffman Gelman, 2014) 43 / 55
  • 63. NUTSzPF aeXwÀóžÃue—z{rcPzsPFžÃue—t| ´òÖêzP…{|0|vp—sàP[XPP vzs6 - žgf|P…žuŸuŸü|crP[ ü|ceZrå”XU¾–òž¥k•|P…žü|ezžµ— izP…wN—Æ–¾FW•|cP´òÖꞤ— P…W•z´òÖéò¯{|ÍQ–PžVavP”Rwe— ÍQ–P(detailed balance)❏ t{| ÚXÓ/wv—kzP ãL 44 / 55
  • 64. No! U­Turn!! ú P…zàazÔ/B{|¥F W•xWzF ŠszØ®Çêt 唣خÇê Sú zw‡ºe—: ú 5 E ú ú 5Sú + + + E EU ú+ 5 ú+ EU _z–X ’Awvok•|P…XU¾–òžc¥k_twv—} 45 / 55
  • 65. àPzsDwv—[{´òÖê²–Èznuts.jlžˆ¹crAaP} # L: logarithm of the joint density θ # ∇L: gradient of L # θ₀: initial state # M: number of samples # ϵ: step size function nuts(L::Function, ∇L::Function, θ₀::Vector{Float64}, M::Int, ϵ::Float64) d = length(θ₀) samples = Array(typeof(θ₀), M) θ = θ₀ for m in 1:M r₀ = randn(d) u = rand() * exp(L(θ) - r₀ ⋅ r₀ / 2) θ⁻ = θ⁺ = θ r⁻ = r⁺ = r₀ C = Set([(θ, r₀)]) j = 0 s = 1 while s == 1 v = randbool() ? -1 : 1 if v == -1 θ⁻, r⁻, _, _, C′, s′ = build_tree(L, ∇L, θ⁻, r⁻, u, v, j, ϵ) else _, _, θ⁺, r⁺, C′, s′ = build_tree(L, ∇L, θ⁺, r⁺, u, v, j, ϵ) end if s′ == 1 C = C ∪ C′ end s = s′ * ((θ⁺ - θ⁻) ⋅ r⁻ ≥ 0) * ((θ⁺ - θ⁻) ⋅ r⁺ ≥ 0) j += 1 end θ, _ = rand(C) samples[m] = θ print_sample(θ) end samples end nuts.jl 46 / 55
  • 66. HQ ­created with Gadfly.jl -3 -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y NUTS (ϵ = 0.1) 47 / 55
  • 67. HQ ­created with Gadfly.jl -3 -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 4 2 0 -2 -4 y NUTS (ϵ = 0.01) -3 -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y NUTS (ϵ = 0.05) -3 -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y NUTS (ϵ = 0.1) -3 -2 -1 0 1 2 3 x Iteration 500 400 300 200 100 1 3 2 1 0 -1 -2 -3 y NUTS (ϵ = 0.5) 48 / 55
  • 69. JuliasžT—MCMCа–· MCMC.jl - https://github.com/JuliaStats/MCMC.jl ´òÖè–zÆÐ–Ç (12$·!) ȬäàòÇXvP Stan.jl - https://github.com/goedman/Stan.jl StanÏ£òÆ¢ò¯ (via CmdStan) izRmMCMC.jlw–Š˜—o‰P? Mamba.jl - https://github.com/brian-j-smith/Mamba.jl Wv–˜Do‰PJuliakzöJ0vMCMCÔë–ßî–® OözȬäàòÇ 50 / 55
  • 70. Št HMC{Š¨z唞ð…cr´òÖéò¯e—_tw”–|@q žA^•˜— NUTS{HMCzÕcPÐèà–¾Ûž|ß”Bcr[˜— Mamba.jlXJuliazöJ0v´òÖè–z¶ö×W 51 / 55
  • 71. ˆæ Bishop, C. M. (2006). Pattern recognition and machine learning. New York: springer. (pJÙ (2012) ´òÖéò¯] о–òéå tA†»? A, pp.237-273. ½ch) Hoffman, M. D., Gelman, A. (2014). The No-U-Turn Sampler : Adaptively Setting Path Lengths in Hamiltonian Monte Carlo. Journal of Machine Learning Research, 15, 1351–1381. MacKay, D. J. C. (2003). Information Theory, Inference, and Learning Algorithms. Cambridge University Press. Neal, R. M. (2011). MCMC Using Hamiltonian Dynamics. In Handbook of Markov Chain Monte Carlo, pp.113-162. Chapman Hall/CRC. iJ;. (2008). Ýê²Ô×7áòŪêì] ÒÞ„? 52 / 55
  • 72. VŠ] 53 / 55
  • 73. Juliaz¼–¸²–ÈtͲ–Èz£àv·Í function build_tree(L::Function, ∇L::Function, θ::Vector{Float64}, r::Vector{Float64}, u::Float64, v::Int if j == 0 θ′, r′ = leapfrog(∇L, θ, r, v * ϵ) C′ = u ≤ exp(L(θ′) - r′ ⋅ r′ / 2) ? Set([(θ′, r′)]) : Set([]) s′ = int(L(θ′) - r′ ⋅ r′ / 2 log(u) - Δmax) return θ′, r′, θ′, r′, C′, s′ else θ⁻, r⁻, θ⁺, r⁺, C′, s′ = build_tree(L, ∇L, θ, r, u, v, j - 1, ϵ) if v == -1 θ⁻, r⁻, _, _, C″, s″ = build_tree(L, ∇L, θ⁻, r⁻, u, v, j - 1, ϵ) else _, _, θ⁺, r⁺, C″, s″ = build_tree(L, ∇L, θ⁺, r⁺, u, v, j - 1, ϵ) end s′ = s′ * s″ * ((θ⁺ - θ⁻) ⋅ r⁻ ≥ 0) * ((θ⁺ - θ⁻) ⋅ r⁺ ≥ 0) C′ = C′ ∪ C″ return θ⁻, r⁻, θ⁺, r⁺, C′, s′ end end nuts.jl 54 / 55
  • 75. YJ EU QJ EU #J ) ) ) ) #J + QJ YJ QJ YJ 55 / 55