Home > matlab > evaluate_smoother.m

evaluate_smoother

PURPOSE ^

Evaluate the smoother at parameters.

SYNOPSIS ^

function oo = evaluate_smoother(parameters)

DESCRIPTION ^

 Evaluate the smoother 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 oo       [structure]  results:
                              - SmoothedVariables
                              - SmoothedShocks
                              - SmoothedVariables
                              - SmoothedVariables
                              - SmoothedVariables
                              - SmoothedVariables
                              - SmoothedVariables
                              - SmoothedVariables

 SPECIAL REQUIREMENTS
    None

 REMARKS
 [1] 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 oo = evaluate_smoother(parameters)
0002 % Evaluate the smoother 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 oo       [structure]  results:
0011 %                              - SmoothedVariables
0012 %                              - SmoothedShocks
0013 %                              - SmoothedVariables
0014 %                              - SmoothedVariables
0015 %                              - SmoothedVariables
0016 %                              - SmoothedVariables
0017 %                              - SmoothedVariables
0018 %                              - SmoothedVariables
0019 %
0020 % SPECIAL REQUIREMENTS
0021 %    None
0022 %
0023 % REMARKS
0024 % [1] This function use persistent variables for the dataset and the description of the missing observations. Consequently, if this function
0025 %     is called more than once (by changing the value of parameters) the sample *must not* change.
0026 
0027 % Copyright (C) 2010-2011 Dynare Team
0028 %
0029 % This file is part of Dynare.
0030 %
0031 % Dynare is free software: you can redistribute it and/or modify
0032 % it under the terms of the GNU General Public License as published by
0033 % the Free Software Foundation, either version 3 of the License, or
0034 % (at your option) any later version.
0035 %
0036 % Dynare is distributed in the hope that it will be useful,
0037 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0038 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0039 % GNU General Public License for more details.
0040 %
0041 % You should have received a copy of the GNU General Public License
0042 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0043 
0044 global options_ M_ bayestopt_ oo_
0045 
0046 persistent load_data
0047 persistent gend  data  data_index  number_of_observations  no_more_missing_observations
0048 
0049 if nargin==0
0050     parameters = 'posterior_mode';
0051 end
0052 
0053 if ischar(parameters)
0054     switch parameters
0055       case 'posterior_mode'
0056         parameters = get_posterior_parameters('mode');
0057       case 'posterior_mean'
0058         parameters = get_posterior_parameters('mean');
0059       case 'posterior_median'
0060         parameters = get_posterior_parameters('median');
0061       case 'prior_mode'
0062         parameters = bayestopt_.p5(:);
0063       case 'prior_mean'
0064         parameters = bayestopt_.p1;
0065       case 'calibration'
0066         parameters = [];
0067       otherwise
0068         disp('evaluate_smoother:: If the input argument is a string, then it has to be equal to:')
0069         disp('                     ''posterior_mode'', ')
0070         disp('                     ''posterior_mean'', ')
0071         disp('                     ''posterior_median'', ')
0072         disp('                     ''prior_mode'' or')
0073         disp('                     ''prior_mean''.')
0074         disp('                     ''calibration''.')
0075         error
0076     end
0077 end
0078 
0079 if isempty(load_data)
0080     % Get the data.
0081     n_varobs = size(options_.varobs,1);
0082     rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
0083     options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1);
0084     gend = options_.nobs;
0085     rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
0086     % Transform the data.
0087     if options_.loglinear
0088         if ~options_.logdata
0089             rawdata = log(rawdata);
0090         end
0091     end
0092     % Test if the data set is real.
0093     if ~isreal(rawdata)
0094         error('There are complex values in the data! Probably  a wrong transformation')
0095     end
0096     % Detrend the data.
0097     options_.missing_data = any(any(isnan(rawdata)));
0098     if options_.prefilter == 1
0099         if options_.missing_data
0100             bayestopt_.mean_varobs = zeros(n_varobs,1);
0101             for variable=1:n_varobs
0102                 rdx = find(~isnan(rawdata(:,variable)));
0103                 m = mean(rawdata(rdx,variable));
0104                 rawdata(rdx,variable) = rawdata(rdx,variable)-m;
0105                 bayestopt_.mean_varobs(variable) = m;
0106             end
0107         else
0108             bayestopt_.mean_varobs = mean(rawdata,1)';
0109             rawdata = rawdata-repmat(bayestopt_.mean_varobs',gend,1);
0110         end
0111     end
0112     data = transpose(rawdata);
0113     % Handle the missing observations.
0114     [data_index,number_of_observations,no_more_missing_observations] = describe_missing_data(data,gend,n_varobs);
0115     missing_value = ~(number_of_observations == gend*n_varobs);
0116     % Determine if a constant is needed.
0117     if options_.steadystate_flag% if the *_steadystate.m file is provided.
0118         [ys,tchek] = feval([M_.fname '_steadystate'],...
0119                            [zeros(M_.exo_nbr,1);...
0120                             oo_.exo_det_steady_state]);
0121         if size(ys,1) < M_.endo_nbr
0122             if length(M_.aux_vars) > 0
0123                 ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,...
0124                                                             M_.fname,...
0125                                                             zeros(M_.exo_nbr,1),...
0126                                                             oo_.exo_det_steady_state,...
0127                                                             M_.params,...
0128                                                             options_.bytecode);
0129             else
0130                 error([M_.fname '_steadystate.m doesn''t match the model']);
0131             end
0132         end
0133         oo_.steady_state = ys;
0134     else% if the steady state file is not provided.
0135         [dd,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
0136         oo_.steady_state = dd.ys; clear('dd');
0137     end
0138     if all(abs(oo_.steady_state(bayestopt_.mfys))<1e-9)
0139         options_.noconstant = 1;
0140     else
0141         options_.noconstant = 0;
0142     end
0143     load_data = 1;
0144 end
0145 
0146 pshape_original   = bayestopt_.pshape;
0147 bayestopt_.pshape = Inf(size(bayestopt_.pshape));
0148 clear('priordens')%
0149 
0150 [atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp] ...
0151     = DsgeSmoother(parameters,gend,data,data_index,missing_value);
0152 oo.Smoother.SteadyState = ys;
0153 oo.Smoother.TrendCoeffs = trend_coeff;
0154 if options_.filter_covariance
0155     oo.Smoother.variance = P;
0156 end
0157 i_endo = bayestopt_.smoother_saved_var_list;
0158 if options_.nk ~= 0
0159     oo.FilteredVariablesKStepAhead = ...
0160         aK(options_.filter_step_ahead,i_endo,:);
0161     if ~isempty(PK)
0162         oo.FilteredVariablesKStepAheadVariances = ...
0163             PK(options_.filter_step_ahead,i_endo,i_endo,:);
0164     end
0165     if ~isempty(decomp)
0166         oo.FilteredVariablesShockDecomposition = ...
0167             decomp(options_.filter_step_ahead,i_endo,:,:);
0168     end
0169 end
0170 dr = oo_.dr;
0171 order_var = oo_.dr.order_var;
0172 for i=bayestopt_.smoother_saved_var_list'
0173     i1 = order_var(bayestopt_.smoother_var_list(i));
0174     eval(['oo.SmoothedVariables.' deblank(M_.endo_names(i1,:)) ' = atT(i,:)'';']);
0175     eval(['oo.FilteredVariables.' deblank(M_.endo_names(i1,:)) ' = squeeze(aK(1,i,:));']);
0176     eval(['oo.UpdatedVariables.' deblank(M_.endo_names(i1,:)) ' = updated_variables(i,:)'';']);
0177 end
0178 for i=1:M_.exo_nbr
0179     eval(['oo.SmoothedShocks.' deblank(M_.exo_names(i,:)) ' = innov(i,:)'';']);
0180 end
0181 
0182 oo.dr = oo_.dr;
0183 
0184 bayestopt_.pshape = pshape_original;

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