在上篇博客中 MATLAB 抽取随机数 MCMC原理中已经介绍了在Metropolis和Metropolis-Hastings算法中选择proposal分布的三种建议,本文基于实践再给出一种选取proposal分布的一种建议。原理是抽取的样本相关系数大的话,有效样本的个数是减少的,因此近似的效果会变差。因此,我们在选取proposal分布时,也应注意抽样的相关性,选取相关性小的proposal。下面是一个具体的例子:
clc;clear;
standerror=1;
Nsamples=10000; %抽取的样本个数
pdf=@(x) normpdf(x,1,0.3) % target distribution
% Generate random samples using Random Walk
proppdf=@(x,y) normpdf(x);%proppdf defines the proposal distribution density;
proprnd=@(x)(randn(size(x))*standerror+x);%+0.00001 proprnd defines the random number generator for the proposal distribution
[smpl,a]=mhsampl