From 911ca2a54fa6d32f1e516119cd558c3f9da1cb83 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Nov 2017 18:57:26 +0100 Subject: [PATCH 01/51] Add preprocessor interface for fast_realtime option of --- doc/dynare.texi | 5 +++++ preprocessor/DynareBison.yy | 4 +++- preprocessor/DynareFlex.ll | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 1c60a3f5a..a25bf1792 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7543,6 +7543,11 @@ realtime shock decompositions are computed, @i{i.e.} for @item save_realtime = @var{INTEGER_VECTOR} @anchor{save_realtime} Choose for which vintages to save the full realtime shock decomposition. Default: @math{0}. + +@item fast_realtime +@anchor{fast_realtime} Runs the smoother only twice: once for the last in-sample +and once for the last out-of-sample data point. Default: not enabled. + @end table @outputhead diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 801aa600d..97c455149 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -113,7 +113,7 @@ class ParsingDriver; %token CPF_WEIGHTS AMISANOTRISTANI MURRAYJONESPARSLOW WRITE_EQUATION_TAGS %token NONLINEAR_FILTER_INITIALIZATION FILTER_ALGORITHM PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION %token NAME -%token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE RESCALE_PREDICTION_ERROR_COVARIANCE GENERATE_IRFS +%token USE_PENALIZED_OBJECTIVE_FOR_HESSIAN INIT_STATE FAST_REALTIME RESCALE_PREDICTION_ERROR_COVARIANCE GENERATE_IRFS %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS NO_HOMOTOPY %token NOGRAPH POSTERIOR_NOGRAPH POSTERIOR_GRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS STDERR_MULTIPLES DIAGONAL_ONLY %token OBSERVATION_TRENDS OPTIM OPTIM_WEIGHTS ORDER OSR OSR_PARAMS MAX_DIM_COVA_GROUP ADVANCED OUTFILE OUTVARS OVERWRITE @@ -2687,6 +2687,7 @@ realtime_shock_decomposition_option : o_parameter_set | o_shock_decomposition_presample | o_shock_decomposition_forecast | o_save_realtime + | o_fast_realtime ; plot_shock_decomposition_options_list : plot_shock_decomposition_option COMMA plot_shock_decomposition_options_list @@ -3095,6 +3096,7 @@ o_init_state : INIT_STATE EQUAL INT_NUMBER { driver.option_num("shock_decomp.ini o_shock_decomposition_presample : PRESAMPLE EQUAL INT_NUMBER { driver.option_num("shock_decomp.presample", $3); }; o_shock_decomposition_forecast : FORECAST EQUAL INT_NUMBER { driver.option_num("shock_decomp.forecast", $3); }; o_save_realtime : SAVE_REALTIME EQUAL vec_int { driver.option_vec_int("shock_decomp.save_realtime", $3); }; +o_fast_realtime : FAST_REALTIME { driver.option_num("shock_decomp.fast_realtime", "1"); }; o_nodisplay : NODISPLAY { driver.option_num("nodisplay","1"); }; o_psd_nodisplay : NODISPLAY { driver.option_num("plot_shock_decomp.nodisplay","1"); }; o_graph_format : GRAPH_FORMAT EQUAL allowed_graph_formats diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index c35b8a011..db43397d6 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -584,6 +584,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 controlled_varexo {return token::CONTROLLED_VAREXO; } parameter_set {return token::PARAMETER_SET; } init_state {return token::INIT_STATE; } +fast_realtime {return token::FAST_REALTIME; } save_realtime {return token::SAVE_REALTIME;} detail_plot {return token::DETAIL_PLOT;} interactive {return token::INTERACTIVE;} From 0d11246c3562fb7a4d0d2f5d474bb17b05837093 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Nov 2017 19:04:01 +0100 Subject: [PATCH 02/51] Add fast_realtime option to integration test --- tests/shock_decomposition/ls2003_plot.mod | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/shock_decomposition/ls2003_plot.mod b/tests/shock_decomposition/ls2003_plot.mod index 7faa00d0c..69e8774f8 100644 --- a/tests/shock_decomposition/ls2003_plot.mod +++ b/tests/shock_decomposition/ls2003_plot.mod @@ -129,6 +129,12 @@ close all plot_shock_decomposition(detail_plot, interactive, use_shock_groups = row, type = qoq); plot_shock_decomposition(detail_plot, interactive, realtime = 3, vintage = 29); +close all, + + +// testing realtime decomposition with fast_realtime option +realtime_shock_decomposition(fast_realtime); + collect_latex_files; if system(['pdflatex -halt-on-error -interaction=batchmode ' M_.fname '_TeX_binder.tex']) error('TeX-File did not compile.') From b4204f8b9ecbfe63b660bb019169e2f352730f8c Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 11 Jan 2018 22:08:03 +0100 Subject: [PATCH 03/51] Make sure that mean and covariance of data are correctly computed with only one observation Need to always compute mean along first dimension (cherry picked from commit 2d371b1997f5fa07fcbbf47e5923d7817d07c6b9) --- matlab/utilities/dataset/makedataset.m | 2 +- matlab/utilities/dataset/nancovariance.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/utilities/dataset/makedataset.m b/matlab/utilities/dataset/makedataset.m index c5c244b54..a26a074c5 100644 --- a/matlab/utilities/dataset/makedataset.m +++ b/matlab/utilities/dataset/makedataset.m @@ -267,7 +267,7 @@ else end % Compute the empirical mean of the observed variables. -DatasetInfo.descriptive.mean = nanmean(DynareDataset.data); +DatasetInfo.descriptive.mean = nanmean(DynareDataset.data,1); % Compute the empirical covariance matrix of the observed variables. DatasetInfo.descriptive.covariance = nancovariance(DynareDataset.data); diff --git a/matlab/utilities/dataset/nancovariance.m b/matlab/utilities/dataset/nancovariance.m index 8e2e2b227..09f2a38af 100644 --- a/matlab/utilities/dataset/nancovariance.m +++ b/matlab/utilities/dataset/nancovariance.m @@ -51,7 +51,7 @@ function CovarianceMatrix = nancovariance(data) CovarianceMatrix = zeros(size(data,2)); if isanynan(data) - data = bsxfun(@minus,data,nanmean(data)); + data = bsxfun(@minus,data,nanmean(data,1)); for i=1:size(data,2) for j=i:size(data,2) CovarianceMatrix(i,j) = nanmean(data(:,i).*data(:,j)); @@ -61,7 +61,7 @@ if isanynan(data) end end else - data = bsxfun(@minus,data,mean(data)); + data = bsxfun(@minus,data,mean(data,1)); CovarianceMatrix = (transpose(data)*data)/size(data,1); end From ec35210e06ac45a46da52c272d78173990cb92c4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 14 Nov 2017 18:08:19 +0100 Subject: [PATCH 04/51] - bug fix for when NO parameter is detected below pvalue threshold - fix to the case when no plot is done when there are too few behavioral/non-behavioral runs [as it already happens when one of the two sets is empty] - added more explicit messages on screen --- matlab/gsa/redform_map.m | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/matlab/gsa/redform_map.m b/matlab/gsa/redform_map.m index fbc56af00..4e5923ceb 100644 --- a/matlab/gsa/redform_map.m +++ b/matlab/gsa/redform_map.m @@ -232,10 +232,27 @@ for j = 1:length(anamendo) istable=[1:length(iy)]; save([xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namexo '_threshold' ],'lpmat','lpmat0','istable','y0','x0','xx0','iy','iyc') lpmat=[]; lpmat0=[]; istable=[]; + if length(iy)<=10 || length(iyc)<=10 + icheck = []; % do the generic plot in any case + end else icheck=[]; end if isempty(icheck) + if length(iy)<=10 + if isempty(iy) + disp(['There are NO MC samples in the desired range [' num2str(threshold) ']!']) + else + disp(['There are TOO FEW (<=10) MC samples in the desired range [' num2str(threshold) ']!']) + end + elseif length(iyc)<=10 + if isempty(iyc) + disp(['ALL MC samples are in the desired range [' num2str(threshold) ']!']) + else + disp(['Almost ALL MC samples are in the desired range [' num2str(threshold) ']!']) + disp('There are TOO FEW (<=10) MC samples OUTSIDE the desired range!') + end + end atitle0=['Monte Carlo Filtering for ',namendo,' vs ', namexo]; options_mcf.title = atitle0; indmcf = redform_mcf(y0, x0, options_mcf, options_); @@ -280,6 +297,8 @@ for j = 1:length(anamendo) end end + else + disp(['This entry in the shock matrix is CONSTANT = ' num2str(mean(y0),3)]) end end end @@ -369,11 +388,28 @@ for j = 1:length(anamendo) istable=[1:length(iy)]; save([xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namlagendo '_threshold' ],'lpmat','lpmat0','istable','y0','x0','xx0','iy','iyc') lpmat=[]; lpmat0=[]; istable=[]; + if length(iy)<=10 || length(iyc)<=10, + icheck = []; % do the generic plot in any case + end else icheck = []; end if isempty(icheck) + if length(iy)<=10 + if isempty(iy) + disp(['There are NO MC samples in the desired range [' num2str(threshold) ']!']) + else + disp(['There are TOO FEW (<=10) MC samples in the desired range [' num2str(threshold) ']!']) + end + elseif length(iyc)<=10 + if isempty(iyc) + disp(['ALL MC samples are in the desired range [' num2str(threshold) ']!']) + else + disp(['Almost ALL MC samples are in the desired range [' num2str(threshold) ']!']) + disp('There are TOO FEW (<=10) MC samples OUTSIDE the desired range!') + end + end atitle0=['Monte Carlo Filtering for ',namendo,' vs ', namlagendo]; options_mcf.title = atitle0; indmcf = redform_mcf(y0, x0, options_mcf, options_); @@ -417,6 +453,8 @@ for j = 1:length(anamendo) end end + else + disp(['This entry in the transition matrix is CONSTANT = ' num2str(mean(y0),3)]) end end end @@ -736,6 +774,11 @@ for jt=1:10 end [proba, dproba] = stab_map_1(x0, indy{1}, indy{end}, [],0); indmcf=find(proba Date: Sat, 13 Jan 2018 00:10:50 +0100 Subject: [PATCH 05/51] Added second input argument to missing/nanmean routine. This additional argument is optional and can be used to specify along which dimension the mean has to be computed. Fixes the bug introduced in b4204f8b9ecbfe63b660bb019169e2f352730f8c for those who do not have the statistics toolbox. --- matlab/missing/nanmean/nanmean.m | 83 +++++++++++++++++--------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/matlab/missing/nanmean/nanmean.m b/matlab/missing/nanmean/nanmean.m index 6b66bad0f..9babd1460 100644 --- a/matlab/missing/nanmean/nanmean.m +++ b/matlab/missing/nanmean/nanmean.m @@ -1,36 +1,20 @@ -function y = nanmean(x) -% Computes the mean of each column of a matrix with some NaNs. +function y = nanmean(x, dim) -%@info: -%! @deftypefn {Function File} {@var{y} =} nanmean (@var{x}) -%! @anchor{nanmean} -%! @sp 1 -%! Computes the mean of each column of a matrix with some NaNs. -%! @sp 2 -%! @strong{Inputs} -%! @table @ @var -%! @item x -%! Matlab matrix (T-by-N). -%! @end table -%! @sp 2 -%! @strong{Outputs} -%! @table @ @var -%! @item y -%! Matlab vector (1-by-N), the mean. -%! @end table -%! @sp 2 -%! @strong{This function is called by:} -%! @sp 1 -%! @ref{compute_cova}, @ref{compute_acov}, @ref{compute_std}, @ref{nandemean} -%! @sp 2 -%! @strong{This function calls:} -%! @sp 1 -%! @ref{ndim} -%! -%! @end deftypefn -%@eod: +% Returns the mean of a matrix with some NaNs. +% +% INPUTS +% - x [double] m*n matrix +% - dim [integer] scalar, dimension along which the mean has to be computed. +% +% OUTPUTS +% - y [double] 1*n vector (if dim=1) or m*1 vector (if dim=2). +% +% REMARKS +% (1) Default value for dim is the first non singleton dimension. +% (2) Works with vector and matrices, not implemented for arrays with more +% than two dimensions. -% Copyright (C) 2011 Dynare Team +% Copyright (C) 2011-2018 Dynare Team % % This file is part of Dynare. % @@ -47,16 +31,39 @@ function y = nanmean(x) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr +if nargin<2 + % By default dim is the first non singleton dimension + nonsingletondims = find(find(size(x)>1)); + if ~isempty(nonsingletondims) + dim = nonsingletondims(1); + else + dim = NaN; + end +end -switch ndim(x) +switch ndims(x) case 1 - y = mean(x(find(~isnan(x)))); + if isnan(dim) + y = x; + else + y = mean(x(find(~isnan(x))), dim); + end case 2 - y = NaN(1,size(x,2)); - for i = 1:size(x,2) - y(i) = mean(x(find(~isnan(x(:,i))),i)); + if isnan(dim) + y = x; + else + if isequal(dim, 1) + y = NaN(1, size(x, 2)); + for i = 1:size(x, 2) + y(i) = mean(x(find(~isnan(x(:,i))),i)); + end + else + y = NaN(size(x, 1), 1); + for i = 1:size(x, 1) + y(i) = mean(x(i, find(~isnan(x(i,:))))); + end + end end otherwise - error('descriptive_statistics::nanmean:: This function is not implemented for arrays with dimension greater than two!') + error('This function is not implemented for arrays with dimension greater than two!') end \ No newline at end of file From 92549e48b12c60165693f9ea1289825e88b35cdd Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 20 Jan 2018 08:26:00 +0100 Subject: [PATCH 06/51] Make demean.m use nanmean Otherwise estimation with missing observations and prefilter option will crash --- matlab/utilities/general/demean.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/utilities/general/demean.m b/matlab/utilities/general/demean.m index 741a2f107..b9dda8d13 100644 --- a/matlab/utilities/general/demean.m +++ b/matlab/utilities/general/demean.m @@ -47,9 +47,9 @@ function c = demean(x) % Original author: stephane DOT adjemian AT univ DASH lemans DOT fr if ndim(x)==1 - c = x-mean(x); + c = x-nanmean(x); elseif ndim(x)==2 - c = bsxfun(@minus,x,mean(x)); + c = bsxfun(@minus,x,nanmean(x)); else error('descriptive_statistics::demean:: This function is not implemented for arrays with dimension greater than two!') end \ No newline at end of file From 204d9cd05fef9ac6fda8530536578c05fab66366 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 23 Jan 2018 16:31:33 +0100 Subject: [PATCH 07/51] macroprocessor: interpret arrays passed on the command line as arrays instead of strings. closes #1578 --- preprocessor/macro/MacroDriver.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/preprocessor/macro/MacroDriver.cc b/preprocessor/macro/MacroDriver.cc index bd15152b3..446a9a9e6 100644 --- a/preprocessor/macro/MacroDriver.cc +++ b/preprocessor/macro/MacroDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2017 Dynare Team + * Copyright (C) 2008-2018 Dynare Team * * This file is part of Dynare. * @@ -60,7 +60,11 @@ MacroDriver::parse(const string &f, const string &fb, const string &modfiletxt, } catch (boost::bad_lexical_cast &) { - file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; + if (it->second.front() == '[' && it->second.back() == ']') + // If the input is an array. Issue #1578 + file_with_endl << "@#define " << it->first << " = " << it->second << endl; + else + file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; } file_with_endl << modfiletxt << endl; From 82de9c1d1855a593ee7227c9ad0edaef997c8dd2 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 23 Jan 2018 17:13:46 +0100 Subject: [PATCH 08/51] macroprocessor: allow inline comments. closes #1550 --- preprocessor/macro/MacroFlex.ll | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/preprocessor/macro/MacroFlex.ll b/preprocessor/macro/MacroFlex.ll index 5125ffa73..577767098 100644 --- a/preprocessor/macro/MacroFlex.ll +++ b/preprocessor/macro/MacroFlex.ll @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2017 Dynare Team + * Copyright (C) 2008-2018 Dynare Team * * This file is part of Dynare. * @@ -71,6 +71,8 @@ CONT \\\\ yylloc->step(); %} +["/"]["/"].* + ^{SPC}*@#{SPC}*includepath{SPC}+\"([^\"\r\n:;|<>]*){1}(:[^\"\r\n:;|<>]*)*\"{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); From 145f1e7b1cc71281bf9c32e5c4a1f092c000755d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 24 Jan 2018 15:59:04 +0100 Subject: [PATCH 09/51] Streamlined code by removing unnecessary conditions. --- matlab/utilities/general/demean.m | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/matlab/utilities/general/demean.m b/matlab/utilities/general/demean.m index b9dda8d13..dffd31444 100644 --- a/matlab/utilities/general/demean.m +++ b/matlab/utilities/general/demean.m @@ -44,12 +44,8 @@ function c = demean(x) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr +if ndim(x)>2 + error('This function is not implemented for arrays with dimension greater than two!') +end -if ndim(x)==1 - c = x-nanmean(x); -elseif ndim(x)==2 - c = bsxfun(@minus,x,nanmean(x)); -else - error('descriptive_statistics::demean:: This function is not implemented for arrays with dimension greater than two!') -end \ No newline at end of file +c = bsxfun(@minus, x, nanmean(x)); \ No newline at end of file From e6cc7d6a7f76854dee1d2077300778b6d41fa283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 24 Jan 2018 15:59:47 +0100 Subject: [PATCH 10/51] Rewrote header. --- matlab/utilities/general/demean.m | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/matlab/utilities/general/demean.m b/matlab/utilities/general/demean.m index dffd31444..c56c47367 100644 --- a/matlab/utilities/general/demean.m +++ b/matlab/utilities/general/demean.m @@ -1,33 +1,14 @@ function c = demean(x) + % Removes the mean of each column of a matrix. +% +% INPUTS +% - x [double] T*N matrix of data. +% +% OUTPUTS +% - c [double] T*N matrix of demeaned data. -%@info: -%! @deftypefn {Function File} {@var{c} =} demean (@var{x}) -%! @anchor{demean} -%! This function removes the mean of each column of a matrix. -%! -%! @strong{Inputs} -%! @table @var -%! @item x -%! Matlab matrix (T-by-N). -%! @end table -%! -%! @strong{Outputs} -%! @table @var -%! @item c -%! Matlab matrix (T-by-N). The demeaned x matrix. -%! @end table -%! -%! @strong{This function is called by:} -%! @ref{compute_cova}, @ref{compute_acov}, @ref{compute_std}. -%! -%! @strong{This function calls:} -%! @ref{ndim}, -%! -%! @end deftypefn -%@eod: - -% Copyright (C) 2011-2017 Dynare Team +% Copyright (C) 2011-2018 Dynare Team % % This file is part of Dynare. % From 99e4cb6e7e18385c5ef8ab7fc74ac40207ce9940 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 1 Dec 2017 13:48:13 +0100 Subject: [PATCH 11/51] evaluate_steady_state_file.m: Condition call to str2func on function being present Workaround for Octave bug https://savannah.gnu.org/bugs/?52568 --- matlab/evaluate_steady_state_file.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/matlab/evaluate_steady_state_file.m b/matlab/evaluate_steady_state_file.m index 104ae71e5..cecf3ec50 100644 --- a/matlab/evaluate_steady_state_file.m +++ b/matlab/evaluate_steady_state_file.m @@ -70,7 +70,9 @@ else updated_params_flag = 0; end -h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); +if M.set_auxiliary_variables %otherwise Octave may crash, see https://savannah.gnu.org/bugs/?52568 + h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); +end if isnan(updated_params_flag) || (updated_params_flag && any(isnan(params(~isnan(params))-params1(~isnan(params))))) %checks if new NaNs were added info(1) = 24; info(2) = NaN; From ad0bff3771730f76cec1d568d7cdd7ec94a131da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 24 Jan 2018 17:24:21 +0100 Subject: [PATCH 12/51] Added comments. --- matlab/evaluate_steady_state_file.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/matlab/evaluate_steady_state_file.m b/matlab/evaluate_steady_state_file.m index cecf3ec50..be84e6f39 100644 --- a/matlab/evaluate_steady_state_file.m +++ b/matlab/evaluate_steady_state_file.m @@ -70,9 +70,14 @@ else updated_params_flag = 0; end -if M.set_auxiliary_variables %otherwise Octave may crash, see https://savannah.gnu.org/bugs/?52568 +if M.set_auxiliary_variables + % Define function handle for the function setting the auxiliary + % variables only if the model has auxiliary variables. Otherwise + % Octave may crash (see https://savannah.gnu.org/bugs/?52568) because + % the function does not exist in the path. h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']); end + if isnan(updated_params_flag) || (updated_params_flag && any(isnan(params(~isnan(params))-params1(~isnan(params))))) %checks if new NaNs were added info(1) = 24; info(2) = NaN; From 28b499af3bb53fc8afd02e209f8120e241e519e6 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Nov 2017 15:46:57 +0100 Subject: [PATCH 13/51] Filter out cases where stochastic_solvers.m is called at higher order without k_order_solver --- matlab/stochastic_solvers.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/matlab/stochastic_solvers.m b/matlab/stochastic_solvers.m index e958056c2..6ba76fd5f 100644 --- a/matlab/stochastic_solvers.m +++ b/matlab/stochastic_solvers.m @@ -29,7 +29,7 @@ function [dr,info] = stochastic_solvers(dr,task,M_,options_,oo_) % none. % -% Copyright (C) 1996-2017 Dynare Team +% Copyright (C) 1996-2018 Dynare Team % % This file is part of Dynare. % @@ -57,6 +57,9 @@ if M_.hessian_eq_zero && local_order~=1 local_order = 1; warning('stochastic_solvers: using order = 1 because Hessian is equal to zero'); end +if options_.order>2 && ~options_.k_order_solver + error('You need to set k_order_solver for order>2') +end if (options_.aim_solver == 1) && (local_order > 1) error('Option "aim_solver" is incompatible with order >= 2') From c7a860e6b68059d55e039cdceff7f642457cd927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 24 Jan 2018 18:22:45 +0100 Subject: [PATCH 14/51] Fixed bug in interactive choice of the endogenous variables. Bug introduced when we replaced the character arrays by cell of row character arrays. Closes #1577. --- matlab/check_list_of_variables.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/matlab/check_list_of_variables.m b/matlab/check_list_of_variables.m index 332372665..8fabffe54 100644 --- a/matlab/check_list_of_variables.m +++ b/matlab/check_list_of_variables.m @@ -31,8 +31,7 @@ function varlist = check_list_of_variables(options_, M_, varlist) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -%get uniques - +% Get uniques [junk1, junk2, index_uniques] = varlist_indices(varlist, M_.endo_names); varlist = varlist(index_uniques); @@ -130,7 +129,7 @@ elseif isempty(varlist) && isempty(options_.endo_vars_for_moment_computations_in elseif choice==2 varlist = options_.varobs; elseif choice==3 - varlist = NaN; + varlist = cell(0); else skipline() disp('YOU HAVE TO ANSWER 1, 2 or 3!') @@ -138,7 +137,7 @@ elseif isempty(varlist) && isempty(options_.endo_vars_for_moment_computations_in end end end - if isnan(varlist) + if isempty(varlist) edit([M_.fname '.mod']) end skipline() From 4d89452e1bb6cc55f0800d6cbf976f2519f822c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 24 Jan 2018 22:15:57 +0100 Subject: [PATCH 15/51] Revert "macroprocessor: interpret arrays passed on the command line as arrays instead of strings. closes #1578" Commit 204d9cd05fef9ac6fda8530536578c05fab66366 fails with gcc 4.9 (I checked that it works flawlessly with 6.x). The error message is: MacroDriver.cc:63:24: error: 'class std::basic_string' has no member named 'front' if (it->second.front() == '[' && it->second.back() == ']') ^ MacroDriver.cc:63:53: error: 'class std::basic_string' has no member named 'back' if (it->second.front() == '[' && it->second.back() == ']') Ideally we should bump the version of gcc used in the build system, but I will not do that before the next bug fix release. I suppose it is easier to replace the front() and back() methods. --- preprocessor/macro/MacroDriver.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/preprocessor/macro/MacroDriver.cc b/preprocessor/macro/MacroDriver.cc index 446a9a9e6..bd15152b3 100644 --- a/preprocessor/macro/MacroDriver.cc +++ b/preprocessor/macro/MacroDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2018 Dynare Team + * Copyright (C) 2008-2017 Dynare Team * * This file is part of Dynare. * @@ -60,11 +60,7 @@ MacroDriver::parse(const string &f, const string &fb, const string &modfiletxt, } catch (boost::bad_lexical_cast &) { - if (it->second.front() == '[' && it->second.back() == ']') - // If the input is an array. Issue #1578 - file_with_endl << "@#define " << it->first << " = " << it->second << endl; - else - file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; + file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; } file_with_endl << modfiletxt << endl; From ef797eec0f59b5e363966cd90776e76ec8c2f5f8 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Nov 2017 11:05:12 +0100 Subject: [PATCH 16/51] mode_check.m: account for case where bounds are infinite and not plots are shown --- matlab/mode_check.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/matlab/mode_check.m b/matlab/mode_check.m index 3131f10cc..b9a24e315 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -111,14 +111,22 @@ for plt = 1:nbplt end end xx = x; - if x(kk)~=0 + if x(kk)~=0 || ~isinf(BoundsInfo.lb(kk)) || ~isinf(BoundsInfo.lb(kk)) l1 = max(BoundsInfo.lb(kk),(1-sign(x(kk))*ll)*x(kk)); m1 = 0; %lower bound l2 = min(BoundsInfo.ub(kk),(1+sign(x(kk))*ll)*x(kk)); %upper bound else %size info for 0 parameter is missing, use prior standard %deviation - l1 = max(BoundsInfo.lb(kk),-BayesInfo.p2(kk)); m1 = 0; %lower bound - l2 = min(BoundsInfo.ub(kk),BayesInfo.p2(kk)); %upper bound + upper_bound=BoundsInfo.lb(kk); + if isinf(upper_bound) + upper_bound=-1e-6*DynareOptions.huge_number; + end + lower_bound=BoundsInfo.ub(kk); + if isinf(lower_bound) + lower_bound=-1e-6*DynareOptions.huge_number; + end + l1 = max(lower_bound,-BayesInfo.p2(kk)); m1 = 0; %lower bound + l2 = min(upper_bound,BayesInfo.p2(kk)); %upper bound end binding_lower_bound=0; binding_upper_bound=0; From 3a6227387b497d90d00a117777020ad0191c0988 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 25 Jan 2018 00:47:50 +0100 Subject: [PATCH 17/51] Fix commit reverted in 4d89452e1bb6cc55f0800d6cbf976f2519f822c1. --- preprocessor/macro/MacroDriver.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/preprocessor/macro/MacroDriver.cc b/preprocessor/macro/MacroDriver.cc index bd15152b3..b0420b441 100644 --- a/preprocessor/macro/MacroDriver.cc +++ b/preprocessor/macro/MacroDriver.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2017 Dynare Team + * Copyright (C) 2008-2018 Dynare Team * * This file is part of Dynare. * @@ -60,7 +60,11 @@ MacroDriver::parse(const string &f, const string &fb, const string &modfiletxt, } catch (boost::bad_lexical_cast &) { - file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; + if (!it->second.empty() && it->second.at(0) == '[' && it->second.at(it->second.length()-1) == ']') + // If the input is an array. Issue #1578 + file_with_endl << "@#define " << it->first << " = " << it->second << endl; + else + file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; } file_with_endl << modfiletxt << endl; From 4c7960fbdc702134c4e853d2dd17733552ca0b9f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Nov 2017 15:39:48 +0100 Subject: [PATCH 18/51] AnalyseComputationalEnvironment.m: print out command that caused error as well as system response --- .../AnalyseComputationalEnvironment.m | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/matlab/parallel/AnalyseComputationalEnvironment.m b/matlab/parallel/AnalyseComputationalEnvironment.m index d00ca1b69..a1e5c5326 100644 --- a/matlab/parallel/AnalyseComputationalEnvironment.m +++ b/matlab/parallel/AnalyseComputationalEnvironment.m @@ -284,14 +284,19 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' else ssh_token = ''; end - - [si2 de2]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']); + command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']; + [si2 de2]=system(command_string); if (si2) disp ('Remote Directory does not exist or is not reachable!') skipline() disp('ErrorCode 5.') skipline(2) + disp('The command causing the error was:') + disp(command_string) + disp('The system returned:') + disp(de2) + skipline(2) ErrorCode=5; return end @@ -317,13 +322,19 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' si2=[]; de2=[]; - [si2 de2]=system(['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]); + command_string=['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]; + [si2 de2]=system(command_string); if (si2) disp ('Remote Directory does not exist or it is not reachable!') skipline() disp('ErrorCode 5.') skipline(2) + disp('The command causing the error was:') + disp(command_string) + disp('The system returned:') + disp(de2) + skipline(2) ErrorCode=5; return end @@ -576,19 +587,30 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' end if OStargetUnix if RemoteEnvironment ==1 - [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']); + command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']; + [si0 de0]=system(command_string); else % it is MAC - [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' sysctl -n hw.ncpu']); + command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' sysctl -n hw.ncpu']; + [si0 de0]=system(command_string); Environment1=2; end else - [si0 de0]=system(['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']); + command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']; + [si0 de0]=system(command_string); end else - [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]); + command_string=['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]; + [si0 de0]=system(command_string); end end + if (si0) + disp('The command causing the error was:') + disp(command_string) + disp('The system returned:') + disp(de0) + skipline(2) + end RealCPUnbr=''; % keyboard; From 2647f258d418e30a35735d3ac8c7bbfe321d4797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 25 Jan 2018 11:34:54 +0100 Subject: [PATCH 19/51] Cosmetic changes (code factorization). --- .../AnalyseComputationalEnvironment.m | 125 ++++++------------ 1 file changed, 37 insertions(+), 88 deletions(-) diff --git a/matlab/parallel/AnalyseComputationalEnvironment.m b/matlab/parallel/AnalyseComputationalEnvironment.m index a1e5c5326..be01f3c8d 100644 --- a/matlab/parallel/AnalyseComputationalEnvironment.m +++ b/matlab/parallel/AnalyseComputationalEnvironment.m @@ -251,10 +251,7 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' % computer! if Environment - - % This check can be removed ... according to the dynare parser - % strategy. - + % This check can be removed ... according to the dynare parser strategy. if isempty(DataInput(Node).RemoteDirectory) disp('The field RemoteDirectory is empty!') skipline() @@ -263,10 +260,7 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' ErrorCode=5; return end - - % This check can be removed ... according to the dynare parser - % strategy. - + % This check can be removed ... according to the dynare parser strategy. if (~isempty(DataInput(Node).RemoteDrive)) disp('[WARNING] The fields RemoteDrive should be empty under unix or mac!') skipline() @@ -276,40 +270,14 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' skipline(2) ErrorCode=5; end - - si2=[]; - de2=[]; if ~isempty(DataInput(Node).Port) ssh_token = ['-p ',DataInput(Node).Port]; else ssh_token = ''; end - command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']; - [si2 de2]=system(command_string); - - if (si2) - disp ('Remote Directory does not exist or is not reachable!') - skipline() - disp('ErrorCode 5.') - skipline(2) - disp('The command causing the error was:') - disp(command_string) - disp('The system returned:') - disp(de2) - skipline(2) - ErrorCode=5; - return - end - - disp('Check on RemoteDirectory Variable ..... Ok!') - skipline(2) - disp('Check on RemoteDrive Variable ..... Ok!') - skipline(2) - + command_string = ['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']; else - % This check can be removed ... according to the dynare parser - % strategy. - + % This check can be removed ... according to the dynare parser strategy. if (isempty(DataInput(Node).RemoteDrive)||isempty(DataInput(Node).RemoteDirectory)) disp('Remote RemoteDrive and/or RemoteDirectory is/are empty!') skipline() @@ -318,38 +286,31 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' ErrorCode=5; return end - - - si2=[]; - de2=[]; - command_string=['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]; - [si2 de2]=system(command_string); - - if (si2) - disp ('Remote Directory does not exist or it is not reachable!') - skipline() - disp('ErrorCode 5.') - skipline(2) - disp('The command causing the error was:') - disp(command_string) - disp('The system returned:') - disp(de2) - skipline(2) - ErrorCode=5; - return - end - - disp('Check on RemoteDirectory Variable ..... Ok!') - skipline(2) - disp('Check on RemoteDrive Variable ..... Ok!') - skipline(2) - + command_string = ['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]; end + [si2, de2] = system(command_string); - % Now we verify if it possible to exchange data with the remote - % computer: + if (si2) + disp ('Remote Directory does not exist or is not reachable!') + skipline() + disp('ErrorCode 5.') + skipline(2) + disp('The command causing the error was:') + disp(command_string) + disp('The system returned:') + disp(de2) + skipline(2) + ErrorCode=5; + return + end + disp('Check on RemoteDirectory Variable ..... Ok!') + skipline(2) + disp('Check on RemoteDrive Variable ..... Ok!') + skipline(2) + + % Now we verify if it possible to exchange data with the remote computer. % Build a command file to test the matlab execution and dynare path ... @@ -517,13 +478,8 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' % Now we verify if it is possible delete remote computational traces! - dynareParallelRmDir(RemoteTmpFolder,DataInput(Node)); - - si3=[]; - - si3=dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node)); - + si3 = dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node)); if (isempty(si3)) disp ('Check on Delete Remote Computational Traces ..... Ok!') skipline(2) @@ -561,22 +517,18 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' % We look for the information on local computer hardware. - - si0=[]; - de0=[]; - - Environment1=Environment; + Environment1 = Environment; disp('Checking Hardware please wait ...'); if (DataInput(Node).Local == 1) if Environment if ~ismac - [si0 de0]=system('grep processor /proc/cpuinfo'); + [si0, de0] = system('grep processor /proc/cpuinfo'); else - [si0 de0]=system('sysctl -n hw.ncpu'); - Environment1=2; + [si0, de0] = system('sysctl -n hw.ncpu'); + Environment1 = 2; end else - [si0 de0]=system(['psinfo \\']); + [si0, de0] = system(['psinfo \\']); end else if Environment @@ -587,21 +539,18 @@ for Node=1:length(DataInput) % To obtain a recoursive function remove the 'for' end if OStargetUnix if RemoteEnvironment ==1 - command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']; - [si0 de0]=system(command_string); + command_string = ['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']; else % it is MAC - command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' sysctl -n hw.ncpu']; - [si0 de0]=system(command_string); - Environment1=2; + command_string = ['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' sysctl -n hw.ncpu']; + Environment1 = 2; end else - command_string=['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']; - [si0 de0]=system(command_string); + command_string = ['ssh ',ssh_token,' ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']; end else - command_string=['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]; - [si0 de0]=system(command_string); + command_string = ['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]; end + [si0, de0] = system(command_string); end if (si0) From ec3fb76aa7794141dc72bbd5f151dcc7a837b8bb Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 1 Dec 2017 08:48:20 +0100 Subject: [PATCH 20/51] posterior_sampler: Fix naming error that crashes parallel estimation --- matlab/posterior_sampler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/posterior_sampler.m b/matlab/posterior_sampler.m index bfd209619..ea19c320d 100644 --- a/matlab/posterior_sampler.m +++ b/matlab/posterior_sampler.m @@ -127,7 +127,7 @@ else % which files have to be copied to run remotely NamFileInput(1,:) = {'',[ModelName '_static.m']}; NamFileInput(2,:) = {'',[ModelName '_dynamic.m']}; - if M.set_auxiliary_variables + if M_.set_auxiliary_variables NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']}; end if options_.steadystate_flag From 9fadf19bc296959c4eec24c2b1f14035aab57d67 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 1 Dec 2017 09:10:03 +0100 Subject: [PATCH 21/51] Add -accepteula flag to psexec call Prevents freezing if dialog has not been opened before --- matlab/parallel/masterParallel.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m index e51c6d023..4fbe69a8c 100644 --- a/matlab/parallel/masterParallel.m +++ b/matlab/parallel/masterParallel.m @@ -347,9 +347,9 @@ for j=1:totCPU end else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + command1=['psexec -accepteula -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; + command1=['psexec -accepteula -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; end end else % 0.2 Parallel(indPC).Local==0: Run using network on remote machine or also on local machine. @@ -387,20 +387,20 @@ for j=1:totCPU if ~strcmpi(Parallel(indPC).ComputerName,MasterName) % 0.3 Run on a remote machine! % Hybrid computing Matlab(Master)-> Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; end else % 0.4 Run on the local machine via the network % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; else - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); fParallel(',int2str(offset+1),',',int2str(sum(nBlockPerCPU(1:j))),',',int2str(j),',',int2str(indPC),',''',fname,''')"']; end end @@ -418,9 +418,9 @@ for j=1:totCPU end else % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; + command1=['psexec -accepteula -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else - command1=['psexec -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; + command1=['psexec -accepteula -d -W "',DyMo, '" -a ',my_affinity,' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; end end elseif Parallel(indPC).Local==0 % 1.2 Run using network on remote machine or also on local machine. @@ -462,19 +462,19 @@ for j=1:totCPU if ~strcmpi(Parallel(indPC).ComputerName,MasterName) % 1.3 Run on a remote machine. % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7'');addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -u ',Parallel(indPC).UserName,' -p ',Parallel(indPC).Password,' -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; end else % 1.4 Run on the local machine via the network. % Hybrid computing Matlab(Master)->Octave(Slaves) and Vice Versa! if regexpi([Parallel(indPC).MatlabOctavePath], 'octave') - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -f --eval "default_save_options(''-v7''); addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; else - command1=['psexec \\',Parallel(indPC).ComputerName,' -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... + command1=['psexec \\',Parallel(indPC).ComputerName,' -accepteula -d -e -W "',Parallel(indPC).RemoteDrive,':\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\" -a ',my_affinity, ... ' -low ',Parallel(indPC).MatlabOctavePath,' -nosplash -nodesktop -minimize ',compThread,' -r "addpath(''',Parallel(indPC).DynarePath,'''), dynareroot = dynare_config(); slaveParallel(',int2str(j),',',int2str(indPC),')"']; end end From a418a04249129f1db70d6e0b2718bdc3a4a338d6 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 25 Jan 2018 17:37:12 +0100 Subject: [PATCH 22/51] model_diagnostics.m: bugfix after transition to cell arrays disp does not work with cell --- matlab/model_diagnostics.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m index bfca7dda6..21084ead7 100644 --- a/matlab/model_diagnostics.m +++ b/matlab/model_diagnostics.m @@ -154,7 +154,7 @@ for b=1:nb break end end - disp(endo_names{k}) + fprintf('%s\n',endo_names{k}) end neq = null(jacob'); n_rel = size(neq,2); From 60efdd49bb14bf496716509f243988b97273e830 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 25 Jan 2018 17:59:34 +0100 Subject: [PATCH 23/51] disp_steady_state.m: Use character array to make sure alignment in display of steady state is right --- matlab/disp_steady_state.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/disp_steady_state.m b/matlab/disp_steady_state.m index 70f52173b..8c1bd549b 100644 --- a/matlab/disp_steady_state.m +++ b/matlab/disp_steady_state.m @@ -32,9 +32,9 @@ function disp_steady_state(M,oo) skipline() disp('STEADY-STATE RESULTS:') skipline() -endo_names = M.endo_names; +endo_names = char(M.endo_names); steady_state = oo.steady_state; for i = 1:M.orig_endo_nbr - disp(sprintf('%s \t\t %g', endo_names{i}, steady_state(i))); + fprintf('%s \t\t %g\n', endo_names(i,:), steady_state(i)); end From cf8213f7a0d71c7520e7e0f0904f826cfc8026f5 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Nov 2017 16:55:58 +0100 Subject: [PATCH 24/51] fix to the Kitigawa transformation that allows to reduce the computing time of the likelihood in large models, with a lot of static variables, by 30-50%. This fixes the bug in e97e5c340757098a2904b24aaeb5f8011812cdf3 that led to 2f9dc092855bbdb0b3fdd970b6ab551842c5080a It is tested and completely fixes the issue highlighted in #1312. --- matlab/DsgeSmoother.m | 2 +- matlab/compute_Pinf_Pstar.m | 83 ++++++++++++++++++++++++++++++++++--- matlab/dsge_likelihood.m | 2 +- 3 files changed, 80 insertions(+), 7 deletions(-) diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index 6466ad2f1..d83aa07d7 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -183,7 +183,7 @@ elseif options_.lik_init == 3 % Diffuse Kalman filter Z = [Z, eye(vobs)]; end end - [Pstar,Pinf] = compute_Pinf_Pstar(mf,T,R,Q,options_.qz_criterium,oo_.dr.restrict_var_list); + [Pstar,Pinf] = compute_Pinf_Pstar(mf,T,R,Q,options_.qz_criterium); elseif options_.lik_init == 4 % Start from the solution of the Riccati equation. [err, Pstar] = kalman_steady_state(transpose(T),R*Q*transpose(R),transpose(build_selection_matrix(mf,np,vobs)),H); mexErrCheck('kalman_steady_state',err); diff --git a/matlab/compute_Pinf_Pstar.m b/matlab/compute_Pinf_Pstar.m index d847ffacc..4eb5fbc87 100644 --- a/matlab/compute_Pinf_Pstar.m +++ b/matlab/compute_Pinf_Pstar.m @@ -48,8 +48,24 @@ function [Pstar,Pinf] = compute_Pinf_Pstar(mf,T,R,Q,qz_criterium, restrict_colum % along with Dynare. If not, see . np = size(T,1); +if nargin == 6 + indx = restrict_columns; + indx0=find(~ismember([1:np],indx)); +else +% indx=(find(max(abs(T))>0)); +% indx0=(find(max(abs(T))==0)); + indx=(find(max(abs(T))>=1.e-10)); + indx0=(find(max(abs(T))<1.e-10)); +end +np0=length(indx0); +Tbkp = T; +T0=T(indx0,indx); %static variables vs. dynamic ones +R0=R(indx0,:); % matrix of shocks for static variables -% perform Kitagawa transformation +% perform Kitagawa transformation only for non-zero columns of T +T=T(indx,indx); +R=R(indx,:); +np = size(T,1); [QT,ST] = schur(T); e1 = abs(ordeig(ST)) > 2-qz_criterium; [QT,ST] = ordschur(QT,ST,e1); @@ -59,7 +75,6 @@ nk1 = nk+1; Pstar = zeros(np,np); R1 = QT'*R; B = R1*Q*R1'; -% computes variance of stationary block (lower right) i = np; while i >= nk+2 if ST(i,i-1) == 0 @@ -100,13 +115,71 @@ if i == nk+1 Pstar(nk1,nk1)=(B(nk1,nk1)+c)/(1-ST(nk1,nk1)*ST(nk1,nk1)); end +if np0 + ST1=ST; + + % now I recover stationarized static variables + % using + % ss = s-A*z and + % z-z(-1) (growth rates of unit roots) only depends on stationary variables + Pstar = blkdiag(zeros(np0),Pstar); + ST = [zeros(length(Pstar),length(indx0)) [T0*QT ;ST]]; + R1 = [R0; R1]; + % build the matrix for stationarized variables + STinf = ST(np0+1:np0+nk,np0+1:np0+nk); + iSTinf = inv(STinf); + ST0=ST; + ST0(:,1:np0+nk)=0; % stationarized static + 1st difference only respond to lagged stationary states + ST00 = ST(1:np0,np0+1:np0+nk); + % A\B is the matrix division of A into B, which is roughly the + % same as INV(A)*B + ST0(1:np0,np0+nk+1:end) = ST(1:np0,np0+nk+1:end)-ST00*(iSTinf*ST(np0+1:np0+nk,np0+nk+1:end)); % snip non-stationary part + R10 = R1; + R10(1:np0,:) = R1(1:np0,:)-ST00*(iSTinf*R1(np0+1:np0+nk,:)); % snip non-stationary part + + % kill non-stationary part before projecting Pstar + ST0(np0+1:np0+nk,:)=0; + R10(np0+1:np0+nk,:)=0; % is this questionable???? IT HAS TO in order to match Michel's version!!! + + % project Pstar onto static x + Pstar = ... + ST0*Pstar*ST0'+ ... + R10*Q*R10'; + + % QT(1:np0,np0+1:np0+nk) = QT(1:np0,np0+1:np0+nk)+ST(1:np0,np0+1:np0+nk); %%% is this questionable ???? + % reorder QT entries +else + STinf = ST(np0+1:np0+nk,np0+1:np0+nk); + +end + % stochastic trends with no influence on observed variables are % arbitrarily initialized to zero Pinf = zeros(np,np); Pinf(1:nk,1:nk) = eye(nk); -for k = 1:nk - if norm(QT(mf,:)*ST(:,k)) < 1e-8 - Pinf(k,k) = 0; +if np0 + STtriu = STinf-eye(nk); +% A\B is the matrix division of A into B, which is roughly the +% same as INV(A)*B + STinf0 = ST00*(eye(nk)-iSTinf*STtriu); + Pinf = blkdiag(zeros(np0),Pinf); + QT = blkdiag(eye(np0),QT); + QTinf = QT; + QTinf(1:np0,np0+1:np0+nk) = STinf0; + QTinf([indx0(:); indx(:)],:) = QTinf; + STinf1 = [zeros(np0+np,np0) [STinf0; eye(nk); zeros(np-nk,nk)] zeros(np0+np,np-nk)]; + for k = 1:nk + if norm(QTinf(mf,:)*ST([indx0(:); indx(:)],k+np0)) < 1e-8 + Pinf(k+np0,k+np0) = 0; + end + end + Pinf = STinf1*Pinf*STinf1'; + QT([indx0(:); indx(:)],:) = QT; +else + for k = 1:nk + if norm(QT(mf,:)*ST(:,k)) < 1e-8 + Pinf(k+np0,k+np0) = 0; + end end end diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index c3e69b0ef..a6b9071fc 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -372,7 +372,7 @@ switch DynareOptions.lik_init error(['The model requires Diffuse filter, but you specified a different Kalman filter. You must set options_.kalman_algo ' ... 'to 0 (default), 3 or 4']) end - [Pstar,Pinf] = compute_Pinf_Pstar(Z,T,R,Q,DynareOptions.qz_criterium,[1:length(T)]); + [Pstar,Pinf] = compute_Pinf_Pstar(Z,T,R,Q,DynareOptions.qz_criterium); Z =zeros(length(BayesInfo.mf),size(T,1)); for i = 1:length(BayesInfo.mf) Z(i,BayesInfo.mf(i))=1; From b9741548b0da873c5ff3c81c92d2f9f30129f63f Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Nov 2017 17:19:39 +0100 Subject: [PATCH 25/51] As we do for the smoother, check the rank of Pinf only for the observables (i.e. using Z*Pinf*Z') --- matlab/kalman/likelihood/kalman_filter_d.m | 2 +- matlab/kalman/likelihood/univariate_kalman_filter_d.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/kalman/likelihood/kalman_filter_d.m b/matlab/kalman/likelihood/kalman_filter_d.m index 79b3607fb..48c0d91c4 100644 --- a/matlab/kalman/likelihood/kalman_filter_d.m +++ b/matlab/kalman/likelihood/kalman_filter_d.m @@ -65,7 +65,7 @@ dLIK = Inf; % Default value of the log likelihood. oldK = Inf; s = 0; -while rank(Pinf,diffuse_kalman_tol) && (t<=last) +while rank(Z*Pinf*Z',diffuse_kalman_tol) && (t<=last) s = t-start+1; v = Y(:,t)-Z*a; %get prediction error v^(0) in (5.13) DK (2012) Finf = Z*Pinf*Z'; % (5.7) in DK (2012) diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_d.m b/matlab/kalman/likelihood/univariate_kalman_filter_d.m index ce78d2421..6abe6b9a7 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter_d.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter_d.m @@ -154,7 +154,7 @@ while newRank && (t<=last) end end if newRank - oldRank = rank(Pinf,diffuse_kalman_tol); + oldRank = rank(Z*Pinf*Z',diffuse_kalman_tol); else oldRank = 0; end @@ -162,7 +162,7 @@ while newRank && (t<=last) Pstar = T*Pstar*T'+QQ; Pinf = T*Pinf*T'; if newRank - newRank = rank(Pinf,diffuse_kalman_tol); + newRank = rank(Z*Pinf*Z',diffuse_kalman_tol); end if oldRank ~= newRank disp('univariate_diffuse_kalman_filter:: T does influence the rank of Pinf!') From b933a440bf07241aff56275e2af60270ddddcb42 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Nov 2017 15:55:36 +0100 Subject: [PATCH 26/51] Add debugging info to Kalman filter routines --- matlab/kalman/likelihood/univariate_kalman_filter_d.m | 1 + matlab/missing_DiffuseKalmanSmootherH3_Z.m | 1 + 2 files changed, 2 insertions(+) diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_d.m b/matlab/kalman/likelihood/univariate_kalman_filter_d.m index 6abe6b9a7..b3038a312 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter_d.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter_d.m @@ -166,6 +166,7 @@ while newRank && (t<=last) end if oldRank ~= newRank disp('univariate_diffuse_kalman_filter:: T does influence the rank of Pinf!') + disp('This may happen for models with order of integration >1.') end t = t+1; end diff --git a/matlab/missing_DiffuseKalmanSmootherH3_Z.m b/matlab/missing_DiffuseKalmanSmootherH3_Z.m index de40741fc..08658db51 100644 --- a/matlab/missing_DiffuseKalmanSmootherH3_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH3_Z.m @@ -184,6 +184,7 @@ while newRank && t < smpl end if oldRank ~= newRank disp('univariate_diffuse_kalman_filter:: T does influence the rank of Pinf!') + disp('This may happen for models with order of integration >1.') end end From c4f19586902ef4b5b3ba28eb8a6316e2e615fa94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 26 Jan 2018 12:00:27 +0100 Subject: [PATCH 27/51] Cosmetic changes + Copyright headers fixes. --- matlab/DsgeSmoother.m | 2 +- matlab/compute_Pinf_Pstar.m | 35 +++++++------------ matlab/dsge_likelihood.m | 2 +- matlab/kalman/likelihood/kalman_filter_d.m | 2 +- .../likelihood/univariate_kalman_filter_d.m | 2 +- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index d83aa07d7..793afa561 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -58,7 +58,7 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,de % SPECIAL REQUIREMENTS % None -% Copyright (C) 2006-2017 Dynare Team +% Copyright (C) 2006-2018 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/compute_Pinf_Pstar.m b/matlab/compute_Pinf_Pstar.m index 4eb5fbc87..0ccbd02d8 100644 --- a/matlab/compute_Pinf_Pstar.m +++ b/matlab/compute_Pinf_Pstar.m @@ -30,7 +30,7 @@ function [Pstar,Pinf] = compute_Pinf_Pstar(mf,T,R,Q,qz_criterium, restrict_colum % SPECIAL REQUIREMENTS % None -% Copyright (C) 2006-2017 Dynare Team +% Copyright (C) 2006-2018 Dynare Team % % This file is part of Dynare. % @@ -52,17 +52,15 @@ if nargin == 6 indx = restrict_columns; indx0=find(~ismember([1:np],indx)); else -% indx=(find(max(abs(T))>0)); -% indx0=(find(max(abs(T))==0)); indx=(find(max(abs(T))>=1.e-10)); indx0=(find(max(abs(T))<1.e-10)); end np0=length(indx0); Tbkp = T; -T0=T(indx0,indx); %static variables vs. dynamic ones -R0=R(indx0,:); % matrix of shocks for static variables +T0=T(indx0,indx); % static variables vs. dynamic ones +R0=R(indx0,:); % matrix of shocks for static variables -% perform Kitagawa transformation only for non-zero columns of T +% Perform Kitagawa transformation only for non-zero columns of T T=T(indx,indx); R=R(indx,:); np = size(T,1); @@ -117,40 +115,33 @@ end if np0 ST1=ST; - - % now I recover stationarized static variables - % using - % ss = s-A*z and + % Now I recover stationarized static variables using + % ss = s-A*z + % and % z-z(-1) (growth rates of unit roots) only depends on stationary variables Pstar = blkdiag(zeros(np0),Pstar); ST = [zeros(length(Pstar),length(indx0)) [T0*QT ;ST]]; R1 = [R0; R1]; - % build the matrix for stationarized variables + % Build the matrix for stationarized variables STinf = ST(np0+1:np0+nk,np0+1:np0+nk); iSTinf = inv(STinf); ST0=ST; ST0(:,1:np0+nk)=0; % stationarized static + 1st difference only respond to lagged stationary states ST00 = ST(1:np0,np0+1:np0+nk); % A\B is the matrix division of A into B, which is roughly the - % same as INV(A)*B + % same as INV(A)*B ST0(1:np0,np0+nk+1:end) = ST(1:np0,np0+nk+1:end)-ST00*(iSTinf*ST(np0+1:np0+nk,np0+nk+1:end)); % snip non-stationary part R10 = R1; R10(1:np0,:) = R1(1:np0,:)-ST00*(iSTinf*R1(np0+1:np0+nk,:)); % snip non-stationary part - - % kill non-stationary part before projecting Pstar - ST0(np0+1:np0+nk,:)=0; + % Kill non-stationary part before projecting Pstar + ST0(np0+1:np0+nk,:)=0; R10(np0+1:np0+nk,:)=0; % is this questionable???? IT HAS TO in order to match Michel's version!!! - % project Pstar onto static x - Pstar = ... - ST0*Pstar*ST0'+ ... - R10*Q*R10'; - + Pstar = ST0*Pstar*ST0'+R10*Q*R10'; % QT(1:np0,np0+1:np0+nk) = QT(1:np0,np0+1:np0+nk)+ST(1:np0,np0+1:np0+nk); %%% is this questionable ???? % reorder QT entries else STinf = ST(np0+1:np0+nk,np0+1:np0+nk); - end % stochastic trends with no influence on observed variables are @@ -160,7 +151,7 @@ Pinf(1:nk,1:nk) = eye(nk); if np0 STtriu = STinf-eye(nk); % A\B is the matrix division of A into B, which is roughly the -% same as INV(A)*B +% same as INV(A)*B STinf0 = ST00*(eye(nk)-iSTinf*STtriu); Pinf = blkdiag(zeros(np0),Pinf); QT = blkdiag(eye(np0),QT); diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index a6b9071fc..3ea377dcf 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -115,7 +115,7 @@ function [fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff,Model,DynareOpti %! @end deftypefn %@eod: -% Copyright (C) 2004-2017 Dynare Team +% Copyright (C) 2004-2018 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/kalman/likelihood/kalman_filter_d.m b/matlab/kalman/likelihood/kalman_filter_d.m index 48c0d91c4..7a7cdef13 100644 --- a/matlab/kalman/likelihood/kalman_filter_d.m +++ b/matlab/kalman/likelihood/kalman_filter_d.m @@ -36,7 +36,7 @@ function [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, start, last, a, Pinf, Pstar, k % Durbin/Koopman (2012): "Time Series Analysis by State Space Methods", Oxford University Press, % Second Edition, Ch. 5 and 7.2 -% Copyright (C) 2004-2017 Dynare Team +% Copyright (C) 2004-2018 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_d.m b/matlab/kalman/likelihood/univariate_kalman_filter_d.m index b3038a312..81f7d5778 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter_d.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter_d.m @@ -87,7 +87,7 @@ function [dLIK, dlikk, a, Pstar, llik] = univariate_kalman_filter_d(data_index, % Series Analysis by State Space Methods", Oxford University Press, % Second Edition, Ch. 5, 6.4 + 7.2.5 -% Copyright (C) 2004-2017 Dynare Team +% Copyright (C) 2004-2018 Dynare Team % % This file is part of Dynare. % From 74fc7cc078c2a000c9e13b20b9e3d2a2ab810972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 26 Jan 2018 12:01:07 +0100 Subject: [PATCH 28/51] Copyright header fix. --- matlab/missing_DiffuseKalmanSmootherH3_Z.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/missing_DiffuseKalmanSmootherH3_Z.m b/matlab/missing_DiffuseKalmanSmootherH3_Z.m index 08658db51..1551b8e04 100644 --- a/matlab/missing_DiffuseKalmanSmootherH3_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH3_Z.m @@ -56,7 +56,7 @@ function [alphahat,epsilonhat,etahat,a,P,aK,PK,decomp,V] = missing_DiffuseKalman % Models", S.J. Koopman and J. Durbin (2003), in Journal of Time Series % Analysis, vol. 24(1), pp. 85-98. -% Copyright (C) 2004-2017 Dynare Team +% Copyright (C) 2004-2018 Dynare Team % % This file is part of Dynare. % From 6b9f4694593ae8fd858c67faf863536ecae4e4c0 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 23 Nov 2017 19:29:25 +0100 Subject: [PATCH 29/51] initial_condition_decomposition: return oo_ output argument to base workspace --- preprocessor/ComputingTasks.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 9e0b157b1..e8372134e 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2418,7 +2418,7 @@ InitialConditionDecompositionStatement::writeOutput(ostream &output, const strin output << "options_ = set_default_initial_condition_decomposition_options(options_);" << endl; options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); - output << "initial_condition_decomposition(M_, oo_, options_, var_list_, bayestopt_, estim_params_);" << endl; + output << "oo_ = initial_condition_decomposition(M_, oo_, options_, var_list_, bayestopt_, estim_params_);" << endl; } ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &options_list_arg) : From 0a80ca4028ffea5fffdb7866ab16a48ca7b98b75 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 23 Nov 2017 19:32:25 +0100 Subject: [PATCH 30/51] initial_condition_decomposition: Add nodisplay, graph_format, fig_name options --- preprocessor/DynareBison.yy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 97c455149..7fbae92a4 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -2721,6 +2721,9 @@ initial_condition_decomposition_option : o_icd_type | o_icd_write_xls | o_icd_plot_init_date | o_icd_plot_end_date + | o_nodisplay + | o_graph_format + | o_psd_fig_name ; homotopy_setup: HOMOTOPY_SETUP ';' homotopy_list END ';' From 8e73289fe5ebbe5ae9f69260afc7ffa69571362f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 26 Nov 2017 17:47:19 +0100 Subject: [PATCH 31/51] read_variables.m: consistently account for variables being stored as cell array --- matlab/read_variables.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/read_variables.m b/matlab/read_variables.m index a50501252..354adf855 100644 --- a/matlab/read_variables.m +++ b/matlab/read_variables.m @@ -91,7 +91,7 @@ switch (extension) case { '.xls', '.xlsx' } [freq,init,data,varlist] = load_xls_file_data(fullname,xls_sheet,xls_range); for dyn_i_01=1:var_size_01 - iv = strmatch(strtrim(var_names_01(dyn_i_01,:)),varlist,'exact'); + iv = strmatch(strtrim(var_names_01{dyn_i_01}),varlist,'exact'); if ~isempty(iv) dyn_tmp_01 = [data(:,iv)]'; if length(dyn_tmp_01) > dyn_size_01 && dyn_size_01 > 0 @@ -101,7 +101,7 @@ switch (extension) dyn_data_01(:,dyn_i_01) = dyn_tmp_01; else cd(old_pwd) - error([strtrim(var_names_01(dyn_i_01,:)) ' not found in ' fullname]) + error([strtrim(var_names_01{dyn_i_01}) ' not found in ' fullname]) end end case '.csv' From dde1acd18d40238849f16d72b865a3b5cadbf577 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 12 Jan 2018 14:25:26 +0100 Subject: [PATCH 32/51] Make fast_realtime accept observation as input --- doc/dynare.texi | 6 ++++-- preprocessor/DynareBison.yy | 2 +- tests/shock_decomposition/ls2003_plot.mod | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index a25bf1792..72f63800d 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7544,9 +7544,11 @@ realtime shock decompositions are computed, @i{i.e.} for @anchor{save_realtime} Choose for which vintages to save the full realtime shock decomposition. Default: @math{0}. -@item fast_realtime +@item fast_realtime = @var{INTEGER} @anchor{fast_realtime} Runs the smoother only twice: once for the last in-sample -and once for the last out-of-sample data point. Default: not enabled. +and once for the last out-of-sample data point, where the provided integer defines the last observation +(equivalent to @ref{nobs}). +Default: not enabled. @end table diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 7fbae92a4..64c3a796c 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -3099,7 +3099,7 @@ o_init_state : INIT_STATE EQUAL INT_NUMBER { driver.option_num("shock_decomp.ini o_shock_decomposition_presample : PRESAMPLE EQUAL INT_NUMBER { driver.option_num("shock_decomp.presample", $3); }; o_shock_decomposition_forecast : FORECAST EQUAL INT_NUMBER { driver.option_num("shock_decomp.forecast", $3); }; o_save_realtime : SAVE_REALTIME EQUAL vec_int { driver.option_vec_int("shock_decomp.save_realtime", $3); }; -o_fast_realtime : FAST_REALTIME { driver.option_num("shock_decomp.fast_realtime", "1"); }; +o_fast_realtime : FAST_REALTIME EQUAL INT_NUMBER { driver.option_num("shock_decomp.fast_realtime", $3); }; o_nodisplay : NODISPLAY { driver.option_num("nodisplay","1"); }; o_psd_nodisplay : NODISPLAY { driver.option_num("plot_shock_decomp.nodisplay","1"); }; o_graph_format : GRAPH_FORMAT EQUAL allowed_graph_formats diff --git a/tests/shock_decomposition/ls2003_plot.mod b/tests/shock_decomposition/ls2003_plot.mod index 69e8774f8..895de40e9 100644 --- a/tests/shock_decomposition/ls2003_plot.mod +++ b/tests/shock_decomposition/ls2003_plot.mod @@ -133,7 +133,7 @@ close all, // testing realtime decomposition with fast_realtime option -realtime_shock_decomposition(fast_realtime); +realtime_shock_decomposition(fast_realtime=75); collect_latex_files; if system(['pdflatex -halt-on-error -interaction=batchmode ' M_.fname '_TeX_binder.tex']) From cbc0cdfef838b58f17c9a564a27b0bc7c302a6ec Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 12 Jan 2018 21:32:59 +0100 Subject: [PATCH 33/51] Fix bug in multivariate Kalman smoother when observations are missing The singularity branch did not correctly account for the switching number of observables --- matlab/missing_DiffuseKalmanSmootherH1_Z.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/matlab/missing_DiffuseKalmanSmootherH1_Z.m b/matlab/missing_DiffuseKalmanSmootherH1_Z.m index 5ba614f94..0552da20b 100644 --- a/matlab/missing_DiffuseKalmanSmootherH1_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH1_Z.m @@ -49,7 +49,7 @@ function [alphahat,epsilonhat,etahat,atilde,P,aK,PK,decomp,V] = missing_DiffuseK % Durbin/Koopman (2012): "Time Series Analysis by State Space Methods", Oxford University Press, % Second Edition, Ch. 5 -% Copyright (C) 2004-2017 Dynare Team +% Copyright (C) 2004-2018 Dynare Team % % This file is part of Dynare. % @@ -134,9 +134,9 @@ while rank(Pinf(:,:,t+1),diffuse_kalman_tol) && t Date: Wed, 17 Jan 2018 19:28:44 +0100 Subject: [PATCH 34/51] Bug fixes after changes in the options structures for shock decompositions. --- matlab/expand_group.m | 15 +++++++++------ matlab/graph_decomp.m | 9 ++++++--- matlab/graph_decomp_detail.m | 7 +++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/matlab/expand_group.m b/matlab/expand_group.m index c20d38c37..1793c9c21 100644 --- a/matlab/expand_group.m +++ b/matlab/expand_group.m @@ -34,16 +34,19 @@ mydata=get(findobj(gcf,'tag',['group' int2str(ic)]),'userdata'); if isfield(mydata,'shock_decomp') options.shock_decomp=mydata.shock_decomp; end +options.plot_shock_decomp=mydata.plot_shock_decomp; +options.first_obs=mydata.first_obs; +options.nobs=mydata.nobs; % define expanded group label = mydata.shock_group.label; shocks = mydata.shock_group.shocks; -options.shock_decomp.fig_name = [mydata.fig_name '. Expand']; -options.use_shock_groups = strrep(label,' ','_'); %[use_shock_groups_old int2str(ic)]; +options.plot_shock_decomp.fig_name = [mydata.fig_name '. Expand']; +options.plot_shock_decomp.use_shock_groups = strrep(label,' ','_'); %[use_shock_groups_old int2str(ic)]; for j=1:length(shocks) - M.shock_groups.(options.use_shock_groups).(['group' int2str(j)]).label=shocks{j}; - M.shock_groups.(options.use_shock_groups).(['group' int2str(j)]).shocks=shocks(j); + M.shock_groups.(options.plot_shock_decomp.use_shock_groups).(['group' int2str(j)]).label=shocks{j}; + M.shock_groups.(options.plot_shock_decomp.use_shock_groups).(['group' int2str(j)]).shocks=shocks(j); end -options.shock_decomp.interactive=0; -options.shock_decomp.expand=1; +options.plot_shock_decomp.interactive=0; +options.plot_shock_decomp.expand=1; plot_shock_decomposition(M,oo,options,var_list_); diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m index 33793d276..81e971693 100644 --- a/matlab/graph_decomp.m +++ b/matlab/graph_decomp.m @@ -193,12 +193,15 @@ for j=1:nvar mydata.fig_name = DynareOptions.plot_shock_decomp.fig_name(2:end); mydata.use_shock_groups = DynareOptions.plot_shock_decomp.use_shock_groups; mydata.shock_group = shock_groups.(shock_ind{i}); - mydata.shock_decomp = DynareOptions.plot_shock_decomp; - if ~isempty(mydata.shock_group.shocks{1}) + mydata.shock_decomp = DynareOptions.shock_decomp; + mydata.plot_shock_decomp = DynareOptions.plot_shock_decomp; + mydata.first_obs = DynareOptions.first_obs; + mydata.nobs = DynareOptions.nobs; + if ~isempty(mydata.shock_group.shocks) c = uicontextmenu; hl.UIContextMenu=c; browse_menu = uimenu(c,'Label','Browse group'); - expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.use_shock_groups ''',''' deblank(mydata.shock_decomp.orig_varlist(j,:)) ''',' int2str(i) ')']); + expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' deblank(mydata.plot_shock_decomp.orig_varlist{j}) ''',' int2str(i) ')']); set(expand_menu,'UserData',mydata,'Tag',['group' int2str(i)]); for jmember = mydata.shock_group.shocks uimenu('parent',browse_menu,'Label',char(jmember)) diff --git a/matlab/graph_decomp_detail.m b/matlab/graph_decomp_detail.m index 39e6fd7cf..70dc4d640 100644 --- a/matlab/graph_decomp_detail.m +++ b/matlab/graph_decomp_detail.m @@ -195,12 +195,15 @@ for j=1:nvar mydata.fig_name = DynareOptions.plot_shock_decomp.fig_name(2:end); mydata.use_shock_groups = DynareOptions.plot_shock_decomp.use_shock_groups; mydata.shock_group = shock_groups.(shock_ind{ic}); - mydata.shock_decomp = DynareOptions.plot_shock_decomp; + mydata.shock_decomp = DynareOptions.shock_decomp; + mydata.plot_shock_decomp = DynareOptions.plot_shock_decomp; + mydata.first_obs = DynareOptions.first_obs; + mydata.nobs = DynareOptions.nobs; if ~isempty(mydata.shock_group.shocks) c = uicontextmenu; hax.UIContextMenu=c; browse_menu = uimenu(c,'Label','Browse group'); - expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.use_shock_groups ''',''' deblank(mydata.shock_decomp.orig_varlist(j,:)) ''',' int2str(ic) ')']); + expand_menu = uimenu(c,'Label','Expand group','Callback',['expand_group(''' mydata.plot_shock_decomp.use_shock_groups ''',''' deblank(mydata.plot_shock_decomp.orig_varlist{j}) ''',' int2str(ic) ')']); set(expand_menu,'UserData',mydata,'Tag',['group' int2str(ic)]); for jmember = mydata.shock_group.shocks uimenu('parent',browse_menu,'Label',char(jmember)) From b3bcd2c8b08148a4cb0a0acd1477e2648a047d06 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 17 Jan 2018 19:32:29 +0100 Subject: [PATCH 35/51] bug fixes: wrong name of field fig_name and properly using user defined fig_name --- matlab/initial_condition_decomposition.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/matlab/initial_condition_decomposition.m b/matlab/initial_condition_decomposition.m index af98862c6..52e468a9f 100644 --- a/matlab/initial_condition_decomposition.m +++ b/matlab/initial_condition_decomposition.m @@ -128,6 +128,11 @@ M_.exo_nbr = M_.endo_nbr; options_.plot_shock_decomp.realtime=0; options_.plot_shock_decomp.screen_shocks=1; options_.plot_shock_decomp.use_shock_groups = ''; -options_.plot_shock_decomp.fig_names='initval'; -plot_shock_decomposition(M_, oo, options_, varlist); +fig_name = options_.plot_shock_decomp.fig_name; +if ~isempty(fig_name) + options_.plot_shock_decomp.fig_name=[fig_name '_initval']; +else +options_.plot_shock_decomp.fig_name='initval'; +end +plot_shock_decomposition(M_,oo,options_,varlist); % end \ No newline at end of file From 13a30a0a4e95f1a71577441c20298cd87256334f Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 17 Jan 2018 19:33:39 +0100 Subject: [PATCH 36/51] add a new case for ratios between endogenous variables, like trade balance to GDP. --- matlab/utilities/dataset/quarterly2annual.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/matlab/utilities/dataset/quarterly2annual.m b/matlab/utilities/dataset/quarterly2annual.m index 8663a09ff..13c6bafd9 100644 --- a/matlab/utilities/dataset/quarterly2annual.m +++ b/matlab/utilities/dataset/quarterly2annual.m @@ -14,6 +14,7 @@ function [ya, yass, gya, gyass] = quarterly2annual(y,yss,GYTREND0,type,islog,aux % 5 annual price as quantity weighted average % 6 annual quantity from average price % 7 annual nominal from Q real and deflator +% 8 annual ratio [e.g. trade balance to GDP] % islog 0 level (default) % 1 log-level % 2 growth rate Q frequency @@ -120,6 +121,19 @@ switch type yn = (y+yss).*(yaux+yauxss) - yss.*yauxss; [ya, yass] = quarterly2annual(yn,yss.*yauxss,GYTREND0+GYTREND0aux,typeaux,0,0); GYTREND0=GYTREND0+GYTREND0aux; + + case 8 + % numerator + yn = y; + [yna, ynass] = quarterly2annual(yn,yss,GYTREND0,typeaux(1),0,0); + % denominator + yd = yaux; + [yda, ydass] = quarterly2annual(yd,yauxss,GYTREND0aux,typeaux(2),0,0); + % ratio + yass = ynass/ydass; + ya = (yna+ynass)./(yda+ydass)-yass; + GYTREND0 = GYTREND0 - GYTREND0aux; + otherwise error('Wrong type input') end From bfe07d389bae4cc5d33d432a3886067d5e28fa28 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 29 Jan 2018 10:56:41 +0100 Subject: [PATCH 37/51] macroprocessor: fix unhandled case of nested ifdef/ifndef statements. closes #1587 --- preprocessor/macro/MacroFlex.ll | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/preprocessor/macro/MacroFlex.ll b/preprocessor/macro/MacroFlex.ll index 577767098..21a35a1c9 100644 --- a/preprocessor/macro/MacroFlex.ll +++ b/preprocessor/macro/MacroFlex.ll @@ -305,6 +305,16 @@ CONT \\\\ then_body_tmp.append(yytext); yylloc->step(); } +^{SPC}*@#{SPC}*ifdef({SPC}|{CONT}) { + nested_if_nb++; + then_body_tmp.append(yytext); + yylloc->step(); + } +^{SPC}*@#{SPC}*ifndef({SPC}|{CONT}) { + nested_if_nb++; + then_body_tmp.append(yytext); + yylloc->step(); + } . { then_body_tmp.append(yytext); yylloc->step(); } <> { driver.error(if_stmt_loc_tmp, "@#if/@#ifdef/@#ifndef not matched by an @#endif or file does not end with a new line (unexpected end of file)"); } ^{SPC}*@#{SPC}*else{SPC}*(\/\/.*)?{EOL} { From 48b5839414b96c69c0ea0a0da4b129b0195d7dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 29 Jan 2018 16:31:24 +0100 Subject: [PATCH 38/51] Updated NEWS file for 4.5.4. --- NEWS | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/NEWS b/NEWS index 8cec1a2f2..e060e2e18 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,56 @@ +Announcement for Dynare 4.5.4 (on 2018-01-29) +============================================= + +We are pleased to announce the release of Dynare 4.5.4. + +This is a bugfix release. + +The Windows packages are already available for download at: + + http://www.dynare.org/download/dynare-stable + +The Mac and GNU/Linux packages (for Debian and Ubuntu LTS) should follow soon. + +This release is compatible with MATLAB versions 7.3 (R2006b) to 9.3 (R2017b) +and with GNU Octave versions 4.2. + +Here is a list of the problems identified in version 4.5.3 and that have been +fixed in version 4.5.4: + + - The `type` option of `plot_shock_decomposition` was always set to `qoq` regardless of what is specified. + + - Bug in GSA when no parameter was detected below pvalue threshold. + + - Various bug fixes in shock decompositions. + + - Bug in reading in macro arrays passed on `dynare` command line via the `-D` option. + + - Estimation with missing values was crashing if the `prefilter` option was used. + + - Added a workaround for a difference in behaviour between Octave and Matlab regarding the creation + of function handles for functions that do not exist in the path. With Octave 4.2.1, steady state + files did not work if no auxiliary variables were created. + + - The `stoch_simul` command was crashing with a cryptic message if option `order=3` was used without + setting `k_order_solver`. + + - In cases where the prior bounds are infinite and the mode is estimated at exactly 0, no `mode_check` + graphs were displayed. + + - Parallel execution of MCMC was broken in models without auxiliary variables. + + - Reading data with column names from Excel might crash. + + - The multivariate Kalman smoother was crashing in case of missing data in the observations and + `Finf` became singular. + + - The `plot_shock_decomposition` command ignored various user-defined options like `fig_name`, + `use_shock_groups` or `interactive` and instead used the default options. + + - Nested `@#ifdef` and `@#ifndef` statements don't work in the macroprocessor. + + + Announcement for Dynare 4.5.3 (on 2017-10-19) ============================================= From 2f4b883f42628df7c434c3158b17d1f51a04e310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 29 Jan 2018 18:20:24 +0100 Subject: [PATCH 39/51] Closes #1588. --- windows/README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/README.txt b/windows/README.txt index 56d8a6aa4..c4b67a297 100644 --- a/windows/README.txt +++ b/windows/README.txt @@ -61,7 +61,7 @@ This version of Dynare is compiled for Octave 4.2.1 (MinGW, 32bit and 64bit), an with other versions of Octave. The recommended version of Octave can be downloaded at: - http://www.dynare.org/download/octave/windows + https://www.gnu.org/software/octave/download.html Every time you run Octave, you should type the two following commands (assuming that you have installed Dynare at the standard location, and replacing '4.x.y' From b91fa10fa1b35a872492319b1757526bde050235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 29 Jan 2018 20:17:45 +0100 Subject: [PATCH 40/51] Fixed Matlab's version requirement. --- NEWS | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index e060e2e18..41c273654 100644 --- a/NEWS +++ b/NEWS @@ -11,7 +11,7 @@ The Windows packages are already available for download at: The Mac and GNU/Linux packages (for Debian and Ubuntu LTS) should follow soon. -This release is compatible with MATLAB versions 7.3 (R2006b) to 9.3 (R2017b) +This release is compatible with MATLAB versions 7.5 (R2007b) to 9.3 (R2017b) and with GNU Octave versions 4.2. Here is a list of the problems identified in version 4.5.3 and that have been @@ -65,7 +65,7 @@ The Windows packages are already available for download at: The Mac and GNU/Linux packages (for Debian and Ubuntu LTS) should follow soon. -This release is compatible with MATLAB versions 7.3 (R2006b) to 9.3 (R2017b) +This release is compatible with MATLAB versions 7.5 (R2007b) to 9.3 (R2017b) and with GNU Octave versions 4.2. Here is a list of the problems identified in version 4.5.2 and that have been @@ -90,7 +90,7 @@ The Windows packages are already available for download at: The Mac and GNU/Linux packages (for Debian and Ubuntu LTS) should follow soon. -This release is compatible with MATLAB versions 7.3 (R2006b) to 9.3 (R2017b) +This release is compatible with MATLAB versions 7.5 (R2007b) to 9.3 (R2017b) and with GNU Octave versions 4.2. Here is a list of the problems identified in version 4.5.1 and that have been @@ -169,7 +169,7 @@ The Windows packages are already available for download at: The Mac and GNU/Linux packages (for Debian and Ubuntu LTS) should follow soon. -This release is compatible with MATLAB versions 7.3 (R2006b) to 9.2 (R2017a) +This release is compatible with MATLAB versions 7.5 (R2007b) to 9.2 (R2017a) and with GNU Octave versions 4.2. Here is a list of the problems identified in version 4.5.0 and that have been @@ -215,7 +215,7 @@ The Mac and Debian/Ubuntu packages should follow soon. All users are strongly encouraged to upgrade. -This release is compatible with MATLAB versions ranging from 7.3 (R2006b) to +This release is compatible with MATLAB versions ranging from 7.5 (R2007b) to 9.2 (R2017a) and with GNU Octave version 4.2. Here is the list of major user-visible changes: From 3679afe849c600bc61e2d0db111b4600c3894d78 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 31 Jan 2018 22:23:02 +0100 Subject: [PATCH 41/51] Discretion: Added catch for infinities Comment: A user provided a file in which the Sylvester equation solved using doubling can evaluate to inf. When Doubling fails, one can try the Hessenberg-Schur algorithm. --- matlab/discretionary_policy_engine.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/discretionary_policy_engine.m b/matlab/discretionary_policy_engine.m index 05c781ae4..bcf48267c 100644 --- a/matlab/discretionary_policy_engine.m +++ b/matlab/discretionary_policy_engine.m @@ -112,9 +112,9 @@ F1=F10; while 1 iter=iter+1; P=SylvesterDoubling(W+beta*F1'*Q*F1,beta*H1',H1,discretion_tol,solve_maxit); - if any(any(isnan(P))) + if any(any(isnan(P))) || any(any(isinf(P))) P=SylvesterHessenbergSchur(W+beta*F1'*Q*F1,beta*H1',H1); - if any(any(isnan(P))) + if any(any(isnan(P))) || any(any(isinf(P))) retcode=2; return end From 410f8bd07cf15786c05d2181d9c289acee116501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 1 Feb 2018 09:48:50 +0100 Subject: [PATCH 42/51] Cosmetic change and fixed copyright header. --- matlab/discretionary_policy_engine.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/discretionary_policy_engine.m b/matlab/discretionary_policy_engine.m index bcf48267c..ba12347b8 100644 --- a/matlab/discretionary_policy_engine.m +++ b/matlab/discretionary_policy_engine.m @@ -48,7 +48,7 @@ function [H,G,retcode]=discretionary_policy_engine(AAlag,AA0,AAlead,BB,bigw,inst % Dennis, Richard (2007): Optimal policy in rational expectations models: new solution algorithms, % Macroeconomic Dynamics, 11, 31–55. -% Copyright (C) 2007-2017 Dynare Team +% Copyright (C) 2007-2018 Dynare Team % % This file is part of Dynare. % @@ -112,7 +112,7 @@ F1=F10; while 1 iter=iter+1; P=SylvesterDoubling(W+beta*F1'*Q*F1,beta*H1',H1,discretion_tol,solve_maxit); - if any(any(isnan(P))) || any(any(isinf(P))) + if any(any(isnan(P))) || any(any(isinf(P))) P=SylvesterHessenbergSchur(W+beta*F1'*Q*F1,beta*H1',H1); if any(any(isnan(P))) || any(any(isinf(P))) retcode=2; From da48dea37cddd6af7a9c3c85bef0127253a9b468 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 31 Jan 2018 22:44:23 +0100 Subject: [PATCH 43/51] identification_analysis.m: remove transformation to char when cell is expected --- matlab/identification_analysis.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index c59e08ec6..80d22d737 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -152,7 +152,7 @@ if info(1)==0 end analytic_derivation = options_.analytic_derivation; options_.analytic_derivation = -2; - info = stoch_simul(char(options_.varobs)); + info = stoch_simul(options_.varobs); dataset_ = dseries(oo_.endo_simul(options_.varobs_id,100+1:end)',dates('1Q1'), options_.varobs); derivatives_info.no_DLIK=1; %bounds = prior_bounds(bayestopt_, options_.prior_trunc); From fe7da22853f90545b9bcfd44ea4c88d2700b2625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 1 Feb 2018 10:05:03 +0100 Subject: [PATCH 44/51] Fixed copyright header. --- matlab/identification_analysis.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index 80d22d737..51d71a276 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -28,7 +28,7 @@ function [ide_hess, ide_moments, ide_model, ide_lre, derivatives_info, info, opt % SPECIAL REQUIREMENTS % None -% Copyright (C) 2008-2017 Dynare Team +% Copyright (C) 2008-2018 Dynare Team % % This file is part of Dynare. % From 127a543b656719dcf4a35be373eec9bbc9dec7d7 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 31 Jan 2018 23:25:03 +0100 Subject: [PATCH 45/51] prior bounds: make sure that lower and upper bounds only affect mode-finding https://github.com/DynareTeam/dynare/commit/99dbc8c74d0ecf4c7a610c4a394fd85028cf2741 introduced a bug by disabling the resetting of the prior bounds used for the MCMC. The manual clearly states the bounds are only operational during mode-finding, but not during MCMC (and therefore prior sampling) --- matlab/dynare_estimation_1.m | 1 + matlab/identification_analysis.m | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 49a48a3ec..200898e00 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -422,6 +422,7 @@ end if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ... (any(bayestopt_.pshape >0 ) && options_.load_mh_file) %% not ML estimation + bounds = prior_bounds(bayestopt_, options_.prior_trunc); %reset bounds as lb and ub must only be operational during mode-finding outside_bound_pars=find(xparam1 < bounds.lb | xparam1 > bounds.ub); if ~isempty(outside_bound_pars) for ii=1:length(outside_bound_pars) diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index 51d71a276..108945134 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -155,7 +155,7 @@ if info(1)==0 info = stoch_simul(options_.varobs); dataset_ = dseries(oo_.endo_simul(options_.varobs_id,100+1:end)',dates('1Q1'), options_.varobs); derivatives_info.no_DLIK=1; - %bounds = prior_bounds(bayestopt_, options_.prior_trunc); + bounds = prior_bounds(bayestopt_, options_.prior_trunc); %reset bounds as lb and ub must only be operational during mode-finding [fval,info,cost_flag,DLIK,AHess,ys,trend_coeff,M_,options_,bayestopt_,oo_] = dsge_likelihood(params',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_,derivatives_info); % fval = DsgeLikelihood(xparam1,data_info,options_,M_,estim_params_,bayestopt_,oo_); options_.analytic_derivation = analytic_derivation; From a7bc6414f504313c7b21cb145c346a3ec6748ef3 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 1 Feb 2018 19:14:13 +0100 Subject: [PATCH 46/51] fixed bug to logical if condition --- matlab/utilities/dataset/makedataset.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/utilities/dataset/makedataset.m b/matlab/utilities/dataset/makedataset.m index a26a074c5..7af245efa 100644 --- a/matlab/utilities/dataset/makedataset.m +++ b/matlab/utilities/dataset/makedataset.m @@ -81,7 +81,7 @@ elseif isempty(DynareOptions.datafile) && ~isempty(DynareOptions.dataset.series) elseif ~isempty(DynareOptions.datafile) && isempty(DynareOptions.dataset.file) datafile = DynareOptions.datafile; newdatainterface = 0; -elseif isempty(DynareOptions.datafile) && ~isempty(DynareOptions.dataset.file) +elseif ~isempty(DynareOptions.datafile) && ~isempty(DynareOptions.dataset.file) error('makedataset: You cannot simultaneously use the data command and the datafile option (in the estimation command)!') else error('makedataset: You have to specify the datafile!') From e45acc11ccf7f654be3ca157f50e612ceb12236e Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 1 Feb 2018 19:15:07 +0100 Subject: [PATCH 47/51] fix error in documentation of presample in realtime shock decomposition --- doc/dynare.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 72f63800d..d5a2ff654 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7532,9 +7532,9 @@ model). (@xref{plot_shock_decomposition}). @item presample = @var{INTEGER} -@anchor{presample_shock_decomposition} First data point from which recursive +@anchor{presample_shock_decomposition} Data point above which recursive realtime shock decompositions are computed, @i{i.e.} for -@math{T=[@code{presample}@dots{}@code{nobs}]}. +@math{T=[@code{presample+1}@dots{}@code{nobs}]}. @item forecast = @var{INTEGER} @anchor{forecast_shock_decomposition} Compute shock decompositions up to From cf5f556f4a3aed56c5c0dc2a3a64f94ad38775f0 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 1 Feb 2018 19:17:59 +0100 Subject: [PATCH 48/51] Do not re-set auxiliary variables if they are already available in the input info [i.e. smoothed variables]. This makes the function robust when one provides info using UpdatedVariables, instead, for faster realtime exercises. --- matlab/smoother2histval.m | 58 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/matlab/smoother2histval.m b/matlab/smoother2histval.m index 2668bbef9..8e981fa20 100644 --- a/matlab/smoother2histval.m +++ b/matlab/smoother2histval.m @@ -193,36 +193,38 @@ end % Handle auxiliary variables for lags (both on endogenous and exogenous) for i = 1:length(M_.aux_vars) - if M_.aux_vars(i).type ~= 1 && M_.aux_vars(i).type ~= 3 - continue - end - if M_.aux_vars(i).type == 1 - % Endogenous - orig_var = M_.endo_names{M_.aux_vars(i).orig_index}; - else - % Exogenous - orig_var = M_.exo_names{M_.aux_vars(i).orig_index}; - end - [m, k] = ismember(orig_var, outvars); - if m - if ~isempty(strmatch(invars{k}, M_.endo_names)) - s = getfield(smoothedvars, invars{k}); - else - s = getfield(smoothedshocks, invars{k}); + if ~ ismember(M_.endo_names{M_.aux_vars(i).endo_index},invars) + if M_.aux_vars(i).type ~= 1 && M_.aux_vars(i).type ~= 3 + continue end - l = M_.aux_vars(i).orig_lead_lag; - if period-M_.maximum_endo_lag+1+l < 1 - error('The period that you indicated is too small to construct initial conditions') - end - j = M_.aux_vars(i).endo_index; - v = s((period-M_.maximum_endo_lag+1+l):(period+l)); %+steady_state(j); - if ~isfield(opts, 'outfile') - M_.endo_histval(j, :) = v; + if M_.aux_vars(i).type == 1 + % Endogenous + orig_var = M_.endo_names{M_.aux_vars(i).orig_index}; else - % When saving to a file, x(-2) is in the variable called "x_l2" - lead_lag = num2str(l); - lead_lag = regexprep(lead_lag, '-', 'l'); - o = setfield(o, [ orig_var '_' lead_lag ], v); + % Exogenous + orig_var = M_.exo_names{M_.aux_vars(i).orig_index}; + end + [m, k] = ismember(orig_var, outvars); + if m + if ~isempty(strmatch(invars{k}, M_.endo_names)) + s = getfield(smoothedvars, invars{k}); + else + s = getfield(smoothedshocks, invars{k}); + end + l = M_.aux_vars(i).orig_lead_lag; + if period-M_.maximum_endo_lag+1+l < 1 + error('The period that you indicated is too small to construct initial conditions') + end + j = M_.aux_vars(i).endo_index; + v = s((period-M_.maximum_endo_lag+1+l):(period+l)); %+steady_state(j); + if ~isfield(opts, 'outfile') + M_.endo_histval(j, :) = v; + else + % When saving to a file, x(-2) is in the variable called "x_l2" + lead_lag = num2str(l); + lead_lag = regexprep(lead_lag, '-', 'l'); + o = setfield(o, [ orig_var '_' lead_lag ], v); + end end end end From 4adebd441976c0e31927ed453c3ed17842093510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 1 Feb 2018 22:51:23 +0100 Subject: [PATCH 49/51] Fixed copyright header. --- matlab/utilities/dataset/makedataset.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/utilities/dataset/makedataset.m b/matlab/utilities/dataset/makedataset.m index 7af245efa..0e895f0ac 100644 --- a/matlab/utilities/dataset/makedataset.m +++ b/matlab/utilities/dataset/makedataset.m @@ -24,7 +24,7 @@ function [DynareDataset, DatasetInfo, newdatainterface] = makedataset(DynareOpti % % See also dynare_estimation_init -% Copyright (C) 2014-2017 Dynare Team +% Copyright (C) 2014-2018 Dynare Team % % This file is part of Dynare. % From 224ccb7bab5877efea3e963b2a1859948a9a91eb Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 6 Feb 2018 07:14:47 +0100 Subject: [PATCH 50/51] sim1_linear.m: change hard-coded tolerance to option The tolerance for the steady state check should depend on the accuracy of the steady state computation --- matlab/perfect-foresight-models/sim1_linear.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/sim1_linear.m b/matlab/perfect-foresight-models/sim1_linear.m index af75a61b7..1f64e55c7 100644 --- a/matlab/perfect-foresight-models/sim1_linear.m +++ b/matlab/perfect-foresight-models/sim1_linear.m @@ -116,7 +116,7 @@ x = repmat(transpose(steadystate_x), 1+M.maximum_exo_lag+M.maximum_exo_lead, 1); [d1, jacobian] = dynamicmodel(z, x, params, steadystate_y, M.maximum_exo_lag+1); % Check that the dynamic model was evaluated at the steady state. -if max(abs(d1))>1e-12 +if max(abs(d1))>options.solve_tolf error('Jacobian is not evaluated at the steady state!') end From 350b8fb529e5dccb029f159ba2c201c842348955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sat, 10 Feb 2018 12:24:20 +0100 Subject: [PATCH 51/51] Updated dseries submodule (prevent initialization crash if unable to install X13 binary). --- matlab/modules/dseries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index 883b54f97..67d083402 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit 883b54f977798c0e450a0649a38bae07e95fcedd +Subproject commit 67d08340297265b8da1d059f851627d688a2df69