2017-10-03 15:32:17 +02:00
|
|
|
function [llik,parameters] = evaluate_likelihood(parameters,M_,estim_params_,oo_,options_,bayestopt_)
|
2009-10-16 23:01:52 +02:00
|
|
|
% Evaluate the logged likelihood at parameters.
|
|
|
|
%
|
|
|
|
% INPUTS
|
2011-09-17 12:33:07 +02:00
|
|
|
% o parameters a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean') or a vector of values for
|
2009-10-16 23:01:52 +02:00
|
|
|
% the (estimated) parameters of the model.
|
2017-10-03 15:32:17 +02:00
|
|
|
% o M_ [structure] Definition of the model
|
|
|
|
% o estim_params_ [structure] characterizing parameters to be estimated
|
|
|
|
% o oo_ [structure] Storage of results
|
|
|
|
% o options_ [structure] Options
|
|
|
|
% o bayestopt_ [structure] describing the priors
|
2011-09-17 12:33:07 +02:00
|
|
|
%
|
2009-10-16 23:01:52 +02:00
|
|
|
% OUTPUTS
|
|
|
|
% o ldens [double] value of the sample logged density at parameters.
|
|
|
|
% o parameters [double] vector of values for the estimated parameters.
|
2011-09-17 12:33:07 +02:00
|
|
|
%
|
2009-10-16 23:01:52 +02:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% None
|
|
|
|
%
|
|
|
|
% REMARKS
|
|
|
|
% [1] This function cannot evaluate the likelihood of a dsge-var model...
|
2011-09-17 12:33:07 +02:00
|
|
|
% [2] This function use persistent variables for the dataset and the description of the missing observations. Consequently, if this function
|
2009-10-16 23:01:52 +02:00
|
|
|
% is called more than once (by changing the value of parameters) the sample *must not* change.
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2009-2017 Dynare Team
|
2009-10-16 23:01:52 +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/>.
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2014-06-23 17:11:01 +02:00
|
|
|
persistent dataset dataset_info
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
if nargin==0
|
|
|
|
parameters = 'posterior mode';
|
|
|
|
end
|
|
|
|
|
|
|
|
if ischar(parameters)
|
|
|
|
switch parameters
|
2022-12-02 09:17:38 +01:00
|
|
|
case 'posterior mode'
|
|
|
|
parameters = get_posterior_parameters('mode',M_,estim_params_,oo_,options_);
|
|
|
|
case 'posterior mean'
|
|
|
|
parameters = get_posterior_parameters('mean',M_,estim_params_,oo_,options_);
|
|
|
|
case 'posterior median'
|
|
|
|
parameters = get_posterior_parameters('median',M_,estim_params_,oo_,options_);
|
|
|
|
case 'prior mode'
|
|
|
|
parameters = bayestopt_.p5(:);
|
|
|
|
case 'prior mean'
|
|
|
|
parameters = bayestopt_.p1;
|
|
|
|
otherwise
|
|
|
|
disp('eval_likelihood:: If the input argument is a string, then it has to be equal to:')
|
|
|
|
disp(' ''posterior mode'', ')
|
|
|
|
disp(' ''posterior mean'', ')
|
|
|
|
disp(' ''posterior median'', ')
|
|
|
|
disp(' ''prior mode'' or')
|
|
|
|
disp(' ''prior mean''.')
|
|
|
|
error
|
2009-10-16 23:01:52 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2011-10-22 15:30:23 +02:00
|
|
|
if isempty(dataset)
|
2014-06-23 17:11:01 +02:00
|
|
|
[dataset, dataset_info] = makedataset(options_);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2017-02-15 10:22:28 +01:00
|
|
|
options_=select_qz_criterium_value(options_);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2022-12-02 09:17:38 +01:00
|
|
|
if ~isempty(bayestopt_) && any(bayestopt_.pshape > 0)
|
|
|
|
% Plot prior densities.
|
|
|
|
% Set prior bounds
|
|
|
|
bounds = prior_bounds(bayestopt_, options_.prior_trunc);
|
|
|
|
else % estimated parameters but no declared priors
|
|
|
|
% No priors are declared so Dynare will estimate the model by
|
|
|
|
% maximum likelihood with inequality constraints for the parameters.
|
2023-01-26 09:27:07 +01:00
|
|
|
[~,~,~,lb,ub] = set_prior(estim_params_,M_,options_);
|
2022-12-02 09:17:38 +01:00
|
|
|
bounds.lb = lb;
|
|
|
|
bounds.ub = ub;
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-05-17 21:24:25 +02:00
|
|
|
if options_.occbin.likelihood.status && options_.occbin.likelihood.inversion_filter
|
2022-12-02 09:17:38 +01:00
|
|
|
llik = -occbin.IVF_posterior(parameters,dataset,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
|
|
|
|
else
|
|
|
|
llik = -dsge_likelihood(parameters,dataset,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
|
2021-05-17 21:24:25 +02:00
|
|
|
end
|
2017-10-03 15:32:17 +02:00
|
|
|
ldens = evaluate_prior(parameters,M_,estim_params_,oo_,options_,bayestopt_);
|
2014-06-23 17:11:01 +02:00
|
|
|
llik = llik - ldens;
|