Home > matlab > evaluate_likelihood.m

evaluate_likelihood

PURPOSE ^

Evaluate the logged likelihood at parameters.

SYNOPSIS ^

function [llik,parameters] = evaluate_likelihood(parameters)

DESCRIPTION ^

 Evaluate the logged likelihood at parameters.

 INPUTS
    o parameters  a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean') or a vector of values for
                  the (estimated) parameters of the model.


 OUTPUTS
    o ldens       [double]  value of the sample logged density at parameters.
    o parameters  [double]  vector of values for the estimated parameters.

 SPECIAL REQUIREMENTS
    None

 REMARKS
 [1] This function cannot evaluate the likelihood of a dsge-var model...
 [2] This function use persistent variables for the dataset and the description of the missing observations. Consequently, if this function
     is called more than once (by changing the value of parameters) the sample *must not* change.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [llik,parameters] = evaluate_likelihood(parameters)
0002 % Evaluate the logged likelihood at parameters.
0003 %
0004 % INPUTS
0005 %    o parameters  a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean') or a vector of values for
0006 %                  the (estimated) parameters of the model.
0007 %
0008 %
0009 % OUTPUTS
0010 %    o ldens       [double]  value of the sample logged density at parameters.
0011 %    o parameters  [double]  vector of values for the estimated parameters.
0012 %
0013 % SPECIAL REQUIREMENTS
0014 %    None
0015 %
0016 % REMARKS
0017 % [1] This function cannot evaluate the likelihood of a dsge-var model...
0018 % [2] This function use persistent variables for the dataset and the description of the missing observations. Consequently, if this function
0019 %     is called more than once (by changing the value of parameters) the sample *must not* change.
0020 
0021 % Copyright (C) 2009-2010 Dynare Team
0022 %
0023 % This file is part of Dynare.
0024 %
0025 % Dynare is free software: you can redistribute it and/or modify
0026 % it under the terms of the GNU General Public License as published by
0027 % the Free Software Foundation, either version 3 of the License, or
0028 % (at your option) any later version.
0029 %
0030 % Dynare is distributed in the hope that it will be useful,
0031 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0032 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0033 % GNU General Public License for more details.
0034 %
0035 % You should have received a copy of the GNU General Public License
0036 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0037 
0038 global options_ M_ bayestopt_ oo_ estim_params_
0039 
0040 persistent dataset
0041 
0042 if nargin==0
0043     parameters = 'posterior mode';
0044 end
0045 
0046 if ischar(parameters)
0047     switch parameters
0048       case 'posterior mode'
0049         parameters = get_posterior_parameters('mode');
0050       case 'posterior mean'
0051         parameters = get_posterior_parameters('mean');
0052       case 'posterior median'
0053         parameters = get_posterior_parameters('median');
0054       case 'prior mode'
0055         parameters = bayestopt_.p5(:);
0056       case 'prior mean'
0057         parameters = bayestopt_.p1;
0058       otherwise
0059         disp('eval_likelihood:: If the input argument is a string, then it has to be equal to:')
0060         disp('                   ''posterior mode'', ')
0061         disp('                   ''posterior mean'', ')
0062         disp('                   ''posterior median'', ')
0063         disp('                   ''prior mode'' or')
0064         disp('                   ''prior mean''.')
0065         error
0066     end
0067 end
0068 
0069 if isempty(dataset)
0070     % Load and transform data.
0071     transformation = [];
0072     if options_.loglinear && ~options_.logdata
0073         transformation = @log;
0074     end
0075     xls.sheet = options_.xls_sheet;
0076     xls.range = options_.xls_range;
0077 
0078     if ~isfield(options_,'nobs')
0079         options_.nobs = [];
0080     end
0081 
0082     dataset = initialize_dataset(options_.datafile,options_.varobs,options_.first_obs,options_.nobs,transformation,options_.prefilter,xls);
0083 end
0084 
0085 pshape_original   = bayestopt_.pshape;
0086 bayestopt_.pshape = Inf(size(bayestopt_.pshape));
0087 
0088 llik = -dsge_likelihood(parameters,dataset,options_,M_,estim_params_,bayestopt_,oo_);
0089 
0090 bayestopt_.pshape = pshape_original;

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005