Merge branch 'master' into use-dynSeries

time-shift
Stéphane Adjemian (Charybdis) 2013-09-10 22:26:12 +02:00
commit ddce110bf2
7 changed files with 120 additions and 30 deletions

3
.gitignore vendored
View File

@ -27,6 +27,9 @@ install-sh
/missing
/mex/build/matlab/missing
/mex/build/octave/missing
/compile
/mex/build/matlab/compile
/mex/build/octave/compile
ylwrap
ar-lib

View File

@ -78,7 +78,7 @@ else
objective_function = str2func('DsgeVarLikelihood');
end
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_] = dynare_estimation_init(var_list_, dname, [], M_, options_, oo_, estim_params_, bayestopt_);
[dataset_,xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_] = dynare_estimation_init(var_list_, dname, [], M_, options_, oo_, estim_params_, bayestopt_);
% Set sigma_e_is_diagonal flag (needed if the shocks block is not declared in the mod file).
M_.sigma_e_is_diagonal = 1;
@ -136,15 +136,6 @@ ub = bayestopt_.ub;
dr = oo_.dr;
%% load mode file is necessary
if ~isempty(options_.mode_file) && ~options_.mh_posterior_mode_estimation
load(options_.mode_file);
if length(xparam1) ~= nx
error([ 'ESTIMATION: the posterior mode file ' options_.mode_file ' has been generated using another specification. Please delete it and recompute the posterior mode.'])
end
end
%% load optimal_mh_scale parameter if previous run was with
%% mode_compute=6
mh_scale_fname = [M_.fname '_optimal_mh_scale_parameter.mat'];
@ -702,7 +693,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
fprintf(fidTeX,' \n');
end
for plt = 1:nbplt,
hh = dyn_figure(options_,'Name','Smoothed shocks');
fh = dyn_figure(options_,'Name','Smoothed shocks');
NAMES = [];
if options_.TeX, TeXNAMES = []; end
nstar0=min(nstar,M_.exo_nbr-(plt-1)*nstar);
@ -743,7 +734,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
end
title(name,'Interpreter','none')
end
dyn_saveas(hh,[M_.fname '_SmoothedShocks' int2str(plt)],options_);
dyn_saveas(fh,[M_.fname '_SmoothedShocks' int2str(plt)],options_);
if options_.TeX
fprintf(fidTeX,'\\begin{figure}[H]\n');
for jj = 1:nstar0
@ -794,7 +785,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
fprintf(fidTeX,' \n');
end
for plt = 1:nbplt
hh = dyn_figure(options_,'Name','Smoothed observation errors');
fh = dyn_figure(options_,'Name','Smoothed observation errors');
NAMES = [];
if options_.TeX, TeXNAMES = []; end
nstar0=min(nstar,number_of_plots_to_draw-(nbplt-1)*nstar);
@ -836,7 +827,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
end
title(name,'Interpreter','none')
end
dyn_saveas(hh,[M_.fname '_SmoothedObservationErrors' int2str(plt)],options_);
dyn_saveas(fh,[M_.fname '_SmoothedObservationErrors' int2str(plt)],options_);
if options_.TeX
fprintf(fidTeX,'\\begin{figure}[H]\n');
for jj = 1:nstar0
@ -869,7 +860,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
fprintf(fidTeX,' \n');
end
for plt = 1:nbplt,
hh = dyn_figure(options_,'Name','Historical and smoothed variables');
fh = dyn_figure(options_,'Name','Historical and smoothed variables');
NAMES = [];
if options_.TeX, TeXNAMES = []; end
nstar0=min(nstar,n_varobs-(plt-1)*nstar);
@ -911,7 +902,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
end
title(name,'Interpreter','none')
end
dyn_saveas(hh,[M_.fname '_HistoricalAndSmoothedVariables' int2str(plt)],options_);
dyn_saveas(fh,[M_.fname '_HistoricalAndSmoothedVariables' int2str(plt)],options_);
if options_.TeX
fprintf(fidTeX,'\\begin{figure}[H]\n');
for jj = 1:nstar0,

