📄 metrop.m
字号:
% METROP - perform a Metropolis-Hastings step% Copyright (c) 1998, Harvard University. Full copyright in the file Copyright%% [KEEPV, ACCEPT] = METROP(LOGQ,NV,OV)%% LOGQ = log (unnormalized) density ratio%% If targ(x) is the target density (may be unnormalized)% and gen(x) is the generating density (may be unnormalized),% % then LOGQ = log( targ(NV) gen(OV|NV) / targ(OV) gen(NV|OV) ) %% NV = new sample value% OV = old sample value%% KEEPV = value of NV or OV that is kept% ACCEPT = 1 if NV was kept, 0 if OV was kept%% See also: BETALPR, GAMLPR, INVWISHLPR, MVNORMLPRfunction [ keepv, accept ] = metrop ( logq, newval, oldval, acc, ix ) ;accept = acc ;if (logq>0), keepv = newval ; accept(ix) = 1 ;elseif (unifrnd(0,1) <= exp(logq)), keepv = newval ; accept(ix) = 1 ;else keepv = oldval ; accept(ix) = 0 ;end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -