diff --git a/matlab/PosteriorIRF_core1.m b/matlab/PosteriorIRF_core1.m index bc2b3160afe3bb2d4fd14ad98e2cd532c0dfc74f..37f98209bad6c628fb3cb78d73a00fbb789639b9 100644 --- a/matlab/PosteriorIRF_core1.m +++ b/matlab/PosteriorIRF_core1.m @@ -194,7 +194,7 @@ while fpar<B end if MAX_nirfs_dsgevar IRUN = IRUN+1; - [fval,junk1,junk2,cost_flag,info,PHI,SIGMAu,iXX] = dsge_var_likelihood(deep',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + [fval,info,junk1,junk2,junk3,junk3,junk4,PHI,SIGMAu,iXX] = dsge_var_likelihood(deep',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); dsge_prior_weight = M_.params(strmatch('dsge_prior_weight',M_.param_names)); DSGE_PRIOR_WEIGHT = floor(dataset_.nobs*(1+dsge_prior_weight)); SIGMA_inv_upper_chol = chol(inv(SIGMAu*dataset_.nobs*(dsge_prior_weight+1))); diff --git a/matlab/TaRB_optimizer_wrapper.m b/matlab/TaRB_optimizer_wrapper.m index 9c7ed4cccbdde7ea5079275d9d6d08737ebc7044..4d29add34a3c4777b98097124e03bfa62d2ea32a 100644 --- a/matlab/TaRB_optimizer_wrapper.m +++ b/matlab/TaRB_optimizer_wrapper.m @@ -1,5 +1,5 @@ -function [fval,DLIK,Hess,exit_flag] = TaRB_optimizer_wrapper(optpar,par_vector,parameterindices,TargetFun,varargin) -% function [fval,DLIK,Hess,exit_flag] = TaRB_optimizer_wrapper(optpar,par_vector,parameterindices,TargetFun,varargin) +function [fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff] = TaRB_optimizer_wrapper(optpar,par_vector,parameterindices,TargetFun,varargin) +% function [fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff] = TaRB_optimizer_wrapper(optpar,par_vector,parameterindices,TargetFun,varargin) % Wrapper function for target function used in TaRB algorithm; reassembles % full parameter vector before calling target function % @@ -14,11 +14,14 @@ function [fval,DLIK,Hess,exit_flag] = TaRB_optimizer_wrapper(optpar,par_vector,p % % OUTPUTS % o fval [scalar] value of (minus) the likelihood. +% o info [double] (p*2) error code vector +% o exit_flag [scalar] equal to zero if the routine return with a penalty (one otherwise). % o DLIK [double] (p*1) score vector of the likelihood. % o Hess [double] (p*p) asymptotic Hessian matrix. -% o exit_flag [scalar] equal to zero if the routine return with a penalty (one otherwise). +% o SteadyState [double] Vector of doubles, steady state level for the endogenous variables. +% o trend_coeff [double] Matrix of doubles, coefficients of the deterministic trend in the measurement equation % -% Copyright (C) 2015 Dynare Team +% Copyright (C) 2015-16 Dynare Team % % This file is part of Dynare. % @@ -36,5 +39,5 @@ function [fval,DLIK,Hess,exit_flag] = TaRB_optimizer_wrapper(optpar,par_vector,p % along with Dynare. If not, see <http://www.gnu.org/licenses/>. par_vector(parameterindices,:)=optpar; %reassemble parameter -[fval,DLIK,Hess,exit_flag] = feval(TargetFun,par_vector,varargin{:}); %call target function +[fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff] = feval(TargetFun,par_vector,varargin{:}); %call target function diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index 5b8c6f2828c8a2ecfba403a336d2a627a1ce201c..d5dfaefdf37284f892dc18a1047b1215c9fad72e 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -1,4 +1,4 @@ -function [fval,DLIK,Hess,exit_flag,SteadyState,trend_coeff,info,Model,DynareOptions,BayesInfo,DynareResults] = dsge_likelihood(xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults,derivatives_info) +function [fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff,Model,DynareOptions,BayesInfo,DynareResults] = dsge_likelihood(xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults,derivatives_info) % Evaluates the posterior kernel of a dsge model using the specified % kalman_algo; the resulting posterior includes the 2*pi constant of the % likelihood function @@ -35,14 +35,8 @@ function [fval,DLIK,Hess,exit_flag,SteadyState,trend_coeff,info,Model,DynareOpti %! @table @ @var %! @item fval %! Double scalar, value of (minus) the likelihood. -%! @item exit_flag -%! Integer scalar, equal to zero if the routine return with a penalty (one otherwise). -%! @item ys -%! Vector of doubles, steady state level for the endogenous variables. -%! @item trend_coeff -%! Matrix of doubles, coefficients of the deterministic trend in the measurement equation. %! @item info -%! Integer scalar, error code. +%! Double vector, second entry stores penalty, first entry the error code. %! @table @ @code %! @item info==0 %! No error. @@ -91,6 +85,16 @@ function [fval,DLIK,Hess,exit_flag,SteadyState,trend_coeff,info,Model,DynareOpti %! @item info==48 %! Posterior kernel is a complex valued number (logged prior density is complex). %! @end table +%! @item exit_flag +%! Integer scalar, equal to zero if the routine return with a penalty (one otherwise). +%! @item DLIK +%! Vector of doubles, score of the likelihood. +%! @item AHess +%! Matrix of doubles, asymptotic hessian matrix. +%! @item SteadyState +%! Vector of doubles, steady state level for the endogenous variables. +%! @item trend_coeff +%! Matrix of doubles, coefficients of the deterministic trend in the measurement equation. %! @item Model %! Matlab's structure describing the model (initialized by dynare, see @ref{M_}). %! @item DynareOptions @@ -99,10 +103,6 @@ function [fval,DLIK,Hess,exit_flag,SteadyState,trend_coeff,info,Model,DynareOpti %! Matlab's structure describing the priors (initialized by dynare, see @ref{bayesopt_}). %! @item DynareResults %! Matlab's structure gathering the results (initialized by dynare, see @ref{oo_}). -%! @item DLIK -%! Vector of doubles, score of the likelihood. -%! @item AHess -%! Matrix of doubles, asymptotic hessian matrix. %! @end table %! @sp 2 %! @strong{This function is called by:} diff --git a/matlab/dsge_var_likelihood.m b/matlab/dsge_var_likelihood.m index 87d09edb215adbe306a1f39953a4c03e5f2ecb6d..1317f7e6c8b20924aff6824b51915f7617908578 100644 --- a/matlab/dsge_var_likelihood.m +++ b/matlab/dsge_var_likelihood.m @@ -1,4 +1,4 @@ -function [fval,grad,hess,exit_flag,info,PHI,SIGMAu,iXX,prior] = dsge_var_likelihood(xparam1,DynareDataset,DynareInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults) +function [fval,info,exit_flag,grad,hess,SteadyState,trend_coeff,PHI,SIGMAu,iXX,prior] = dsge_var_likelihood(xparam1,DynareDataset,DynareInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults) % Evaluates the posterior kernel of the bvar-dsge model. % % INPUTS @@ -7,8 +7,16 @@ function [fval,grad,hess,exit_flag,info,PHI,SIGMAu,iXX,prior] = dsge_var_likelih % % OUTPUTS % o fval [double] Value of the posterior kernel at xparam1. -% o cost_flag [integer] Zero if the function returns a penalty, one otherwise. % o info [integer] Vector of informations about the penalty. +% o exit_flag [integer] Zero if the function returns a penalty, one otherwise. +% o grad [double] place holder for gradient of the likelihood +% currently not supported by dsge_var +% o hess [double] place holder for hessian matrix of the likelihood +% currently not supported by dsge_var +% o SteadyState [double] Steady state vector possibly recomputed +% by call to dynare_resolve() +% o trend_coeff [double] place holder for trend coefficients, +% currently not supported by dsge_var % o PHI [double] Stacked BVAR-DSGE autoregressive matrices (at the mode associated to xparam1). % o SIGMAu [double] Covariance matrix of the BVAR-DSGE (at the mode associated to xparam1). % o iXX [double] inv(X'X). @@ -45,6 +53,7 @@ PHI = []; SIGMAu = []; iXX = []; prior = []; +trend_coeff=[]; % Initialization of of the index for parameter dsge_prior_weight in Model.params. if isempty(dsge_prior_weight_idx) @@ -271,7 +280,7 @@ if imag(fval)~=0 return end -if (nargout == 8) +if (nargout == 10) if isinf(dsge_prior_weight) iXX = iGXX; else @@ -279,7 +288,7 @@ if (nargout == 8) end end -if (nargout==9) +if (nargout==11) if isinf(dsge_prior_weight) iXX = iGXX; else diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index a2be89596bae10e3bfc7700f47b5aa47f756fd94..6e71390b9dd78a0eb30ae616bd61ecfc05fae832 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -236,7 +236,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation if options_.analytic_derivation && strcmp(func2str(objective_function),'dsge_likelihood'), ana_deriv_old = options_.analytic_derivation; options_.analytic_derivation = 2; - [junk1, junk2, hh] = feval(objective_function,xparam1, ... + [junk1, junk2,junk3, junk4, hh] = feval(objective_function,xparam1, ... dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); options_.analytic_derivation = ana_deriv_old; elseif ~isnumeric(options_.mode_compute) || ~(isequal(options_.mode_compute,5) && newratflag~=1), diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index 53fc6ad33257a1f47c0ed264e5ebe85d96dcc7ec..3e05e16391db63fc0287153c4ff47ee889c6a1ae 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -156,7 +156,7 @@ if info(1)==0, dataset_ = dseries(oo_.endo_simul(options_.varobs_id,100+1:end)',dates('1Q1'), options_.varobs); derivatives_info.no_DLIK=1; bounds = prior_bounds(bayestopt_, options_.prior_trunc); - [fval,DLIK,AHess,cost_flag,ys,trend_coeff,info,M_,options_,bayestopt_,oo_] = dsge_likelihood(params',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_,derivatives_info); + [fval,info,cost_flag,DLIK,AHess,ys,trend_coeff,M_,options_,bayestopt_,oo_] = dsge_likelihood(params',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_,derivatives_info); % fval = DsgeLikelihood(xparam1,data_info,options_,M_,estim_params_,bayestopt_,oo_); options_.analytic_derivation = analytic_derivation; AHess=-AHess; diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 84adbde0cd02bddd45c403f81620c72d861c8a53..3e6430a8206650b73f8646198dd9085cf3f2dd05 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -116,9 +116,9 @@ ana_deriv = DynareOptions.analytic_derivation; DynareOptions.analytic_derivation=0; if ~isequal(DynareOptions.mode_compute,11) || ... (isequal(DynareOptions.mode_compute,11) && isequal(DynareOptions.order,1)) - [fval,junk1,junk2,a,b,c,d] = feval(objective_function,xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults); + [fval,info] = feval(objective_function,xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults); else - b=0; + info=0; fval = 0; end if DynareOptions.debug @@ -126,12 +126,6 @@ if DynareOptions.debug end DynareOptions.analytic_derivation=ana_deriv; -if DynareOptions.dsge_var || strcmp(func2str(objective_function),'non_linear_dsge_likelihood') - info = b; -else - info = d; -end - % if DynareOptions.mode_compute==5 % if ~strcmp(func2str(objective_function),'dsge_likelihood') % error('Options mode_compute=5 is not compatible with non linear filters or Dsge-VAR models!') diff --git a/matlab/mode_check.m b/matlab/mode_check.m index 40b675739bab202dc8b09656b75c6acf4235b0dc..7a282af2e0e4d562aacc62692eef0784aa342c7a 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -140,7 +140,7 @@ for plt = 1:nbplt, end for i=1:length(z) xx(kk) = z(i); - [fval, junk1, junk2, exit_flag] = feval(fun,xx,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults); + [fval, info, exit_flag] = feval(fun,xx,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults); if exit_flag y(i,1) = fval; else diff --git a/matlab/non_linear_dsge_likelihood.m b/matlab/non_linear_dsge_likelihood.m index 94c46eee170bbaec5b81474e53c98d667ea2a2d7..35685ed2a47540f703303244573f60543af7f4c6 100644 --- a/matlab/non_linear_dsge_likelihood.m +++ b/matlab/non_linear_dsge_likelihood.m @@ -1,4 +1,4 @@ -function [fval,ys,trend_coeff,exit_flag,info,Model,DynareOptions,BayesInfo,DynareResults] = non_linear_dsge_likelihood(xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults) +function [fval,info,exit_flag,DLIK,Hess,ys,trend_coeff,Model,DynareOptions,BayesInfo,DynareResults] = non_linear_dsge_likelihood(xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults) % Evaluates the posterior kernel of a dsge model using a non linear filter. %@info: @@ -31,14 +31,8 @@ function [fval,ys,trend_coeff,exit_flag,info,Model,DynareOptions,BayesInfo,Dynar %! @table @ @var %! @item fval %! Double scalar, value of (minus) the likelihood. -%! @item exit_flag -%! Integer scalar, equal to zero if the routine return with a penalty (one otherwise). -%! @item ys -%! Vector of doubles, steady state level for the endogenous variables. -%! @item trend_coeffs -%! Matrix of doubles, coefficients of the deterministic trend in the measurement equation. %! @item info -%! Integer scalar, error code. +%! Double vector, second entry stores penalty, first entry the error code. %! @table @ @code %! @item info==0 %! No error. @@ -81,6 +75,18 @@ function [fval,ys,trend_coeff,exit_flag,info,Model,DynareOptions,BayesInfo,Dynar %! @item info==45 %! Likelihood is a complex valued number. %! @end table +%! @item exit_flag +%! Integer scalar, equal to zero if the routine return with a penalty (one otherwise). +%! @item DLIK +%! Vector of doubles, placeholder for score of the likelihood, currently +%! not supported by non_linear_dsge_likelihood +%! @item AHess +%! Matrix of doubles, placeholder for asymptotic hessian matrix, currently +%! not supported by non_linear_dsge_likelihood +%! @item ys +%! Vector of doubles, steady state level for the endogenous variables. +%! @item trend_coeffs +%! Matrix of doubles, coefficients of the deterministic trend in the measurement equation. %! @item Model %! Matlab's structure describing the model (initialized by dynare, see @ref{M_}). %! @item DynareOptions @@ -132,6 +138,8 @@ fval = []; ys = []; trend_coeff = []; exit_flag = 1; +DLIK = []; +Hess = []; % Issue an error if loglinear option is used. if DynareOptions.loglinear diff --git a/matlab/osr1.m b/matlab/osr1.m index d5070cdbb787f2a15be8ffda557e40628669abf9..51fd5475fa1737132febdb286db6728c4b5891a0 100644 --- a/matlab/osr1.m +++ b/matlab/osr1.m @@ -77,7 +77,7 @@ inv_order_var = oo_.dr.inv_order_var; %extract unique entries of covariance i_var=unique(i_var); %% do initial checks -[loss,vx,info,exit_flag]=osr_obj(t0,i_params,inv_order_var(i_var),weights(i_var,i_var)); +[loss,info,exit_flag,vx]=osr_obj(t0,i_params,inv_order_var(i_var),weights(i_var,i_var)); if info~=0 print_info(info, options_.noprint, options_); else diff --git a/matlab/osr_obj.m b/matlab/osr_obj.m index 378d2b06ed0b50362aa14018eb3d07c3c86f741e..7c3e7035312a51cb724a863390de6dc7ff50f672 100644 --- a/matlab/osr_obj.m +++ b/matlab/osr_obj.m @@ -1,4 +1,4 @@ -function [loss,vx,info,exit_flag]=osr_obj(x,i_params,i_var,weights) +function [loss,info,exit_flag,vx,junk]=osr_obj(x,i_params,i_var,weights) % objective function for optimal simple rules (OSR) % INPUTS % x vector values of the parameters @@ -9,13 +9,15 @@ function [loss,vx,info,exit_flag]=osr_obj(x,i_params,i_var,weights) % % OUTPUTS % loss scalar loss function returned to solver -% vx vector variances of the endogenous variables % info vector info vector returned by resol % exit_flag scalar exit flag returned to solver +% vx vector variances of the endogenous variables +% junk empty dummy output for conformable +% header % % SPECIAL REQUIREMENTS % none -% Copyright (C) 2005-2013 Dynare Team +% Copyright (C) 2005-2016 Dynare Team % % This file is part of Dynare. %