-
-
Save astronasutarou/7272147 to your computer and use it in GitHub Desktop.
Metropolis–Hastings algorithm で乱数生成するためのスクリプト
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
function x1 = mh(x0,func,xgen) | |
## input: | |
## x0 - input distribution | |
## func - target distribution function | |
## xgen - random generator for next step | |
## output: | |
## x1 - resultant distribution | |
xp = xgen(x0); | |
y0 = func(x0); y1 = func(xp); | |
a = y1./(y0+(y0==0)) + (y0==0); | |
b = rand(size(y0)); | |
x1 = x0; x1(a>b) = xp(a>b); | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment