From 7cbac0c989f6aa4863fca7a6dc9b06a1e2f74578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 5 Jun 2018 19:43:43 +0200 Subject: [PATCH 01/11] Fix user_has_octave_forge_package Packages are no longer autoloaded, so testing whether they are "Loaded" does not work in all cases. The function now ensures that the package is loaded. --- matlab/optimization/dynare_minimize_objective.m | 6 +----- matlab/user_has_octave_forge_package.m | 9 ++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 025d41189..b51617010 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -135,11 +135,7 @@ switch minimizer_algorithm simulated_annealing(objective_function,start_par_value,sa_options,LB,UB,varargin{:}); case 3 if isoctave && ~user_has_octave_forge_package('optim') - try - pkg load optim - catch - error('Optimization algorithm 3 requires the optim package') - end + error('Optimization algorithm 3 requires the optim package') elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox') error('Optimization algorithm 3 requires the Optimization Toolbox') end diff --git a/matlab/user_has_octave_forge_package.m b/matlab/user_has_octave_forge_package.m index 07d918d42..a3f1bc38d 100644 --- a/matlab/user_has_octave_forge_package.m +++ b/matlab/user_has_octave_forge_package.m @@ -20,4 +20,11 @@ function [hasPackage] = user_has_octave_forge_package(package) [desc,flag] = pkg('describe', package); -hasPackage = isequal(flag{1,1}, 'Loaded'); +if isequal(flag{1,1}, 'Not installed') + hasPackage = 0; +else + if isequal(flag{1,1}, 'Not loaded') + pkg('load', package); + end + hasPackage = 1; +end From 933ed45ead196d0805feead898358c3cc7892d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 5 Jun 2018 19:46:09 +0200 Subject: [PATCH 02/11] Octave 4.4 no longer includes statistics functions Those have been moved to the statistics package. If that package is not there, use a fallback. --- matlab/dynare_config.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 513b99c33..05326a246 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -77,16 +77,11 @@ p = {'/distributions/' ; ... % For functions that exist only under some Octave versions % or some MATLAB versions, and for which we provide some replacement functions +% Replacements for rows(), columns(), vec() and issquare() (inexistent under MATLAB) if ~isoctave - % Replacements for rows(), columns() and issquare() (inexistent under MATLAB) p{end+1} = '/missing/rows_columns'; p{end+1} = '/missing/issquare'; - % Replacement for vec() (inexistent under MATLAB) p{end+1} = '/missing/vec'; - if ~user_has_matlab_license('statistics_toolbox') - % Replacements for functions of the stats toolbox - p{end+1} = '/missing/stats/'; - end end % ordeig() doesn't exist in Octave @@ -106,6 +101,13 @@ if (isoctave && ~user_has_octave_forge_package('statistics')) ... p{end+1} = '/missing/nanmean'; end +% Replacements for functions of the MATLAB statistics toolbox +% These functions were part of Octave < 4.4, they are now in the statistics Forge package +if (isoctave && ~octave_ver_less_than('4.4') && ~user_has_octave_forge_package('statistics')) ... + || (~isoctave && ~user_has_matlab_license('statistics_toolbox')) + p{end+1} = '/missing/stats/'; +end + % Check if struct2array is available. if ~exist('struct2array') p{end+1} = '/missing/struct2array'; From 9211d902a09806cffcccdc6412df14f6a110f9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 5 Jun 2018 19:56:42 +0200 Subject: [PATCH 03/11] Update dseries --- matlab/modules/dseries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index 094eafddb..9435d1d72 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit 094eafddb4777f9a6df90fc45db02f3e5a4ca539 +Subproject commit 9435d1d72b9b33596ab5b605bd95873b4eb513ed From 57f6183d2f84c18ab1e7435f33610d29c665b993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 6 Jun 2018 13:02:42 +0200 Subject: [PATCH 04/11] Move some functions out of missing/stats/, since they are only needed for MATLAB --- license.txt | 7 ++++--- matlab/dynare_config.m | 3 +++ matlab/missing/{stats => stats-matlab}/common_size.m | 0 matlab/missing/{stats => stats-matlab}/corr.m | 0 matlab/missing/{stats => stats-matlab}/quantile.m | 0 5 files changed, 7 insertions(+), 3 deletions(-) rename matlab/missing/{stats => stats-matlab}/common_size.m (100%) rename matlab/missing/{stats => stats-matlab}/corr.m (100%) rename matlab/missing/{stats => stats-matlab}/quantile.m (100%) diff --git a/license.txt b/license.txt index 651112b5c..afb06aa4b 100644 --- a/license.txt +++ b/license.txt @@ -143,23 +143,24 @@ Copyright: 2005 Henning Schmidt, FCC, henning@fcc.chalmers.se License: GPL-3+ Files: matlab/missing/stats/normpdf.m matlab/missing/stats/gamcdf.m - matlab/missing/stats/common_size.m matlab/missing/stats/chi2inv.m + matlab/missing/stats/chi2inv.m matlab/missing/stats/gaminv.m matlab/missing/stats/gampdf.m matlab/missing/stats/stdnormal_inv.m matlab/missing/stats/betacdf.m matlab/missing/stats/betapdf.m matlab/missing/stats/normcdf.m matlab/missing/stats/stdnormal_cdf.m matlab/missing/stats/norminv.m matlab/missing/stats/stdnormal_pdf.m matlab/missing/stats/betainv.m + matlab/missing/stats-matlab/common_size.m Copyright: 1995-2007 Kurt Hornik 2008-2011 Dynare Team License: GPL-3+ -Files: matlab/missing/stats/quantile.m +Files: matlab/missing/stats-matlab/quantile.m Copyright: 2014-2016 Christopher Hummersone 2016 Dynare Team License: GPL-3+ -Files: matlab/missing/stats/corr.m +Files: matlab/missing/stats-matlab/corr.m Copyright: 1993-1996 Kurt Hornik 1996-2015 John W. Eaton 2013-2015 Julien Bect diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 05326a246..acdf95456 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -106,6 +106,9 @@ end if (isoctave && ~octave_ver_less_than('4.4') && ~user_has_octave_forge_package('statistics')) ... || (~isoctave && ~user_has_matlab_license('statistics_toolbox')) p{end+1} = '/missing/stats/'; + if ~isoctave + p{end+1} = '/missing/stats-matlab/'; + end end % Check if struct2array is available. diff --git a/matlab/missing/stats/common_size.m b/matlab/missing/stats-matlab/common_size.m similarity index 100% rename from matlab/missing/stats/common_size.m rename to matlab/missing/stats-matlab/common_size.m diff --git a/matlab/missing/stats/corr.m b/matlab/missing/stats-matlab/corr.m similarity index 100% rename from matlab/missing/stats/corr.m rename to matlab/missing/stats-matlab/corr.m diff --git a/matlab/missing/stats/quantile.m b/matlab/missing/stats-matlab/quantile.m similarity index 100% rename from matlab/missing/stats/quantile.m rename to matlab/missing/stats-matlab/quantile.m From 88e89dfb21f2f8232cf13733435de50a958e8322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 6 Jun 2018 14:27:53 +0200 Subject: [PATCH 05/11] Refactor test for Octave version Distinguish between a minimal version required (from a source code perspective, applicable on all platforms) and an exact version requirement (from a binary package perspective, in practice used only for our Windows package). --- matlab/dynare.m | 13 ++++++++++--- matlab/supported_octave_version.m | 20 -------------------- 2 files changed, 10 insertions(+), 23 deletions(-) delete mode 100644 matlab/supported_octave_version.m diff --git a/matlab/dynare.m b/matlab/dynare.m index 6c25e1915..fccfe619c 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -71,13 +71,20 @@ dynareroot = dynare_config('', preprocessoroutput); warning_config() if isoctave - if octave_ver_less_than(supported_octave_version) + % The supported_octave_version.m file is not in git nor in the source + % package, it is manually added in binary packages distributed on dynare.org + if exist('supported_octave_version', 'file') && ~strcmp(supported_octave_version, version) skipline() warning(['This version of Octave is not supported. Consider installing ' ... - 'version %s+ of Octave,\notherwise m files will be used instead ' ... - 'of precompiled mex files and some features, like solution\n' ... + 'version %s of Octave\n' ... + 'from www.octave.org, otherwise m files will be used instead ' ... + 'of precompiled mex files and some\nfeatures, like solution ' ... 'of models approximated at third order, will not be available.'], supported_octave_version()) skipline() + elseif octave_ver_less_than('4.2') % Should match the test in mex/build/octave/configure.ac + skipline() + warning(['This version of Dynare has only been tested on Octave 4.2 and above. Dynare may fail to run or give unexpected result. Consider upgrading your version of Octave.']) + skipline() end else if matlab_ver_less_than('7.5') diff --git a/matlab/supported_octave_version.m b/matlab/supported_octave_version.m deleted file mode 100644 index 97e2c4605..000000000 --- a/matlab/supported_octave_version.m +++ /dev/null @@ -1,20 +0,0 @@ -function v = supported_octave_version() - -% Copyright (C) 2017 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -v = '4.2.1'; \ No newline at end of file From a71e0ebee4c52748436c0e7ae2066705c9a3aea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 6 Jun 2018 14:31:25 +0200 Subject: [PATCH 06/11] Add a compile-time check for MATLAB version, as we already do for Octave --- matlab/dynare.m | 2 +- mex/build/matlab/configure.ac | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index fccfe619c..e04d24d79 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -87,7 +87,7 @@ if isoctave skipline() end else - if matlab_ver_less_than('7.5') + if matlab_ver_less_than('7.5') % Should match the test in mex/build/matlab/configure.ac skipline() warning('This version of Dynare has only been tested on MATLAB 7.5 (R2007b) and above. Since your MATLAB version is older than that, Dynare may fail to run, or give unexpected results. Consider upgrading your MATLAB installation, or switch to Octave.'); skipline() diff --git a/mex/build/matlab/configure.ac b/mex/build/matlab/configure.ac index 668706229..40e93d6f8 100644 --- a/mex/build/matlab/configure.ac +++ b/mex/build/matlab/configure.ac @@ -34,6 +34,7 @@ if test "x$ax_enable_matlab" = "xyes"; then if test "x$ax_matlab_version_ok" = "xyes"; then AX_MEXOPTS + AX_COMPARE_VERSION([$MATLAB_VERSION], [lt], [7.5], [AC_MSG_ERROR([Your MATLAB is too old, please upgrade to version 7.5 (R2007b) at least.])]) fi CFLAGS="$MATLAB_CFLAGS" From b080e5d7b1633fdfcbdd6007ecbae804c34f7c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 6 Jun 2018 16:42:50 +0200 Subject: [PATCH 07/11] Convert the ramst.mod example to new perfect foresight syntax --- examples/ramst.mod | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/ramst.mod b/examples/ramst.mod index df4029ad4..90654a4ef 100644 --- a/examples/ramst.mod +++ b/examples/ramst.mod @@ -74,8 +74,11 @@ periods 1; values 1.2; end; -// Deterministic simulation of the model for 200 periods -simul(periods=200); +// Prepare the deterministic simulation of the model over 200 periods +perfect_foresight_setup(periods=200); + +// Perform the simulation +perfect_foresight_solver; // Display the path of consumption and capital rplot c; From 8913791ff0972f8a56d6c5d0d325d1cb6fda7189 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Thu, 7 Jun 2018 12:20:04 +0200 Subject: [PATCH 08/11] fixes bug for solve_algo = 10 and lags on exogenous variables --- matlab/perfect-foresight-models/perfect_foresight_problem.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/perfect_foresight_problem.m b/matlab/perfect-foresight-models/perfect_foresight_problem.m index a4df03f80..d27ec6eaf 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_problem.m +++ b/matlab/perfect-foresight-models/perfect_foresight_problem.m @@ -71,7 +71,7 @@ i_rows = 1:ny; i_cols_J = i_cols; offset = 0; -for it = 2:(T+1) +for it = (maximum_lag+1):(T+1) if nargout == 1 residuals(i_rows) = dynamic_function(YY(i_cols),exo_simul, params, ... steady_state,it); From 09ac7f6249e1553396ab0b70ff7e96ed72aafb1c Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 7 Jun 2018 13:17:21 +0200 Subject: [PATCH 09/11] identification_analysis.m: make sure that increase in options_.ar is passed back via options_ident --- matlab/identification_analysis.m | 1 + 1 file changed, 1 insertion(+) diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index 108945134..768bc5b31 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -102,6 +102,7 @@ if info(1)==0 derivatives_info.DOm=dOm; derivatives_info.DYss=dYss; options_.ar=nlags; + options_ident.ar=nlags; indJJ = (find(max(abs(JJ'),[],1)>1.e-8)); end if length(indJJ) Date: Thu, 7 Jun 2018 16:14:02 +0200 Subject: [PATCH 10/11] Fix various issues with stack_solve_algo=7 and lags on exogenous > 1 Complete the fix started in 8913791ff0972f8a56d6c5d0d325d1cb6fda7189. Change the test case to prevent regressions. --- .../linear_perfect_foresight_problem.m | 4 ++-- .../perfect_foresight_mcp_problem.m | 8 ++++---- .../perfect-foresight-models/perfect_foresight_problem.m | 8 ++++---- .../private/initialize_stacked_problem.m | 6 +++--- matlab/perfect-foresight-models/solve_stacked_problem.m | 2 +- tests/deterministic_simulations/rbc_det.mod | 2 +- .../rbc_det_stack_solve_algo_7.mod | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m b/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m index 78d9fed41..3a04ea8e1 100644 --- a/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m +++ b/matlab/perfect-foresight-models/linear_perfect_foresight_problem.m @@ -55,9 +55,9 @@ for it = maximum_lag+(1:T) z(jexog) = transpose(exo_simul(it,:)); residuals(i_rows) = dynamicjacobian*z; if nargout == 2 - if it == 2 + if it == maximum_lag+1 JJacobian(i_rows,i_cols_J1) = dynamicjacobian(:,i_cols_1); - elseif it == T + 1 + elseif it == maximum_lag+T JJacobian(i_rows,i_cols_J(i_cols_T)) = dynamicjacobian(:,i_cols_T); else JJacobian(i_rows,i_cols_J) = dynamicjacobian(:,i_cols_j); diff --git a/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m b/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m index eb898322d..000fff50f 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m +++ b/matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m @@ -74,7 +74,7 @@ i_rows = 1:ny; offset = 0; i_cols_J = i_cols; -for it = 2:(T+1) +for it = maximum_lag+(1:T) if nargout == 1 res = dynamic_function(YY(i_cols),exo_simul, params, ... steady_state,it); @@ -83,15 +83,15 @@ for it = 2:(T+1) [res,jacobian] = dynamic_function(YY(i_cols),exo_simul, params, ... steady_state,it); residuals(i_rows) = res(eq_index); - if it == 2 + if it == maximum_lag+1 [rows,cols,vals] = find(jacobian(eq_index,i_cols_1)); iJacobian{1} = [offset+rows, i_cols_J1(cols), vals]; - elseif it == T + 1 + elseif it == maximum_lag+T [rows,cols,vals] = find(jacobian(eq_index,i_cols_T)); iJacobian{T} = [offset+rows, i_cols_J(i_cols_T(cols)), vals]; else [rows,cols,vals] = find(jacobian(eq_index,i_cols_j)); - iJacobian{it-1} = [offset+rows, i_cols_J(cols), vals]; + iJacobian{it-maximum_lag} = [offset+rows, i_cols_J(cols), vals]; i_cols_J = i_cols_J + ny; end offset = offset + ny; diff --git a/matlab/perfect-foresight-models/perfect_foresight_problem.m b/matlab/perfect-foresight-models/perfect_foresight_problem.m index d27ec6eaf..c6c6f77a7 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_problem.m +++ b/matlab/perfect-foresight-models/perfect_foresight_problem.m @@ -71,22 +71,22 @@ i_rows = 1:ny; i_cols_J = i_cols; offset = 0; -for it = (maximum_lag+1):(T+1) +for it = maximum_lag+(1:T) if nargout == 1 residuals(i_rows) = dynamic_function(YY(i_cols),exo_simul, params, ... steady_state,it); elseif nargout == 2 [residuals(i_rows),jacobian] = dynamic_function(YY(i_cols),exo_simul, params, ... steady_state,it); - if it == 2 + if it == maximum_lag+1 [rows,cols,vals] = find(jacobian(:,i_cols_1)); iJacobian{1} = [offset+rows, i_cols_J1(cols), vals]; - elseif it == T + 1 + elseif it == maximum_lag+T [rows,cols,vals] = find(jacobian(:,i_cols_T)); iJacobian{T} = [offset+rows, i_cols_J(i_cols_T(cols)), vals]; else [rows,cols,vals] = find(jacobian(:,i_cols_j)); - iJacobian{it-1} = [offset+rows, i_cols_J(cols), vals]; + iJacobian{it-maximum_lag} = [offset+rows, i_cols_J(cols), vals]; i_cols_J = i_cols_J + ny; end offset = offset + ny; diff --git a/matlab/perfect-foresight-models/private/initialize_stacked_problem.m b/matlab/perfect-foresight-models/private/initialize_stacked_problem.m index 014bb9acb..0f14b2367 100644 --- a/matlab/perfect-foresight-models/private/initialize_stacked_problem.m +++ b/matlab/perfect-foresight-models/private/initialize_stacked_problem.m @@ -67,9 +67,9 @@ elseif (options.solve_algo == 11) end end -y0 = endogenousvariables(:,1); -yT = endogenousvariables(:,periods+2); -z = endogenousvariables(:,2:periods+1); +y0 = endogenousvariables(:,M.maximum_lag); +yT = endogenousvariables(:,M.maximum_lag+periods+1); +z = endogenousvariables(:,M.maximum_lag+(1:periods)); illi = M.lead_lag_incidence'; [i_cols, junk,i_cols_j] = find(illi(:)); illi = illi(:,2:3); diff --git a/matlab/perfect-foresight-models/solve_stacked_problem.m b/matlab/perfect-foresight-models/solve_stacked_problem.m index 8f033bbf6..3a1e2e715 100644 --- a/matlab/perfect-foresight-models/solve_stacked_problem.m +++ b/matlab/perfect-foresight-models/solve_stacked_problem.m @@ -69,7 +69,7 @@ else check = 1; end -endogenousvariables = [y0 reshape(y, M.endo_nbr, options.periods) yT]; +endogenousvariables(:, M.maximum_lag+(1:options.periods)) = reshape(y, M.endo_nbr, options.periods); if check info.status = false; diff --git a/tests/deterministic_simulations/rbc_det.mod b/tests/deterministic_simulations/rbc_det.mod index 71fdbd59f..1454609c0 100644 --- a/tests/deterministic_simulations/rbc_det.mod +++ b/tests/deterministic_simulations/rbc_det.mod @@ -17,7 +17,7 @@ sigma2 = 0; model; // Eq. n°1: - efficiency = rho*efficiency(-1) + EfficiencyInnovation; + efficiency = rho*efficiency(-1) + EfficiencyInnovation(-2); // Use a lag of two to test the maximum_lag logic // Eq. n°2: Efficiency = effstar*exp(efficiency); diff --git a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod index a4c829ffb..baf60baf2 100644 --- a/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod +++ b/tests/deterministic_simulations/rbc_det_stack_solve_algo_7.mod @@ -17,7 +17,7 @@ sigma2 = 0; model; // Eq. n°1: - efficiency = rho*efficiency(-1) + EfficiencyInnovation; + efficiency = rho*efficiency(-1) + EfficiencyInnovation(-2); // Use a lag of two to test the maximum_lag logic // Eq. n°2: Efficiency = effstar*exp(efficiency); From 856fc060a2e82a5d9f36861d81a57af47d15586f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 7 Jun 2018 17:41:54 +0200 Subject: [PATCH 11/11] submodule update: preprocessor --- preprocessor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor b/preprocessor index a30f8f365..84c2dc5f3 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit a30f8f365e89b9520fa44caa6c3c1c288c0adbba +Subproject commit 84c2dc5f3621d47407397d519b623eb9d1fc1eb3