2006-05-04 10:52:43 +02:00
|
|
|
function [xparams, logpost]=metropolis_draw(init)
|
2008-01-28 16:52:37 +01:00
|
|
|
|
|
|
|
% function [xparams, logpost]=metropolis_draw(init)
|
|
|
|
% Builds draws from metropolis
|
|
|
|
%
|
|
|
|
% INPUTS:
|
|
|
|
% init: scalar equal to 1 (first call) or 0
|
|
|
|
%
|
|
|
|
% OUTPUTS:
|
|
|
|
% xparams: vector of estimated parameters
|
|
|
|
% logpost: log of posterior density
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% part of DYNARE, copyright Dynare Team (2003-2007)
|
|
|
|
% Gnu Public License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-10 14:04:50 +01:00
|
|
|
global options_ estim_params_ M_
|
|
|
|
persistent mh_nblck NumberOfDraws fname FirstLine FirstMhFile MAX_nruns
|
2006-03-05 22:01:27 +01:00
|
|
|
|
|
|
|
if init
|
|
|
|
nvx = estim_params_.nvx;
|
|
|
|
nvn = estim_params_.nvn;
|
|
|
|
ncx = estim_params_.ncx;
|
|
|
|
ncn = estim_params_.ncn;
|
|
|
|
np = estim_params_.np ;
|
|
|
|
npar = nvx+nvn+ncx+ncn+np;
|
2006-03-17 12:20:25 +01:00
|
|
|
MhDirectoryName = CheckPath('metropolis');
|
|
|
|
fname = [ MhDirectoryName '/' M_.fname];
|
2006-03-08 18:27:09 +01:00
|
|
|
load([ fname '_mh_history']);
|
2006-03-05 22:01:27 +01:00
|
|
|
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
|
|
|
FirstLine = record.KeepedDraws.FirstLine;
|
2006-03-10 14:04:50 +01:00
|
|
|
TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
|
|
|
|
LastMhFile = TotalNumberOfMhFiles;
|
2006-03-05 22:01:27 +01:00
|
|
|
TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
|
2006-03-10 14:04:50 +01:00
|
|
|
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
|
2006-03-05 22:01:27 +01:00
|
|
|
MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
|
2006-03-10 14:04:50 +01:00
|
|
|
mh_nblck = options_.mh_nblck;
|
2006-03-05 22:01:27 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
ChainNumber = ceil(rand*mh_nblck);
|
|
|
|
DrawNumber = ceil(rand*NumberOfDraws);
|
|
|
|
|
|
|
|
if DrawNumber <= MAX_nruns-FirstLine+1
|
|
|
|
MhFilNumber = FirstMhFile;
|
|
|
|
MhLine = FirstLine+DrawNumber-1;
|
|
|
|
else
|
|
|
|
DrawNumber = DrawNumber-(MAX_nruns-FirstLine+1);
|
|
|
|
MhFilNumber = FirstMhFile+ceil(DrawNumber/MAX_nruns);
|
|
|
|
MhLine = DrawNumber-(MhFilNumber-FirstMhFile-1)*MAX_nruns;
|
|
|
|
end
|
|
|
|
|
2006-05-04 10:52:43 +02:00
|
|
|
load( [ fname '_mh' int2str(MhFilNumber) '_blck' int2str(ChainNumber) '.mat' ],'x2','logpo2');
|
|
|
|
xparams = x2(MhLine,:);
|
|
|
|
logpost= logpo2(MhLine);
|