0001 function CutSample(M_, options_, estim_params_)
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
0033
0034 npar = estim_params_.np+estim_params_.nvn+estim_params_.ncx+estim_params_.ncn+estim_params_.nvx;
0035
0036 DirectoryName = CheckPath('metropolis',M_.dname);
0037 file = dir([ DirectoryName ,filesep, M_.fname '_mh_history.mat']);
0038 files = dir([ DirectoryName ,filesep, M_.fname '_mh*.mat' ]);
0039 if ~length(files)
0040 disp('MH:: FAILURE! there is no MH file to load here!')
0041 return
0042 end
0043 if ~length(file)
0044 disp('MH:: FAILURE! there is no MH-history file!')
0045 return
0046 else
0047 load([ DirectoryName '/' M_.fname '_mh_history.mat'])
0048 end
0049 TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
0050 TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
0051 MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
0052 FirstDraw = max(1,floor(options_.mh_drop*TotalNumberOfMhDraws));
0053 FirstMhFile = ceil(FirstDraw/MAX_nruns);
0054 FirstLine = FirstDraw-(FirstMhFile-1)*MAX_nruns;
0055 record.KeepedDraws.FirstMhFile = FirstMhFile;
0056 record.KeepedDraws.FirstLine = FirstLine;
0057 if (TotalNumberOfMhFiles-1)-(FirstMhFile+1)+1 > 0
0058 record.KeepedDraws.Distribution = [ MAX_nruns-FirstLine+1 ; ...
0059 ones((TotalNumberOfMhFiles-1)-(FirstMhFile+1)+1,1)*MAX_nruns ; ...
0060 record.MhDraws(end,3) ];
0061 elseif TotalNumberOfMhFiles == 1
0062 record.KeepedDraws.Distribution = [];
0063 elseif TotalNumberOfMhFiles == 2 && FirstMhFile > 1
0064 record.KeepedDraws.Distribution = [MAX_nruns-FirstLine+1 ; record.MhDraws(end,3)];
0065 end
0066 save([DirectoryName '/' M_.fname '_mh_history.mat'],'record');
0067 fprintf('MH: Total number of Mh draws: %d.\n',TotalNumberOfMhDraws);
0068 fprintf('MH: Total number of generated Mh files: %d.\n',TotalNumberOfMhFiles);
0069 fprintf('MH: I''ll use mh-files %d to %d.\n',FirstMhFile,TotalNumberOfMhFiles);
0070 fprintf('MH: In mh-file number %d i''ll start at line %d.\n',FirstMhFile,FirstLine);
0071 fprintf('MH: Finally I keep %d draws.\n',TotalNumberOfMhDraws-FirstDraw);
0072 disp(' ');