From d5eb6e2d13255046e96ed8be622a4c3fb9b4ff49 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 11 Jul 2018 14:38:17 +0200 Subject: [PATCH 01/24] preprocessor: submodule update --- preprocessor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor b/preprocessor index 15f5f4f1b..3776e3b89 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 15f5f4f1bedbaf289aeda49466e01c6025db4cd0 +Subproject commit 3776e3b890a137e690008a59a8552cc4eaa47a3d From 8ff8d787e824392ae33a4c3d265d90b269dc1fa7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 11 Jul 2018 14:45:32 +0200 Subject: [PATCH 02/24] modify on-the-fly example to accept variables declared in equation tag --- tests/example1_on_the_fly.mod | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/example1_on_the_fly.mod b/tests/example1_on_the_fly.mod index fd0786eda..84f7b6d62 100644 --- a/tests/example1_on_the_fly.mod +++ b/tests/example1_on_the_fly.mod @@ -9,6 +9,11 @@ ** |x is an exogenous variable, ** |p is a parameter. ** +** Variables can also be declared on the fly via equation tags: +** [endogenous='varname'] +** [exogenous='varname'] +** [parameter='varname'] +** ** Example. If the first equation (consumption/leisure arbitrage) is removed from the following model block, then h (hours) ** will be interpreted as an exogenous variable. */ @@ -17,7 +22,8 @@ model; c*theta|p*h|e^(1+psi|p)=(1-alpha)*y; k|e = beta|p*(((exp(b)*c)/(exp(b(+1))*c(+1))) *(exp(b(+1))*alpha|p*y(+1)+(1-delta)*k)); -y|e = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); +[endogenous='y'] +y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); k = exp(b)*(y-c|e)+(1-delta|p)*k(-1); a|e = rho|p*a(-1)+tau*b(-1) + e|x; b|e = tau|p*a(-1)+rho*b(-1) + u|x; From 30c41733bcc9f437621dd4d7914ce0509e706fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Thu, 12 Jul 2018 19:38:15 +0200 Subject: [PATCH 03/24] Updated dseries submodule. --- matlab/modules/dseries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index c39250be8..97b8749f5 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit c39250be89c8ee4bf90e499ea9a6c417cc92d9b9 +Subproject commit 97b8749f5a59d95b4367310c13d2fd26e851cd6c From ff676f550544f47d014a7b98d4fbeb80807cdcf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 13 Jul 2018 14:12:58 +0200 Subject: [PATCH 04/24] Gracefully fail when Octave crashes in a *.m test --- tests/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 22d8accd3..194cdda69 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -902,7 +902,8 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) %.o.trs %.o.log : %.m @echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ - $(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1 + $(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1 || \ + printf ":test-result: FAIL\n:number-tests: 1\n:number-failed-tests: 1\n:list-of-failed-tests: $*.m\n:elapsed-time: 0.0\n" > $*.o.trs @echo "`tput bold``tput setaf 8`OCTAVE: $(PWD)/$* Done!`tput sgr0`" %.m.tls : %.m From 7685a0ccda2a2b70bd0cde2ac442c61df41b7776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 13 Jul 2018 17:21:16 +0200 Subject: [PATCH 05/24] Octave compatibility fix Now that the set_auxiliary_variables file is in a "+" directory, Octave fails at str2func if the file does not exist. --- matlab/evaluate_steady_state.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index 7b35ffce9..6247d88ff 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -46,11 +46,9 @@ steadystate_flag = options.steadystate_flag; params = M.params; exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state]; -if length(M.aux_vars) > 0 && ~steadystate_flag +if length(M.aux_vars) > 0 && ~steadystate_flag && M.set_auxiliary_variables h_set_auxiliary_variables = str2func([M.fname '.set_auxiliary_variables']); - if M.set_auxiliary_variables - ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); - end + ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params); end if options.ramsey_policy From 0074561182fb38adf598e9a507003625d461bd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Sat, 14 Jul 2018 11:54:01 +0200 Subject: [PATCH 06/24] Updated dseries submodule (unit test fix). --- matlab/modules/dseries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index 97b8749f5..bbb133b9a 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit 97b8749f5a59d95b4367310c13d2fd26e851cd6c +Subproject commit bbb133b9ad1f30b0fa835053f68e39a6ec299d4f From 9d01b17e03b35199c1b82a0e9edeffd8ae23fc4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Tue, 17 Jul 2018 11:30:20 +0200 Subject: [PATCH 07/24] Removed one unit test from Octave testsuite. --- matlab/missing/stats-matlab/corr.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/matlab/missing/stats-matlab/corr.m b/matlab/missing/stats-matlab/corr.m index ec2f719a1..24c53c010 100644 --- a/matlab/missing/stats-matlab/corr.m +++ b/matlab/missing/stats-matlab/corr.m @@ -135,10 +135,14 @@ end %@eof:2 %@test:3 -%$ t = zeros(3,1); -%$ t(1) = dassert(corr(5), NaN); -%$ t(2) = dassert(corr([1 2 3],5),NaN(3,1)); -%$ t(3) = dassert(corr(5,[1 2 3]),NaN(1,3)); +%$ if ~isoctave() +%$ t = zeros(3,1); +%$ t(1) = dassert(corr(5), NaN); +%$ t(2) = dassert(corr([1 2 3],5),NaN(3,1)); +%$ t(3) = dassert(corr(5,[1 2 3]),NaN(1,3)); +%$ else +%$ t = 1; +%$ end %$ T = all(t); %@eof:3 From 4154817acc9ea4384731992f485cd1b3c03a5ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Tue, 17 Jul 2018 14:37:10 +0200 Subject: [PATCH 08/24] Added missin semicolons. (cherry picked from commit 4a0b1c2e93d23c85a7874b1bbea85819f56739f5) --- matlab/distributions/lpdfgweibull.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/matlab/distributions/lpdfgweibull.m b/matlab/distributions/lpdfgweibull.m index 708a5b4d4..f09791903 100644 --- a/matlab/distributions/lpdfgweibull.m +++ b/matlab/distributions/lpdfgweibull.m @@ -252,7 +252,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(density, .0000000001, 100000,1e-10) +%$ s = quadv(density, .0000000001, 100000,1e-10); %$ else %$ s = integral(density, 0, 100000); %$ end @@ -279,7 +279,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(xdens, .0000000001, 20,1e-10) +%$ s = quadv(xdens, .0000000001, 20,1e-10); %$ else %$ s = integral(xdens, 0, 100000); %$ end @@ -302,7 +302,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(xdens, .0000000001, 100000,1e-10) +%$ s = quadv(xdens, .0000000001, 100000,1e-10); %$ else %$ s = integral(xdens, 0, 100000); %$ end @@ -325,7 +325,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(xdens, .0000000001, 100000,1e-10) +%$ s = quadv(xdens, .0000000001, 100000,1e-10); %$ else %$ s = integral(xdens, 0, 100000); %$ end @@ -351,7 +351,7 @@ end %$ s = NaN(n, 1); %$ for i=1:n %$ if isoctave() -%$ s(i) = quadv(density, .0000000001, .1*i,1e-10) +%$ s(i) = quadv(density, .0000000001, .1*i,1e-10); %$ else %$ s(i) = integral(density, 0, .1*i); %$ end @@ -382,7 +382,7 @@ end %$ s = NaN(n, 1); %$ for i=1:n %$ if isoctave() -%$ s(i) = quadv(density, .0000000001, .1*i,1e-10) +%$ s(i) = quadv(density, .0000000001, .1*i,1e-10); %$ else %$ s(i) = integral(density, 0, .1*i); %$ end @@ -413,7 +413,7 @@ end %$ s = NaN(n, 1); %$ for i=1:n %$ if isoctave() -%$ s(i) = quadv(density, .0000000001, .1*i,1e-10) +%$ s(i) = quadv(density, .0000000001, .1*i,1e-10); %$ else %$ s(i) = integral(density, 0, .1*i); %$ end From 0d27bd8dea4634f76a5fa36265f96cdfa06a462a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Tue, 17 Jul 2018 15:32:07 +0200 Subject: [PATCH 09/24] Fixed unit tests on Weibull pdf (Octave testsuite). (cherry picked from commit bc962a91c0749e6c9f108c867acde134e6bb80fc) --- matlab/distributions/lpdfgweibull.m | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/matlab/distributions/lpdfgweibull.m b/matlab/distributions/lpdfgweibull.m index f09791903..cd8c8fd5c 100644 --- a/matlab/distributions/lpdfgweibull.m +++ b/matlab/distributions/lpdfgweibull.m @@ -206,7 +206,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(density, .0000000001, 100000,1e-10); +%$ s = quadl(density, .0000000001, 100000, 1e-10); %$ else %$ s = integral(density, 0, 100000); %$ end @@ -229,7 +229,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(density, .0000000001, 100000,1e-10); +%$ s = quadl(density, .0000000001, 100000, 1e-10); %$ else %$ s = integral(density, 0, 100000); %$ end @@ -252,7 +252,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(density, .0000000001, 100000,1e-10); +%$ s = quadl(density, .0000000001, 100000, 1e-10); %$ else %$ s = integral(density, 0, 100000); %$ end @@ -279,7 +279,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(xdens, .0000000001, 20,1e-10); +%$ s = quadgk(xdens, .0000000001, 100000, 1e-10); %$ else %$ s = integral(xdens, 0, 100000); %$ end @@ -302,7 +302,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(xdens, .0000000001, 100000,1e-10); +%$ s = quadl(xdens, .0000000001, 100000, 1e-10); %$ else %$ s = integral(xdens, 0, 100000); %$ end @@ -325,7 +325,7 @@ end %$ %$ try %$ if isoctave -%$ s = quadv(xdens, .0000000001, 100000,1e-10); +%$ s = quadl(xdens, .0000000001, 100000, 1e-10); %$ else %$ s = integral(xdens, 0, 100000); %$ end @@ -351,7 +351,7 @@ end %$ s = NaN(n, 1); %$ for i=1:n %$ if isoctave() -%$ s(i) = quadv(density, .0000000001, .1*i,1e-10); +%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10); %$ else %$ s(i) = integral(density, 0, .1*i); %$ end @@ -382,7 +382,7 @@ end %$ s = NaN(n, 1); %$ for i=1:n %$ if isoctave() -%$ s(i) = quadv(density, .0000000001, .1*i,1e-10); +%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10); %$ else %$ s(i) = integral(density, 0, .1*i); %$ end @@ -413,7 +413,7 @@ end %$ s = NaN(n, 1); %$ for i=1:n %$ if isoctave() -%$ s(i) = quadv(density, .0000000001, .1*i,1e-10); +%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10); %$ else %$ s(i) = integral(density, 0, .1*i); %$ end From 8b0d6734580c75d4a7bcea132d3f4b2248e6f8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Tue, 17 Jul 2018 15:36:29 +0200 Subject: [PATCH 10/24] Cosmetic change (Octave unit test). (cherry picked from commit 48ee13646a072d0ad9466f901f2d048594717d71) --- matlab/isolder.m | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/matlab/isolder.m b/matlab/isolder.m index d364c5c62..2c4de8bfd 100644 --- a/matlab/isolder.m +++ b/matlab/isolder.m @@ -58,31 +58,31 @@ end %@test:1 %$ t = false(3,1); -%$ mkdir toto +%$ mkdir toto; %$ cd toto -%$ mkdir titi -%$ mkdir tata +%$ mkdir titi; +%$ mkdir tata; %$ cd tata -%$ mkdir tutu +%$ mkdir tutu; %$ cd tutu -%$ system('touch a.m') +%$ system('touch a.m'); %$ cd .. -%$ system('touch b.m') -%$ system('touch c.m') +%$ system('touch b.m'); +%$ system('touch c.m'); %$ cd ../titi -%$ system('touch d.m') +%$ system('touch d.m'); %$ cd .. %$ pause(1) -%$ system('touch e.m') +%$ system('touch e.m'); %$ t(1) = isequal(isolder('e.m'), false); %$ pause(1) -%$ system('touch tata/tutu/a.m') -%$ system('touch tata/b.m') -%$ system('touch tata/c.m') -%$ system('touch titi/d.m') +%$ system('touch tata/tutu/a.m'); +%$ system('touch tata/b.m'); +%$ system('touch tata/c.m'); +%$ system('touch titi/d.m'); %$ t(2) = isequal(isolder('e.m'), true); %$ pause(1) -%$ system('touch e.m') +%$ system('touch e.m'); %$ t(3) = isequal(isolder('e.m'), false); %$ cd .. %$ if isoctave() From 064b270795e9cacf99687cdc476eecc10e287110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Tue, 17 Jul 2018 18:41:25 +0200 Subject: [PATCH 11/24] Updated dseries submodule (Octave testsuite fixes). --- matlab/modules/dseries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index bbb133b9a..18e9c7533 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit bbb133b9ad1f30b0fa835053f68e39a6ec299d4f +Subproject commit 18e9c7533f0432bdce424bfde6c9dc480a2e823e From 59b77857193df1b28ece3000e07730607d25cfcc Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Wed, 18 Jul 2018 11:04:46 +0200 Subject: [PATCH 12/24] adding package update command line for Debian --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1b0f72c42..562c7074c 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,12 @@ Alternatively, if you want to build everything, manually install the following p - `latex2html` - `doxygen` +You can load all necessary packages at once with +``` +sudo apt install build-essential gfortran liboctave-dev libboost-graph-dev libboost-filesystem-dev libgsl-dev libmatio-dev libslicot-dev libslicot-pic libsuitesparse-dev flex bison autoconf automake texlive texlive-publishers texlive-extra-utils texlive-formats-extra texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texinfo lmodern latex2html doxygen + +``` + ## Fedora **NB**: Documentation still in progress… From ac3af2052acd7e2026fa3d6ffd5878775722a928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Wed, 18 Jul 2018 11:12:30 +0200 Subject: [PATCH 13/24] Remove test from Octave testsuite. The function is only called by Matlab if the statistics toolbox is not available. --- matlab/missing/stats-matlab/quantile.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/matlab/missing/stats-matlab/quantile.m b/matlab/missing/stats-matlab/quantile.m index a63baada0..7cb017f14 100644 --- a/matlab/missing/stats-matlab/quantile.m +++ b/matlab/missing/stats-matlab/quantile.m @@ -236,6 +236,12 @@ y = ipermute(y,order); %@test:1 +%$ if isoctave() +%$ t = true; +%$ T = t; +%$ LOG = NaN; +%$ return +%$ end %$ X = randn(10000000, 1); %$ %$ try From 5361325ba9b6a3b8a961cf8b9466c2a2468004b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Wed, 18 Jul 2018 12:18:43 +0200 Subject: [PATCH 14/24] Fixed unit test (false negative in Octave testsuite). --- matlab/load_m_file_data_legacy.m | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/matlab/load_m_file_data_legacy.m b/matlab/load_m_file_data_legacy.m index 9d4b8e34c..a78563796 100644 --- a/matlab/load_m_file_data_legacy.m +++ b/matlab/load_m_file_data_legacy.m @@ -82,7 +82,7 @@ return %@test:1 % Write a data file -fid = fopen('example.m','w'); +fid = fopen('example1.m','w'); fwriten(fid, 'a = randn(100,1);'); fwriten(fid, 'b = randn(100,1);'); fwriten(fid, 'c = transpose(randn(100,1));'); @@ -98,8 +98,8 @@ fclose(fid); listofvariablestobeloaded = {'b', 'a'}; % Test if we can load the data. try - data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); - delete example.m + data = load_m_file_data_legacy('example1.m', listofvariablestobeloaded); + delete('example1.m'); t(1) = 1; catch t(1) = 0; @@ -109,7 +109,7 @@ T = all(t); %@test:2 % Write a data file -fid = fopen('example.m','w'); +fid = fopen('example2.m','w'); fwriten(fid, 'a = randn(100,1);'); fwriten(fid, 'b = randn(100,1);'); fwriten(fid, 'c = transpose(randn(100,1));'); @@ -125,8 +125,8 @@ fclose(fid); listofvariablestobeloaded = {'e', 'a'}; % Test if we can load the data. try - data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); - delete example.m + data = load_m_file_data_legacy('example2.m', listofvariablestobeloaded); + delete('example2.m'); t(1) = 0; catch t(1) = 1; @@ -136,7 +136,7 @@ T = all(t); %@test:3 % Write a data file -fid = fopen('example.m','w'); +fid = fopen('example3.m','w'); fwriten(fid, 'a = randn(100,1);'); fwriten(fid, 'b = randn(100,1);'); fwriten(fid, 'c = transpose(randn(100,1));'); @@ -152,8 +152,8 @@ fclose(fid); listofvariablestobeloaded = {'c', 'a'}; % Test if we can load the data. try - data = load_m_file_data_legacy('example.m', listofvariablestobeloaded); - delete example.m + data = load_m_file_data_legacy('example3.m', listofvariablestobeloaded); + delete('example3.m'); t(1) = 1; catch t(1) = 0; From 9c3ce0350dee72322dccf3ae363288a1d1d16f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 18 Jul 2018 14:38:11 +0200 Subject: [PATCH 15/24] Replace LMMCP test with another one that converges Incidentally the new one takes far less time, especially on Octave. --- tests/lmmcp/rbcii.mod | 99 ++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/tests/lmmcp/rbcii.mod b/tests/lmmcp/rbcii.mod index 9b284182b..84ca64539 100644 --- a/tests/lmmcp/rbcii.mod +++ b/tests/lmmcp/rbcii.mod @@ -1,74 +1,67 @@ -var Capital, Output, Labour, Consumption, Investment, Efficiency, efficiency, residual, marginal_utility; - -varexo EfficiencyInnovation; - -parameters beta, theta, tau, alpha, psi, delta, rho, effstar, sigma; - -/* -** Calibration -*/ +var k, y, L, c, i, A, a, mu; +varexo epsilon; +parameters beta, theta, tau, alpha, psi, delta, rho, Astar, sigma; beta = 0.990; theta = 0.357; tau = 2.000; alpha = 0.450; -psi = -0.200; +psi = -2.500; delta = 0.020; -rho = 0.800; -effstar = 1.000; +rho = 0.998; +Astar = 1.000; sigma = 0.100; model; + a = rho*a(-1) + sigma*epsilon; + A = Astar*exp(a); + (c^theta*(1-L)^(1-theta))^(1-tau)/c - mu = beta*((c(+1)^theta*(1-L(+1))^(1-theta))^(1-tau)/c(+1)*(alpha*(y(+1)/k)^(1-psi)+1-delta)-mu(+1)*(1-delta)); + ((1-theta)/theta)*(c/(1-L)) - (1-alpha)*(y/L)^(1-psi); + y = A*(alpha*(k(-1)^psi)+(1-alpha)*(L^psi))^(1/psi); + k = y-c+(1-delta)*k(-1); + i = k-(1-delta)*k(-1); - efficiency = rho*efficiency(-1) + sigma*EfficiencyInnovation; - - Efficiency = effstar*exp(efficiency); - - [mcp = 'Investment > 0',name='Investment Euler Equation'] - -(((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption + beta*((((Consumption(+1)^theta)*((1-Labour(+1))^(1-theta)))^(1-tau))/Consumption(+1))*(alpha*((Output(+1)/Capital)^(1-psi))+1-delta); - - residual = (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - beta*((((Consumption(+1)^theta)*((1-Labour(+1))^(1-theta)))^(1-tau))/Consumption(+1))*(alpha*((Output(+1)/Capital)^(1-psi))+1-delta); - - ((1-theta)/theta)*(Consumption/(1-Labour)) - (1-alpha)*(Output/Labour)^(1-psi); - - Output = Efficiency*(alpha*(Capital(-1)^psi)+(1-alpha)*(Labour^psi))^(1/psi); - - Output = Consumption + Investment; - - Investment = Capital - (1-delta)*Capital(-1); - - marginal_utility = (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption; +[ mcp = 'i > 0' ] + mu = 0; end; steady_state_model; -Efficiency = effstar; -y_k = (Efficiency^(-psi)*(1/beta-1+delta)/alpha)^(1/(1-psi)); -c_k = y_k - delta; -n_k = (((y_k/Efficiency)^psi-alpha)/(1-alpha))^(1/psi); -y_n = y_k/n_k; -c_n = c_k/n_k; -Labour = y_k*(1-alpha)/(((1-theta)/theta)*c_k*(alpha*n_k^(-psi)+1-alpha)+y_k*(1-alpha)); -Capital = Labour/n_k; -Consumption = c_n*Labour; -Output = Efficiency*(alpha*Capital^psi+(1-alpha)*Labour^psi)^(1/psi); -Investment = delta*Capital; -residual = 0; -marginal_utility = (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption; -end; + a=0; + mu=0; + A=Astar; -resid; -steady; + // Steady state ratios + Output_per_unit_of_Capital=((1/beta-1+delta)/alpha)^(1/(1-psi)); + Consumption_per_unit_of_Capital=Output_per_unit_of_Capital-delta; + Labour_per_unit_of_Capital=(((Output_per_unit_of_Capital/A)^psi-alpha)/(1-alpha))^(1/psi); + Output_per_unit_of_Labour=Output_per_unit_of_Capital/Labour_per_unit_of_Capital; + Consumption_per_unit_of_Labour=Consumption_per_unit_of_Capital/Labour_per_unit_of_Capital; + + L=1/(1+Consumption_per_unit_of_Labour/((1-alpha)*theta/(1-theta)*Output_per_unit_of_Labour^(1-psi))); + c=Consumption_per_unit_of_Labour*L; + k=L/Labour_per_unit_of_Capital; + y=Output_per_unit_of_Capital*k; + i=delta*k; +end; shocks; -var EfficiencyInnovation; -periods 1; -values -4; + var epsilon; + periods 10; + values -1; end; -perfect_foresight_setup(periods=100); +steady; -perfect_foresight_solver(lmmcp); +perfect_foresight_setup(periods=400); +perfect_foresight_solver(lmmcp, maxit=200); -rplot Investment; +n = 40; + +figure(2); +subplot(3,2,1); plot(1:n,A(1:n)); title('A'); +subplot(3,2,2); plot(2:n,y(2:n)); title('y'); +subplot(3,2,3); plot(2:n,L(2:n)); title('L'); +subplot(3,2,4); plot(1:n,k(1:n)); title('k'); +subplot(3,2,5); plot(2:n,c(2:n)); title('c'); +subplot(3,2,6); plot(2:n, y(2:n)-c(2:n)); title('i'); -rplot residual; From 932e5f946c32cb83f9bd0274e706290c252fcfcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 18 Jul 2018 17:51:59 +0200 Subject: [PATCH 16/24] Update preprocessor submodule Adapt bytecode DLL as a consequence. --- mex/sources/bytecode/ErrorHandling.hh | 248 +++++++++++++------------- mex/sources/bytecode/Evaluate.cc | 160 ++++++++--------- mex/sources/bytecode/Interpreter.cc | 4 +- mex/sources/bytecode/bytecode.cc | 12 +- preprocessor | 2 +- 5 files changed, 213 insertions(+), 213 deletions(-) diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh index 82d4b2c8c..e94b84dc9 100644 --- a/mex/sources/bytecode/ErrorHandling.hh +++ b/mex/sources/bytecode/ErrorHandling.hh @@ -419,14 +419,14 @@ public: for (unsigned int i = 0; i < endo_name_length; i++) if (P_endo_names[CHAR_LENGTH*(variable_num+i*nb_endo)] != ' ') res << P_endo_names[CHAR_LENGTH*(variable_num+i*nb_endo)]; - Variable_list.push_back(make_pair(res.str(), make_pair(eEndogenous, variable_num))); + Variable_list.push_back(make_pair(res.str(), make_pair(SymbolType::endogenous, variable_num))); } for (unsigned int variable_num = 0; variable_num < (unsigned int) nb_exo; variable_num++) { for (unsigned int i = 0; i < exo_name_length; i++) if (P_exo_names[CHAR_LENGTH*(variable_num+i*nb_exo)] != ' ') res << P_exo_names[CHAR_LENGTH*(variable_num+i*nb_exo)]; - Variable_list.push_back(make_pair(res.str(), make_pair(eExogenous, variable_num))); + Variable_list.push_back(make_pair(res.str(), make_pair(SymbolType::exogenous, variable_num))); } } @@ -460,7 +460,7 @@ public: ostringstream res; switch (variable_type) { - case eEndogenous: + case SymbolType::endogenous: if (variable_num <= nb_endo) { for (unsigned int i = 0; i < endo_name_length; i++) @@ -470,8 +470,8 @@ public: else mexPrintf("=> Unknown endogenous variable # %d", variable_num); break; - case eExogenous: - case eExogenousDet: + case SymbolType::exogenous: + case SymbolType::exogenousDet: if (variable_num <= nb_exo) { for (unsigned int i = 0; i < exo_name_length; i++) @@ -481,7 +481,7 @@ public: else mexPrintf("=> Unknown exogenous variable # %d", variable_num); break; - case eParameter: + case SymbolType::parameter: if (variable_num <= nb_param) { for (unsigned int i = 0; i < param_name_length; i++) @@ -518,33 +518,33 @@ public: break; case FirstEndoDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; break; case FirstOtherEndoDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; break; case FirstExoDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; break; case FirstExodetDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; break; case FirstParamDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1) << " at time " << it_; + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1) << " at time " << it_; break; default: return ("???"); @@ -566,33 +566,33 @@ public: break; case FirstEndoDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); break; case FirstOtherEndoDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to other endogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); break; case FirstExoDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); break; case FirstExodetDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to deterministic exogenous variable " << get_variable(SymbolType::endogenous, EQN_dvar1); break; case FirstParamDerivative: if (EQN_block_number > 1) - Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " in block " << EQN_block+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1); else - Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(eEndogenous, EQN_dvar1); + Error_loc << "first order derivative of equation " << EQN_equation+1 << " with respect to parameter " << get_variable(SymbolType::endogenous, EQN_dvar1); break; default: return ("???"); @@ -616,7 +616,7 @@ public: ExpressionType equation_type = TemporaryTerm; size_t found; double *jacob = NULL, *jacob_other_endo = NULL, *jacob_exo = NULL, *jacob_exo_det = NULL; - external_function_type function_type = ExternalFunctionWithoutDerivative; + ExternalFunctionType function_type = ExternalFunctionType::withoutDerivative; if (evaluate) { @@ -693,35 +693,35 @@ public: break; case FLDV: //load a variable in the processor - switch (((FLDV_ *) it_code->second)->get_type()) + switch (static_cast(((FLDV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FLDV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDV_ Param var=%d\n", var); - mexPrintf("get_variable(eParameter, var)=%s\n", get_variable(eParameter, var).c_str()); + mexPrintf("get_variable(SymbolType::parameter, var)=%s\n", get_variable(SymbolType::parameter, var).c_str()); mexEvalString("drawnow;"); #endif - Stack.push(get_variable(eParameter, var)); + Stack.push(get_variable(SymbolType::parameter, var)); if (compute) Stackf.push(params[var]); break; - case eEndogenous: + case SymbolType::endogenous: var = ((FLDV_ *) it_code->second)->get_pos(); lag = ((FLDV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG mexPrintf("FLDV_ endo var=%d, lag=%d\n", var, lag); - mexPrintf("get_variable(eEndogenous, var)=%s, compute=%d\n", get_variable(eEndogenous, var).c_str(), compute); + mexPrintf("get_variable(SymbolType::endogenous, var)=%s, compute=%d\n", get_variable(SymbolType::endogenous, var).c_str(), compute); mexPrintf("it_=%d, lag=%d, y_size=%d, var=%d, y=%x\n", it_, lag, y_size, var, y); mexEvalString("drawnow;"); #endif tmp_out.str(""); if (lag > 0) - tmp_out << get_variable(eEndogenous, var) << "(+" << lag << ")"; + tmp_out << get_variable(SymbolType::endogenous, var) << "(+" << lag << ")"; else if (lag < 0) - tmp_out << get_variable(eEndogenous, var) << "(" << lag << ")"; + tmp_out << get_variable(SymbolType::endogenous, var) << "(" << lag << ")"; else - tmp_out << get_variable(eEndogenous, var); + tmp_out << get_variable(SymbolType::endogenous, var); Stack.push(tmp_out.str()); if (compute) { @@ -731,7 +731,7 @@ public: Stackf.push(y[(it_+lag)*y_size+var]); } break; - case eExogenous: + case SymbolType::exogenous: var = ((FLDV_ *) it_code->second)->get_pos(); lag = ((FLDV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG @@ -739,14 +739,14 @@ public: #endif tmp_out.str(""); if (lag != 0) - tmp_out << get_variable(eExogenous, var) << "(" << lag << ")"; + tmp_out << get_variable(SymbolType::exogenous, var) << "(" << lag << ")"; else - tmp_out << get_variable(eExogenous, var); + tmp_out << get_variable(SymbolType::exogenous, var); Stack.push(tmp_out.str()); if (compute) Stackf.push(x[it_+lag+var*nb_row_x]); break; - case eExogenousDet: + case SymbolType::exogenousDet: var = ((FLDV_ *) it_code->second)->get_pos(); lag = ((FLDV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG @@ -754,14 +754,14 @@ public: #endif tmp_out.str(""); if (lag != 0) - tmp_out << get_variable(eExogenousDet, var) << "(" << lag << ")"; + tmp_out << get_variable(SymbolType::exogenousDet, var) << "(" << lag << ")"; else - tmp_out << get_variable(eExogenousDet, var); + tmp_out << get_variable(SymbolType::exogenousDet, var); Stack.push(tmp_out.str()); if (compute) Stackf.push(x[it_+lag+var*nb_row_xd]); break; - case eModelLocalVariable: + case SymbolType::modelLocalVariable: break; default: mexPrintf("FLDV: Unknown variable type\n"); @@ -770,23 +770,23 @@ public: case FLDSV: case FLDVS: //load a variable in the processor - switch (((FLDSV_ *) it_code->second)->get_type()) + switch (static_cast(((FLDSV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV_ param var=%d", var); #endif - Stack.push(get_variable(eParameter, var)); + Stack.push(get_variable(SymbolType::parameter, var)); if (compute) Stackf.push(params[var]); break; - case eEndogenous: + case SymbolType::endogenous: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV_ endo var=%d", var); #endif - Stack.push(get_variable(eEndogenous, var)); + Stack.push(get_variable(SymbolType::endogenous, var)); if (compute) { if (it_code->first == FLDSV) @@ -800,28 +800,28 @@ public: Stackf.push(steady_y[var]); } break; - case eExogenous: + case SymbolType::exogenous: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV_ exo var=%d", var); #endif - Stack.push(get_variable(eExogenous, var)); + Stack.push(get_variable(SymbolType::exogenous, var)); #ifdef DEBUG mexPrintf("oka var=%d, Stack.size()=%d x=%x\n", var, Stack.size(), x); #endif if (compute) Stackf.push(x[var]); break; - case eExogenousDet: + case SymbolType::exogenousDet: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV_ exo_det var=%d", var); #endif - Stack.push(get_variable(eExogenousDet, var)); + Stack.push(get_variable(SymbolType::exogenousDet, var)); if (compute) Stackf.push(x[var]); break; - case eModelLocalVariable: + case SymbolType::modelLocalVariable: break; default: mexPrintf("FLDSV: Unknown variable type\n"); @@ -913,9 +913,9 @@ public: case FSTPV: //load a variable in the processor go_on = false; - switch (((FSTPV_ *) it_code->second)->get_type()) + switch (static_cast(((FSTPV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FSTPV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FSTPV_ param var=%d", var); @@ -923,7 +923,7 @@ public: tmp_out2.str(""); tmp_out2 << Stack.top(); tmp_out.str(""); - tmp_out << get_variable(eParameter, var) << " = " << tmp_out2.str(); + tmp_out << get_variable(SymbolType::parameter, var) << " = " << tmp_out2.str(); Stack.pop(); if (compute) { @@ -931,7 +931,7 @@ public: Stackf.pop(); } break; - case eEndogenous: + case SymbolType::endogenous: var = ((FSTPV_ *) it_code->second)->get_pos(); lag = ((FSTPV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG @@ -940,7 +940,7 @@ public: tmp_out2.str(""); tmp_out2 << Stack.top(); tmp_out.str(""); - tmp_out << get_variable(eEndogenous, var); + tmp_out << get_variable(SymbolType::endogenous, var); if (lag > 0) tmp_out << "(+" << lag << ")"; else if (lag < 0) @@ -953,7 +953,7 @@ public: Stackf.pop(); } break; - case eExogenous: + case SymbolType::exogenous: var = ((FSTPV_ *) it_code->second)->get_pos(); lag = ((FSTPV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG @@ -962,7 +962,7 @@ public: tmp_out2.str(""); tmp_out2 << Stack.top(); tmp_out.str(""); - tmp_out << get_variable(eExogenous, var); + tmp_out << get_variable(SymbolType::exogenous, var); if (lag != 0) tmp_out << "(" << lag << ")"; tmp_out << " = " << tmp_out2.str(); @@ -973,7 +973,7 @@ public: Stackf.pop(); } break; - case eExogenousDet: + case SymbolType::exogenousDet: var = ((FSTPV_ *) it_code->second)->get_pos(); lag = ((FSTPV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG @@ -982,7 +982,7 @@ public: tmp_out2.str(""); tmp_out2 << Stack.top(); tmp_out.str(""); - tmp_out << get_variable(eExogenousDet, var); + tmp_out << get_variable(SymbolType::exogenousDet, var); if (lag != 0) tmp_out << "(" << lag << ")"; tmp_out << " = " << tmp_out2.str(); @@ -1000,9 +1000,9 @@ public: case FSTPSV: go_on = false; //load a variable in the processor - switch (((FSTPSV_ *) it_code->second)->get_type()) + switch (static_cast(((FSTPSV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FSTPSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FSTPSV_ param var=%d", var); @@ -1010,7 +1010,7 @@ public: tmp_out2.str(""); tmp_out2 << Stack.top(); tmp_out.str(""); - tmp_out << get_variable(eParameter, var); + tmp_out << get_variable(SymbolType::parameter, var); tmp_out << " = " << tmp_out2.str(); Stack.pop(); if (compute) @@ -1019,7 +1019,7 @@ public: Stackf.pop(); } break; - case eEndogenous: + case SymbolType::endogenous: var = ((FSTPSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FSTPSV_ endo var=%d", var); @@ -1027,7 +1027,7 @@ public: tmp_out2.str(""); tmp_out2 << Stack.top(); tmp_out.str(""); - tmp_out << get_variable(eEndogenous, var); + tmp_out << get_variable(SymbolType::endogenous, var); tmp_out << " = " << tmp_out2.str(); Stack.pop(); if (compute) @@ -1036,8 +1036,8 @@ public: Stackf.pop(); } break; - case eExogenous: - case eExogenousDet: + case SymbolType::exogenous: + case SymbolType::exogenousDet: var = ((FSTPSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FSTPSV_ exo var=%d", var); @@ -1045,7 +1045,7 @@ public: tmp_out2.str(""); tmp_out2 << Stack.top(); tmp_out.str(""); - tmp_out << get_variable(eExogenous, var); + tmp_out << get_variable(SymbolType::exogenous, var); tmp_out << " = " << tmp_out2.str(); Stack.pop(); if (compute) @@ -1251,9 +1251,9 @@ public: v1f = Stackf.top(); Stackf.pop(); } - switch (op) + switch (static_cast(op)) { - case oPlus: + case BinaryOpcode::plus: #ifdef DEBUG mexPrintf("+"); #endif @@ -1263,7 +1263,7 @@ public: tmp_out << v1 << " + " << v2; Stack.push(tmp_out.str()); break; - case oMinus: + case BinaryOpcode::minus: #ifdef DEBUG mexPrintf("-"); #endif @@ -1285,7 +1285,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oTimes: + case BinaryOpcode::times: #ifdef DEBUG mexPrintf("*"); #endif @@ -1307,7 +1307,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oDivide: + case BinaryOpcode::divide: #ifdef DEBUG mexPrintf("/"); #endif @@ -1341,7 +1341,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oLess: + case BinaryOpcode::less: #ifdef DEBUG mexPrintf("<"); #endif @@ -1363,7 +1363,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oGreater: + case BinaryOpcode::greater: #ifdef DEBUG mexPrintf(">"); #endif @@ -1385,7 +1385,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oLessEqual: + case BinaryOpcode::lessEqual: #ifdef DEBUG mexPrintf("<="); #endif @@ -1407,7 +1407,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oGreaterEqual: + case BinaryOpcode::greaterEqual: #ifdef DEBUG mexPrintf(">="); #endif @@ -1429,7 +1429,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oEqualEqual: + case BinaryOpcode::equalEqual: #ifdef DEBUG mexPrintf("=="); #endif @@ -1451,7 +1451,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oDifferent: + case BinaryOpcode::different: #ifdef DEBUG mexPrintf("!="); #endif @@ -1473,7 +1473,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oPower: + case BinaryOpcode::power: #ifdef DEBUG mexPrintf("^"); #endif @@ -1506,7 +1506,7 @@ public: tmp_out << ")"; Stack.push(tmp_out.str()); break; - case oPowerDeriv: + case BinaryOpcode::powerDeriv: { v3 = Stack.top(); Stack.pop(); @@ -1514,9 +1514,9 @@ public: { int derivOrder = int (nearbyint(Stackf.top())); Stackf.pop(); - if (fabs(v1f) < NEAR_ZERO && v2f > 0 + if (fabs(v1f) < near_zero && v2f > 0 && derivOrder > v2f - && fabs(v2f-nearbyint(v2f)) < NEAR_ZERO) + && fabs(v2f-nearbyint(v2f)) < near_zero) { r = 0.0; Stackf.push(r); @@ -1547,7 +1547,7 @@ public: tmp_out << " |PowerDeriv(" << v1 << ", " << v2 << v3 << ")|"; #endif break; - case oMax: + case BinaryOpcode::max: #ifdef DEBUG mexPrintf("max"); #endif @@ -1557,7 +1557,7 @@ public: tmp_out << "max(" << v1 << ", " << v2 << ")"; Stack.push(tmp_out.str()); break; - case oMin: + case BinaryOpcode::min: #ifdef DEBUG mexPrintf("min"); #endif @@ -1567,7 +1567,7 @@ public: tmp_out << "min(" << v1 << ", " << v2 << ")"; Stack.push(tmp_out.str()); break; - case oEqual: + case BinaryOpcode::equal: default: mexPrintf("Error unknown Unary operator=%d\n", op); mexEvalString("drawnow;"); ; @@ -1582,23 +1582,23 @@ public: v1f = Stackf.top(); Stackf.pop(); } - switch (op) + switch (static_cast(op)) { - case oUminus: + case UnaryOpcode::uminus: if (compute) Stackf.push(-v1f); tmp_out.str(""); tmp_out << " -" << v1; Stack.push(tmp_out.str()); break; - case oExp: + case UnaryOpcode::exp: if (compute) Stackf.push(exp(v1f)); tmp_out.str(""); tmp_out << "exp(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oLog: + case UnaryOpcode::log: if (compute) { r = log(v1f); @@ -1616,7 +1616,7 @@ public: tmp_out << "log(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oLog10: + case UnaryOpcode::log10: if (compute) { r = log10(v1f); @@ -1634,98 +1634,98 @@ public: tmp_out << "log10(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oCos: + case UnaryOpcode::cos: if (compute) Stackf.push(cos(v1f)); tmp_out.str(""); tmp_out << "cos(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oSin: + case UnaryOpcode::sin: if (compute) Stackf.push(sin(v1f)); tmp_out.str(""); tmp_out << "sin(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oTan: + case UnaryOpcode::tan: if (compute) Stackf.push(tan(v1f)); tmp_out.str(""); tmp_out << "tan(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oAcos: + case UnaryOpcode::acos: if (compute) Stackf.push(acos(v1f)); tmp_out.str(""); tmp_out << "acos(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oAsin: + case UnaryOpcode::asin: if (compute) Stackf.push(asin(v1f)); tmp_out.str(""); tmp_out << "asin(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oAtan: + case UnaryOpcode::atan: if (compute) Stackf.push(atan(v1f)); tmp_out.str(""); tmp_out << "atan(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oCosh: + case UnaryOpcode::cosh: if (compute) Stackf.push(cosh(v1f)); tmp_out.str(""); tmp_out << "cosh(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oSinh: + case UnaryOpcode::sinh: if (compute) Stackf.push(sinh(v1f)); tmp_out.str(""); tmp_out << "sinh(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oTanh: + case UnaryOpcode::tanh: if (compute) Stackf.push(tanh(v1f)); tmp_out.str(""); tmp_out << "tanh(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oAcosh: + case UnaryOpcode::acosh: if (compute) Stackf.push(acosh(v1f)); tmp_out.str(""); tmp_out << "acosh(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oAsinh: + case UnaryOpcode::asinh: if (compute) Stackf.push(asinh(v1f)); tmp_out.str(""); tmp_out << "asinh(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oAtanh: + case UnaryOpcode::atanh: if (compute) Stackf.push(atanh(v1f)); tmp_out.str(""); tmp_out << "atanh(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oSqrt: + case UnaryOpcode::sqrt: if (compute) Stackf.push(sqrt(v1f)); tmp_out.str(""); tmp_out << "sqrt(" << v1 << ")"; Stack.push(tmp_out.str()); break; - case oErf: + case UnaryOpcode::erf: if (compute) Stackf.push(erf(v1f)); tmp_out.str(""); @@ -1754,16 +1754,16 @@ public: v1f = Stackf.top(); Stackf.pop(); } - switch (op) + switch (static_cast(op)) { - case oNormcdf: + case TrinaryOpcode::normcdf: if (compute) Stackf.push(0.5*(1+erf((v1f-v2f)/v3f/M_SQRT2))); tmp_out.str(""); tmp_out << "normcdf(" << v1 << ", " << v2 << ", " << v3 << ")"; Stack.push(tmp_out.str()); break; - case oNormpdf: + case TrinaryOpcode::normpdf: if (compute) Stackf.push(1/(v3f*sqrt(2*M_PI)*exp(pow((v1f-v2f)/v3f, 2)/2))); tmp_out.str(""); @@ -1809,9 +1809,9 @@ public: mxArray **input_arguments; switch (function_type) { - case ExternalFunctionWithoutDerivative: - case ExternalFunctionWithFirstDerivative: - case ExternalFunctionWithFirstandSecondDerivative: + case ExternalFunctionType::withoutDerivative: + case ExternalFunctionType::withFirstDerivative: + case ExternalFunctionType::withFirstAndSecondDerivative: { if (compute) { @@ -1848,7 +1848,7 @@ public: Stack.push(tmp_out.str()); } break; - case ExternalFunctionNumericalFirstDerivative: + case ExternalFunctionType::numericalFirstDerivative: { if (compute) { @@ -1902,7 +1902,7 @@ public: Stack.push(tmp_out.str()); } break; - case ExternalFunctionFirstDerivative: + case ExternalFunctionType::firstDerivative: { if (compute) { @@ -1933,7 +1933,7 @@ public: Stack.push(tmp_out.str()); } break; - case ExternalFunctionNumericalSecondDerivative: + case ExternalFunctionType::numericalSecondDerivative: { if (compute) { @@ -1986,7 +1986,7 @@ public: Stack.push(tmp_out.str()); } break; - case ExternalFunctionSecondDerivative: + case ExternalFunctionType::secondDerivative: { if (compute) { @@ -2043,13 +2043,13 @@ public: tmp_out.str(""); switch (function_type) { - case ExternalFunctionWithoutDerivative: + case ExternalFunctionType::withoutDerivative: tmp_out << "TEF(" << var << ") = " << Stack.top(); break; - case ExternalFunctionWithFirstDerivative: + case ExternalFunctionType::withFirstDerivative: tmp_out << "[TEF(" << var << "), TEFD(" << var << ") ]= " << Stack.top(); break; - case ExternalFunctionWithFirstandSecondDerivative: + case ExternalFunctionType::withFirstAndSecondDerivative: tmp_out << "[TEF(" << var << "), TEFD(" << var << "), TEFDD(" << var << ") ]= " << Stack.top(); break; default: @@ -2105,9 +2105,9 @@ public: Stackf.pop(); } tmp_out.str(""); - if (function_type == ExternalFunctionNumericalFirstDerivative) + if (function_type == ExternalFunctionType::numericalFirstDerivative) tmp_out << "TEFD(" << indx << ", " << row << ") = " << Stack.top(); - else if (function_type == ExternalFunctionFirstDerivative) + else if (function_type == ExternalFunctionType::firstDerivative) tmp_out << "TEFD(" << indx << ") = " << Stack.top(); Stack.pop(); } @@ -2155,9 +2155,9 @@ public: Stackf.pop(); } tmp_out.str(""); - if (function_type == ExternalFunctionNumericalSecondDerivative) + if (function_type == ExternalFunctionType::numericalSecondDerivative) tmp_out << "TEFDD(" << indx << ", " << row << ", " << col << ") = " << Stack.top(); - else if (function_type == ExternalFunctionSecondDerivative) + else if (function_type == ExternalFunctionType::secondDerivative) tmp_out << "TEFDD(" << indx << ") = " << Stack.top(); Stack.pop(); } diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc index 16b4e4d22..5693ba0a4 100644 --- a/mex/sources/bytecode/Evaluate.cc +++ b/mex/sources/bytecode/Evaluate.cc @@ -120,7 +120,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int double *jacob = NULL, *jacob_other_endo = NULL, *jacob_exo = NULL, *jacob_exo_det = NULL; EQN_block = block_num; stack Stack; - external_function_type function_type = ExternalFunctionWithoutDerivative; + ExternalFunctionType function_type = ExternalFunctionType::withoutDerivative; #ifdef DEBUG mexPrintf("compute_block_time\n"); @@ -310,9 +310,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int break; case FLDV: //load a variable in the processor - switch (((FLDV_ *) it_code->second)->get_type()) + switch (static_cast(((FLDV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FLDV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDV Param[var=%d]\n", var); @@ -320,7 +320,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int #endif Stack.push(params[var]); break; - case eEndogenous: + case SymbolType::endogenous: var = ((FLDV_ *) it_code->second)->get_pos(); lag = ((FLDV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG @@ -337,7 +337,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int tmp_out << " y[" << it_+lag << ", " << var << "](" << y[(it_+lag)*y_size+var] << ")"; #endif break; - case eExogenous: + case SymbolType::exogenous: var = ((FLDV_ *) it_code->second)->get_pos(); lag = ((FLDV_ *) it_code->second)->get_lead_lag(); #ifdef DEBUG @@ -346,12 +346,12 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int #endif Stack.push(x[it_+lag+var*nb_row_x]); break; - case eExogenousDet: + case SymbolType::exogenousDet: var = ((FLDV_ *) it_code->second)->get_pos(); lag = ((FLDV_ *) it_code->second)->get_lead_lag(); Stack.push(x[it_+lag+var*nb_row_xd]); break; - case eModelLocalVariable: + case SymbolType::modelLocalVariable: #ifdef DEBUG mexPrintf("FLDV a local variable in Block %d Stack.size()=%d", block_num, Stack.size()); mexPrintf(" value=%f\n", Stack.top()); @@ -363,9 +363,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int break; case FLDSV: //load a variable in the processor - switch (((FLDSV_ *) it_code->second)->get_type()) + switch (static_cast(((FLDSV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV Param[var=%d]=%f\n", var, params[var]); @@ -373,7 +373,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int #endif Stack.push(params[var]); break; - case eEndogenous: + case SymbolType::endogenous: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV y[var=%d]=%f\n", var, ya[var]); @@ -384,7 +384,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int else Stack.push(y[var]); break; - case eExogenous: + case SymbolType::exogenous: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV x[var=%d]\n", var); @@ -392,14 +392,14 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int #endif Stack.push(x[var]); break; - case eExogenousDet: + case SymbolType::exogenousDet: var = ((FLDSV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDSV xd[var=%d]\n", var); #endif Stack.push(x[var]); break; - case eModelLocalVariable: + case SymbolType::modelLocalVariable: #ifdef DEBUG mexPrintf("FLDSV a local variable in Block %d Stack.size()=%d", block_num, Stack.size()); mexPrintf(" value=%f\n", Stack.top()); @@ -411,37 +411,37 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int break; case FLDVS: //load a variable in the processor - switch (((FLDVS_ *) it_code->second)->get_type()) + switch (static_cast(((FLDVS_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FLDVS_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("params[%d]\n", var); #endif Stack.push(params[var]); break; - case eEndogenous: + case SymbolType::endogenous: var = ((FLDVS_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDVS steady_y[%d]\n", var); #endif Stack.push(steady_y[var]); break; - case eExogenous: + case SymbolType::exogenous: var = ((FLDVS_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDVS x[%d] \n", var); #endif Stack.push(x[var]); break; - case eExogenousDet: + case SymbolType::exogenousDet: var = ((FLDVS_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FLDVS xd[%d]\n", var); #endif Stack.push(x[var]); break; - case eModelLocalVariable: + case SymbolType::modelLocalVariable: #ifdef DEBUG mexPrintf("FLDVS a local variable in Block %d Stack.size()=%d", block_num, Stack.size()); mexPrintf(" value=%f\n", Stack.top()); @@ -521,9 +521,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int break; case FSTPV: //load a variable in the processor - switch (((FSTPV_ *) it_code->second)->get_type()) + switch (static_cast(((FSTPV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FSTPV_ *) it_code->second)->get_pos(); #ifdef DEBUG mexPrintf("FSTPV params[%d]\n", var); @@ -531,7 +531,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int params[var] = Stack.top(); Stack.pop(); break; - case eEndogenous: + case SymbolType::endogenous: var = ((FSTPV_ *) it_code->second)->get_pos(); lag = ((FSTPV_ *) it_code->second)->get_lead_lag(); y[(it_+lag)*y_size+var] = Stack.top(); @@ -542,7 +542,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int #endif Stack.pop(); break; - case eExogenous: + case SymbolType::exogenous: var = ((FSTPV_ *) it_code->second)->get_pos(); lag = ((FSTPV_ *) it_code->second)->get_lead_lag(); x[it_+lag+var*nb_row_x] = Stack.top(); @@ -554,7 +554,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int Stack.pop(); break; - case eExogenousDet: + case SymbolType::exogenousDet: var = ((FSTPV_ *) it_code->second)->get_pos(); lag = ((FSTPV_ *) it_code->second)->get_lead_lag(); x[it_+lag+var*nb_row_xd] = Stack.top(); @@ -571,14 +571,14 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int break; case FSTPSV: //load a variable in the processor - switch (((FSTPSV_ *) it_code->second)->get_type()) + switch (static_cast(((FSTPSV_ *) it_code->second)->get_type())) { - case eParameter: + case SymbolType::parameter: var = ((FSTPSV_ *) it_code->second)->get_pos(); params[var] = Stack.top(); Stack.pop(); break; - case eEndogenous: + case SymbolType::endogenous: var = ((FSTPSV_ *) it_code->second)->get_pos(); y[var] = Stack.top(); #ifdef DEBUG @@ -588,8 +588,8 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int #endif Stack.pop(); break; - case eExogenous: - case eExogenousDet: + case SymbolType::exogenous: + case SymbolType::exogenousDet: var = ((FSTPSV_ *) it_code->second)->get_pos(); x[var] = Stack.top(); #ifdef DEBUG @@ -800,27 +800,27 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int Stack.pop(); v1 = Stack.top(); Stack.pop(); - switch (op) + switch (static_cast(op)) { - case oPlus: + case BinaryOpcode::plus: Stack.push(v1 + v2); #ifdef DEBUG tmp_out << " |" << v1 << "+" << v2 << "|"; #endif break; - case oMinus: + case BinaryOpcode::minus: Stack.push(v1 - v2); #ifdef DEBUG tmp_out << " |" << v1 << "-" << v2 << "|"; #endif break; - case oTimes: + case BinaryOpcode::times: Stack.push(v1 * v2); #ifdef DEBUG tmp_out << " |" << v1 << "*" << v2 << "|"; #endif break; - case oDivide: + case BinaryOpcode::divide: double tmp; #ifdef DEBUG mexPrintf("v1=%f / v2=%f\n", v1, v2); @@ -839,43 +839,43 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int tmp_out << " |" << v1 << "/" << v2 << "|"; #endif break; - case oLess: + case BinaryOpcode::less: Stack.push(double (v1 < v2)); #ifdef DEBUG mexPrintf("v1=%f v2=%f v1 < v2 = %f\n", v1, v2, double (v1 < v2)); #endif break; - case oGreater: + case BinaryOpcode::greater: Stack.push(double (v1 > v2)); #ifdef DEBUG tmp_out << " |" << v1 << ">" << v2 << "|"; #endif break; - case oLessEqual: + case BinaryOpcode::lessEqual: Stack.push(double (v1 <= v2)); #ifdef DEBUG tmp_out << " |" << v1 << "<=" << v2 << "|"; #endif break; - case oGreaterEqual: + case BinaryOpcode::greaterEqual: Stack.push(double (v1 >= v2)); #ifdef DEBUG tmp_out << " |" << v1 << ">=" << v2 << "|"; #endif break; - case oEqualEqual: + case BinaryOpcode::equalEqual: Stack.push(double (v1 == v2)); #ifdef DEBUG tmp_out << " |" << v1 << "==" << v2 << "|"; #endif break; - case oDifferent: + case BinaryOpcode::different: Stack.push(double (v1 != v2)); #ifdef DEBUG tmp_out << " |" << v1 << "!=" << v2 << "|"; #endif break; - case oPower: + case BinaryOpcode::power: #ifdef DEBUG mexPrintf("pow\n"); #endif @@ -894,15 +894,15 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int tmp_out << " |" << v1 << "^" << v2 << "|"; #endif break; - case oPowerDeriv: + case BinaryOpcode::powerDeriv: { int derivOrder = int (nearbyint(Stack.top())); Stack.pop(); try { - if (fabs(v1) < NEAR_ZERO && v2 > 0 + if (fabs(v1) < near_zero && v2 > 0 && derivOrder > v2 - && fabs(v2-nearbyint(v2)) < NEAR_ZERO) + && fabs(v2-nearbyint(v2)) < near_zero) Stack.push(0.0); else { @@ -923,19 +923,19 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int tmp_out << " |PowerDeriv(" << v1 << ", " << v2 << ")|"; #endif break; - case oMax: + case BinaryOpcode::max: Stack.push(max(v1, v2)); #ifdef DEBUG tmp_out << " |max(" << v1 << "," << v2 << ")|"; #endif break; - case oMin: + case BinaryOpcode::min: Stack.push(min(v1, v2)); #ifdef DEBUG tmp_out << " |min(" << v1 << "," << v2 << ")|"; #endif break; - case oEqual: + case BinaryOpcode::equal: // Nothing to do break; default: @@ -954,22 +954,22 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int #ifdef DEBUG mexPrintf("FUNARY, op=%d\n", op); #endif - switch (op) + switch (static_cast(op)) { - case oUminus: + case UnaryOpcode::uminus: Stack.push(-v1); #ifdef DEBUG tmp_out << " |-(" << v1 << ")|"; #endif break; - case oExp: + case UnaryOpcode::exp: Stack.push(exp(v1)); #ifdef DEBUG tmp_out << " |exp(" << v1 << ")|"; #endif break; - case oLog: + case UnaryOpcode::log: double tmp; try { @@ -987,7 +987,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int tmp_out << " |log(" << v1 << ")|"; #endif break; - case oLog10: + case UnaryOpcode::log10: try { tmp = log10_1(v1); @@ -1002,85 +1002,85 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int tmp_out << " |log10(" << v1 << ")|"; #endif break; - case oCos: + case UnaryOpcode::cos: Stack.push(cos(v1)); #ifdef DEBUG tmp_out << " |cos(" << v1 << ")|"; #endif break; - case oSin: + case UnaryOpcode::sin: Stack.push(sin(v1)); #ifdef DEBUG tmp_out << " |sin(" << v1 << ")|"; #endif break; - case oTan: + case UnaryOpcode::tan: Stack.push(tan(v1)); #ifdef DEBUG tmp_out << " |tan(" << v1 << ")|"; #endif break; - case oAcos: + case UnaryOpcode::acos: Stack.push(acos(v1)); #ifdef DEBUG tmp_out << " |acos(" << v1 << ")|"; #endif break; - case oAsin: + case UnaryOpcode::asin: Stack.push(asin(v1)); #ifdef DEBUG tmp_out << " |asin(" << v1 << ")|"; #endif break; - case oAtan: + case UnaryOpcode::atan: Stack.push(atan(v1)); #ifdef DEBUG tmp_out << " |atan(" << v1 << ")|"; #endif break; - case oCosh: + case UnaryOpcode::cosh: Stack.push(cosh(v1)); #ifdef DEBUG tmp_out << " |cosh(" << v1 << ")|"; #endif break; - case oSinh: + case UnaryOpcode::sinh: Stack.push(sinh(v1)); #ifdef DEBUG tmp_out << " |sinh(" << v1 << ")|"; #endif break; - case oTanh: + case UnaryOpcode::tanh: Stack.push(tanh(v1)); #ifdef DEBUG tmp_out << " |tanh(" << v1 << ")|"; #endif break; - case oAcosh: + case UnaryOpcode::acosh: Stack.push(acosh(v1)); #ifdef DEBUG tmp_out << " |acosh(" << v1 << ")|"; #endif break; - case oAsinh: + case UnaryOpcode::asinh: Stack.push(asinh(v1)); #ifdef DEBUG tmp_out << " |asinh(" << v1 << ")|"; #endif break; - case oAtanh: + case UnaryOpcode::atanh: Stack.push(atanh(v1)); #ifdef DEBUG tmp_out << " |atanh(" << v1 << ")|"; #endif break; - case oSqrt: + case UnaryOpcode::sqrt: Stack.push(sqrt(v1)); #ifdef DEBUG tmp_out << " |sqrt(" << v1 << ")|"; #endif break; - case oErf: + case UnaryOpcode::erf: Stack.push(erf(v1)); #ifdef DEBUG tmp_out << " |erf(" << v1 << ")|"; @@ -1104,15 +1104,15 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int Stack.pop(); v1 = Stack.top(); Stack.pop(); - switch (op) + switch (static_cast(op)) { - case oNormcdf: + case TrinaryOpcode::normcdf: Stack.push(0.5*(1+erf((v1-v2)/v3/M_SQRT2))); #ifdef DEBUG tmp_out << " |normcdf(" << v1 << ", " << v2 << ", " << v3 << ")|"; #endif break; - case oNormpdf: + case TrinaryOpcode::normpdf: Stack.push(1/(v3*sqrt(2*M_PI)*exp(pow((v1-v2)/v3, 2)/2))); #ifdef DEBUG tmp_out << " |normpdf(" << v1 << ", " << v2 << ", " << v3 << ")|"; @@ -1166,9 +1166,9 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int mxArray **input_arguments; switch (function_type) { - case ExternalFunctionWithoutDerivative: - case ExternalFunctionWithFirstDerivative: - case ExternalFunctionWithFirstandSecondDerivative: + case ExternalFunctionType::withoutDerivative: + case ExternalFunctionType::withFirstDerivative: + case ExternalFunctionType::withFirstAndSecondDerivative: { input_arguments = (mxArray **) mxMalloc(nb_input_arguments * sizeof(mxArray *)); test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *)); @@ -1191,7 +1191,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int double *rr = mxGetPr(output_arguments[0]); Stack.push(*rr); - if (function_type == ExternalFunctionWithFirstDerivative || function_type == ExternalFunctionWithFirstandSecondDerivative) + if (function_type == ExternalFunctionType::withFirstDerivative || function_type == ExternalFunctionType::withFirstAndSecondDerivative) { unsigned int indx = fc->get_indx(); double *FD1 = mxGetPr(output_arguments[1]); @@ -1199,7 +1199,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int for (unsigned int i = 0; i < rows; i++) TEFD[make_pair(indx, i)] = FD1[i]; } - if (function_type == ExternalFunctionWithFirstandSecondDerivative) + if (function_type == ExternalFunctionType::withFirstAndSecondDerivative) { unsigned int indx = fc->get_indx(); double *FD2 = mxGetPr(output_arguments[2]); @@ -1212,7 +1212,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int } } break; - case ExternalFunctionNumericalFirstDerivative: + case ExternalFunctionType::numericalFirstDerivative: { input_arguments = (mxArray **) mxMalloc((nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *)); test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, (nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *)); @@ -1252,7 +1252,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int Stack.push(*rr); } break; - case ExternalFunctionFirstDerivative: + case ExternalFunctionType::firstDerivative: { input_arguments = (mxArray **) mxMalloc(nb_input_arguments * sizeof(mxArray *)); test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *)); @@ -1276,7 +1276,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int TEFD[make_pair(indx, i)] = FD1[i]; } break; - case ExternalFunctionNumericalSecondDerivative: + case ExternalFunctionType::numericalSecondDerivative: { input_arguments = (mxArray **) mxMalloc((nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *)); test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, (nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *)); @@ -1315,7 +1315,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int Stack.push(*rr); } break; - case ExternalFunctionSecondDerivative: + case ExternalFunctionType::secondDerivative: { input_arguments = (mxArray **) mxMalloc(nb_input_arguments * sizeof(mxArray *)); test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *)); @@ -1375,7 +1375,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int mexPrintf("FSTPTEFD\n"); mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size()); #endif - if (function_type == ExternalFunctionNumericalFirstDerivative) + if (function_type == ExternalFunctionType::numericalFirstDerivative) { TEFD[make_pair(indx, row-1)] = Stack.top(); #ifdef DEBUG @@ -1409,7 +1409,7 @@ Evaluate::compute_block_time(const int Per_u_, const bool evaluate, /*const int mexPrintf("FSTPTEFD\n"); mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size()); #endif - if (function_type == ExternalFunctionNumericalSecondDerivative) + if (function_type == ExternalFunctionType::numericalSecondDerivative) { TEFDD[make_pair(indx, make_pair(row-1, col-1))] = Stack.top(); #ifdef DEBUG diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index bb986cff8..a3762c9bb 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -609,7 +609,7 @@ Interpreter::check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, vector if ((find(endogenous.begin(), endogenous.end(), it->exo_num) != endogenous.end()) && (find(exogenous.begin(), exogenous.end(), it->var_num) == exogenous.end())) { ostringstream tmp; - tmp << "\n the conditional forecast involving as constrained variable " << get_variable(eEndogenous, it->exo_num) << " and as endogenized exogenous " << get_variable(eExogenous, it->var_num) << " that do not appear in block=" << Block_Count+1 << ")\n You should not use block in model options\n"; + tmp << "\n the conditional forecast involving as constrained variable " << get_variable(SymbolType::endogenous, it->exo_num) << " and as endogenized exogenous " << get_variable(SymbolType::exogenous, it->var_num) << " that do not appear in block=" << Block_Count+1 << ")\n You should not use block in model options\n"; throw FatalExceptionHandling(tmp.str()); } else if ((find(endogenous.begin(), endogenous.end(), it->exo_num) != endogenous.end()) && (find(exogenous.begin(), exogenous.end(), it->var_num) != exogenous.end()) && ((fb->get_type() == EVALUATE_FORWARD) || (fb->get_type() != EVALUATE_BACKWARD))) @@ -621,7 +621,7 @@ Interpreter::check_for_controlled_exo_validity(FBEGINBLOCK_ *fb, vector else if (find(previous_block_exogenous.begin(), previous_block_exogenous.end(), it->var_num) != previous_block_exogenous.end()) { ostringstream tmp; - tmp << "\n the conditional forecast involves in the block " << Block_Count+1 << " the endogenized exogenous " << get_variable(eExogenous, it->var_num) << " that appear also in a previous block\n You should not use block in model options\n"; + tmp << "\n the conditional forecast involves in the block " << Block_Count+1 << " the endogenized exogenous " << get_variable(SymbolType::exogenous, it->var_num) << " that appear also in a previous block\n You should not use block in model options\n"; throw FatalExceptionHandling(tmp.str()); } } diff --git a/mex/sources/bytecode/bytecode.cc b/mex/sources/bytecode/bytecode.cc index 2bac3e3f2..daa6de10d 100644 --- a/mex/sources/bytecode/bytecode.cc +++ b/mex/sources/bytecode/bytecode.cc @@ -729,9 +729,9 @@ main(int nrhs, const char *prhs[]) char name [100]; mxGetString(tmp, name, 100); splan[i].var = name; - SymbolType variable_type = eEndogenous; + SymbolType variable_type = SymbolType::endogenous; int exo_num = emsg.get_ID(name, &variable_type); - if (variable_type == eExogenous || variable_type == eExogenousDet) + if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet) splan[i].var_num = exo_num; else { @@ -749,7 +749,7 @@ main(int nrhs, const char *prhs[]) splan[i].exo = name; SymbolType variable_type; int exo_num = emsg.get_ID(name, &variable_type); - if (variable_type == eEndogenous) + if (variable_type == SymbolType::endogenous) splan[i].exo_num = exo_num; else { @@ -807,9 +807,9 @@ main(int nrhs, const char *prhs[]) char name [100]; mxGetString(tmp, name, 100); spfplan[i].var = name; - SymbolType variable_type = eEndogenous; + SymbolType variable_type = SymbolType::endogenous; int exo_num = emsg.get_ID(name, &variable_type); - if (variable_type == eExogenous || variable_type == eExogenousDet) + if (variable_type == SymbolType::exogenous || variable_type == SymbolType::exogenousDet) splan[i].var_num = exo_num; else { @@ -827,7 +827,7 @@ main(int nrhs, const char *prhs[]) spfplan[i].exo = name; SymbolType variable_type; int exo_num = emsg.get_ID(name, &variable_type); - if (variable_type == eEndogenous) + if (variable_type == SymbolType::endogenous) spfplan[i].exo_num = exo_num; else { diff --git a/preprocessor b/preprocessor index 3776e3b89..4a04a3837 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 3776e3b890a137e690008a59a8552cc4eaa47a3d +Subproject commit 4a04a383744a7769f7f20838168eeb808553655c From 97229177b44cfabcafa8f4ab4eada0de7c9cc37c Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 19 Jul 2018 09:25:27 +0200 Subject: [PATCH 17/24] simplex_optimization_routine.m: account for penalty indicator being third output, not fourth one Caused occasional crashes --- matlab/optimization/simplex_optimization_routine.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/optimization/simplex_optimization_routine.m b/matlab/optimization/simplex_optimization_routine.m index ccd81367e..ba784558d 100644 --- a/matlab/optimization/simplex_optimization_routine.m +++ b/matlab/optimization/simplex_optimization_routine.m @@ -186,7 +186,7 @@ if verbose skipline() end initial_point = x; -[initial_score,junk1,junk2,nopenalty] = feval(objective_function,x,varargin{:}); +[initial_score,junk1,nopenalty] = feval(objective_function,x,varargin{:}); if ~nopenalty error('simplex_optimization_routine:: Initial condition is wrong!') else @@ -537,7 +537,7 @@ for j = 1:n end v(:,j+1) = y; x = y; - [fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:}); + [fv(j+1),junk1,nopenalty_flag] = feval(objective_function,x,varargin{:}); if check_delta while ~nopenalty_flag if y(j)~=0 @@ -553,7 +553,7 @@ for j = 1:n end v(:,j+1) = y; x = y; - [fv(j+1),junk1,junk2,nopenalty_flag] = feval(objective_function,x,varargin{:}); + [fv(j+1),junk1,nopenalty_flag] = feval(objective_function,x,varargin{:}); end end end From 2d321cb0e399614913f21d767925ae3e684f3686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Tue, 5 Jun 2018 08:46:56 +0200 Subject: [PATCH 18/24] Increased default number of iterations in simplex. --- matlab/default_option_values.m | 2 +- matlab/optimization/simplex_optimization_routine.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/default_option_values.m b/matlab/default_option_values.m index d5fa2da16..d1a46cb32 100644 --- a/matlab/default_option_values.m +++ b/matlab/default_option_values.m @@ -516,7 +516,7 @@ options_.newrat=newrat; % Simplex optimization routine (variation on Nelder Mead algorithm). simplex.tolerance.x = 1e-4; simplex.tolerance.f = 1e-4; -simplex.maxiter = 5000; +simplex.maxiter = 10000; simplex.maxfcallfactor = 500; simplex.maxfcall = []; simplex.verbosity = 2; diff --git a/matlab/optimization/simplex_optimization_routine.m b/matlab/optimization/simplex_optimization_routine.m index ba784558d..be668c9c4 100644 --- a/matlab/optimization/simplex_optimization_routine.m +++ b/matlab/optimization/simplex_optimization_routine.m @@ -77,7 +77,7 @@ end if isfield(options,'maxiter') max_iterations = options.maxiter; else - max_iterations = 5000; + max_iterations = 10000; end % Set reflection parameter. From 44c49eaef86d307343128d2916b2d7cb8f135e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Tue, 5 Jun 2018 11:02:29 +0200 Subject: [PATCH 19/24] Improved iterations display of Dynare's simplex routine. --- .../simplex_optimization_routine.m | 151 ++++++++---------- 1 file changed, 70 insertions(+), 81 deletions(-) diff --git a/matlab/optimization/simplex_optimization_routine.m b/matlab/optimization/simplex_optimization_routine.m index be668c9c4..585f683cb 100644 --- a/matlab/optimization/simplex_optimization_routine.m +++ b/matlab/optimization/simplex_optimization_routine.m @@ -49,6 +49,13 @@ function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,o % Set verbose mode verbose = options.verbosity; +% Set header +if verbose + header = sprintf('#Iter. #FnCalls. Best Value Worst Value Norm(f) Norm(x) Move'); + iter_ = ' '; + fval_ = ' '; +end + % Set number of control variables. number_of_variables = length(x); @@ -179,27 +186,23 @@ trend_vector_2 = 2:(number_of_variables+1); % Set initial simplex around the initial guess (x). if verbose - skipline(3) - disp('+----------------------+') - disp(' SIMPLEX INITIALIZATION ') - disp('+----------------------+') skipline() + disp('Simplex initialization...') end initial_point = x; [initial_score,junk1,nopenalty] = feval(objective_function,x,varargin{:}); if ~nopenalty + disp('Cannot initialize the simplex with the provided initial guess.') + skipline() error('simplex_optimization_routine:: Initial condition is wrong!') else [v,fv,delta] = simplex_initialization(objective_function,initial_point,initial_score,delta,zero_delta,1,varargin{:}); + disp('Done!') + skipline() func_count = number_of_variables + 1; iter_count = 1; if verbose disp(['Objective function value: ' num2str(fv(1))]) - disp(['Current parameter values: ']) - fprintf(1,'%s: \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \n','Names','Best point', 'Worst point', 'Mean values', 'Min values', 'Max values'); - for i=1:number_of_variables - fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',var_names{i},v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2)); - end skipline() end end @@ -220,10 +223,15 @@ tooslow = 0; iter_no_improvement_break = 0; max_no_improvement_break = 1; +if verbose + disp(header) +end + +critF = 1.0; +critX = 1.0; + while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex_algo_iterations<=max_simplex_algo_iterations) % Do we really need to continue? - critF = max(abs(fv(1)-fv(trend_vector_2))); - critX = max(max(abs(v(:,trend_vector_2)-v(:,unit_vector)))); if critF <= max(f_tolerance,10*eps(fv(1))) && critX <= max(x_tolerance,10*eps(max(v(:,1)))) convergence = 1; end @@ -258,10 +266,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex func_count = func_count+1; if fxe < fxr% xe is even better than xr. if optimize_expansion_parameter - if verbose>1 - skipline(2) - disp('Compute optimal expansion...') - end + % Compute optimal expansion... xee = xbar + rho*chi*1.01*(xbar-v(:,end)); x = xee; fxee = feval(objective_function,x,varargin{:}); @@ -271,14 +276,8 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex weight = rho*chi*1.02; fxeee_old = fxee; xeee_old = xee; - if verbose>1 - fprintf(1,'Weight = '); - end while decrease weight = 1.02*weight; - if verbose>1 - fprintf(1,'\b\b\b\b\b\b\b %6.4f',weight); - end xeee = xbar + weight*(xbar-v(:,end)); x = xeee; fxeee = feval(objective_function,x,varargin{:}); @@ -290,9 +289,6 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex decrease = 0; end end - if verbose>1 - fprintf(1,'\n'); - end xe = xeee_old; fxe = fxeee_old; else @@ -300,14 +296,8 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex weight = rho*chi; fxeee_old = fxee; xeee_old = xee; - if verbose>1 - fprintf(1,'Weight = '); - end while decrease weight = weight/1.02; - if verbose>1 - fprintf(1,'\b\b\b\b\b\b\b %6.4f',weight); - end xeee = xbar + weight*(xbar-v(:,end)); x = xeee; fxeee = feval(objective_function,x,varargin{:}); @@ -319,20 +309,15 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex decrease = 0; end end - if verbose>1 - fprintf(1,'\n'); - end xe = xeee_old; fxe = fxeee_old; end - if verbose>1 - disp('Done!') - skipline(2) - end + move = 'expand-opt'; + else + move = 'expand'; end v(:,end) = xe; fv(end) = fxe; - move = 'expand'; else% if xe is not better than xr. v(:,end) = xr; fv(end) = fxr; @@ -383,37 +368,37 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex % Sort n+1 points by incresing order of the objective function values. [fv,sort_idx] = sort(fv); v = v(:,sort_idx); + critF = max(abs(fv(1)-fv(trend_vector_2))); + critX = max(max(abs(v(:,trend_vector_2)-v(:,unit_vector)))); + if verbose + if ~mod(simplex_iterations, 50) + skipline() + disp(header) + end + iter = int2str(simplex_iterations); + fval = int2str(func_count); + iter_(1:length(iter)) = iter; + fval_(1:length(fval)) = fval; + if isfinite(fv(end)) && isfinite(fv(1)) + if fv(end)<0 + disp(sprintf('%s %s %12.7E %12.7E %12.7E %12.7E %s', iter_, fval_, fv(1), fv(end), critF, critX, move)) + else + if fv(1)>0 + disp(sprintf('%s %s %12.7E %12.7E %12.7E %12.7E %s', iter_, fval_, fv(1), fv(end), critF, critX, move)) + else + disp(sprintf('%s %s %12.7E %12.7E %12.7E %12.7E %s', iter_, fval_, fv(1), fv(end), critF, critX, move)) + end + end + else + if isfinite(fv(1)) + disp(sprintf(['%s %s %12.7E %12.7E %s'], iter_, fval_, fv(1) , critX, move)) + else + disp(sprintf('%s %s %12.7E %s', iter_, fval_, critX, move)) + end + end + end iter_count = iter_count + 1; simplex_iterations = simplex_iterations+1; - if verbose>1 - disp(['Simplex iteration number: ' int2str(simplex_iterations) '-' int2str(simplex_init) '-' int2str(simplex_algo_iterations)]) - disp(['Simplex move: ' move]) - disp(['Objective function value: ' num2str(fv(1))]) - disp(['Mode improvement: ' num2str(best_point_score-fv(1))]) - disp(['Norm of dx: ' num2str(norm(best_point-v(:,1)))]) - disp(['Norm of dSimplex: ' num2str(norm(v-vold,'fro'))]) - disp(['Crit. f: ' num2str(critF)]) - disp(['Crit. x: ' num2str(critX)]) - skipline() - end - if verbose && max(abs(best_point-v(:,1)))>x_tolerance - if verbose<2 - disp(['Simplex iteration number: ' int2str(simplex_iterations) '-' int2str(simplex_init) '-' int2str(simplex_algo_iterations)]) - disp(['Objective function value: ' num2str(fv(1))]) - disp(['Mode improvement: ' num2str(best_point_score-fv(1))]) - disp(['Norm of dx: ' num2str(norm(best_point-v(:,1)))]) - disp(['Norm of dSimplex: ' num2str(norm(v-vold,'fro'))]) - disp(['Crit. f: ' num2str(critF)]) - disp(['Crit. x: ' num2str(critX)]) - skipline() - end - disp(['Current parameter values: ']) - fprintf(1,'%s: \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \n','Names','Best point', 'Worst point', 'Mean values', 'Min values', 'Max values'); - for i=1:number_of_variables - fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',var_names{i}, v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2)); - end - skipline() - end if abs(best_point_score-fv(1))max_no_improvements if verbose + skipline() disp(['NO SIGNIFICANT IMPROVEMENT AFTER ' int2str(no_improvements) ' ITERATIONS!']) + skipline() end if simplex_algo_iterations<=max_simplex_algo_iterations % Compute the size of the simplex @@ -432,12 +419,9 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex % Compute the new initial simplex. [v,fv,delta] = simplex_initialization(objective_function,best_point,best_point_score,delta,zero_delta,1,varargin{:}); if verbose - disp(['(Re)Start with a lager simplex around the based on the best current ']) - disp(['values for the control variables. ']) - disp(['New value of delta (size of the new simplex) is: ']) - for i=1:number_of_variables - fprintf(1,'%s: \t\t\t %+8.6f \n',var_names{i}, delta(i)); - end + disp('(Re)Start with a lager simplex based on the best current values for the control variables.') + skipline() + disp(header) end % Reset counters no_improvements = 0; @@ -446,22 +430,27 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex iter_no_improvement_break = iter_no_improvement_break + 1; simplex_init = simplex_init+1; simplex_iterations = simplex_iterations+1; - skipline(2) end end if ((func_count==max_func_calls) || (iter_count==max_iterations) || (iter_no_improvement_break==max_no_improvement_break) || convergence || tooslow) [v,fv,delta] = simplex_initialization(objective_function,best_point,best_point_score,DELTA,zero_delta,1,varargin{:}); if func_count==max_func_calls if verbose + skipline() disp(['MAXIMUM NUMBER OF OBJECTIVE FUNCTION CALLS EXCEEDED (' int2str(max_func_calls) ')!']) + skipline() end elseif iter_count== max_iterations if verbose + skipline() disp(['MAXIMUM NUMBER OF ITERATIONS EXCEEDED (' int2str(max_iterations) ')!']) + skipline() end elseif iter_no_improvement_break==max_no_improvement_break if verbose + skipline() disp(['MAXIMUM NUMBER OF SIMPLEX REINITIALIZATION EXCEEDED (' int2str(max_no_improvement_break) ')!']) + skipline() end iter_no_improvement_break = 0; if simplex_algo_iterations==max_simplex_algo_iterations @@ -469,9 +458,13 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex continue end elseif tooslow + skipline() disp(['CONVERGENCE NOT ACHIEVED AFTER ' int2str(simplex_iterations) ' ITERATIONS! IMPROVING TOO SLOWLY!']) + skipline() else + skipline() disp(['CONVERGENCE ACHIEVED AFTER ' int2str(simplex_iterations) ' ITERATIONS!']) + skipline() end if simplex_algo_iterations Date: Thu, 19 Jul 2018 15:36:02 +0200 Subject: [PATCH 20/24] Fixed copyright header. --- matlab/optimization/simplex_optimization_routine.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/optimization/simplex_optimization_routine.m b/matlab/optimization/simplex_optimization_routine.m index 585f683cb..7c103a933 100644 --- a/matlab/optimization/simplex_optimization_routine.m +++ b/matlab/optimization/simplex_optimization_routine.m @@ -29,7 +29,7 @@ function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,o % o exitflag [integer] scalar equal to 0 or 1 (0 if the algorithm did not converge to % a minimum). -% Copyright (C) 2010-2017 Dynare Team +% Copyright (C) 2010-2018 Dynare Team % % This file is part of Dynare. % From 5f8b2c5a773b457cb1c37a502312f8d93269caa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Thu, 19 Jul 2018 19:08:07 +0200 Subject: [PATCH 21/24] Revert "modify on-the-fly example to accept variables declared in equation tag" This reverts commit 8ff8d787e824392ae33a4c3d265d90b269dc1fa7. --- tests/example1_on_the_fly.mod | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/example1_on_the_fly.mod b/tests/example1_on_the_fly.mod index 84f7b6d62..fd0786eda 100644 --- a/tests/example1_on_the_fly.mod +++ b/tests/example1_on_the_fly.mod @@ -9,11 +9,6 @@ ** |x is an exogenous variable, ** |p is a parameter. ** -** Variables can also be declared on the fly via equation tags: -** [endogenous='varname'] -** [exogenous='varname'] -** [parameter='varname'] -** ** Example. If the first equation (consumption/leisure arbitrage) is removed from the following model block, then h (hours) ** will be interpreted as an exogenous variable. */ @@ -22,8 +17,7 @@ model; c*theta|p*h|e^(1+psi|p)=(1-alpha)*y; k|e = beta|p*(((exp(b)*c)/(exp(b(+1))*c(+1))) *(exp(b(+1))*alpha|p*y(+1)+(1-delta)*k)); -[endogenous='y'] -y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); +y|e = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); k = exp(b)*(y-c|e)+(1-delta|p)*k(-1); a|e = rho|p*a(-1)+tau*b(-1) + e|x; b|e = tau|p*a(-1)+rho*b(-1) + u|x; From 39d1d5461a1e2e6caf455b2192c62b702edfb242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Thu, 19 Jul 2018 23:47:40 +0200 Subject: [PATCH 22/24] Updated preprocessor submodule. --- preprocessor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor b/preprocessor index 4a04a3837..49e1c43ae 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 4a04a383744a7769f7f20838168eeb808553655c +Subproject commit 49e1c43aed1acd80237d7fe911603ac4dd52d67d From 3dcd8fc9f57ab5826d84a698d4cc92523b95fb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Thu, 19 Jul 2018 23:43:24 +0200 Subject: [PATCH 23/24] Added preprocessor unit tests (on the fly declarations of types). --- tests/Makefile.am | 19 ++++++--- .../ex1.mod} | 26 +++++------- tests/on-the-fly/ex2.mod | 38 ++++++++++++++++++ tests/on-the-fly/ex3.mod | 40 +++++++++++++++++++ tests/on-the-fly/ex4.mod | 39 ++++++++++++++++++ tests/on-the-fly/ex5.mod | 36 +++++++++++++++++ tests/on-the-fly/ex6.mod | 33 +++++++++++++++ 7 files changed, 209 insertions(+), 22 deletions(-) rename tests/{example1_on_the_fly.mod => on-the-fly/ex1.mod} (76%) create mode 100644 tests/on-the-fly/ex2.mod create mode 100644 tests/on-the-fly/ex3.mod create mode 100644 tests/on-the-fly/ex4.mod create mode 100644 tests/on-the-fly/ex5.mod create mode 100644 tests/on-the-fly/ex6.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 194cdda69..651f1ba03 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -52,8 +52,13 @@ MODFILES = \ ramst.mod \ ramst_a.mod \ ramst_static_tag.mod \ + on-the-fly/ex1.mod \ + on-the-fly/ex2.mod \ + on-the-fly/ex3.mod \ + on-the-fly/ex4.mod \ + on-the-fly/ex5.mod \ + on-the-fly/ex6.mod \ example1.mod \ - example1_on_the_fly.mod \ example2.mod \ example1_use_dll.mod \ example1_with_tags.mod \ @@ -482,13 +487,13 @@ deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs: determ deterministic_simulations/multiple_lead_lags/sim_lead_lag.m.trs: deterministic_simulations/multiple_lead_lags/sim_base.m.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.m.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag.o.trs: deterministic_simulations/multiple_lead_lags/sim_base.o.trs deterministic_simulations/multiple_lead_lags/sim_lead_lag_aux_vars.o.trs -deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: ramst.m.trs +deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.m.trs: ramst.m.trs deterministic_simulations/multiple_lead_lags/ramst_augmented_histval.o.trs: ramst.o.trs loglinear/example4_loglinear.m.trs: loglinear/example4_exp.m.trs loglinear/example4_loglinear.o.trs: loglinear/example4_exp.o.trs -loglinear/example4_loglinear_lagged_exogenous_a.m.trs: loglinear/example4_loglinear_lagged_exogenous.m.trs -loglinear/example4_loglinear_lagged_exogenous_a.o.trs: loglinear/example4_loglinear_lagged_exogenous.o.trs +loglinear/example4_loglinear_lagged_exogenous_a.m.trs: loglinear/example4_loglinear_lagged_exogenous.m.trs +loglinear/example4_loglinear_lagged_exogenous_a.o.trs: loglinear/example4_loglinear_lagged_exogenous.o.trs loglinear/example4_loglinear_histval.m.trs: loglinear/example4_exp_histval.m.trs loglinear/example4_loglinear_histval.o.trs: loglinear/example4_exp_histval.o.trs @@ -581,6 +586,10 @@ external_function: m/external_function o/external_function m/external_function: $(patsubst %.mod, %.m.trs, $(filter external_function/%.mod, $(MODFILES))) o/external_function: $(patsubst %.mod, %.o.trs, $(filter external_function/%.mod, $(MODFILES))) +on-the-fly: m/on-the-fly o/on-the-fly +m/on-the-fly: $(patsubst %.mod, %.m.trs, $(filter on-the-fly/%.mod, $(MODFILES))) +o/on-the-fly: $(patsubst %.mod, %.o.trs, $(filter on-the-fly/%.mod, $(MODFILES))) + trend_var: m/trend_var o/trend_var m/trend_var: $(patsubst %.mod, %.m.trs, $(filter trend_var/%.mod, $(MODFILES))) o/trend_var: $(patsubst %.mod, %.o.trs, $(filter trend_var/%.mod, $(MODFILES))) @@ -882,7 +891,7 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) %.m.trs %.m.log : %.m @echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ - $(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null + $(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null @echo "`tput bold``tput setaf 8`MATLAB: $(PWD)/$* Done!`tput sgr0`" %.o.trs %.o.log: %.mod diff --git a/tests/example1_on_the_fly.mod b/tests/on-the-fly/ex1.mod similarity index 76% rename from tests/example1_on_the_fly.mod rename to tests/on-the-fly/ex1.mod index fd0786eda..8ef9c1b9a 100644 --- a/tests/example1_on_the_fly.mod +++ b/tests/on-the-fly/ex1.mod @@ -30,24 +30,16 @@ beta = 0.99; delta = 0.025; psi = 0; theta = 2.95; - phi = 0.1; -initval; -y = 1.08068253095672; -c = 0.80359242014163; -h = 0.29175631001732; -k = 11.08360443260358; -a = 0; -b = 0; -e = 0; -u = 0; -end; +if ~isequal(length(intersect(M_.endo_names, {'c'; 'h'; 'y'; 'k'; 'b'; 'a'})), 6) + error('Endogenous variables are wrong.') +end -shocks; -var e; stderr 0.009; -var u; stderr 0.009; -var e, u = phi*0.009*0.009; -end; +if ~isequal(length(intersect(M_.param_names, {'theta'; 'psi'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 7) + error('Parameters are wrong.') +end -stoch_simul; +if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'})), 2) + error('Exogenous variables are wrong.') +end \ No newline at end of file diff --git a/tests/on-the-fly/ex2.mod b/tests/on-the-fly/ex2.mod new file mode 100644 index 000000000..cc73d29f0 --- /dev/null +++ b/tests/on-the-fly/ex2.mod @@ -0,0 +1,38 @@ +// --+ options: nostrict +-- +/* +** Same as ex1.mod without the first equation -> h is an exogenous variable, psi is not a model object (because it +** is not used in the remaining equations), and theta is an exogenous equation (see the last equation). +*/ + +model; +//c*theta|p*h|e^(1+psi|p)=(1-alpha)*y; +k|e = beta|p*(((exp(b)*c)/(exp(b(+1))*c(+1))) + *(exp(b(+1))*alpha|p*y(+1)+(1-delta)*k)); +y|e = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); +k = exp(b)*(y-c|e)+(1-delta|p)*k(-1); +a|e = rho|p*a(-1)+tau*b(-1) + e|x; +b|e = tau|p*a(-1)+rho*b(-1) + u|x + .0*theta; // The last term is here just for testing purpose. +end; + +alpha = 0.36; +rho = 0.95; +tau = 0.025; +beta = 0.99; +delta = 0.025; +psi = 0; +// If the following line is uncommented, this will trigger an error from the preprocessor +// because it is not allowed to give a value to an exogenous variable. +//theta = 2.95; +phi = 0.1; + +if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'})), 5) + error('Endogenous variables are wrong.') +end + +if ~isequal(length(intersect(M_.param_names, {'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 5) + error('Parameters are wrong.') +end + +if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'h'; 'theta'})), 4) + error('Exogenous variables are wrong.') +end \ No newline at end of file diff --git a/tests/on-the-fly/ex3.mod b/tests/on-the-fly/ex3.mod new file mode 100644 index 000000000..d1f02a459 --- /dev/null +++ b/tests/on-the-fly/ex3.mod @@ -0,0 +1,40 @@ +// --+ options: nostrict +-- +/* +** In the following example, we only declare one endogenous variable per equation. Because the other objects are not declared +** they are treated as exogenous variables. An equation tag is used to associate an endogenous variable to each equation. +*/ + +model; + +[endogenous='h'] +c*theta*h^(1+psi)=(1-alpha)*y; + +[endogenous='k'] +k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) + *(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); + +[endogenous='y'] +y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); + +[endogenous='c'] +k = exp(b)*(y-c)+(1-delta)*k(-1); + +[endogenous='a'] +a = rho*a(-1)+tau*b(-1) + e; + +[endogenous='b'] +b = tau*a(-1)+rho*b(-1) + u; + +end; + +if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'; 'h'})), 6) + error('Endogenous variables are wrong.') +end + +if isfield(M_, 'param_names') + error('Parameters are wrong.') +end + +if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'theta'; 'psi'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 9) + error('Exogenous variables are wrong.') +end \ No newline at end of file diff --git a/tests/on-the-fly/ex4.mod b/tests/on-the-fly/ex4.mod new file mode 100644 index 000000000..601699e95 --- /dev/null +++ b/tests/on-the-fly/ex4.mod @@ -0,0 +1,39 @@ +// --+ options: nostrict +-- +/* +** Same as ex3.mod without the first equation, hours (h) are exogenous. +*/ + +model; + +//[endogenous='h'] +//c*theta*h^(1+psi)=(1-alpha)*y; + +[endogenous='k'] +k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) + *(exp(b(+1))*alpha*y(+1)+(1-delta)*k)); + +[endogenous='y'] +y = exp(a)*(k(-1)^alpha)*(h^(1-alpha)); + +[endogenous='c'] +k = exp(b)*(y-c)+(1-delta)*k(-1); + +[endogenous='a'] +a = rho*a(-1)+tau*b(-1) + e; + +[endogenous='b'] +b = tau*a(-1)+rho*b(-1) + u; + +end; + +if ~isequal(length(intersect(M_.endo_names, {'c'; 'y'; 'k'; 'b'; 'a'})), 5) + error('Endogenous variables are wrong.') +end + +if isfield(M_, 'param_names') + error('Parameters are wrong.') +end + +if ~isequal(length(intersect(M_.exo_names, {'e'; 'u'; 'h'; 'alpha'; 'beta'; 'delta'; 'rho'; 'tau'})), 8) + error('Exogenous variables are wrong.') +end \ No newline at end of file diff --git a/tests/on-the-fly/ex5.mod b/tests/on-the-fly/ex5.mod new file mode 100644 index 000000000..4129465a7 --- /dev/null +++ b/tests/on-the-fly/ex5.mod @@ -0,0 +1,36 @@ +// --+ options: nostrict +-- + +/* +** It is possible to associate an endogenous variable to an equation were the variable does not appear (if it makes sense). +*/ + + +parameters a0, a1, b0, b1; + +a0 = 1.0; +a1 = 0.1; +b0 = 0.5; +b1 = 0.2; + + + +model; + +[endogenous='D'] +D = a0 - a1*p; + +[endogenous='S'] +S = b0 + b1*p; + +[endogenous='p'] +S = D; + +end; + +if ~isequal(length(intersect(M_.endo_names, {'D'; 'S'; 'p'})), 3) + error('Endogenous variables are wrong.') +end + +if isfield(M_, 'exo_names') + error('Exogenous variables are wrong.') +end diff --git a/tests/on-the-fly/ex6.mod b/tests/on-the-fly/ex6.mod new file mode 100644 index 000000000..2d40e991e --- /dev/null +++ b/tests/on-the-fly/ex6.mod @@ -0,0 +1,33 @@ +// --+ options: nostrict +-- + +/* +** Same as ex5.mod, but price is treated as an exoenous variable. +*/ + +parameters a0, a1, b0, b1; + +a0 = 1.0; +a1 = 0.1; +b0 = 0.5; +b1 = 0.2; + +model; + +[endogenous='D'] +D = a0 - a1*p; + +[endogenous='S'] +S = b0 + b1*p; + +//[endogenous='p'] +//S = D; + +end; + +if ~isequal(length(intersect(M_.endo_names, {'D'; 'S'})), 2) + error('Endogenous variables are wrong.') +end + +if ~isequal(M_.exo_names, {'p'}) + error('Exogenous variables are wrong.') +end From cffff796f154710754e7223175dca1300885888f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Mon, 23 Jul 2018 10:41:34 +0200 Subject: [PATCH 24/24] Added routine to test if an auxiliary variable is a lag of a variable. --- matlab/islagof.m | 129 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 matlab/islagof.m diff --git a/matlab/islagof.m b/matlab/islagof.m new file mode 100644 index 000000000..271cbe186 --- /dev/null +++ b/matlab/islagof.m @@ -0,0 +1,129 @@ +function b = islagof(v1, v2) + +% Returns true if and only if variable v1 is a lag of variable v2. +% +% INPUTS +% - v1 [string] Variable name. +% - v2 [string] Variable name. +% +% OUTPUTS +% - b [logical] + +% Copyright (C) 2018 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 . + +global M_ + +if ~ischar(v1) && isscalar(v1) && isnumeric(v1) && isint(v1) + id1 = v1; + if id1>M_.endo_nbr + error('First input must be an integer between 1 and %u', M_.endo_nbr) + end +end + +if ~ischar(v2) && isscalar(v2) && isnumeric(v2) && isint(v2) + id2 = v2; + if id2>M_.endo_nbr + error('First input must be an integer between 1 and %u', M_.endo_nbr) + end +end + +% Set output default value +b = false; + +% Get index of v1 +if ischar(v1) + id1 = find(strcmp(v1, M_.endo_names)); +end + +if isempty(id1) + error('First input must be a variable name.') +end + +% Get index of v2 +if ischar(v2) + id2 = find(strcmp(v2, M_.endo_names)); +end + +if isempty(id2) + error('Second input must be a variable name.') +end + +% A variable cannot be a lag of itself. +if isequal(id1, id2) + return +end + +% Are v1 and v2 auxiliary variables? +v1_is_an_auxiliary_variable = id1>M_.orig_endo_nbr; +v2_is_an_auxiliary_variable = id2>M_.orig_endo_nbr; + +% At least one of the variables must be an auxiliary variable +if ~v1_is_an_auxiliary_variable && ~v2_is_an_auxiliary_variable + return +end + +% If v1 and v2 are auxiliary variables +if v1_is_an_auxiliary_variable && v2_is_an_auxiliary_variable + auxinfo1 = M_.aux_vars(get_aux_variable_id(id1)); + auxinfo2 = M_.aux_vars(get_aux_variable_id(id2)); + isleadlag1 = ismember(auxinfo1.type, [1,0]); + isleadlag2 = ismember(auxinfo2.type, [1,0]); + % If v1 and v2 are lead/lag auxiliary variables + if isleadlag1 && isleadlag2 + % If v1 and v2 are lead/lag of a common endogenous variable. + if auxinfo1.orig_index && auxinfo2.orig_index + if auxinfo1.orig_lead_lag