Home > . > metropolis_draw.m

metropolis_draw

PURPOSE ^

SYNOPSIS ^

function [xparams, logpost]=metropolis_draw(init)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [xparams, logpost]=metropolis_draw(init)
0002   global options_ estim_params_ M_
0003   persistent mh_nblck NumberOfDraws fname FirstLine FirstMhFile MAX_nruns
0004   
0005   if init
0006     nvx  = estim_params_.nvx;
0007     nvn  = estim_params_.nvn;
0008     ncx  = estim_params_.ncx;
0009     ncn  = estim_params_.ncn;
0010     np   = estim_params_.np ;
0011     npar = nvx+nvn+ncx+ncn+np;
0012     MhDirectoryName = CheckPath('metropolis');
0013     fname = [ MhDirectoryName '/' M_.fname];
0014     load([ fname '_mh_history']);
0015     FirstMhFile = record.KeepedDraws.FirstMhFile;
0016     FirstLine = record.KeepedDraws.FirstLine; 
0017     TotalNumberOfMhFiles = sum(record.MhDraws(:,2)); 
0018     LastMhFile = TotalNumberOfMhFiles; 
0019     TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
0020     NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
0021     MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
0022     mh_nblck = options_.mh_nblck;
0023     return
0024   end
0025   
0026   ChainNumber = ceil(rand*mh_nblck);
0027   DrawNumber  = ceil(rand*NumberOfDraws);
0028 
0029   if DrawNumber <= MAX_nruns-FirstLine+1
0030     MhFilNumber = FirstMhFile;
0031     MhLine = FirstLine+DrawNumber-1;
0032   else
0033     DrawNumber  = DrawNumber-(MAX_nruns-FirstLine+1);
0034     MhFilNumber = FirstMhFile+ceil(DrawNumber/MAX_nruns); 
0035     MhLine = DrawNumber-(MhFilNumber-FirstMhFile-1)*MAX_nruns;
0036   end
0037 
0038   load( [ fname '_mh' int2str(MhFilNumber) '_blck' int2str(ChainNumber) '.mat' ],'x2','logpo2');
0039   xparams = x2(MhLine,:);
0040   logpost= logpo2(MhLine);

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003