From fe48de44068224552813e264313d0dc94b2915d4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 8 Apr 2015 15:44:39 +0200 Subject: [PATCH 1/4] Re-set default of new option diffuse_kalman_tol to 1e-6: former hardcoded value was 1e-6 in the univariate smoother (i.e. the one most often used). Updated documentation. --- doc/dynare.texi | 2 +- matlab/global_initialization.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 094089cb4..f107bbf98 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -5222,7 +5222,7 @@ singularity is encountered, Dynare by default automatically switches to the univ @anchor{kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors during the Kalman filter (minimum allowed reciprocal of the matrix condition number). Default value is @code{1e-10} @item diffuse_kalman_tol = @var{DOUBLE} -@anchor{diffuse_kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors (@math{F_{\infty}}) and the rank of the covariance matrix of the state variables (@math{P_{\infty}}) during the Diffuse Kalman filter. Default value is @code{1e-8} +@anchor{diffuse_kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors (@math{F_{\infty}}) and the rank of the covariance matrix of the non-stationary state variables (@math{P_{\infty}}) during the Diffuse Kalman filter. Default value is @code{1e-6} @item filter_covariance @anchor{filter_covariance} Saves the series of one step ahead error of diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index f169bfe6a..93deba482 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -387,7 +387,7 @@ options_.nobs = NaN; options_.kalman_algo = 0; options_.fast_kalman = 0; options_.kalman_tol = 1e-10; -options_.diffuse_kalman_tol = 1e-8; +options_.diffuse_kalman_tol = 1e-6; options_.use_univariate_filters_if_singularity_is_detected = 1; options_.riccati_tol = 1e-6; options_.lik_algo = 1; From ca8f0ea006e4ec9ecb38165a5bc3d2297313ca8c Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 8 Apr 2015 15:49:12 +0200 Subject: [PATCH 2/4] Harmonize filters/likelihood with smoothers by using new option diffuse_kalman_tol --- matlab/dsge_likelihood.m | 7 ++++--- matlab/kalman/likelihood/kalman_filter_d.m | 9 ++++----- .../likelihood/missing_observations_kalman_filter_d.m | 9 ++++----- matlab/kalman/likelihood/univariate_kalman_filter_d.m | 9 ++++----- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index aae1224e4..41b326c14 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -328,6 +328,7 @@ mm = length(T); pp = DynareDataset.vobs; rr = length(Q); kalman_tol = DynareOptions.kalman_tol; +diffuse_kalman_tol = DynareOptions.kalman_tol; riccati_tol = DynareOptions.riccati_tol; Y = transpose(DynareDataset.data)-trend; @@ -405,13 +406,13 @@ switch DynareOptions.lik_init if no_missing_data_flag [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, 1, size(Y,2), ... zeros(mm,1), Pinf, Pstar, ... - kalman_tol, riccati_tol, DynareOptions.presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... T,R,Q,H,Z,mm,pp,rr); else [dLIK,dlik,a,Pstar] = missing_observations_kalman_filter_d(DatasetInfo.missing.aindex,DatasetInfo.missing.number_of_observations,DatasetInfo.missing.no_more_missing_observations, ... Y, 1, size(Y,2), ... zeros(mm,1), Pinf, Pstar, ... - kalman_tol, riccati_tol, DynareOptions.presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... T,R,Q,H,Z,mm,pp,rr); end diffuse_periods = length(dlik); @@ -448,7 +449,7 @@ switch DynareOptions.lik_init DatasetInfo.missing.no_more_missing_observations, ... Y, 1, size(Y,2), ... zeros(mmm,1), Pinf, Pstar, ... - kalman_tol, riccati_tol, DynareOptions.presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... T,R,Q,H1,Z,mmm,pp,rr); diffuse_periods = size(dlik,1); end diff --git a/matlab/kalman/likelihood/kalman_filter_d.m b/matlab/kalman/likelihood/kalman_filter_d.m index bbec1fe7c..3b1161b75 100644 --- a/matlab/kalman/likelihood/kalman_filter_d.m +++ b/matlab/kalman/likelihood/kalman_filter_d.m @@ -1,4 +1,4 @@ -function [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, start, last, a, Pinf, Pstar, kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) +function [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, start, last, a, Pinf, Pstar, kalman_tol, diffuse_kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) % Computes the diffuse likelihood of a state space model. % % INPUTS @@ -59,14 +59,13 @@ dlik = zeros(smpl,1); % Initialization of the vector gathering the densitie dLIK = Inf; % Default value of the log likelihood. oldK = Inf; s = 0; -crit1=1.e-6; -while rank(Pinf,crit1) && (t<=last) +while rank(Pinf,diffuse_kalman_tol) && (t<=last) s = t-start+1; v = Y(:,t)-Z*a; Finf = Z*Pinf*Z'; - if rcond(Finf) < kalman_tol - if ~all(abs(Finf(:)) < kalman_tol) + if rcond(Finf) < diffuse_kalman_tol + if ~all(abs(Finf(:)) < diffuse_kalman_tol) % The univariate diffuse kalman filter should be used instead. return else diff --git a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m index c09194820..008e1aa89 100644 --- a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m +++ b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m @@ -1,7 +1,7 @@ function [dLIK,dlik,a,Pstar] = missing_observations_kalman_filter_d(data_index,number_of_observations,no_more_missing_observations, ... Y, start, last, ... a, Pinf, Pstar, ... - kalman_tol, riccati_tol, presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, presample, ... T, R, Q, H, Z, mm, pp, rr) % Computes the diffuse likelihood of a state space model when some observations are missing. % @@ -66,14 +66,13 @@ t = start; % Initialization of the time index. dlik = zeros(smpl,1); % Initialization of the vector gathering the densities. dLIK = Inf; % Default value of the log likelihood. oldK = Inf; -crit1=1.e-6; if isequal(H,0) H = zeros(pp,pp); end s = 0; -while rank(Pinf,crit1) && (t<=last) +while rank(Pinf,diffuse_kalman_tol) && (t<=last) s = t-start+1; d_index = data_index{t}; if isempty(d_index) @@ -84,8 +83,8 @@ while rank(Pinf,crit1) && (t<=last) ZZ = Z(d_index,:); v = Y(d_index,t)-ZZ*a; Finf = ZZ*Pinf*ZZ'; - if rcond(Finf) < kalman_tol - if ~all(abs(Finf(:)) < kalman_tol) + if rcond(Finf) < diffuse_kalman_tol + if ~all(abs(Finf(:)) < diffuse_kalman_tol) % The univariate diffuse kalman filter should be used. return else diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_d.m b/matlab/kalman/likelihood/univariate_kalman_filter_d.m index e3368a6c1..0782f9507 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter_d.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter_d.m @@ -1,4 +1,4 @@ -function [dLIK, dlikk, a, Pstar, llik] = univariate_kalman_filter_d(data_index, number_of_observations, no_more_missing_observations, Y, start, last, a, Pinf, Pstar, kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) +function [dLIK, dlikk, a, Pstar, llik] = univariate_kalman_filter_d(data_index, number_of_observations, no_more_missing_observations, Y, start, last, a, Pinf, Pstar, kalman_tol, diffuse_kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) % Computes the likelihood of a state space model (initialization with diffuse steps, univariate approach). %@info: @@ -110,8 +110,7 @@ dLIK = Inf; % Default value of the log likelihood. oldK = Inf; llik = zeros(smpl,pp); -crit1 = 1.e-6; -newRank = rank(Pinf,crit1); +newRank = rank(Pinf,diffuse_kalman_tol); l2pi = log(2*pi); while newRank && (t<=last) @@ -139,7 +138,7 @@ while newRank && (t<=last) end end if newRank - oldRank = rank(Pinf,crit1); + oldRank = rank(Pinf,diffuse_kalman_tol); else oldRank = 0; end @@ -147,7 +146,7 @@ while newRank && (t<=last) Pstar = T*Pstar*T'+QQ; Pinf = T*Pinf*T'; if newRank - newRank = rank(Pinf,crit1); + newRank = rank(Pinf,diffuse_kalman_tol); end if oldRank ~= newRank disp('univariate_diffuse_kalman_filter:: T does influence the rank of Pinf!') From b49388891f4bf0cbbbc5a2b960b9fd7542b6a0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 14 Apr 2015 11:56:11 +0200 Subject: [PATCH 3/4] Moved README file for extended preprocessor in subfolder. --- .../README.extended-preprocessor.org | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.extended-preprocessor.org => README/README.extended-preprocessor.org (100%) diff --git a/README.extended-preprocessor.org b/README/README.extended-preprocessor.org similarity index 100% rename from README.extended-preprocessor.org rename to README/README.extended-preprocessor.org From f5cf7617a6a84f98a212c2830957c1c022b8a5cd Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 14:47:26 +0200 Subject: [PATCH 4/4] preprocessor: method out of order --- preprocessor/ComputingTasks.cc | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 889694726..76ed6faad 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2818,6 +2818,33 @@ CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const writeOptionsOutput(output, lhs_field, name1); } +void +CorrOptionsStatement::writeCOutput(ostream &output, const string &basename) +{ + output << endl + << "index = "; + if (is_structural_innovation(symbol_table.getType(name))) + output << "exo_names"; + else + output << "endo_names"; + output << "[\""<< name << "\"];" << endl; + + output << "index1 = "; + if (is_structural_innovation(symbol_table.getType(name1))) + output << "exo_names"; + else + output << "endo_names"; + output << "[\""<< name1 << "\"];" << endl; + + writeCOutputHelper(output, "init"); + + if (is_structural_innovation(symbol_table.getType(name))) + output << "msdsgeinfo->addStructuralInnovationCorrOption(new ModFileStructuralInnovationCorrOption("; + else + output << "msdsgeinfo->addMeasurementErrorCorrOption(new ModFileMeasurementErrorCorrOption("; + output << "index, index1, init));" << endl; +} + OptionsEqualStatement::OptionsEqualStatement(const string &to_declaration_type_arg, const string &to_name1_arg, const string &to_name2_arg, @@ -2985,33 +3012,6 @@ ModelDiagnosticsStatement::writeOutput(ostream &output, const string &basename) output << "model_diagnostics(M_,options_,oo_);" << endl; } -void -CorrOptionsStatement::writeCOutput(ostream &output, const string &basename) -{ - output << endl - << "index = "; - if (is_structural_innovation(symbol_table.getType(name))) - output << "exo_names"; - else - output << "endo_names"; - output << "[\""<< name << "\"];" << endl; - - output << "index1 = "; - if (is_structural_innovation(symbol_table.getType(name1))) - output << "exo_names"; - else - output << "endo_names"; - output << "[\""<< name1 << "\"];" << endl; - - writeCOutputHelper(output, "init"); - - if (is_structural_innovation(symbol_table.getType(name))) - output << "msdsgeinfo->addStructuralInnovationCorrOption(new ModFileStructuralInnovationCorrOption("; - else - output << "msdsgeinfo->addMeasurementErrorCorrOption(new ModFileMeasurementErrorCorrOption("; - output << "index, index1, init));" << endl; -} - Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_list_arg) : options_list(options_list_arg) {