2023-05-10 08:56:35 +02:00
|
|
|
|
function [fval, info, exitflag, ~, ~] = minus_logged_prior_density(xparams, Prior, options_, M_, estim_params_, oo_)
|
|
|
|
|
|
2009-06-05 12:16:31 +02:00
|
|
|
|
% Evaluates minus the logged prior density.
|
2023-05-10 08:56:35 +02:00
|
|
|
|
%
|
2017-05-16 15:10:20 +02:00
|
|
|
|
% INPUTS
|
2023-05-10 08:56:35 +02:00
|
|
|
|
% - xparams [double] vector of parameters.
|
|
|
|
|
% - Prior [dprior] vector specifying prior densities shapes.
|
|
|
|
|
% - DynareOptions [struct] Options, AKA options_
|
|
|
|
|
% - DynareModel [struct] Model description, AKA M_
|
|
|
|
|
% - EstimatedParams [struct] Info about estimated parameters, AKA estimated_params_
|
|
|
|
|
% - DynareResults [struct] Results, AKA oo_
|
2009-06-05 12:16:31 +02:00
|
|
|
|
%
|
2017-05-16 15:10:20 +02:00
|
|
|
|
% OUTPUTS
|
2023-05-10 08:56:35 +02:00
|
|
|
|
% - fval [double] value of minus the logged prior density.
|
|
|
|
|
% - info [double] 4×1 vector, second entry stores penalty, first entry the error code, last entry a penalty (used for optimization).
|
|
|
|
|
|
2023-09-15 09:01:48 +02:00
|
|
|
|
% Copyright © 2009-2023 Dynare Team
|
2009-06-05 12:16:31 +02:00
|
|
|
|
%
|
|
|
|
|
% This file is part of Dynare.
|
|
|
|
|
%
|
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
% (at your option) any later version.
|
|
|
|
|
%
|
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
|
%
|
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2012-09-21 22:59:03 +02:00
|
|
|
|
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = true;
|
2018-02-17 21:00:23 +01:00
|
|
|
|
info = zeros(4,1);
|
2012-09-21 22:59:03 +02:00
|
|
|
|
|
|
|
|
|
%------------------------------------------------------------------------------
|
|
|
|
|
% 1. Get the structural parameters & define penalties
|
|
|
|
|
%------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
% Return, with endogenous penalty, if some parameters are smaller than the lower bound of the prior domain.
|
2023-05-10 08:56:35 +02:00
|
|
|
|
if ~isequal(options_.mode_compute, 1) && any(xparams<Prior.p3)
|
|
|
|
|
k = find(xparams<Prior.p3);
|
2016-06-01 18:22:51 +02:00
|
|
|
|
fval = Inf;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
info(1) = 41;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
info(4) = sum((Prior.p3(k)-xparams(k)).^2);
|
2012-09-21 22:59:03 +02:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
% Return, with endogenous penalty, if some parameters are greater than the upper bound of the prior domain.
|
2023-05-10 08:56:35 +02:00
|
|
|
|
if ~isequal(options_.mode_compute, 1) && any(xparams>Prior.p4)
|
|
|
|
|
k = find(xparams>Prior.p4);
|
2016-06-01 18:22:51 +02:00
|
|
|
|
fval = Inf;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
info(1) = 42;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
info(4) = sum((xparams(k)-Prior.p4(k)).^2);
|
2012-09-21 22:59:03 +02:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
% Get the diagonal elements of the covariance matrices for the structural innovations (Q) and the measurement error (H).
|
2023-05-10 08:56:35 +02:00
|
|
|
|
M_ = set_all_parameters(xparams, estim_params_, M_);
|
2012-09-21 22:59:03 +02:00
|
|
|
|
|
2023-10-24 22:21:15 +02:00
|
|
|
|
Q = M_.Sigma_e;
|
|
|
|
|
H = M_.H;
|
2012-09-21 22:59:03 +02:00
|
|
|
|
|
|
|
|
|
% Test if Q is positive definite.
|
2023-05-10 08:56:35 +02:00
|
|
|
|
if ~issquare(Q) || estim_params_.ncx || isfield(estim_params_, 'calibrated_covariances')
|
2012-09-21 22:59:03 +02:00
|
|
|
|
% Try to compute the cholesky decomposition of Q (possible iff Q is positive definite)
|
2014-01-28 18:42:47 +01:00
|
|
|
|
[Q_is_positive_definite, penalty] = ispd(Q);
|
|
|
|
|
if ~Q_is_positive_definite
|
2023-05-10 08:56:35 +02:00
|
|
|
|
% The variance-covariance matrix of the structural innovations is not definite positive. We have to compute the
|
|
|
|
|
% eigenvalues of this matrix in order to build the endogenous penalty.
|
2016-06-01 18:22:51 +02:00
|
|
|
|
fval = Inf;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
info(1) = 43;
|
2018-02-17 21:00:23 +01:00
|
|
|
|
info(4) = penalty;
|
2014-01-28 18:42:47 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2023-05-10 08:56:35 +02:00
|
|
|
|
if isfield(estim_params_, 'calibrated_covariances')
|
|
|
|
|
correct_flag = check_consistency_covariances(Q);
|
2014-01-28 18:42:47 +01:00
|
|
|
|
if ~correct_flag
|
2023-10-24 22:21:15 +02:00
|
|
|
|
penalty = sum(Q(estim_params_.calibrated_covariances.position).^2);
|
2016-06-01 18:22:51 +02:00
|
|
|
|
fval = Inf;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
info(1) = 71;
|
2018-02-17 21:00:23 +01:00
|
|
|
|
info(4) = penalty;
|
2023-10-24 22:21:15 +02:00
|
|
|
|
return4
|
2012-09-21 22:59:03 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
% Test if H is positive definite.
|
2023-05-10 08:56:35 +02:00
|
|
|
|
if ~issquare(H) || estim_params_.ncn || isfield(estim_params_, 'calibrated_covariances_ME')
|
2014-01-28 18:42:47 +01:00
|
|
|
|
[H_is_positive_definite, penalty] = ispd(H);
|
|
|
|
|
if ~H_is_positive_definite
|
2023-05-10 08:56:35 +02:00
|
|
|
|
% The variance-covariance matrix of the measurement errors is not definite positive. We have to compute the eigenvalues
|
|
|
|
|
% of this matrix in order to build the endogenous penalty.
|
2016-06-01 18:22:51 +02:00
|
|
|
|
fval = Inf;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
info(1) = 44;
|
2018-02-17 21:00:23 +01:00
|
|
|
|
info(4) = penalty;
|
2014-01-28 18:42:47 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2023-05-10 08:56:35 +02:00
|
|
|
|
if isfield(estim_params_, 'calibrated_covariances_ME')
|
|
|
|
|
correct_flag = check_consistency_covariances(H);
|
2014-01-28 18:42:47 +01:00
|
|
|
|
if ~correct_flag
|
2023-10-24 22:21:15 +02:00
|
|
|
|
penalty = sum(H(estim_params_.calibrated_covariances_ME.position).^2);
|
2016-06-01 18:22:51 +02:00
|
|
|
|
fval = Inf;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
info(1) = 72;
|
2018-02-17 21:00:23 +01:00
|
|
|
|
info(4) = penalty;
|
2012-09-21 22:59:03 +02:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%-----------------------------
|
|
|
|
|
% 2. Check BK and steady state
|
|
|
|
|
%-----------------------------
|
|
|
|
|
|
2023-05-10 08:56:35 +02:00
|
|
|
|
[~, info] = resol(0, M_, options_, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
|
2012-09-21 22:59:03 +02:00
|
|
|
|
|
2016-06-01 18:22:51 +02:00
|
|
|
|
% Return, with endogenous penalty when possible, if dynare_resolve issues an error code (defined in resol).
|
|
|
|
|
if info(1)
|
2023-09-15 09:01:48 +02:00
|
|
|
|
if info(1) == 3 || info(1) == 4 || info(1) == 5 || info(1)==6 ||info(1) == 19 ||...
|
2017-05-16 15:10:20 +02:00
|
|
|
|
info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1) == 26 || ...
|
|
|
|
|
info(1) == 81 || info(1) == 84 || info(1) == 85
|
2016-06-01 18:22:51 +02:00
|
|
|
|
%meaningful second entry of output that can be used
|
|
|
|
|
fval = Inf;
|
|
|
|
|
info(4) = info(2);
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
fval = Inf;
|
|
|
|
|
info(4) = 0.1;
|
2023-05-10 08:56:35 +02:00
|
|
|
|
exitflag = false;
|
2016-06-01 18:22:51 +02:00
|
|
|
|
return
|
|
|
|
|
end
|
2012-09-21 22:59:03 +02:00
|
|
|
|
end
|
|
|
|
|
|
2023-05-10 08:56:35 +02:00
|
|
|
|
fval = - Prior.density(xparams);
|