Commit e81f9d48 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Improved display of mode_compute=6 optimization algorithm. Fixed bugs. Changed the options.

parent 37440611
......@@ -273,15 +273,15 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
end
OldPostVar = CovJump;
Scale = options_.mh_jscale;
for i=1:options_.Opt6Iter
for i=1:options_.gmhmaxlik.iterations
if i == 1
if options_.Opt6Iter > 1
if options_.gmhmaxlik.iterations>1
flag = '';
else
flag = 'LastCall';
end
[xparam1,PostVar,Scale,PostMean] = ...
gmhmaxlik(objective_function,xparam1,[lb ub],options_.Opt6Numb,Scale,flag,MeanPar,CovJump,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
gmhmaxlik(objective_function,xparam1,[lb ub],options_.gmhmaxlik,Scale,flag,MeanPar,CovJump,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
fval = feval(objective_function,xparam1,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
options_.mh_jscale = Scale;
mouvement = max(max(abs(PostVar-OldPostVar)));
......@@ -294,20 +294,24 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
OldMode = fval;
else
OldPostVar = PostVar;
if i<options_.Opt6Iter
if i<options_.gmhmaxlik.iterations
flag = '';
else
flag = 'LastCall';
end
[xparam1,PostVar,Scale,PostMean] = ...
gmhmaxlik(objective_function,xparam1,[lb ub],...
options_.Opt6Numb,Scale,flag,PostMean,PostVar,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
options_.gmhmaxlik,Scale,flag,PostMean,PostVar,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
fval = feval(objective_function,xparam1,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
options_.mh_jscale = Scale;
mouvement = max(max(abs(PostVar-OldPostVar)));
fval = dsge_likelihood(xparam1,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
disp(['Change in the covariance matrix = ' num2str(mouvement) '.'])
disp(['Mode improvement = ' num2str(abs(OldMode-fval))])
fval = feval(objective_function,xparam1,dataset_,options_,M_,estim_params_,bayestopt_,oo_);
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;
end
hh = inv(PostVar);
......@@ -315,6 +319,11 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
save([M_.fname '_optimal_mh_scale_parameter.mat'],'Scale');
bayestopt_.jscale = ones(length(xparam1),1)*Scale;
end
disp(' ')
disp(['Optimal value of the scale parameter = ' num2str(Scale)])
disp(' ')
disp(['Final value of the log posterior (or likelihood): ' num2str(fval)])
disp(' ')
parameter_names = bayestopt_.name;
save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names');
case 7
......
......@@ -99,8 +99,11 @@ options_.bvar_prior_flat = 0;
options_.bvar_prior_train = 0;
% Optimization algorithm [6] gmhmaxlik
options_.Opt6Iter = 2;
options_.Opt6Numb = 5000;
gmhmaxlik.iterations = 3;
gmhmaxlik.number = 20000;
gmhmaxlik.nclimb = 200000;
gmhmaxlik.nscale = 200000;
options_.gmhmaxlik = gmhmaxlik;
% Graphics
options_.graphics.nrows = 3;
......
function [PostMod,PostVar,Scale,PostMean] = ...
gmhmaxlik(ObjFun,xparam1,mh_bounds,num,iScale,info,MeanPar,VarCov,varargin)
gmhmaxlik(ObjFun,xparam1,mh_bounds,options,iScale,info,MeanPar,VarCov,varargin)
%function [PostMod,PostVar,Scale,PostMean] = ...
%gmhmaxlik(ObjFun,xparam1,mh_bounds,num,iScale,info,MeanPar,VarCov,varargin)
......@@ -9,7 +9,7 @@ function [PostMod,PostVar,Scale,PostMean] = ...
% o ObjFun [char] string specifying the name of the objective function.
% o xparam1 [double] (p*1) vector of parameters to be estimated.
% o mh_bounds [double] (p*2) matrix defining lower and upper bounds for the parameters.
% o num [integer] scalar specifying the number of MH iterations in step 2.
% o options [structure] options for the optimization algorithm (options_.gmhmaxlik).
% o iScale [double] scalar specifying the initial of the jumping distribution's scale parameter.
% o info [char] string, empty or equal to 'LastCall'.
% o MeanPar [double] (p*1) vector specifying the initial posterior mean.
......@@ -59,7 +59,7 @@ function [PostMod,PostVar,Scale,PostMean] = ...
% SPECIAL REQUIREMENTS
% None.
% Copyright (C) 2006-2011 Dynare Team
% Copyright (C) 2006-2012 Dynare Team
%
% This file is part of Dynare.
%
......@@ -81,9 +81,9 @@ global bayestopt_ estim_params_ options_
options_.lik_algo = 1;
npar = length(xparam1);
NumberOfIterations = num;
MaxNumberOfTuningSimulations = 200000;
MaxNumberOfClimbingSimulations = 200000;
NumberOfIterations = options.number;
MaxNumberOfTuningSimulations = options.nscale;
MaxNumberOfClimbingSimulations = options.nclimb;
AcceptanceTarget = 1/3;
CovJump = VarCov;
......@@ -187,6 +187,7 @@ PostMean = MeanPar;
%% this is the last call to the routine, and I climb the hill (without
%% updating the covariance matrix)...
if strcmpi(info,'LastCall')
hh = dyn_waitbar(0,'Tuning of the scale parameter...');
set(hh,'Name','Tuning of the scale parameter.'),
j = 1; jj = 1;
......@@ -236,11 +237,9 @@ if strcmpi(info,'LastCall')
%%
%% Now I climb the hill
%%
climb = 1;
if climb
if options.nclimb
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment