Display minimum in check plots in method of moments

time-shift
Willi Mutschler 2020-11-26 13:28:29 +01:00
parent 94f7058639
commit 4aa0fa540e
No known key found for this signature in database
GPG Key ID: 91E724BF17A73F6D
2 changed files with 19 additions and 19 deletions

View File

@ -49,8 +49,8 @@ function [oo_, options_mom_, M_] = method_of_moments(bayestopt_, options_, oo_,
% o get_all_parameters.m
% o get_matrix_entries_for_psd_check.m
% o makedataset.m
% o method_of_moments_check_plot.m
% o method_of_moments_data_moments.m
% o method_of_moments_mode_check.m
% o method_of_moments_objective_function.m
% o method_of_moments_optimal_weighting_matrix
% o method_of_moments_standard_errors
@ -203,12 +203,12 @@ options_mom_ = set_default_option(options_mom_,'mode_compute',13);
options_mom_ = set_default_option(options_mom_,'additional_optimizer_steps',[]); % vector of additional mode-finders run after mode_compute
options_mom_ = set_default_option(options_mom_,'optim_opt',[]); % a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute
options_mom_ = set_default_option(options_mom_,'silent_optimizer',false); % run minimization of moments distance silently without displaying results or saving files in between
% Mode_check plot options that can be set by the user in the mod file, otherwise default values are provided
% Check plot options that can be set by the user in the mod file, otherwise default values are provided
options_mom_.mode_check.nolik = false; % we don't do likelihood (also this initializes mode_check substructure)
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'status',false); % plot the target function for values around the computed mode for each estimated parameter in turn. This is helpful to diagnose problems with the optimizer.
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'neighbourhood_size',.5); % width of the window around the mode to be displayed on the diagnostic plots. This width is expressed in percentage deviation. The Inf value is allowed, and will trigger a plot over the entire domain
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'symmetric_plots',true); % ensure that the check plots are symmetric around the mode. A value of 0 allows to have asymmetric plots, which can be useful if the posterior mode is close to a domain boundary, or in conjunction with mode_check_neighbourhood_size = Inf when the domain is not the entire real line
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'number_of_points',20); % number of points around the mode where the target function is evaluated (for each parameter)
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'status',false); % plot the target function for values around the computed minimum for each estimated parameter in turn. This is helpful to diagnose problems with the optimizer.
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'neighbourhood_size',.5); % width of the window around the computed minimum to be displayed on the diagnostic plots. This width is expressed in percentage deviation. The Inf value is allowed, and will trigger a plot over the entire domain
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'symmetric_plots',true); % ensure that the check plots are symmetric around the minimum. A value of 0 allows to have asymmetric plots, which can be useful if the minimum is close to a domain boundary, or in conjunction with neighbourhood_size = Inf when the domain is not the entire real line
options_mom_.mode_check = set_default_option(options_mom_.mode_check,'number_of_points',20); % number of points around the minimum where the target function is evaluated (for each parameter)
% Numerical algorithms options that can be set by the user in the mod file, otherwise default values are provided
options_mom_ = set_default_option(options_mom_,'aim_solver',false); % use AIM algorithm to compute perturbation approximation instead of mjdgges
@ -909,7 +909,7 @@ if options_mom_.TeX
end
if options_mom_.mode_check.status
method_of_moments_mode_check(objective_function,xparam1,SE,options_mom_,M_,estim_params_,Bounds,bayestopt_laplace,...
method_of_moments_check_plot(objective_function,xparam1,SE,options_mom_,M_,estim_params_,Bounds,bayestopt_laplace,...
Bounds, oo_, estim_params_, M_, options_mom_)
end

View File

@ -1,5 +1,5 @@
function method_of_moments_mode_check(fun,xparam,SE_vec,options_,M_,estim_params_,Bounds,bayestopt_,varargin)
% Checks the estimated ML mode or Posterior mode.
function method_of_moments_check_plot(fun,xparam,SE_vec,options_,M_,estim_params_,Bounds,bayestopt_,varargin)
% Checks the estimated local minimum of the moment's distance objective
% Copyright (C) 2020 Dynare Team
@ -28,7 +28,7 @@ fval = feval(fun,xparam,varargin{:});
if ~isempty(SE_vec)
skipline()
disp('MODE CHECK')
disp('LOCAL MINIMUM CHECK')
skipline()
fprintf('Fval obtained by the minimization routine: %f', fval);
skipline()
@ -44,7 +44,7 @@ if ~exist([M_.fname filesep 'graphs'],'dir')
end
if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fidTeX = fopen([M_.fname, '/graphs/', M_.fname '_MoMCheckPlots.tex'],'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by method_of_moments_mode_check.m (Dynare).\n');
fprintf(fidTeX,'%% TeX eps-loader file generated by method_of_moments_check_plot.m (Dynare).\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n');
end
@ -54,14 +54,14 @@ if isinf(ll)
options_.mode_check.symmetric_plots = false;
end
mcheck = struct('cross',struct(),'emode',struct());
mcheck = struct('cross',struct(),'emin',struct());
for plt = 1:nbplt
if TeX
NAMES = [];
TeXNAMES = [];
end
hh = dyn_figure(options_.nodisplay,'Name','Mode check plots');
hh = dyn_figure(options_.nodisplay,'Name','Minimum check plots');
for k=1:min(nstar,length(xparam)-(plt-1)*nstar)
subplot(nr,nc,k)
kk = (plt-1)*nstar+k;
@ -119,7 +119,7 @@ for plt = 1:nbplt
else
y(i,1) = NaN;
if options_.debug
fprintf('mode_check:: could not solve model for parameter %s at value %4.3f, error code: %u\n',name,z(i),info(1))
fprintf('method_of_moments_check_plot:: could not solve model for parameter %s at value %4.3f, error code: %u\n',name,z(i),info(1))
end
end
if options_.mom.penalized_estimator
@ -127,9 +127,9 @@ for plt = 1:nbplt
y(i,2) = (y(i,1)+prior-dy);
end
end
mcheck.cross = setfield(mcheck.cross, name, [transpose(z), -y]);
mcheck.emode = setfield(mcheck.emode, name, xparam(kk));
fighandle=plot(z,-y);
mcheck.cross = setfield(mcheck.cross, name, [transpose(z), y]);
mcheck.emin = setfield(mcheck.emin, name, xparam(kk));
fighandle=plot(z,y);
hold on
yl=get(gca,'ylim');
plot( [xparam(kk) xparam(kk)], yl, 'c', 'LineWidth', 1)
@ -170,7 +170,7 @@ for plt = 1:nbplt
% TeX eps loader file
fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%_MoMCheckPlots%s}\n',options_.figures.textwidth*min(k/nc,1),[M_.fname, '/graphs/',M_.fname],int2str(plt));
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_MoMCheckPlots%s}\n',options_.figures.textwidth*min(k/nc,1),[M_.fname, '/graphs/',M_.fname],int2str(plt));
fprintf(fidTeX,'\\caption{Method of Moments check plots.}');
fprintf(fidTeX,'\\label{Fig:MoMCheckPlots:%s}\n',int2str(plt));
fprintf(fidTeX,'\\end{figure}\n');
@ -181,5 +181,5 @@ if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fclose(fidTeX);
end
OutputDirectoryName = CheckPath('modecheck',M_.dname);
OutputDirectoryName = CheckPath('check_plot',M_.dname);
save([OutputDirectoryName '/MoM_check_plot_data.mat'],'mcheck');