0001 function [xparams, logpost]=metropolis_draw(init)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 global options_ estim_params_ M_
0033 persistent mh_nblck NumberOfDraws fname FirstLine FirstMhFile MAX_nruns
0034
0035 if init
0036 nvx = estim_params_.nvx;
0037 nvn = estim_params_.nvn;
0038 ncx = estim_params_.ncx;
0039 ncn = estim_params_.ncn;
0040 np = estim_params_.np ;
0041 npar = nvx+nvn+ncx+ncn+np;
0042 MhDirectoryName = CheckPath('metropolis',M_.dname);
0043 fname = [ MhDirectoryName '/' M_.fname];
0044 load([ fname '_mh_history']);
0045 FirstMhFile = record.KeepedDraws.FirstMhFile;
0046 FirstLine = record.KeepedDraws.FirstLine;
0047 TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
0048 LastMhFile = TotalNumberOfMhFiles;
0049 TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
0050 NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
0051 MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
0052 mh_nblck = options_.mh_nblck;
0053 return
0054 end
0055
0056 ChainNumber = ceil(rand*mh_nblck);
0057 DrawNumber = ceil(rand*NumberOfDraws);
0058
0059 if DrawNumber <= MAX_nruns-FirstLine+1
0060 MhFilNumber = FirstMhFile;
0061 MhLine = FirstLine+DrawNumber-1;
0062 else
0063 DrawNumber = DrawNumber-(MAX_nruns-FirstLine+1);
0064 MhFilNumber = FirstMhFile+ceil(DrawNumber/MAX_nruns);
0065 MhLine = DrawNumber-(MhFilNumber-FirstMhFile-1)*MAX_nruns;
0066 end
0067
0068 load( [ fname '_mh' int2str(MhFilNumber) '_blck' int2str(ChainNumber) '.mat' ],'x2','logpo2');
0069 xparams = x2(MhLine,:);
0070 logpost= logpo2(MhLine);