View File

@ -1,4 +1,4 @@
function [dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_, fake] = dynare_estimation_init(var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_)
function [dataset_, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, fake] = dynare_estimation_init(var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_)
% function dynare_estimation_init(var_list_, gsa_flag)
% preforms initialization tasks before estimation or
@ -37,6 +37,8 @@ function [dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_, fake] =
global objective_function_penalty_base
hh = [];
if isempty(gsa_flag)
gsa_flag = 0;
else
@ -132,14 +134,102 @@ end
% Set priors over the estimated parameters.
if ~isempty(estim_params_)
[xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_);
if ~isempty(options_.mode_file) && ~options_.mh_posterior_mode_estimation
junk=length(xparam1);
load(options_.mode_file,'xparam1');
if length(xparam1) ~= junk
error([ 'ESTIMATION: the posterior mode file ' options_.mode_file ' has been generated using another specification. Please delete it and recompute the posterior mode.'])
end
% Check that the provided mode_file is compatible with the current estimation settings.
if ~isempty(estim_params_) && ~isempty(options_.mode_file) && ~options_.mh_posterior_mode_estimation
number_of_estimated_parameters = length(xparam1);
mode_file = load(options_.mode_file);
if number_of_estimated_parameters>length(mode_file.xparam1)
skipline()
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
disp(['Your mode file contains estimates for ' int2str(length(mode_file.xparam1)) ' parameters, while you are attempting to estimate ' int2str(number_of_estimated_parameters) ' parameters:'])
for i=1:number_of_estimated_parameters
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
if isempty(id)
disp(['--> Estimated parameter ' bayestopt_.name{i} ' is not present in the loaded mod_file.'])
end
end
for i=1:length(mode_file.xparam1)
id = strmatch(mode_file.parameter_names{i},bayestopt_.name,'exact');
if isempty(id)
disp(['--> Parameter ' mode_file.parameter_names{i} ' is not estimated according to the current mod file.'])
end
end
error('Please change the mode_file option or the list of estimated parameters.')
elseif number_of_estimated_parameters<length(mode_file.xparam1)
skipline()
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
disp(['Your mode file contains estimates for ' int2str(length(mode_file.xparam1)) ' parameters, while you are attempting to estimate only ' int2str(number_of_estimated_parameters) ' parameters:'])
Id = [];
for i=1:number_of_estimated_parameters
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
if isempty(id)
disp(['--> Estimated parameter ' deblank(bayestopt_.name(i,:)) ' is not present in the loaded mode file.'])
Id = [];
break
else
Id = [Id; id];
end
end
for i=1:length(mode_file.xparam1)
id = strmatch(mode_file.parameter_names{i},bayestopt_.name,'exact');
if isempty(id)
disp(['--> Parameter ' mode_file.parameter_names{i} ' is not estimated according to the current mod file.'])
end
end
if isempty(Id)
% None of the estimated parameters are present in the mode_file.
error('Please change the mode_file option or the list of estimated parameters.')
else
% If possible, fix the mode_file.
if isequal(length(Id),number_of_estimated_parameters)
disp('==> Fix mode file (remove unused parameters).')
mode_file.parameter_names = mode_file.parameter_names(Id,:);
mode_file.xparam1 = mode_file.xparam1(Id);
mode_file.hh = mode_file.hh(Id,Id);
end
end
else
% The number of declared estimated parameters match the number of parameters in the mode file.
% Check that the parameters in the mode file and according to the current mod file are identical.
if isequal(mode_file.parameter_names, bayestopt_.name)
% Ok! Nothing to do here.
else
skipline()
disp(['The posterior mode file ' options_.mode_file ' has been generated using another specification of the model or another model!'])
% Check if this only an ordering issue.
Id = [];
for i=1:number_of_estimated_parameters
id = strmatch(deblank(bayestopt_.name(i,:)),mode_file.parameter_names,'exact');
if isempty(id)
disp(['--> Estimated parameter ' bayestopt_.name{i} ' is not present in the loaded mode file.'])
Id = [];
break
else
Id = [Id; id];
end
end
if isempty(Id)
% None of the estimated parameters are present in the mode_file.
error('Please change the mode_file option or the list of estimated parameters.')
else
% If possible, fix the mode_file.
if isequal(length(Id),number_of_estimated_parameters)
disp('==> Fix mode file (reorder the parameters).')
mode_file.parameter_names = mode_file.parameter_names(Id,:);
mode_file.xparam1 = mode_file.xparam1(Id);
mode_file.hh = mode_file.hh(Id,Id);
end
end
end
end
if any(bayestopt_.pshape > 0)
xparam1 = mode_file.xparam1;
hh = mode_file.hh;
skipline()
end
if ~isempty(estim_params_) && any(bayestopt_.pshape > 0)
% Plot prior densities.
if ~options_.nograph && options_.plot_priors
plot_priors(bayestopt_,M_,estim_params_,options_)
@ -154,7 +244,9 @@ if ~isempty(estim_params_)
options_.mh_replic = 0;% No metropolis.
bounds(:,1) = lb;
bounds(:,2) = ub;
end
end
if ~isempty(estim_params_)
% Test if initial values of the estimated parameters are all between
% the prior lower and upper bounds.
outside_bound_pars=find(xparam1 < bounds(:,1) | xparam1 > bounds(:,2));
@ -172,7 +264,10 @@ if ~isempty(estim_params_)
ub = bounds(:,2);
bayestopt_.lb = lb;
bayestopt_.ub = ub;
else% If estim_params_ is empty (e.g. when running the smoother on a calibrated model)
end
if isempty(estim_params_)% If estim_params_ is empty (e.g. when running the smoother on a calibrated model)
if ~options_.smoother
error('ESTIMATION: the ''estimated_params'' block is mandatory (unless you are running a smoother)')
end

