2017-01-09 18:10:15 +01:00
function [oo_,M_,options_,bayestopt_,Smoothed_variables_declaration_order_deviation_form]= evaluate_smoother ( parameters,var_list,M_,oo_,options_,bayestopt_,estim_params_)
2010-12-08 12:02:08 +01:00
% Evaluate the smoother at parameters.
%
% INPUTS
2017-08-28 18:22:11 +02:00
% o parameters a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean','mle_mode','calibration') or a vector of values for
2010-12-08 12:02:08 +01:00
% the (estimated) parameters of the model.
2013-06-03 16:44:59 +02:00
% o var_list subset of endogenous variables
2016-12-15 10:36:16 +01:00
% o M_ [structure] Definition of the model
% o oo_ [structure] Storage of results
% o options_ [structure] Options
% o bayestopt_ [structure] describing the priors
% o estim_params_ [structure] characterizing parameters to be estimated
2011-09-17 12:33:07 +02:00
%
2010-12-08 12:02:08 +01:00
% OUTPUTS
% o oo [structure] results:
% - SmoothedVariables
% - SmoothedShocks
2016-04-01 15:25:17 +02:00
% - FilteredVariablesShockDecomposition
% - UpdatedVariables
% - FilteredVariables
% - SmoothedMeasurementErrors
% - FilteredVariablesKStepAhead
% - FilteredVariablesKStepAheadVariances
2017-01-09 18:10:15 +01:00
% o M_ [structure] Definition of the model
% o options_ [structure] Options; returns options_.first_obs
2017-05-16 15:10:20 +02:00
% o bayestopt_ [structure] describing the priors; returns fields like bayestopt_.smoother_var_list from the smoother
2016-04-01 15:25:17 +02:00
% o Smoothed_variables_declaration_order_deviation_form
% Smoothed variables from the Kalman smoother in
% order of declaration of variables (M_.endo_names)
% in deviations from their respective mean, i.e.
% without trend and constant part (used for shock_decomposition)
2011-09-17 12:33:07 +02:00
%
2010-12-08 12:02:08 +01:00
% SPECIAL REQUIREMENTS
% None
%
% REMARKS
2011-09-17 12:33:07 +02:00
% [1] This function use persistent variables for the dataset and the description of the missing observations. Consequently, if this function
2010-12-08 12:02:08 +01:00
% is called more than once (by changing the value of parameters) the sample *must not* change.
2020-03-03 11:45:38 +01:00
% Copyright (C) 2010-2020 Dynare Team
2010-12-08 12:02:08 +01: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
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
2017-04-05 11:01:43 +02:00
% store qz_criterium
2016-09-29 14:32:05 +02:00
qz_criterium_old = options_ . qz_criterium ;
2013-07-22 19:29:55 +02:00
if ischar ( parameters ) && strcmp ( parameters , ' calibration' )
options_ . smoother = 1 ;
end
2017-04-05 11:01:43 +02:00
[ dataset_ , dataset_info , xparam1 , hh , M_ , options_ , oo_ , estim_params_ , bayestopt_ ] = dynare_estimation_init ( var_list , M_ . fname , [ ] , M_ , options_ , oo_ , estim_params_ , bayestopt_ ) ;
2017-02-15 10:22:28 +01:00
% set the qz_criterium
2017-04-05 11:01:43 +02:00
options_ = select_qz_criterium_value ( options_ ) ;
2013-06-03 16:44:59 +02:00
2010-12-08 12:02:08 +01:00
if nargin == 0
parameters = ' posterior_mode' ;
end
if ischar ( parameters )
switch parameters
case ' posterior_mode'
2017-10-03 15:32:17 +02:00
parameters = get_posterior_parameters ( ' mode' , M_ , estim_params_ , oo_ , options_ ) ;
2010-12-08 12:02:08 +01:00
case ' posterior_mean'
2017-10-03 15:32:17 +02:00
parameters = get_posterior_parameters ( ' mean' , M_ , estim_params_ , oo_ , options_ ) ;
2010-12-08 12:02:08 +01:00
case ' posterior_median'
2017-10-03 15:32:17 +02:00
parameters = get_posterior_parameters ( ' median' , M_ , estim_params_ , oo_ , options_ ) ;
2016-06-07 10:02:04 +02:00
case ' mle_mode'
2017-10-03 15:32:17 +02:00
parameters = get_posterior_parameters ( ' mode' , M_ , estim_params_ , oo_ , options_ , ' mle_' ) ;
2010-12-08 12:02:08 +01:00
case ' prior_mode'
parameters = bayestopt_ . p5 ( : ) ;
case ' prior_mean'
parameters = bayestopt_ . p1 ;
2012-04-21 21:37:52 +02:00
case ' calibration'
2012-05-29 16:25:52 +02:00
if isempty ( oo_ . dr )
error ( ' You must run ' ' stoch_simul' ' first.' ) ;
end
2012-04-21 21:37:52 +02:00
parameters = [ ] ;
2010-12-08 12:02:08 +01:00
otherwise
disp ( ' evaluate_smoother:: 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' ' .' )
2012-04-21 21:37:52 +02:00
disp ( ' ' ' calibration' ' .' )
2010-12-08 12:02:08 +01:00
error
end
end
2016-12-15 10:36:16 +01:00
[ atT , innov , measurement_error , updated_variables , ys , trend_coeff , aK , T , R , P , PK , decomp , Trend , state_uncertainty , M_ , oo_ , options_ , bayestopt_ ] = ...
DsgeSmoother ( parameters , dataset_ . nobs , transpose ( dataset_ . data ) , dataset_info . missing . aindex , dataset_info . missing . state , M_ , oo_ , options_ , bayestopt_ , estim_params_ ) ;
2016-10-31 17:59:28 +01:00
[ oo_ ] = store_smoother_results ( M_ , oo_ , options_ , bayestopt_ , dataset_ , dataset_info , atT , innov , measurement_error , updated_variables , ys , trend_coeff , aK , P , PK , decomp , Trend , state_uncertainty ) ;
2016-04-01 15:25:17 +02:00
2017-03-17 14:21:53 +01:00
if nargout > 4
2017-05-16 15:10:20 +02:00
Smoothed_variables_declaration_order_deviation_form = atT ( oo_ . dr . inv_order_var ( bayestopt_ . smoother_var_list ) , : ) ;
2016-09-29 14:32:05 +02:00
end
%reset qz_criterium
options_ . qz_criterium = qz_criterium_old ;
2020-03-03 11:45:38 +01:00
oo_ . gui . ran_calib_smoother = true ;