-
-
Save k1m190r/36481a394ab94b69f027f9005f3b1b59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mcmc←{ | |
⍝ dist mcmc proposals | |
⍝ dist - PMF/PDF function (monadic) | |
⍝ proposals - random proposals for dist() | |
proposals←⍵ | |
N←⊃⍴⍵ ⍝ number of proposals | |
dist←⍺⍺ ⍝ pmf/pdf function | |
coins←?N⍴0 ⍝ random coin tosses | |
⍝ accepted states initialized to first proposal | |
states←N⍴⊃proposals | |
Ni←N-1 ⍝ number of iters | |
⍝ iterate Ni times starting from 2 | |
_←({i←⍵ | |
curr←states[i-1] | |
move←proposals[i] | |
p_curr←dist curr | |
p_move←dist move | |
accept←1+coins[i]≤1⌊p_move÷p_curr | |
⍝ accept 1=False, 2=True | |
states[i]←(curr move)[accept] | |
i+1 | |
}⍣Ni)2 | |
states | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment