From 4b9b90f1bbb75dc2483738a00cce64827b1e1d72 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 20 Dec 2011 16:49:03 +0100 Subject: [PATCH 1/2] Replace waitbar by dyn_waitbar. --- matlab/gmhmaxlik.m | 107 +++++++++------------------------------- matlab/gsa/mc_moments.m | 6 +-- matlab/gsa/speed.m | 6 +-- 3 files changed, 28 insertions(+), 91 deletions(-) diff --git a/matlab/gmhmaxlik.m b/matlab/gmhmaxlik.m index 3537f0106..b1a741147 100644 --- a/matlab/gmhmaxlik.m +++ b/matlab/gmhmaxlik.m @@ -90,13 +90,8 @@ CovJump = VarCov; ModePar = xparam1; %% [1] I tune 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 +hh = dyn_waitbar(0,'Tuning of the scale parameter...'); +set(hh,'Name','Tuning of the scale parameter.'); j = 1; jj = 1; isux = 0; jsux = 0; test = 0; ix2 = ModePar;% initial condition! @@ -126,16 +121,8 @@ while j<=MaxNumberOfTuningSimulations jsux = jsux + 1; end% ... otherwise I don't move. prtfrc = j/MaxNumberOfTuningSimulations; - 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)); + if mod(j, 10)==0 + dyn_waitbar(prtfrc,hh,sprintf('Acceptance rates: %f [%f]',isux/j,jsux/jj)); end if j/500 == round(j/500) test1 = jsux/jj; @@ -156,18 +143,11 @@ while j<=MaxNumberOfTuningSimulations j = j+1; jj = jj + 1; end -if exist('OCTAVE_VERSION') || options_.console_mode - diary on; -else - close(hh); -end + +dyn_waitbar_close(hh); %% [2] One block metropolis, I update the covariance matrix of the jumping distribution -if exist('OCTAVE_VERSION') || options_.console_mode - diary off; -else - hh = waitbar(0,'Metropolis-Hastings...'); - set(hh,'Name','Estimation of the posterior covariance...') -end +hh = dyn_waitbar(0,'Metropolis-Hastings...'); +set(hh,'Name','Estimation of the posterior covariance...'), j = 1; isux = 0; ilogpo2 = - feval(ObjFun,ix2,varargin{:}); @@ -190,16 +170,8 @@ while j<= NumberOfIterations jsux = jsux + 1; end% ... otherwise I don't move. prtfrc = j/NumberOfIterations; - 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)); + if mod(j, 10)==0 + dyn_waitbar(prtfrc,hh,sprintf('Acceptance rate: %f',isux/j)); end % I update the covariance matrix and the mean: oldMeanPar = MeanPar; @@ -208,23 +180,15 @@ while j<= NumberOfIterations (1/j)*(ix2*ix2' - CovJump - oldMeanPar*oldMeanPar'); j = j+1; end -if exist('OCTAVE_VERSION') || options_.console_mode - diary on; -else - close(hh); -end +dyn_waitbar_close(hh); 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') - 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 + hh = dyn_waitbar(0,'Tuning of the scale parameter...'); + set(hh,'Name','Tuning of the scale parameter.'), j = 1; jj = 1; isux = 0; jsux = 0; test = 0; @@ -249,16 +213,8 @@ if strcmpi(info,'LastCall') jsux = jsux + 1; end% ... otherwise I don't move. prtfrc = j/MaxNumberOfTuningSimulations; - 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)); + if mod(j, 10)==0 + dyn_waitbar(prtfrc,hh,sprintf('Acceptance rates: %f [%f]',isux/j,jsux/jj)); end if j/1000 == round(j/1000) test1 = jsux/jj; @@ -275,23 +231,16 @@ if strcmpi(info,'LastCall') j = j+1; jj = jj + 1; end - if exist('OCTAVE_VERSION') || options_.console_mode - diary on; - else - close(hh); - end + dyn_waitbar_close(hh); Scale = iScale; %% %% Now I climb the hill %% climb = 1; if climb - if exist('OCTAVE_VERSION') || options_.console_mode - diary off; - else - hh = waitbar(0,' '); - set(hh,'Name','Now I am climbing the hill...') - end + hh = dyn_waitbar(0,' '); + set(hh,'Name','Now I am climbing the hill...'), + disp('Now I am climbing the hill...'), j = 1; jj = 1; jsux = 0; test = 0; @@ -308,16 +257,8 @@ if strcmpi(info,'LastCall') jsux = jsux + 1; end% otherwise I don't move... prtfrc = j/MaxNumberOfClimbingSimulations; - 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))))); + if mod(j, 10)==0 + dyn_waitbar(prtfrc,hh,sprintf('%f Jumps / MaxStepSize %f',jsux,sqrt(max(diag(iScale*CovJump))))); end if j/200 == round(j/200) if jsux<=1 @@ -338,11 +279,7 @@ if strcmpi(info,'LastCall') j = j+1; jj = jj + 1; end - if exist('OCTAVE_VERSION') || options_.console_mode - diary on; - else - close(hh); - end + dyn_waitbar_close(hh); end%climb else Scale = iScale; diff --git a/matlab/gsa/mc_moments.m b/matlab/gsa/mc_moments.m index 187cca812..b5f0ab412 100644 --- a/matlab/gsa/mc_moments.m +++ b/matlab/gsa/mc_moments.m @@ -3,7 +3,7 @@ global options_ M_ [nr1, nc1, nsam] = size(mm); disp('Computing theoretical moments ...') - h = waitbar(0,'Theoretical moments ...'); + h = dyn_waitbar(0,'Theoretical moments ...'); for j=1:nsam, dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j); @@ -18,8 +18,8 @@ global options_ M_ dum=[dum, autocorr{i}]; end ac(:,:,j)=dum; - waitbar(j/nsam,h) + dyn_waitbar(j/nsam,h) end - close(h) + dyn_waitbar_close(h) disp(' ') disp('... done !') diff --git a/matlab/gsa/speed.m b/matlab/gsa/speed.m index bba35d35f..791d05220 100644 --- a/matlab/gsa/speed.m +++ b/matlab/gsa/speed.m @@ -25,7 +25,7 @@ nrun=size(B,3); iff=zeros(nvar,nshock,nrun); tadj=iff; disp('Computing speed of adjustement ...') -h = waitbar(0,'Speed of adjustement...'); +h = dyn_waitbar(0,'Speed of adjustement...'); for i=1:nrun, irf=zeros(nvar,nshock); @@ -45,8 +45,8 @@ for i=1:nrun, tt=(irf>0.5).*t; tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i); end - waitbar(i/nrun,h) + dyn_waitbar(i/nrun,h) end disp(' ') disp('.. done !') -close(h) +dyn_waitbar_close(h) From 5ec78139c0fcc0791d8ac7f65a43f8246b979765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 20 Dec 2011 12:24:47 +0100 Subject: [PATCH 2/2] Added variable for the expected term. Changed calibration. --- tests/ep/rbc.mod | 14 +++++++++----- tests/ep/rbc_steadystate.m | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/ep/rbc.mod b/tests/ep/rbc.mod index 6340a131a..2494ecf97 100644 --- a/tests/ep/rbc.mod +++ b/tests/ep/rbc.mod @@ -1,4 +1,4 @@ -var Capital, Output, Labour, Consumption, Efficiency, efficiency; +var Capital, Output, Labour, Consumption, Efficiency, efficiency, ExpectedTerm; varexo EfficiencyInnovation; @@ -11,9 +11,9 @@ parameters beta, theta, tau, alpha, psi, delta, rho, effstar, sigma2; beta = 0.990; theta = 0.357; -tau = 2.000; +tau = 30.000; alpha = 0.450; -psi = -0.500; +psi = -5.000; delta = 0.020; rho = 0.950; effstar = 1.000; @@ -39,7 +39,10 @@ model(block,bytecode); ((1-theta)/theta)*(Consumption/(1-Labour)) - (1-alpha)*(Output/Labour)^(1-psi); // Eq. n°6: - (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - beta*((((Consumption(1)^theta)*((1-Labour(1))^(1-theta)))^(1-tau))/Consumption(1))*(alpha*((Output(1)/Capital)^(1-psi))+1-delta); + (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - ExpectedTerm(1); + + // Eq. n°7: + ExpectedTerm = beta*((((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption)*(alpha*((Output/Capital(-1))^(1-psi))+1-delta); end; @@ -50,6 +53,7 @@ end; steady; options_.ep.verbosity = 0; -options_.console_mode = 1; +options_.ep.stochastic = 0; +options_.console_mode = 0; ts = extended_path([],1000); \ No newline at end of file diff --git a/tests/ep/rbc_steadystate.m b/tests/ep/rbc_steadystate.m index 9692aef39..74af861d7 100644 --- a/tests/ep/rbc_steadystate.m +++ b/tests/ep/rbc_steadystate.m @@ -43,4 +43,6 @@ ys(4)=SteadyStateConsumption; ys(1)=SteadyStateCapital; ys(3)=SteadyStateLabour; ys(5)=M_.params(8); -ys(6)=0; \ No newline at end of file +ys(6)=0; +ys(7)=M_.params(1)*((((SteadyStateConsumption^M_.params(2))*((1-SteadyStateLabour)^(1-M_.params(2))))^(1-M_.params(3)))/SteadyStateConsumption)* ... + (M_.params(4)*((SteadyStateOutput/SteadyStateCapital)^(1-M_.params(5)))+1-M_.params(6)); \ No newline at end of file