View File

@ -128,7 +128,7 @@ options_ = set_default_option(options_,'datafile','');
options_.mode_compute = 0;
options_.plot_priors = 0;
options_.smoother=1;
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_]=dynare_estimation_init(M_.endo_names,fname_,1, M_, options_, oo_, estim_params_, bayestopt_);
[dataset_,xparam1,hh, M_, options_, oo_, estim_params_,bayestopt_]=dynare_estimation_init(M_.endo_names,fname_,1, M_, options_, oo_, estim_params_, bayestopt_);
options_ident.analytic_derivation_mode = options_.analytic_derivation_mode;
if isempty(dataset_),
dataset_.info.ntobs = periods;

View File

@ -80,8 +80,7 @@ if ~isempty(options_gsa.datafile) || isempty(bayestopt_) || options_gsa.rmse,
options_.mode_compute = 0;
options_.filtered_vars = 1;
options_.plot_priors = 0;
% [data,rawdata,xparam1,data_info]=dynare_estimation_init([],fname_,1);
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_]=dynare_estimation_init(M_.endo_names,fname_,1, M_, options_, oo_, estim_params_, bayestopt_);
[dataset_,xparam1,hh, M_, options_, oo_, estim_params_,bayestopt_]=dynare_estimation_init(M_.endo_names,fname_,1, M_, options_, oo_, estim_params_, bayestopt_);
% computes a first linear solution to set up various variables
else
if isempty(options_.qz_criterium)

View File

@ -51,7 +51,7 @@ if ischar(parameters) && strcmp(parameters,'calibration')
end
if isempty(dataset_) || isempty(bayestopt_)
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_] = dynare_estimation_init(var_list, M_.fname, [], M_, options_, oo_, estim_params_, bayestopt_);
[dataset_,xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_] = dynare_estimation_init(var_list, M_.fname, [], M_, options_, oo_, estim_params_, bayestopt_);
end
if nargin==0

View File

@ -115,7 +115,9 @@ if ~options_.noprint
end
skipline()
if options_.order <= 2 && ~PI_PCL_solver
disp_dr(oo_.dr,options_.order,var_list);
if ~options_.nofunctions
disp_dr(oo_.dr,options_.order,var_list);
end
end
end