diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 920b1cd208415d2af3deabe80311c5628a87ec66..2f006f23304d95b9cfa8b03a37c4a0f426ba8bd2 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -494,8 +494,12 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation end options_.mh_jscale = Scale; mouvement = max(max(abs(PostVar-OldPostVar))); - disp(['Change in the covariance matrix = ' num2str(mouvement) '.']) - disp(['Mode improvement = ' num2str(abs(OldMode-fval))]) + disp(' ') + disp('========================================================== ') + disp([' Change in the covariance matrix = ' num2str(mouvement) '.']) + disp([' Mode improvement = ' num2str(abs(OldMode-fval))]) + disp([' New value of jscale = ' num2str(Scale)]) + disp('========================================================== ') OldMode = fval; else OldPostVar = PostVar; diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 611e01f8d34ed84ea2abdcca50322cf87052679f..21facd4569c632578bd8570379f337ca80e6c421 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -30,6 +30,8 @@ function global_initialization() global oo_ M_ options_ +options_.console_mode = 0; + options_.terminal_condition = 0; options_.rplottype = 0; options_.smpl = 0; diff --git a/matlab/gmhmaxlik.m b/matlab/gmhmaxlik.m index 230284324aa2c7f842fc7b91e1f9e2bf89e02ba6..65cbe852096e260dcf4a2e93261ae9fb5f1106c6 100644 --- a/matlab/gmhmaxlik.m +++ b/matlab/gmhmaxlik.m @@ -90,8 +90,13 @@ CovJump = VarCov; ModePar = xparam1; %% [1] I tune the scale parameter. -hh = waitbar(0,'Tuning of the scale parameter...'); -set(hh,'Name','Tuning of the scale parameter.') +if exist('OCTAVE_VERSION') || options_.console_mode + diary off; + disp(' '); +else + hh = waitbar(0,'Tuning of the scale parameter...'); + set(hh,'Name','Tuning of the scale parameter.') +end j = 1; jj = 1; isux = 0; jsux = 0; test = 0; ix2 = ModePar;% initial condition! @@ -121,7 +126,17 @@ while j<=MaxNumberOfTuningSimulations jsux = jsux + 1; end% ... otherwise I don't move. prtfrc = j/MaxNumberOfTuningSimulations; - waitbar(prtfrc,hh,sprintf('Acceptation rates: %f [%f]',isux/j,jsux/jj)); + if exist('OCTAVE_VERSION') || options_.console_mode + if mod(j, 10)==0 + if exist('OCTAVE_VERSION') + printf('Tuning of the scale parameter (%f%% done):: Acceptance rates: %f [%f]\r',prtfrc*100,isux/j,jsux/jj); + else + fprintf(' Tuning of the scale parameter (%f \b%% done):: Acceptance rates: %f [%f]\r',prtfrc*100,isux/j,jsux/jj); + end + end + else + waitbar(prtfrc,hh,sprintf('Acceptance rates: %f [%f]',isux/j,jsux/jj)); + end if j/500 == round(j/500) test1 = jsux/jj; cfactor = test1/AcceptanceTarget; @@ -141,11 +156,18 @@ while j<=MaxNumberOfTuningSimulations j = j+1; jj = jj + 1; end -close(hh); -iScale +if exist('OCTAVE_VERSION') || options_.console_mode + diary on; +else + close(hh); +end %% [2] One block metropolis, I update the covariance matrix of the jumping distribution -hh = waitbar(0,'Metropolis-Hastings...'); -set(hh,'Name','Looking for the posterior covariance...') +if exist('OCTAVE_VERSION') || options_.console_mode + diary off; +else + hh = waitbar(0,'Metropolis-Hastings...'); + set(hh,'Name','Estimation of the posterior covariance...') +end j = 1; isux = 0; ilogpo2 = - feval(ObjFun,ix2,varargin{:}); @@ -168,7 +190,17 @@ while j<= NumberOfIterations jsux = jsux + 1; end% ... otherwise I don't move. prtfrc = j/NumberOfIterations; - waitbar(prtfrc,hh,sprintf('%f done, acceptation rate %f',prtfrc,isux/j)); + if exist('OCTAVE_VERSION') || options_.console_mode + if mod(j, 10)==0 + if exist('OCTAVE_VERSION') + printf('Estimation of the posterior covariance (%f%% done):: Acceptance rates: %f\r',prtfrc,isux/j); + else + fprintf(' Estimation of the posterior covariance (%f \b%% done):: Acceptance rates: %f \r',prtfrc*100,isux/j); + end + end + else + waitbar(prtfrc,hh,sprintf('Acceptance rate: %f',isux/j)); + end % I update the covariance matrix and the mean: oldMeanPar = MeanPar; MeanPar = oldMeanPar + (1/j)*(ix2-oldMeanPar); @@ -176,15 +208,23 @@ while j<= NumberOfIterations (1/j)*(ix2*ix2' - CovJump - oldMeanPar*oldMeanPar'); j = j+1; end -close(hh); +if exist('OCTAVE_VERSION') || options_.console_mode + diary on; +else + close(hh); +end PostVar = CovJump; PostMean = MeanPar; %% [3 & 4] I tune the scale parameter (with the new covariance matrix) if %% this is the last call to the routine, and I climb the hill (without %% updating the covariance matrix)... if strcmpi(info,'LastCall') - hh = waitbar(0,'Tuning of the scale parameter...'); - set(hh,'Name','Tuning of the scale parameter.') + if exist('OCTAVE_VERSION') || options_.console_mode + diary off; + else + hh = waitbar(0,'Tuning of the scale parameter...'); + set(hh,'Name','Tuning of the scale parameter.') + end j = 1; jj = 1; isux = 0; jsux = 0; test = 0; @@ -209,7 +249,17 @@ if strcmpi(info,'LastCall') jsux = jsux + 1; end% ... otherwise I don't move. prtfrc = j/MaxNumberOfTuningSimulations; - waitbar(prtfrc,hh,sprintf('Acceptation rates: %f [%f]',isux/j,jsux/jj)); + if exist('OCTAVE_VERSION') || options_.console_mode + if mod(j, 10)==0 + if exist('OCTAVE_VERSION') + printf('Tuning of the scale parameter (%f%% done):: Acceptance rates: %f [%f]\r',prtfrc*100,isux/j,jsux/jj); + else + fprintf(' Tuning of the scale parameter (%f \b%% done):: Acceptance rates: %f [%f] \r',prtfrc*100,isux/j,jsux/jj); + end + end + else + waitbar(prtfrc,hh,sprintf('Acceptance rates: %f [%f]',isux/j,jsux/jj)); + end if j/1000 == round(j/1000) test1 = jsux/jj; cfactor = test1/AcceptanceTarget; @@ -225,16 +275,23 @@ if strcmpi(info,'LastCall') j = j+1; jj = jj + 1; end - close(hh); + if exist('OCTAVE_VERSION') || options_.console_mode + diary on; + else + close(hh); + end Scale = iScale; - iScale %% %% Now I climb the hill %% climb = 1; if climb - hh = waitbar(0,' '); - set(hh,'Name','Now I am climbing the hill...') + if exist('OCTAVE_VERSION') || options_.console_mode + diary off; + else + hh = waitbar(0,' '); + set(hh,'Name','Now I am climbing the hill...') + end j = 1; jj = 1; jsux = 0; test = 0; @@ -251,7 +308,17 @@ if strcmpi(info,'LastCall') jsux = jsux + 1; end% otherwise I don't move... prtfrc = j/MaxNumberOfClimbingSimulations; - waitbar(prtfrc,hh,sprintf('%f Jumps / MaxStepSize %f',jsux,sqrt(max(diag(iScale*CovJump))))); + if exist('OCTAVE_VERSION') || options_.console_mode + if mod(j, 10)==0 + if exist('OCTAVE_VERSION') + printf('Now I am climbing the hill (%f%% done):: %f Jumps / MaxStepSize %f\r',prtfrc*100,jsux,sqrt(max(diag(iScale*CovJump)))); + else + fprintf(' Now I am climbing the hill (%f \b%% done):: %f Jumps / MaxStepSize %f \r',prtfrc*100,jsux,sqrt(max(diag(iScale*CovJump)))); + end + end + else + waitbar(prtfrc,hh,sprintf('%f Jumps / MaxStepSize %f',jsux,sqrt(max(diag(iScale*CovJump))))); + end if j/200 == round(j/200) if jsux<=1 test = test+1; @@ -271,7 +338,11 @@ if strcmpi(info,'LastCall') j = j+1; jj = jj + 1; end - close(hh); + if exist('OCTAVE_VERSION') || options_.console_mode + diary on; + else + close(hh); + end end%climb else Scale = iScale; diff --git a/matlab/independent_metropolis_hastings_core.m b/matlab/independent_metropolis_hastings_core.m index ca7cbad5e8094de68d100bac3f6a9743959e221a..a5bcdda45ef6fd7f7850efba21e4f0e5bd860d00 100644 --- a/matlab/independent_metropolis_hastings_core.m +++ b/matlab/independent_metropolis_hastings_core.m @@ -59,8 +59,9 @@ for b = fblck:nblck, x2 = zeros(InitSizeArray(b),npar); logpo2 = zeros(InitSizeArray(b),1); end - if exist('OCTAVE_VERSION') - diary off; + if exist('OCTAVE_VERSION') || options_.console_mode + diary off + disp(' ') elseif whoiam % keyboard; waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']; @@ -106,9 +107,13 @@ for b = fblck:nblck, logpo2(irun) = ilogpo2(b); end prtfrc = j/nruns(b); - if exist('OCTAVE_VERSION') - if mod(j, 10) == 0, - printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + if exist('OCTAVE_VERSION') || options_.console_mode + if mod(j, 10) == 0 + if exist('OCTAVE_VERSION') + printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + else + fprintf(' MH: Computing Metropolis-Hastings (chain %d/%d): %3.f \b%% done, acception rate: %3.f \b%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + end end if mod(j,50)==0 & whoiam, % keyboard; @@ -169,9 +174,9 @@ for b = fblck:nblck, irun = irun + 1; end% End of the simulations for one mh-block. record.AcceptationRates(b) = isux/j; - if exist('OCTAVE_VERSION') + if exist('OCTAVE_VERSION') || options_.console_mode printf('\n'); - diary on; + diary on elseif ~whoiam close(hh); end diff --git a/matlab/random_walk_metropolis_hastings_core.m b/matlab/random_walk_metropolis_hastings_core.m index c35a07c9e4747d608db635747d148bc75ca1d0a3..128a7f99c980896c0304677b6d1c1d1534fd4f24 100644 --- a/matlab/random_walk_metropolis_hastings_core.m +++ b/matlab/random_walk_metropolis_hastings_core.m @@ -58,8 +58,9 @@ for b = fblck:nblck, x2 = zeros(InitSizeArray(b),npar); logpo2 = zeros(InitSizeArray(b),1); end - if exist('OCTAVE_VERSION') - diary off; + if exist('OCTAVE_VERSION') || options_.console_mode + diary off + disp(' ') elseif whoiam % keyboard; waitbarString = ['Please wait... Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']; @@ -102,11 +103,15 @@ for b = fblck:nblck, logpo2(irun) = ilogpo2(b); end prtfrc = j/nruns(b); - if exist('OCTAVE_VERSION') - if mod(j, 10) == 0, - printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + if exist('OCTAVE_VERSION') || options_.console_mode + if mod(j, 10) == 0 + if exist('OCTAVE_VERSION') + printf('MH: Computing Metropolis-Hastings (chain %d/%d): %3.f%% done, acception rate: %3.f%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + else + fprintf(' MH: Computing Metropolis-Hastings (chain %d/%d): %3.f \b%% done, acceptance rate: %3.f \b%%\r', b, nblck, 100 * prtfrc, 100 * isux / j); + end end - if mod(j,50)==0 & whoiam, + if mod(j,50)==0 & whoiam % keyboard; waitbarString = [ '(' int2str(b) '/' int2str(options_.mh_nblck) '), ' sprintf('accept. %3.f%%%%', 100 * isux/j)]; fMessageStatus(prtfrc,whoiam,waitbarString, '', options_.parallel(ThisMatlab), MasterName, DyMo) @@ -165,7 +170,7 @@ for b = fblck:nblck, irun = irun + 1; end% End of the simulations for one mh-block. record.AcceptationRates(b) = isux/j; - if exist('OCTAVE_VERSION') + if exist('OCTAVE_VERSION') || options_.console_mode printf('\n'); diary on; elseif ~whoiam @@ -180,6 +185,4 @@ end% End of the loop over the mh-blocks. myoutput.record = record; myoutput.irun = irun; myoutput.NewFile = NewFile; -myoutput.OutputFileName = OutputFileName; - - +myoutput.OutputFileName = OutputFileName; \ No newline at end of file