From 6d7c8ef9637e77c74203bc4e5baea174b654399f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 27 Nov 2014 09:08:57 +0100 Subject: [PATCH 01/50] Allow reading in of row vectors in initval file --- matlab/initvalf.m | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/matlab/initvalf.m b/matlab/initvalf.m index 13e1005d7..85be9ae9d 100644 --- a/matlab/initvalf.m +++ b/matlab/initvalf.m @@ -75,27 +75,43 @@ oo_.exo_simul = []; for i_=1:size(M_.endo_names,1) if series_ == 1 x_ = eval(M_.endo_names(i_,:)); - oo_.endo_simul = [oo_.endo_simul; x_']; + if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors + oo_.endo_simul = [oo_.endo_simul; x_]; + else %transpose if column vector + oo_.endo_simul = [oo_.endo_simul; x_']; + end else k_ = strmatch(upper(M_.endo_names(i_,:)),names_v_,'exact'); if isempty(k_) error(['INITVAL_FILE: ' M_.endo_names(i_,:) ' not found']) end x_ = data_(:,k_); - oo_.endo_simul = [oo_.endo_simul; x_']; + if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors + oo_.endo_simul = [oo_.endo_simul; x_]; + else %transpose if column vector + oo_.endo_simul = [oo_.endo_simul; x_']; + end end end for i_=1:size(M_.exo_names,1) if series_ == 1 x_ = eval(M_.exo_names(i_,:) ); - oo_.exo_simul = [oo_.exo_simul x_]; + if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors + oo_.exo_simul = [oo_.exo_simul x_']; + else %if column vector + oo_.exo_simul = [oo_.exo_simul x_]; + end else k_ = strmatch(upper(M_.exo_names(i_,:)),names_v_,'exact'); if isempty(k_) error(['INITVAL_FILE: ' M_.exo_names(i_,:) ' not found']) end x_ = data_(:,k_); - oo_.exo_simul = [oo_.exo_simul x_]; + if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors + oo_.exo_simul = [oo_.exo_simul x_']; + else %if column vector + oo_.exo_simul = [oo_.exo_simul x_]; + end end -end +end \ No newline at end of file From 566835bba673d1a7da766ec5d259855823e22fd4 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 27 Nov 2014 09:09:30 +0100 Subject: [PATCH 02/50] Check size of initval-file provided values and issue more explicit error message --- matlab/perfect_foresight_solver.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/matlab/perfect_foresight_solver.m b/matlab/perfect_foresight_solver.m index bfeb16e4f..fd5211065 100644 --- a/matlab/perfect_foresight_solver.m +++ b/matlab/perfect_foresight_solver.m @@ -54,11 +54,21 @@ end if isempty(oo_.endo_simul) || any(size(oo_.endo_simul) ~= [ M_.endo_nbr, M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead ]) - error('PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') + if options_.initval_file + fprintf('\nPERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Check whether your initval-file provides %d periods.\n',M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead) + error('PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size.') + else + error('PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') + end end if isempty(oo_.exo_simul) || any(size(oo_.exo_simul) ~= [ M_.maximum_lag+options_.periods+M_.maximum_lead, M_.exo_nbr ]) - error('PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') + if options_.initval_file + fprintf('\nPERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Check whether your initval-file provides %d periods.\n',M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead) + error('PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size.') + else + error('PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') + end end From c7237a7d132d1d2ddbf27762364fdc410a513b66 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 27 Nov 2014 10:43:41 +0100 Subject: [PATCH 03/50] Document that all types of vectors are possible in initval file Also documents required size --- doc/dynare.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 6ea52531a..ac81b40cd 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -2389,7 +2389,7 @@ The command accepts three file formats: @item M-file (extension @file{.m}): for each endogenous and exogenous -variable, the file must contain a row vector of the same name. +variable, the file must contain a row or column vector of the same name. Their length must be @code{periods+M_.maximum_lag+M_.maximum_lead} @item MAT-file (extension @file{.mat}): same as for M-files. From da691bb21c6a6855f787c6e2cccd488b5efe25d3 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 27 Nov 2014 10:44:21 +0100 Subject: [PATCH 04/50] Fix reading in of initval files from Excel series_-indicator was not set --- matlab/initvalf.m | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/matlab/initvalf.m b/matlab/initvalf.m index 85be9ae9d..0493a2b48 100644 --- a/matlab/initvalf.m +++ b/matlab/initvalf.m @@ -64,6 +64,7 @@ switch (extension) load(basename); case { '.xls', '.xlsx' } [data_,names_v_]=xlsread(fullname); % Octave needs the extension explicitly + series_=0; otherwise error(['Unsupported extension for datafile: ' extension]) end @@ -81,16 +82,12 @@ for i_=1:size(M_.endo_names,1) oo_.endo_simul = [oo_.endo_simul; x_']; end else - k_ = strmatch(upper(M_.endo_names(i_,:)),names_v_,'exact'); + k_ = strmatch(deblank(M_.endo_names(i_,:)),names_v_,'exact'); if isempty(k_) - error(['INITVAL_FILE: ' M_.endo_names(i_,:) ' not found']) + error(['INITVAL_FILE: ' deblank(M_.endo_names(i_,:)) ' not found']) end x_ = data_(:,k_); - if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors - oo_.endo_simul = [oo_.endo_simul; x_]; - else %transpose if column vector - oo_.endo_simul = [oo_.endo_simul; x_']; - end + oo_.endo_simul = [oo_.endo_simul; x_']; end end @@ -103,15 +100,11 @@ for i_=1:size(M_.exo_names,1) oo_.exo_simul = [oo_.exo_simul x_]; end else - k_ = strmatch(upper(M_.exo_names(i_,:)),names_v_,'exact'); + k_ = strmatch(deblank(M_.exo_names(i_,:)),names_v_,'exact'); if isempty(k_) - error(['INITVAL_FILE: ' M_.exo_names(i_,:) ' not found']) + error(['INITVAL_FILE: ' deblank(M_.exo_names(i_,:)) ' not found']) end x_ = data_(:,k_); - if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors - oo_.exo_simul = [oo_.exo_simul x_']; - else %if column vector - oo_.exo_simul = [oo_.exo_simul x_]; - end + oo_.exo_simul = [oo_.exo_simul x_]; end end \ No newline at end of file From bb92f9bc2a86cefdcd9e2295970a6e7ef362d272 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 27 Nov 2014 10:49:18 +0100 Subject: [PATCH 05/50] Expand unit test on initval file Also moves it to separate directory --- tests/Makefile.am | 7 +++++-- .../{ => initval_file}/ramst_initval_file.mod | 19 +++++++++++++++--- tests/initval_file/ramst_initval_file_data.m | 10 +++++++++ .../ramst_initval_file_data_col_vec_mat.mat | Bin 0 -> 339 bytes .../ramst_initval_file_data_row_vec_mat.mat | Bin 0 -> 339 bytes .../initval_file/ramst_initval_file_excel.xls | Bin 0 -> 38400 bytes tests/ramst_initval_file_data.m | 3 --- 7 files changed, 31 insertions(+), 8 deletions(-) rename tests/{ => initval_file}/ramst_initval_file.mod (67%) create mode 100644 tests/initval_file/ramst_initval_file_data.m create mode 100644 tests/initval_file/ramst_initval_file_data_col_vec_mat.mat create mode 100644 tests/initval_file/ramst_initval_file_data_row_vec_mat.mat create mode 100644 tests/initval_file/ramst_initval_file_excel.xls delete mode 100644 tests/ramst_initval_file_data.m diff --git a/tests/Makefile.am b/tests/Makefile.am index b13370853..4820c603f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,7 +33,7 @@ MODFILES = \ optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod \ optimal_policy/Ramsey/ramsey_ex_aux.mod \ discretionary_policy/dennis_1.mod \ - ramst_initval_file.mod \ + initval_file/ramst_initval_file.mod \ ramst_normcdf_and_friends.mod \ ramst_vec.mod \ example1_varexo_det.mod \ @@ -305,7 +305,10 @@ EXTRA_DIST = \ fs2000_ssfile_aux.m \ printMakeCheckMatlabErrMsg.m \ printMakeCheckOctaveErrMsg.m \ - ramst_initval_file_data.m \ + initval_file/ramst_initval_file_data.m \ + initval_file/ramst_initval_file_data_col_vec_mat.mat \ + initval_file/ramst_initval_file_data_row_vec_mat.mat \ + initval_file/ramst_initval_file_excel.xls \ test.m \ AIM/data_ca1.m \ AIM/fs2000_b1L1L_AIM_steadystate.m \ diff --git a/tests/ramst_initval_file.mod b/tests/initval_file/ramst_initval_file.mod similarity index 67% rename from tests/ramst_initval_file.mod rename to tests/initval_file/ramst_initval_file.mod index 192edc9ba..c45327faf 100644 --- a/tests/ramst_initval_file.mod +++ b/tests/initval_file/ramst_initval_file.mod @@ -26,9 +26,22 @@ initval_file(filename = ramst_initval_file_data); steady; -check; +simul(periods=200); + +initval_file(filename = ramst_initval_file_data_row_vec_mat); + +steady; simul(periods=200); -rplot c; -rplot k; +initval_file(filename = ramst_initval_file_data_col_vec_mat); + +steady; + +simul(periods=200); + +initval_file(filename = ramst_initval_file_excel); + +steady; + +simul(periods=200); diff --git a/tests/initval_file/ramst_initval_file_data.m b/tests/initval_file/ramst_initval_file_data.m new file mode 100644 index 000000000..f7d82234c --- /dev/null +++ b/tests/initval_file/ramst_initval_file_data.m @@ -0,0 +1,10 @@ +x = vertcat([ 1; 1.2 ], repmat(1, 200, 1)); +k = repmat(12.7551, 202, 1); +c = repmat(1.53061, 202, 1); +% save ramst_initval_file_data_col_vec_mat +% xlswrite('ramst_initval_file_excel',[x k c],1,'A2') +% xlswrite('ramst_initval_file_excel',{'x' 'k' 'c'},1,'A1') +% c=c' +% k=k' +% x=x' +% save ramst_initval_file_data_row_vec_mat \ No newline at end of file diff --git a/tests/initval_file/ramst_initval_file_data_col_vec_mat.mat b/tests/initval_file/ramst_initval_file_data_col_vec_mat.mat new file mode 100644 index 0000000000000000000000000000000000000000..48c59f12f63781c4af061077c866309150505170 GIT binary patch literal 339 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2cQV4Jk_w+L}(NSsh5-`93qo*%FkZljd6>}aZCnRJfBquN^ zvGK8S@G`9l_@}9m#**yT#-(tU^9ZAXE06q}-h&S|+xFOd^sh5-`93qo*%FkZljd6>}aZCnRJfBquN^ zvGK8S@G`9luu~S8&vdzmN7P}Ka0hcjmxSF7>E?s!)e`kn46FiDo(mb{Cw*E9 zGRBU8F*m`+G;}d-PM>-{^HPZf%nbKTuM7tL!;3Z(W6DXWDQfoLs%HlLK3s=zi{?Vc JV|9o2008NKV^jbD literal 0 HcmV?d00001 diff --git a/tests/initval_file/ramst_initval_file_excel.xls b/tests/initval_file/ramst_initval_file_excel.xls new file mode 100644 index 0000000000000000000000000000000000000000..1bea58b16c2cd91ac57cb687cbe520a33bcf06f3 GIT binary patch literal 38400 zcmeI536vC7mWE$uZONt-yC9J4`&I>r3RJO)Xt5|L?m|HpV3ma?1tNl!`vPtSqC&av z`!4R_zDzmOXSzL3JDeVShVhK2=S+{z%o)2!&AER>Mc#<`UnW`V%<1lv$$42Bf4=YD z7w_G7<3(g7`HR0P{o>wdd;ivi9@9;M`61QL6#Mjuyq@Q6cQ*2VDuqq&@A2|lr2OO0 zs0Z4`WFU)+%&M|aNmT7hYn=TdWo)4DFsb64m2X{YY%&hs?W#e5MNV}5z;@6Vee7L2f` zMJt_pH#pA&o#(^kIb!xY%;%0W!Spi+q<+lYjBpqCC6QTXxv4X2OtneM^PgIcc86$b z#8jBq(Ty4RC1NHXqJ}Zk59uX#2pdt;^AI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ShN={+DjH~uSI*=qP=3#UbSeiS+v(J+8Y+_ zO^dcKq+yM6k7yeC_fX{D6Nr2eh)yN$CE{Kp5W7m;N5p+ZAhMOXpNRX3K-??w01*!m zfmxx%gG4+?1m=tq4-xSY5tva*JWRyHL}0!t@dy!*5P{jK#G^z!N(APr5|0t_7!jDs zN<2=)<3wPdEAa#oPY{7Dpv03zJV^v{gc45?@e~nH2Z*PMc$x_07xnQB5zi2T?4!i9 zL_A9ba+4Cz5%C-m$XrT1PsH;?Ag?L$0ue6|fvl&*i$uIg1ahJhFA?z)5y+TI>?L9^ z5y+=XyiCN)L?GKL@d^>I5P@8*#H&QSN(3^s60Z^Q8WG6jO1w_Q>qH>SEAa*qZxDfF zfD&&K@g@;CLMXA1hn{eIni`0;8qG2Sj{81jbT{4~h7Y2#mB69})2p5r_jNJ|^Ph0P&gpm-W#C zV?MNg+hDqUC;g>jF=#6BB#&iVjM*mNUELOQx83LJEq%qOn873B{)w)N^)#z|)uJYX zFCZ7p&h|~$&Mw^goUHqE`Zg2svY5sg0oqvqGc4K^4mh;QIHY% z$)oV?`T0?h-^9RN_&*v2->~Li{)zO!4=MTiKj;4>2sQ}m?Tf4K{^k!0S9gB=mY5ke z?D=1h7wsM?B~tKyrIbP`$4fy5JWWa$DXXP)l+q}rla%dJx=O({wy2bY0`-%>U|N4v z(7KH*Ie*QHYZ~HnHm*q2IX)Y^eA3dt{VyVw@_yt0To{eZ>(;C+O8$}WfqW0- zdm!Hf`5wskK)wg^J&^B#d=KP%Am0P|9?17VxCgSG|3^Rl>0`G#F~b6)pZ9O z8WKszQvND}^h^Gc?}2;|a1rA(AENy=m?M@jiX?!!7-{vIRcSSeGbOp`KQN`(}>KSTb`lrl@oY$_m%G% z{poEk74J#;!PIJ}9krgE^WQEen)Z)2 Date: Sun, 22 Feb 2015 21:54:39 +0100 Subject: [PATCH 06/50] adding global test for identification for sbvar --- matlab/ms-sbvar/identification/exclusions.m | 2 +- .../sbvar_global_identification_check.m | 77 +++++++++++++++++++ .../test_global_identification_FAILURE.mod | 16 ++++ .../test_global_identification_OK.mod | 15 ++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 matlab/ms-sbvar/sbvar_global_identification_check.m create mode 100644 tests/ms-sbvar/test_global_identification_FAILURE.mod create mode 100644 tests/ms-sbvar/test_global_identification_OK.mod diff --git a/matlab/ms-sbvar/identification/exclusions.m b/matlab/ms-sbvar/identification/exclusions.m index 9632356fe..a2447b1ba 100644 --- a/matlab/ms-sbvar/identification/exclusions.m +++ b/matlab/ms-sbvar/identification/exclusions.m @@ -1,4 +1,4 @@ -function [Ui,Vi,n0,np,ixmC0Pres] = exclusions(nvar,nexo,options_ms) +function [Ui,Vi,n0,np,ixmC0Pres,Qi] = exclusions(nvar,nexo,options_ms) % function [Ui,Vi,n0,np,ixmC0Pres] = exclusions(nvar,nexo,options_ms) % % INPUTS diff --git a/matlab/ms-sbvar/sbvar_global_identification_check.m b/matlab/ms-sbvar/sbvar_global_identification_check.m new file mode 100644 index 000000000..642220f54 --- /dev/null +++ b/matlab/ms-sbvar/sbvar_global_identification_check.m @@ -0,0 +1,77 @@ +function indent = sbvar_global_identification_check(options_) +% function sbvar_global_identification_check(options_.ms) +% +% INPUTS +% options_ms: (struct) options +% +% OUTPUTS +% ident: (boolean) false = not identified; true = identified +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2015 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 . + +ident = false; + +if isequal(options_.ms.restriction_fname, 'upper_cholesky') || ... + isequal(options_.ms.restriction_fname, 'lower_cholesky') + ident = true; + if ~options_.noprint + disp(' ') + disp('SBVAR: Cholesky identification is always identified') + disp(' ') + end + return +end +nvar = length(options_.varobs); % number of endogenous variables +nexo = 1; + +[Uiconst,Viconst,n0,np,ixmC0Pres,Qi] = exclusions(nvar,nexo,options_.ms ); + +% order column constraints by rank +Qranks = zeros(nvar,2); +for j=1:nvar + Qranks(j,:) = [j,rank(Qi{j})]; +end +Qranks = sortrows(Qranks,-2); + +ident = true; + +for j=1:nvar + i = Qranks(j,1); + for k=1:1 + M = [Qi{i}*rand(size(Qi{i},1),nvar);[eye(j) zeros(j,nvar- ... + j)]]; + disp([j,k,rank(M)]) + if rank(M) < nvar + ident = false + break + end + end +end + +if ~options_.noprint + disp(' ') + if ident + disp('The sufficient condition for SBVAR identification is met') + else + disp('WARNGING: The sufficient condition for SBVAR identification is not met') + end + disp(' ') +end \ No newline at end of file diff --git a/tests/ms-sbvar/test_global_identification_FAILURE.mod b/tests/ms-sbvar/test_global_identification_FAILURE.mod new file mode 100644 index 000000000..8ff9cfddd --- /dev/null +++ b/tests/ms-sbvar/test_global_identification_FAILURE.mod @@ -0,0 +1,16 @@ +// same as test_lower_cholesky.mod, but using exclusion syntax +var R Pie Y; + +varobs Y Pie R; + +svar_identification; +exclusion lag 0; +equation 1, Pie, Y; +exclusion lag 1; +equation 2, Y; +end; + +sbvar_global_identification_check(options_); + +sbvar(datafile = data,freq=4,initial_year=1959,final_year=2005,nlags=4); + diff --git a/tests/ms-sbvar/test_global_identification_OK.mod b/tests/ms-sbvar/test_global_identification_OK.mod new file mode 100644 index 000000000..7e54d9223 --- /dev/null +++ b/tests/ms-sbvar/test_global_identification_OK.mod @@ -0,0 +1,15 @@ +// same as test_lower_cholesky.mod, but using exclusion syntax +var R Pie Y; + +varobs Y Pie R; + +svar_identification; +exclusion lag 0; +equation 1, Pie, Y; +equation 2, Y; +end; + +sbvar_global_identification_check(options_); + +sbvar(datafile = data,freq=4,initial_year=1959,final_year=2005,nlags=4); + From 86f9e53ec63bde9987127692e50dfd413c5a02f0 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sat, 7 Mar 2015 10:51:28 +0100 Subject: [PATCH 07/50] dr_block: fixing bug in solve_foward_complete --- matlab/dr_block.m | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/matlab/dr_block.m b/matlab/dr_block.m index e09eec429..b1e41c083 100644 --- a/matlab/dr_block.m +++ b/matlab/dr_block.m @@ -72,7 +72,7 @@ end; if (options_.bytecode) [chck, zz, data]= bytecode('dynamic','evaluate', z, zx, M_.params, dr.ys, 1, data); else - [r, data] = feval([M_.fname '_dynamic'], options_, M_, oo_, z', zx, M_.params, dr.ys, M_.maximum_lag+1, data); + [r, data] = feval([M_.fname '_dynamic'], z', zx, M_.params, dr.ys, M_.maximum_lag+1, data); chck = 0; end; mexErrCheck('bytecode', chck); @@ -315,13 +315,17 @@ for i = 1:Size; dr.eigval = [dr.eigval ; data(i).eigval]; case 6 %% ------------------------------------------------------------------ - %Solve Forward complete + %Solve Forward complete + if (maximum_lag > 0) + ghx = - jacob(: , n_pred + 1 : n_pred + n_static ... + + n_pred + n_both) \ jacob(: , 1 : n_pred); + else + ghx = 0; + end; if maximum_lag > 0 && n_pred > 0 - data(i).eigval = eig(- jacob(: , 1 : n_pred) / ... - jacob(: , (n_pred + n_static + 1 : n_pred + n_static + n_pred ))); + data(i).eigval = -eig(ghx(n_static+1:end,:)); data(i).rank = 0; - full_rank = (rcond(jacob(: , (n_pred + n_static + 1 : n_pred ... - + n_static + n_pred ))) > 1e-9); + full_rank = (rcond(ghx(n_static+1:end,:)) > 1e-9); else data(i).eigval = []; data(i).rank = 0; @@ -330,11 +334,6 @@ for i = 1:Size; dr.eigval = [dr.eigval ; data(i).eigval]; dr.full_rank = dr.full_rank && full_rank; if task ~= 1 - if (maximum_lag > 0) - ghx = - jacob(: , 1 : n_pred) / jacob(: , n_pred + n_static + 1 : n_pred + n_static + n_pred + n_both); - else - ghx = 0; - end; if other_endo_nbr fx = data(i).g1_o; % retrieves the derivatives with respect to endogenous From 00d67110f2016f9a0689ce06ad895633532e467b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 9 Mar 2015 08:59:48 +0100 Subject: [PATCH 08/50] Removed data files for tests/initval_file. Generate the data instead with matlab's script ramst_initval_file_data.m. Note that the excel files are only produced and tested under Windows (xlswrite is not working on OS X, need to check for Linux). --- tests/Makefile.am | 34 +++++++++++++++--- tests/initval_file/ramst_initval_file.mod | 16 ++++++--- tests/initval_file/ramst_initval_file_data.m | 18 ++++++---- .../ramst_initval_file_data_col_vec_mat.mat | Bin 339 -> 0 bytes .../ramst_initval_file_data_row_vec_mat.mat | Bin 339 -> 0 bytes .../initval_file/ramst_initval_file_excel.xls | Bin 38400 -> 0 bytes 6 files changed, 53 insertions(+), 15 deletions(-) delete mode 100644 tests/initval_file/ramst_initval_file_data_col_vec_mat.mat delete mode 100644 tests/initval_file/ramst_initval_file_data_row_vec_mat.mat delete mode 100644 tests/initval_file/ramst_initval_file_excel.xls diff --git a/tests/Makefile.am b/tests/Makefile.am index 4679cb775..184ddf691 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -211,6 +211,8 @@ XFAIL_MODFILES = ramst_xfail.mod \ estim_param_in_shock_value.mod \ optimal_policy/Ramsey/ramsey_ex_wrong_ss_file.mod +MFILES = initval_file/ramst_initval_file_data.m + # Dependencies example1_use_dll.m.trs: example1.m.trs example1_use_dll.o.trs: example1.o.trs @@ -285,6 +287,11 @@ deterministic_simulations/rbc_det_exo_lag_2c.m.trs: deterministic_simulations/rb deterministic_simulations/rbc_det_exo_lag_2b.o.trs: deterministic_simulations/rbc_det_exo_lag_2a.o.trs deterministic_simulations/rbc_det_exo_lag_2c.o.trs: deterministic_simulations/rbc_det_exo_lag_2a.o.trs +initval_file/ramst_initval_file.m.trs: initval_file/ramst_initval_file_data.m.tls +initval_file/ramst_initval_file.o.trs: initval_file/ramst_initval_file_data.o.tls + + + # Matlab TRS Files M_TRS_FILES = $(patsubst %.mod, %.m.trs, $(MODFILES)) M_TRS_FILES += run_block_byte_tests_matlab.m.trs run_reporting_test_matlab.m.trs run_all_unitary_tests.m.trs @@ -295,12 +302,21 @@ O_TRS_FILES = $(patsubst %.mod, %.o.trs, $(MODFILES)) O_TRS_FILES += run_block_byte_tests_octave.o.trs run_reporting_test_octave.o.trs run_all_unitary_tests.o.trs O_XFAIL_TRS_FILES = $(patsubst %.mod, %.o.trs, $(XFAIL_MODFILES)) +# Matlab TLS Files +M_TLS_FILES = $(patsubst %.m, %.m.tls, $(MFILES)) + +# Octave TLS Files +O_TLS_FILES = $(patsubst %.m, %.o.tls, $(MFILES)) + + + EXTRA_DIST = \ read_trs_files.sh \ run_test_matlab.m \ run_test_octave.m \ $(MODFILES) \ $(XFAIL_MODFILES) \ + $(MFILES) \ run_block_byte_tests_matlab.m \ run_block_byte_tests_octave.m \ run_reporting_test_matlab.m \ @@ -321,10 +337,6 @@ EXTRA_DIST = \ fs2000_ssfile_aux.m \ printMakeCheckMatlabErrMsg.m \ printMakeCheckOctaveErrMsg.m \ - initval_file/ramst_initval_file_data.m \ - initval_file/ramst_initval_file_data_col_vec_mat.mat \ - initval_file/ramst_initval_file_data_row_vec_mat.mat \ - initval_file/ramst_initval_file_excel.xls \ test.m \ AIM/data_ca1.m \ AIM/fs2000_b1L1L_AIM_steadystate.m \ @@ -422,10 +434,22 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ $(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1 +%.m.tls : %.m + TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ + $(MATLAB)/bin/matlab -nosplash -nodisplay -r run_m_script + touch $*.m.tls + +%.o.tls : %.m + TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ + $(OCTAVE) --no-init-file --silent --no-history run_m_script 2>&1 + + clean-local: rm -f $(M_TRS_FILES) \ + $(M_TLS_FILES) \ $(M_XFAIL_TRS_FILES) \ $(O_TRS_FILES) \ + $(O_TLS_FILES) \ $(O_XFAIL_TRS_FILES) \ $(patsubst %.trs, %.log, $(M_TRS_FILES)) \ $(patsubst %.trs, %.log, $(M_XFAIL_TRS_FILES)) \ @@ -492,3 +516,5 @@ clean-local: ms-sbvar/tmv_rr_tr rm -f estimation/test_matrix.mat + + rm -f initval_file/ramst_initval_file_data_col_vec_mat.mat initval_file/ramst_initval_file_data_row_vec_mat.mat initval_file/ramst_initval_file_excel.xls diff --git a/tests/initval_file/ramst_initval_file.mod b/tests/initval_file/ramst_initval_file.mod index c45327faf..8a8e36edc 100644 --- a/tests/initval_file/ramst_initval_file.mod +++ b/tests/initval_file/ramst_initval_file.mod @@ -22,26 +22,34 @@ k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1)); c = aa*k^alph-delt*k; end; +disp('Test #1') initval_file(filename = ramst_initval_file_data); steady; simul(periods=200); + +disp('Test #2') initval_file(filename = ramst_initval_file_data_row_vec_mat); steady; simul(periods=200); + +disp('Test #3') + initval_file(filename = ramst_initval_file_data_col_vec_mat); steady; simul(periods=200); -initval_file(filename = ramst_initval_file_excel); +if ispc() + disp('Test #4') -steady; - -simul(periods=200); + initval_file(filename = ramst_initval_file_excel); + steady; + simul(periods=200); +end diff --git a/tests/initval_file/ramst_initval_file_data.m b/tests/initval_file/ramst_initval_file_data.m index f7d82234c..d5b750a31 100644 --- a/tests/initval_file/ramst_initval_file_data.m +++ b/tests/initval_file/ramst_initval_file_data.m @@ -1,10 +1,14 @@ x = vertcat([ 1; 1.2 ], repmat(1, 200, 1)); k = repmat(12.7551, 202, 1); c = repmat(1.53061, 202, 1); -% save ramst_initval_file_data_col_vec_mat -% xlswrite('ramst_initval_file_excel',[x k c],1,'A2') -% xlswrite('ramst_initval_file_excel',{'x' 'k' 'c'},1,'A1') -% c=c' -% k=k' -% x=x' -% save ramst_initval_file_data_row_vec_mat \ No newline at end of file +save('ramst_initval_file_data_col_vec_mat'); + +if ispc() + xlswrite('ramst_initval_file_excel',[x k c],1,'A2'); + xlswrite('ramst_initval_file_excel',{'x' 'k' 'c'},1,'A1'); +end + +c=c'; +k=k'; +x=x'; +save('ramst_initval_file_data_row_vec_mat'); \ No newline at end of file diff --git a/tests/initval_file/ramst_initval_file_data_col_vec_mat.mat b/tests/initval_file/ramst_initval_file_data_col_vec_mat.mat deleted file mode 100644 index 48c59f12f63781c4af061077c866309150505170..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 339 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2cQV4Jk_w+L}(NSsh5-`93qo*%FkZljd6>}aZCnRJfBquN^ zvGK8S@G`9l_@}9m#**yT#-(tU^9ZAXE06q}-h&S|+xFOd^sh5-`93qo*%FkZljd6>}aZCnRJfBquN^ zvGK8S@G`9luu~S8&vdzmN7P}Ka0hcjmxSF7>E?s!)e`kn46FiDo(mb{Cw*E9 zGRBU8F*m`+G;}d-PM>-{^HPZf%nbKTuM7tL!;3Z(W6DXWDQfoLs%HlLK3s=zi{?Vc JV|9o2008NKV^jbD diff --git a/tests/initval_file/ramst_initval_file_excel.xls b/tests/initval_file/ramst_initval_file_excel.xls deleted file mode 100644 index 1bea58b16c2cd91ac57cb687cbe520a33bcf06f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 38400 zcmeI536vC7mWE$uZONt-yC9J4`&I>r3RJO)Xt5|L?m|HpV3ma?1tNl!`vPtSqC&av z`!4R_zDzmOXSzL3JDeVShVhK2=S+{z%o)2!&AER>Mc#<`UnW`V%<1lv$$42Bf4=YD z7w_G7<3(g7`HR0P{o>wdd;ivi9@9;M`61QL6#Mjuyq@Q6cQ*2VDuqq&@A2|lr2OO0 zs0Z4`WFU)+%&M|aNmT7hYn=TdWo)4DFsb64m2X{YY%&hs?W#e5MNV}5z;@6Vee7L2f` zM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, 9 Mar 2015 17:13:03 +0100 Subject: [PATCH 09/50] =?UTF-8?q?preprocessor:=20cell2table=20doesn?= =?UTF-8?q?=E2=80=99t=20exist=20in=20Octave?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matlab/global_initialization.m | 2 +- preprocessor/ComputingTasks.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index bcd3cff40..85844b75b 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -363,7 +363,7 @@ estimation_info.structural_innovation_corr_prior_index = {}; estimation_info.structural_innovation_corr_options_index = {}; estimation_info.structural_innovation_corr.range_index = {}; estimation_info.joint_parameter_prior_index = {}; -estimation_info.joint_parameter = cell2table(cell(0,11)); +estimation_info.joint_parameter = table(0); options_.initial_period = NaN; %dates(1,1); options_.dataset.file = []; options_.dataset.series = []; diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 2d7b1ffc3..5194cd7f7 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2170,10 +2170,10 @@ JointPriorStatement::writeOutput(ostream &output, const string &basename) const << " " << lhs_field << ".variance, ..." << endl << " 'VariableNames',{'index','domain','interval','mean','median','mode','shape','shift','stdev','truncate','variance'});" << endl; - output << "if height(estimation_info.joint_parameter)" << endl - << " estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl + output << "if rows(estimation_info.joint_parameter)==1 && columns(estimation_info.joint_parameter)==1" << endl + << " estimation_info.joint_parameter = estimation_info.joint_parameter_tmp;" << endl << "else" << endl - << " estimation_info.joint_parameter = estimation_info.joint_parameter_tmp;" << endl + << " estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl << "end" << endl << "clear estimation_info.joint_parameter_tmp;" << endl; } From 6db9f1035351640d14775aca4ef42f79f533e42f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 9 Mar 2015 17:58:06 +0100 Subject: [PATCH 10/50] preprocessor: remove use of tables completely as they were introduced in Matlab R2013b. #824 --- matlab/global_initialization.m | 2 +- preprocessor/ComputingTasks.cc | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 85844b75b..9e75c5995 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -363,7 +363,7 @@ estimation_info.structural_innovation_corr_prior_index = {}; estimation_info.structural_innovation_corr_options_index = {}; estimation_info.structural_innovation_corr.range_index = {}; estimation_info.joint_parameter_prior_index = {}; -estimation_info.joint_parameter = table(0); +estimation_info.joint_parameter = {'index','domain','interval','mean','median','mode','shape','shift','stdev','truncate','variance'}; options_.initial_period = NaN; %dates(1,1); options_.dataset.file = []; options_.dataset.series = []; diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 5194cd7f7..e16d11354 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2157,7 +2157,7 @@ JointPriorStatement::writeOutput(ostream &output, const string &basename) const writeOutputHelper(output, "truncate", lhs_field); writeOutputHelper(output, "variance", lhs_field); - output << "estimation_info.joint_parameter_tmp = table(key, ..." << endl + output << "estimation_info.joint_parameter_tmp = [key, ..." << endl << " " << lhs_field << ".domain , ..." << endl << " " << lhs_field << ".interval , ..." << endl << " " << lhs_field << ".mean , ..." << endl @@ -2167,15 +2167,9 @@ JointPriorStatement::writeOutput(ostream &output, const string &basename) const << " " << lhs_field << ".shift , ..." << endl << " " << lhs_field << ".stdev , ..." << endl << " " << lhs_field << ".truncate , ..." << endl - << " " << lhs_field << ".variance, ..." << endl - << " 'VariableNames',{'index','domain','interval','mean','median','mode','shape','shift','stdev','truncate','variance'});" << endl; - - output << "if rows(estimation_info.joint_parameter)==1 && columns(estimation_info.joint_parameter)==1" << endl - << " estimation_info.joint_parameter = estimation_info.joint_parameter_tmp;" << endl - << "else" << endl - << " estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl - << "end" << endl - << "clear estimation_info.joint_parameter_tmp;" << endl; + << " " << lhs_field << ".variance];" << endl + << "estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl + << "estimation_info=rmfield(estimation_info, 'joint_parameter_tmp');" << endl; } void @@ -2183,10 +2177,14 @@ JointPriorStatement::writeOutputHelper(ostream &output, const string &field, con { OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field); output << lhs_field << "." << field << " = {"; + if (field=="variance") + output << "{"; if (itn != options_list.num_options.end()) output << itn->second; else output << "{}"; + if (field=="variance") + output << "}"; output << "};" << endl; } From 6e0d9197519a1be6ca960cf3dc0eb7e02d959fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 9 Mar 2015 18:21:36 +0100 Subject: [PATCH 11/50] Fix issue with purely forward deterministic models with lags on exogenous. Ref #617 --- matlab/perfect-foresight-models/sim1_purely_forward.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/sim1_purely_forward.m b/matlab/perfect-foresight-models/sim1_purely_forward.m index 8a8fa3294..34b60f510 100644 --- a/matlab/perfect-foresight-models/sim1_purely_forward.m +++ b/matlab/perfect-foresight-models/sim1_purely_forward.m @@ -37,7 +37,7 @@ function oo_ = sim1_purely_forward(options_, M_, oo_) 1, options_.gstep, options_.solve_tolf, ... options_.solve_tolx, options_.simul.maxit, ... options_.debug,oo_.exo_simul, M_.params, oo_.steady_state, ... - it); + it+M_.maximum_lag); if info oo_.deterministic_simulation.status = 0; From 87cb00bd7d3d8d8c85ae751d3ede0a4f82093a3c Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Wed, 11 Mar 2015 09:24:47 +0100 Subject: [PATCH 12/50] fixing bug in calling sequence of *_dynamic function when using block option --- matlab/dr_block.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/dr_block.m b/matlab/dr_block.m index b1e41c083..7eee88acd 100644 --- a/matlab/dr_block.m +++ b/matlab/dr_block.m @@ -72,7 +72,7 @@ end; if (options_.bytecode) [chck, zz, data]= bytecode('dynamic','evaluate', z, zx, M_.params, dr.ys, 1, data); else - [r, data] = feval([M_.fname '_dynamic'], z', zx, M_.params, dr.ys, M_.maximum_lag+1, data); + [r, data] = feval([M_.fname '_dynamic'], options_, M_, oo_, z', zx, M_.params, dr.ys, M_.maximum_lag+1, data); chck = 0; end; mexErrCheck('bytecode', chck); From c881cfff17cadb1db437d5e07b60e75492473042 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 12 Mar 2015 17:24:21 +0100 Subject: [PATCH 13/50] Fixed issues related to newratflag. This options relates to alternative numerical hessian computations: optim=('Hessian',1) is the default dynare numeric Hessian optim=('Hessian',0) is the outer product gradient optim=('Hessian',2) is the 'mixed' outer product gradient, where diagonal elements using second order derivation formula, Both 0 and 2 cases require univariate filters, to ensure using maximum number of individual densities. --- matlab/dynare_estimation_1.m | 43 ++++++++++++++----- matlab/global_initialization.m | 2 +- .../optimization/dynare_minimize_objective.m | 3 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index f64960504..5fdd91895 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -233,7 +233,7 @@ end if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation %prepare settings for newrat if options_.mode_compute==5 - %get whether analytical Hessian with non-analytical mode-finding is requested + %get whether outer product Hessian is requested newratflag=[]; if ~isempty(options_.optim_opt) options_list = read_key_value_string(options_.optim_opt); @@ -246,19 +246,14 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation if options_.analytic_derivation, options_analytic_derivation_old = options_.analytic_derivation; options_.analytic_derivation = -1; - if ~isempty(newratflag) && newratflag~=0 %gradient explicitly specified + if ~isempty(newratflag) && newratflag~=0 %numerical hessian explicitly specified error('newrat: analytic_derivation is incompatible with numerical Hessian.') else %use default - newratflag=0; %use analytical gradient + newratflag=0; %exclude DYNARE numerical hessian end elseif ~options_.analytic_derivation if isempty(newratflag) - newratflag=options_.newrat.hess; %use default gradient - end - if newratflag==0 %Analytic Hessian wanted, but not automatically computed by newrat itself - if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)) %kalman_algo not compatible - error('Analytical Hessian with non-analytical mode-finding requires kalman_algo=2 or 4.') - end + newratflag=options_.newrat.hess; %use default numerical dynare hessian end end end @@ -281,11 +276,39 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation [junk1, junk2, hh] = feval(objective_function,xparam1, ... dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); options_.analytic_derivation = ana_deriv_old; - elseif ~(isequal(options_.mode_compute,5) && newratflag==0), + elseif ~(isequal(options_.mode_compute,5) && newratflag~=1), % with flag==0, we force to use the hessian from outer % product gradient of optimizer 5 hh = reshape(hessian(objective_function,xparam1, ... options_.gstep,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_),nx,nx); + elseif isequal(options_.mode_compute,5) + % other numerical hessian options available with optimizer 5 + % + % if newratflag == 0 + % compute outer product gradient of optimizer 5 + % + % if newratflag == 2 + % compute 'mixed' outer product gradient of optimizer 5 + % with diagonal elements computed with numerical second order derivatives + % + % uses univariate filters, so to get max # of available + % densitities for outer product gradient + kalman_algo0 = options_.kalman_algo; + compute_hessian = 1; + if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)), + options_.kalman_algo=2; + if options_.lik_init == 3, + options_.kalman_algo=4; + end + elseif newratflag==0, % hh already contains outer product gradient with univariate filter + compute_hessian = 0; + end + if compute_hessian, + crit = options_.newrat.tolerance.f; + newratflag = newratflag>0; + hh = reshape(mr_hessian(0,xparam1,objective_function,newratflag,crit,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_), nx, nx); + end + options_.kalman_algo = kalman_algo0; end end end diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 9e75c5995..1470d533f 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -481,7 +481,7 @@ csminwel.maxiter=1000; options_.csminwel=csminwel; %newrat optimization routine -newrat.hess=1; %analytic hessian +newrat.hess=1; % dynare numerical hessian newrat.tolerance.f=1e-5; newrat.tolerance.f_analytic=1e-7; newrat.maxiter=1000; diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 124a4bf3f..b345b8d55 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -177,10 +177,9 @@ switch minimizer_algorithm end end [opt_par_values,hessian_mat,gg,fval,invhess] = newrat(objective_function,start_par_value,analytic_grad,crit,nit,0,varargin{:}); + %hessian_mat is the plain outer product gradient Hessian if options_.analytic_derivation %Hessian is already analytic one, reset option options_.analytic_derivation = ana_deriv; - elseif ~options_.analytic_derivation && newratflag ==0 %Analytic Hessian wanted, but not computed yet - hessian_mat = reshape(mr_hessian(0,opt_par_values,objective_function,1,crit,varargin{:}), n_params, n_params); end case 6 [opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function, start_par_value, ... From 7eeaef8472a554dd83eb9e23865e8d5b74f803f9 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 12 Mar 2015 23:16:53 +0100 Subject: [PATCH 14/50] Added documentation for optimizer 5. --- doc/dynare.texi | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index c7ff4cf2d..cd8e19a42 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -4855,7 +4855,9 @@ Uses Chris Sims's @code{csminwel} @item 5 Uses Marco Ratto's @code{newrat}. This value is not compatible with non -linear filters or DSGE-VAR models +linear filters or DSGE-VAR models. +This is a slice optimizer: most iterations are a sequence of univariate optimization step, one for each estimated parameter or shock. +Uses @code{csminwel} for line search in each step. @item 6 Uses a Monte-Carlo based optimization routine (see @@ -4974,6 +4976,25 @@ Initial approximation for the inverse of the Hessian matrix of the posterior ker @end table +@item 5 +Available options are: + +@table @code + +@item 'MaxIter' +Maximum number of iterations. Default: @code{1000} + +@item 'Hessian' +Triggers three types of Hessian computations. @code{0}: outer product gradient; @code{1} default DYNARE Hessian routine; @code{2} 'mixed' outer product gradient, where diagonal elements are obtained using second order derivation formula and outer product is used for correlation structure. +Both @{0} and @{2} options require univariate filters, to ensure using maximum number of individual densities and a positive definite Hessian. +Both @{0} and @{2} are quicker than default DYNARE numeric Hessian, but provide decent starting values for Metropolis for large models (option @{2} being more accurate than @{0}). +Default: @code{1}. + +@item 'TolFun' +Stopping criteria. Default: @code{1e-5} for numerical derivatives @code{1e-7} for analytic derivatives. + +@end table + @item 6 Available options are: From cf5ec64012a3dd19c50b4d0528361fb01def3f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 13 Mar 2015 15:27:16 +0100 Subject: [PATCH 15/50] Removed display of debug info. --- tests/initval_file/ramst_initval_file.mod | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/initval_file/ramst_initval_file.mod b/tests/initval_file/ramst_initval_file.mod index 8a8e36edc..e3eabc43b 100644 --- a/tests/initval_file/ramst_initval_file.mod +++ b/tests/initval_file/ramst_initval_file.mod @@ -22,7 +22,6 @@ k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1)); c = aa*k^alph-delt*k; end; -disp('Test #1') initval_file(filename = ramst_initval_file_data); steady; @@ -30,7 +29,6 @@ steady; simul(periods=200); -disp('Test #2') initval_file(filename = ramst_initval_file_data_row_vec_mat); steady; @@ -38,8 +36,6 @@ steady; simul(periods=200); -disp('Test #3') - initval_file(filename = ramst_initval_file_data_col_vec_mat); steady; From cd7ffc0f5a23b428d658fab72b62ef9bf90180f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 13 Mar 2015 15:39:43 +0100 Subject: [PATCH 16/50] Added missing matlab/octave scripts. --- tests/run_m_script.m | 52 ++++++++++++++++++++++++++++++++++++++++++++ tests/run_o_script.m | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 tests/run_m_script.m create mode 100644 tests/run_o_script.m diff --git a/tests/run_m_script.m b/tests/run_m_script.m new file mode 100644 index 000000000..f40fc242c --- /dev/null +++ b/tests/run_m_script.m @@ -0,0 +1,52 @@ +% Copyright (C) 2015 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 . + +top_test_dir = getenv('TOP_TEST_DIR'); +[mfile, name] = strtok(getenv('FILESTEM')); + +[directory, mscript, ext] = fileparts([top_test_dir '/' mfile]); +cd(directory); + +try + mscript; + testFailed = false; +catch exception + printMakeCheckMatlabErrMsg(strtok(getenv('FILESTEM')), exception); + testFailed = true; +end + +cd(top_test_dir); +name = strtok(getenv('FILESTEM')); +fid = fopen([name '.m.tls'], 'w'); +if fid < 0 + wd = pwd + filestep = getenv('FILESTEM') + error(['ERROR: problem opening file ' name '.m.tls for writing....']); +end +if testFailed + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']); +else + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']); +end +fclose(fid); +exit; \ No newline at end of file diff --git a/tests/run_o_script.m b/tests/run_o_script.m new file mode 100644 index 000000000..317f8cc18 --- /dev/null +++ b/tests/run_o_script.m @@ -0,0 +1,52 @@ +## Copyright (C) 2015 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 . + +top_test_dir = getenv('TOP_TEST_DIR'); +[mfile, name] = strtok(getenv('FILESTEM')); + +[directory, mscript, ext] = fileparts([top_test_dir '/' mfile]); +cd(directory); + +try + mscript; + testFailed = false; +catch + printMakeCheckOctaveErrMsg(getenv('FILESTEM'), lasterror); + testFailed = true; +end_try_catch + +cd(top_test_dir); +name = strtok(getenv('FILESTEM')); +fid = fopen([name '.o.tls'], 'w+'); +if testFailed + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 1\n'); + fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']); +else + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: 1\n'); + fprintf(fid,':number-failed-tests: 0\n'); + fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']); +end +fclose(fid); +exit; + + +## Local variables: +## mode: Octave +## End: From 7343fa8f99cf3323d49aa62e617c4c14ae2a6293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 13 Mar 2015 15:52:33 +0100 Subject: [PATCH 17/50] Fixed typo in tests/Makefile.am --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 184ddf691..ca367c35d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -441,7 +441,7 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) %.o.tls : %.m TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ - $(OCTAVE) --no-init-file --silent --no-history run_m_script 2>&1 + $(OCTAVE) --no-init-file --silent --no-history run_o_script 2>&1 clean-local: From 6d7b72cb0dec1536917c460ddcab7dccb6540a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 13 Mar 2015 15:48:57 +0100 Subject: [PATCH 18/50] Merged with master --- matlab/dr_block.m | 19 +++-- matlab/global_initialization.m | 2 +- matlab/ms-sbvar/identification/exclusions.m | 2 +- .../sbvar_global_identification_check.m | 77 +++++++++++++++++++ .../sim1_purely_forward.m | 2 +- preprocessor/ComputingTasks.cc | 18 ++--- preprocessor/ModFile.cc | 2 +- .../test_global_identification_FAILURE.mod | 16 ++++ .../test_global_identification_OK.mod | 15 ++++ 9 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 matlab/ms-sbvar/sbvar_global_identification_check.m create mode 100644 tests/ms-sbvar/test_global_identification_FAILURE.mod create mode 100644 tests/ms-sbvar/test_global_identification_OK.mod diff --git a/matlab/dr_block.m b/matlab/dr_block.m index e09eec429..7eee88acd 100644 --- a/matlab/dr_block.m +++ b/matlab/dr_block.m @@ -315,13 +315,17 @@ for i = 1:Size; dr.eigval = [dr.eigval ; data(i).eigval]; case 6 %% ------------------------------------------------------------------ - %Solve Forward complete + %Solve Forward complete + if (maximum_lag > 0) + ghx = - jacob(: , n_pred + 1 : n_pred + n_static ... + + n_pred + n_both) \ jacob(: , 1 : n_pred); + else + ghx = 0; + end; if maximum_lag > 0 && n_pred > 0 - data(i).eigval = eig(- jacob(: , 1 : n_pred) / ... - jacob(: , (n_pred + n_static + 1 : n_pred + n_static + n_pred ))); + data(i).eigval = -eig(ghx(n_static+1:end,:)); data(i).rank = 0; - full_rank = (rcond(jacob(: , (n_pred + n_static + 1 : n_pred ... - + n_static + n_pred ))) > 1e-9); + full_rank = (rcond(ghx(n_static+1:end,:)) > 1e-9); else data(i).eigval = []; data(i).rank = 0; @@ -330,11 +334,6 @@ for i = 1:Size; dr.eigval = [dr.eigval ; data(i).eigval]; dr.full_rank = dr.full_rank && full_rank; if task ~= 1 - if (maximum_lag > 0) - ghx = - jacob(: , 1 : n_pred) / jacob(: , n_pred + n_static + 1 : n_pred + n_static + n_pred + n_both); - else - ghx = 0; - end; if other_endo_nbr fx = data(i).g1_o; % retrieves the derivatives with respect to endogenous diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index bcd3cff40..9e75c5995 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -363,7 +363,7 @@ estimation_info.structural_innovation_corr_prior_index = {}; estimation_info.structural_innovation_corr_options_index = {}; estimation_info.structural_innovation_corr.range_index = {}; estimation_info.joint_parameter_prior_index = {}; -estimation_info.joint_parameter = cell2table(cell(0,11)); +estimation_info.joint_parameter = {'index','domain','interval','mean','median','mode','shape','shift','stdev','truncate','variance'}; options_.initial_period = NaN; %dates(1,1); options_.dataset.file = []; options_.dataset.series = []; diff --git a/matlab/ms-sbvar/identification/exclusions.m b/matlab/ms-sbvar/identification/exclusions.m index 9632356fe..a2447b1ba 100644 --- a/matlab/ms-sbvar/identification/exclusions.m +++ b/matlab/ms-sbvar/identification/exclusions.m @@ -1,4 +1,4 @@ -function [Ui,Vi,n0,np,ixmC0Pres] = exclusions(nvar,nexo,options_ms) +function [Ui,Vi,n0,np,ixmC0Pres,Qi] = exclusions(nvar,nexo,options_ms) % function [Ui,Vi,n0,np,ixmC0Pres] = exclusions(nvar,nexo,options_ms) % % INPUTS diff --git a/matlab/ms-sbvar/sbvar_global_identification_check.m b/matlab/ms-sbvar/sbvar_global_identification_check.m new file mode 100644 index 000000000..642220f54 --- /dev/null +++ b/matlab/ms-sbvar/sbvar_global_identification_check.m @@ -0,0 +1,77 @@ +function indent = sbvar_global_identification_check(options_) +% function sbvar_global_identification_check(options_.ms) +% +% INPUTS +% options_ms: (struct) options +% +% OUTPUTS +% ident: (boolean) false = not identified; true = identified +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2015 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 . + +ident = false; + +if isequal(options_.ms.restriction_fname, 'upper_cholesky') || ... + isequal(options_.ms.restriction_fname, 'lower_cholesky') + ident = true; + if ~options_.noprint + disp(' ') + disp('SBVAR: Cholesky identification is always identified') + disp(' ') + end + return +end +nvar = length(options_.varobs); % number of endogenous variables +nexo = 1; + +[Uiconst,Viconst,n0,np,ixmC0Pres,Qi] = exclusions(nvar,nexo,options_.ms ); + +% order column constraints by rank +Qranks = zeros(nvar,2); +for j=1:nvar + Qranks(j,:) = [j,rank(Qi{j})]; +end +Qranks = sortrows(Qranks,-2); + +ident = true; + +for j=1:nvar + i = Qranks(j,1); + for k=1:1 + M = [Qi{i}*rand(size(Qi{i},1),nvar);[eye(j) zeros(j,nvar- ... + j)]]; + disp([j,k,rank(M)]) + if rank(M) < nvar + ident = false + break + end + end +end + +if ~options_.noprint + disp(' ') + if ident + disp('The sufficient condition for SBVAR identification is met') + else + disp('WARNGING: The sufficient condition for SBVAR identification is not met') + end + disp(' ') +end \ No newline at end of file diff --git a/matlab/perfect-foresight-models/sim1_purely_forward.m b/matlab/perfect-foresight-models/sim1_purely_forward.m index 8a8fa3294..34b60f510 100644 --- a/matlab/perfect-foresight-models/sim1_purely_forward.m +++ b/matlab/perfect-foresight-models/sim1_purely_forward.m @@ -37,7 +37,7 @@ function oo_ = sim1_purely_forward(options_, M_, oo_) 1, options_.gstep, options_.solve_tolf, ... options_.solve_tolx, options_.simul.maxit, ... options_.debug,oo_.exo_simul, M_.params, oo_.steady_state, ... - it); + it+M_.maximum_lag); if info oo_.deterministic_simulation.status = 0; diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 2d7b1ffc3..e16d11354 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2157,7 +2157,7 @@ JointPriorStatement::writeOutput(ostream &output, const string &basename) const writeOutputHelper(output, "truncate", lhs_field); writeOutputHelper(output, "variance", lhs_field); - output << "estimation_info.joint_parameter_tmp = table(key, ..." << endl + output << "estimation_info.joint_parameter_tmp = [key, ..." << endl << " " << lhs_field << ".domain , ..." << endl << " " << lhs_field << ".interval , ..." << endl << " " << lhs_field << ".mean , ..." << endl @@ -2167,15 +2167,9 @@ JointPriorStatement::writeOutput(ostream &output, const string &basename) const << " " << lhs_field << ".shift , ..." << endl << " " << lhs_field << ".stdev , ..." << endl << " " << lhs_field << ".truncate , ..." << endl - << " " << lhs_field << ".variance, ..." << endl - << " 'VariableNames',{'index','domain','interval','mean','median','mode','shape','shift','stdev','truncate','variance'});" << endl; - - output << "if height(estimation_info.joint_parameter)" << endl - << " estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl - << "else" << endl - << " estimation_info.joint_parameter = estimation_info.joint_parameter_tmp;" << endl - << "end" << endl - << "clear estimation_info.joint_parameter_tmp;" << endl; + << " " << lhs_field << ".variance];" << endl + << "estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl + << "estimation_info=rmfield(estimation_info, 'joint_parameter_tmp');" << endl; } void @@ -2183,10 +2177,14 @@ JointPriorStatement::writeOutputHelper(ostream &output, const string &field, con { OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field); output << lhs_field << "." << field << " = {"; + if (field=="variance") + output << "{"; if (itn != options_list.num_options.end()) output << itn->second; else output << "{}"; + if (field=="variance") + output << "}"; output << "};" << endl; } diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index e21cf81e8..847fc7e33 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -290,7 +290,7 @@ ModFile::checkPass() // Check if some exogenous is not used in the model block set unusedExo = dynamic_model.findUnusedExogenous(); - if (unusedExo.size() > 1) + if (unusedExo.size() > 0) { warnings << "WARNING: some exogenous ("; for (set::const_iterator it = unusedExo.begin(); diff --git a/tests/ms-sbvar/test_global_identification_FAILURE.mod b/tests/ms-sbvar/test_global_identification_FAILURE.mod new file mode 100644 index 000000000..8ff9cfddd --- /dev/null +++ b/tests/ms-sbvar/test_global_identification_FAILURE.mod @@ -0,0 +1,16 @@ +// same as test_lower_cholesky.mod, but using exclusion syntax +var R Pie Y; + +varobs Y Pie R; + +svar_identification; +exclusion lag 0; +equation 1, Pie, Y; +exclusion lag 1; +equation 2, Y; +end; + +sbvar_global_identification_check(options_); + +sbvar(datafile = data,freq=4,initial_year=1959,final_year=2005,nlags=4); + diff --git a/tests/ms-sbvar/test_global_identification_OK.mod b/tests/ms-sbvar/test_global_identification_OK.mod new file mode 100644 index 000000000..7e54d9223 --- /dev/null +++ b/tests/ms-sbvar/test_global_identification_OK.mod @@ -0,0 +1,15 @@ +// same as test_lower_cholesky.mod, but using exclusion syntax +var R Pie Y; + +varobs Y Pie R; + +svar_identification; +exclusion lag 0; +equation 1, Pie, Y; +equation 2, Y; +end; + +sbvar_global_identification_check(options_); + +sbvar(datafile = data,freq=4,initial_year=1959,final_year=2005,nlags=4); + From e82487ed6228f0cf38124295527dd8dba61eacc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 13 Mar 2015 17:24:07 +0100 Subject: [PATCH 19/50] Added missing extension for o.tls rule. --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index ca367c35d..83f378580 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -441,7 +441,7 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) %.o.tls : %.m TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ - $(OCTAVE) --no-init-file --silent --no-history run_o_script 2>&1 + $(OCTAVE) --no-init-file --silent --no-history run_o_script.m 2>&1 clean-local: From f1d70605201d6d1b104ebbcfba71134a8303f80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 13 Mar 2015 17:25:06 +0100 Subject: [PATCH 20/50] Added explicit extension for generated mat files (needed by octave). --- tests/initval_file/ramst_initval_file_data.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/initval_file/ramst_initval_file_data.m b/tests/initval_file/ramst_initval_file_data.m index d5b750a31..aa94ecbd3 100644 --- a/tests/initval_file/ramst_initval_file_data.m +++ b/tests/initval_file/ramst_initval_file_data.m @@ -1,7 +1,7 @@ x = vertcat([ 1; 1.2 ], repmat(1, 200, 1)); k = repmat(12.7551, 202, 1); c = repmat(1.53061, 202, 1); -save('ramst_initval_file_data_col_vec_mat'); +save('ramst_initval_file_data_col_vec_mat.mat'); if ispc() xlswrite('ramst_initval_file_excel',[x k c],1,'A2'); @@ -11,4 +11,4 @@ end c=c'; k=k'; x=x'; -save('ramst_initval_file_data_row_vec_mat'); \ No newline at end of file +save('ramst_initval_file_data_row_vec_mat.mat'); \ No newline at end of file From e2a149430e485ee441f4c7176329322401dd7732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 13 Mar 2015 17:26:27 +0100 Subject: [PATCH 21/50] Use perfect_foresight_setup and perfect_foresight_solver routines. --- tests/initval_file/ramst_initval_file.mod | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/initval_file/ramst_initval_file.mod b/tests/initval_file/ramst_initval_file.mod index e3eabc43b..354ef410b 100644 --- a/tests/initval_file/ramst_initval_file.mod +++ b/tests/initval_file/ramst_initval_file.mod @@ -26,26 +26,31 @@ initval_file(filename = ramst_initval_file_data); steady; -simul(periods=200); +perfect_foresight_setup(periods=200); +perfect_foresight_solver; initval_file(filename = ramst_initval_file_data_row_vec_mat); steady; -simul(periods=200); +perfect_foresight_setup(periods=200); +perfect_foresight_solver; initval_file(filename = ramst_initval_file_data_col_vec_mat); steady; -simul(periods=200); +perfect_foresight_setup(periods=200); +perfect_foresight_solver; if ispc() disp('Test #4') initval_file(filename = ramst_initval_file_excel); steady; - simul(periods=200); + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + end From 3a3469b8872fa11fb2a0e918616579137c84e19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 13 Mar 2015 17:27:26 +0100 Subject: [PATCH 22/50] Cosmetic change. --- tests/initval_file/ramst_initval_file.mod | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/initval_file/ramst_initval_file.mod b/tests/initval_file/ramst_initval_file.mod index 354ef410b..f6afae20b 100644 --- a/tests/initval_file/ramst_initval_file.mod +++ b/tests/initval_file/ramst_initval_file.mod @@ -23,34 +23,25 @@ c = aa*k^alph-delt*k; end; initval_file(filename = ramst_initval_file_data); - steady; - perfect_foresight_setup(periods=200); perfect_foresight_solver; initval_file(filename = ramst_initval_file_data_row_vec_mat); - steady; - perfect_foresight_setup(periods=200); perfect_foresight_solver; initval_file(filename = ramst_initval_file_data_col_vec_mat); - steady; - perfect_foresight_setup(periods=200); perfect_foresight_solver; if ispc() - disp('Test #4') - initval_file(filename = ramst_initval_file_excel); steady; perfect_foresight_setup(periods=200); perfect_foresight_solver; - end From a988418668cb8d8441c5c483700f03bea9c685f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 13 Mar 2015 17:57:46 +0100 Subject: [PATCH 23/50] Renamed tests/test.m as tests/fataltest.m. Previous routine name was causing octave testsuite to throw a warning. --- tests/{test.m => fataltest.m} | 0 tests/t_sgu_ex1.mod | 12 ++++++------ 2 files changed, 6 insertions(+), 6 deletions(-) rename tests/{test.m => fataltest.m} (100%) diff --git a/tests/test.m b/tests/fataltest.m similarity index 100% rename from tests/test.m rename to tests/fataltest.m diff --git a/tests/t_sgu_ex1.mod b/tests/t_sgu_ex1.mod index 9ac2e6fd9..87e270666 100644 --- a/tests/t_sgu_ex1.mod +++ b/tests/t_sgu_ex1.mod @@ -28,10 +28,10 @@ stoch_simul(nomoments,nocorr,ar=0,irf=0); global dr_ load objectives/sgu_ex1; -test(oo_.dr.ghx,dr_obj_.ghx,1); -test(oo_.dr.ghu,dr_obj_.ghu,2); -test(oo_.dr.ghxx,dr_obj_.ghxx,3); -test(oo_.dr.ghxu,dr_obj_.ghxu,4); -test(oo_.dr.ghuu,dr_obj_.ghuu,5); +fataltest(oo_.dr.ghx,dr_obj_.ghx,1); +fataltest(oo_.dr.ghu,dr_obj_.ghu,2); +fataltest(oo_.dr.ghxx,dr_obj_.ghxx,3); +fataltest(oo_.dr.ghxu,dr_obj_.ghxu,4); +fataltest(oo_.dr.ghuu,dr_obj_.ghuu,5); -disp('TESTS OK'); \ No newline at end of file +disp('TESTS OK'); From 6d304891d19da6f0036eec417a1a4446f6ba29da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Hermes=29?= Date: Fri, 13 Mar 2015 22:51:02 +0100 Subject: [PATCH 24/50] Fixed EXTRA_DIST in Makefile.am. I forgot to update Makefile.am after the change introduced in the previous commit (a988418668cb8d8441c5c483700f03bea9c685f9). --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 83f378580..14e46b716 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -337,7 +337,7 @@ EXTRA_DIST = \ fs2000_ssfile_aux.m \ printMakeCheckMatlabErrMsg.m \ printMakeCheckOctaveErrMsg.m \ - test.m \ + fataltest.m \ AIM/data_ca1.m \ AIM/fs2000_b1L1L_AIM_steadystate.m \ AIM/fs2000_b1L1L_steadystate.m \ From 1a3d8d0b26a398c60221cdceb234036140d8fd4e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 16 Mar 2015 14:44:06 +0100 Subject: [PATCH 25/50] Provisions for MATLAB 8.5 (R2015a) --- m4/ax_matlab_version.m4 | 5 ++++- matlab/dynare_config.m | 4 ++-- windows/dynare.nsi | 12 ++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/m4/ax_matlab_version.m4 b/m4/ax_matlab_version.m4 index c7a1d5f3e..211da8477 100644 --- a/m4/ax_matlab_version.m4 +++ b/m4/ax_matlab_version.m4 @@ -1,4 +1,4 @@ -dnl Copyright (C) 2009-2014 Dynare Team +dnl Copyright (C) 2009-2015 Dynare Team dnl dnl This file is part of Dynare. dnl @@ -22,6 +22,9 @@ AC_REQUIRE([AX_MATLAB]) AC_MSG_CHECKING([for MATLAB version]) if test "x$MATLAB_VERSION" != "x"; then case $MATLAB_VERSION in + *2015a | *2015A) + MATLAB_VERSION="8.5" + ;; *2014b | *2014B) MATLAB_VERSION="8.4" ;; diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 160cd6222..9426c7d76 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -119,7 +119,7 @@ if isoctave else % Add win32 specific paths for Dynare Windows package if strcmp(computer, 'PCWIN') - mexpath = [dynareroot '../mex/matlab/win32-7.5-8.4']; + mexpath = [dynareroot '../mex/matlab/win32-7.5-8.5']; if exist(mexpath, 'dir') addpath(mexpath) end @@ -133,7 +133,7 @@ else addpath(mexpath) end else - mexpath = [dynareroot '../mex/matlab/win64-7.8-8.4']; + mexpath = [dynareroot '../mex/matlab/win64-7.8-8.5']; if exist(mexpath, 'dir') addpath(mexpath) end diff --git a/windows/dynare.nsi b/windows/dynare.nsi index 6f7a45b7a..c6f062a1c 100644 --- a/windows/dynare.nsi +++ b/windows/dynare.nsi @@ -83,9 +83,9 @@ SectionEnd SectionGroup "MEX files for MATLAB" -Section "MEX files for MATLAB 32-bit, version 7.5 to 8.4 (R2007b to R2014b)" - SetOutPath $INSTDIR\mex\matlab\win32-7.5-8.4 - File ..\mex\matlab\win32-7.5-8.4\*.mexw32 +Section "MEX files for MATLAB 32-bit, version 7.5 to 8.5 (R2007b to R2015a)" + SetOutPath $INSTDIR\mex\matlab\win32-7.5-8.5 + File ..\mex\matlab\win32-7.5-8.5\*.mexw32 SectionEnd Section "MEX files for MATLAB 64-bit, version 7.5 to 7.7 (R2007b to R2008b)" @@ -93,9 +93,9 @@ Section "MEX files for MATLAB 64-bit, version 7.5 to 7.7 (R2007b to R2008b)" File ..\mex\matlab\win64-7.5-7.7\*.mexw64 SectionEnd -Section "MEX files for MATLAB 64-bit, version 7.8 to 8.4 (R2009a to R2014b)" - SetOutPath $INSTDIR\mex\matlab\win64-7.8-8.4 - File ..\mex\matlab\win64-7.8-8.4\*.mexw64 +Section "MEX files for MATLAB 64-bit, version 7.8 to 8.5 (R2009a to R2015a)" + SetOutPath $INSTDIR\mex\matlab\win64-7.8-8.5 + File ..\mex\matlab\win64-7.8-8.5\*.mexw64 SectionEnd SectionGroupEnd From 91d8ce38bc234c663d476afc41a743b62f26fda4 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 17 Mar 2015 11:43:30 +0100 Subject: [PATCH 26/50] Disable OSR unit tests for optimizers not supported by Octave --- tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod | 3 ++- tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod index 65dcf6991..2b8a30406 100644 --- a/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod @@ -28,7 +28,7 @@ options_.nograph=1; options_.nocorr=1; osr_params gammax0 gammac0 gamma_y_ gamma_inf_; - +if ~isoctave optim_weights; inflation 1; y 1; @@ -107,3 +107,4 @@ end if max(abs((cell2mat(struct2cell(oo_.osr.optim_params))-cell2mat(struct2cell(oo_covar_single.osr.optim_params)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 error('Parameters should be identical') end +end \ No newline at end of file diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod index fea442457..d23466728 100644 --- a/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod @@ -41,6 +41,7 @@ gammac0 = 1.5; gamma_y_ = 8; gamma_inf_ = 3; +if ~isoctave osr(opt_algo=7); %compute objective function manually objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact')); @@ -107,3 +108,4 @@ end if max(abs((cell2mat(struct2cell(oo_.osr.optim_params))-cell2mat(struct2cell(oo_covar_single.osr.optim_params)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4 error('Parameters should be identical') end +end \ No newline at end of file From d0628af1f2be7056fe12cd4908b390dcdc7e87ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 17 Mar 2015 17:53:11 +0100 Subject: [PATCH 27/50] No longer compile ordschur.oct for Octave >= 4.0. The function is now an Octave builtin. --- mex/build/octave/Makefile.am | 6 +++++- mex/build/octave/configure.ac | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mex/build/octave/Makefile.am b/mex/build/octave/Makefile.am index 77067b24c..71d4639d6 100644 --- a/mex/build/octave/Makefile.am +++ b/mex/build/octave/Makefile.am @@ -2,12 +2,16 @@ ACLOCAL_AMFLAGS = -I ../../../m4 # libdynare++ must come before gensylv, k_order_perturbation, dynare_simul_ if DO_SOMETHING -SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv qzcomplex ordschur block_kalman_filter sobol local_state_space_iterations +SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv qzcomplex block_kalman_filter sobol local_state_space_iterations if COMPILE_LINSOLVE SUBDIRS += linsolve endif +if COMPILE_ORDSCHUR +SUBDIRS += ordschur +endif + if HAVE_MATIO SUBDIRS += k_order_perturbation dynare_simul_ endif diff --git a/mex/build/octave/configure.ac b/mex/build/octave/configure.ac index 499f5fe93..fd563e61c 100755 --- a/mex/build/octave/configure.ac +++ b/mex/build/octave/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -dnl Copyright (C) 2009-2014 Dynare Team +dnl Copyright (C) 2009-2015 Dynare Team dnl dnl This file is part of Dynare. dnl @@ -34,9 +34,11 @@ if test "x$MKOCTFILE" != "x"; then OCTAVE_VERSION=`$MKOCTFILE -v 2>&1 | sed 's/mkoctfile, version //'` AX_COMPARE_VERSION([$OCTAVE_VERSION], [lt], [3.6], [AC_MSG_ERROR([Your Octave is too old, please upgrade to version 3.6 at least.])]) AX_COMPARE_VERSION([$OCTAVE_VERSION], [ge], [3.8], [OCTAVE38=yes]) + AX_COMPARE_VERSION([$OCTAVE_VERSION], [ge], [4.0], [OCTAVE40=yes]) fi AM_CONDITIONAL([COMPILE_LINSOLVE], [test "$OCTAVE38" != "yes"]) +AM_CONDITIONAL([COMPILE_ORDSCHUR], [test "$OCTAVE40" != "yes"]) CFLAGS="$CFLAGS -Wall -Wno-parentheses" FFLAGS="$FFLAGS -Wall" @@ -121,6 +123,12 @@ else BUILD_LINSOLVE_OCTAVE="no (Octave >= 3.8)" fi +if test -n "$MKOCTFILE" -a "$OCTAVE40" != "yes"; then + BUILD_ORDSCHUR_OCTAVE="yes" +else + BUILD_ORDSCHUR_OCTAVE="no (Octave >= 4.0)" +fi + AC_ARG_ENABLE([openmp], AS_HELP_STRING([--enable-openmp], [use OpenMP for parallelization of some MEX files]), [ if test "x$enable_openmp" = "xyes"; then CPPFLAGS="$CPPFLAGS -DUSE_OMP" @@ -139,6 +147,7 @@ Binaries (with "make"): Kalman Steady State MEX file for Octave: $BUILD_KALMAN_STEADY_STATE_OCTAVE Estimation, k-order and dynare_simul MEX for Octave: $BUILD_ESTIMATION_KORDER_DYNSIMUL_MEX_OCTAVE Linsolve for Octave: $BUILD_LINSOLVE_OCTAVE + Ordschur for Octave: $BUILD_ORDSCHUR_OCTAVE ]) From ec65f8061743e7070f63ebfa59ef81793c67e61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 17 Mar 2015 17:59:52 +0100 Subject: [PATCH 28/50] Octave warning "matlab-incompatible" renamed to "language-extension" in 4.0. --- matlab/warning_config.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/matlab/warning_config.m b/matlab/warning_config.m index 6b6f53306..6b19b83b6 100644 --- a/matlab/warning_config.m +++ b/matlab/warning_config.m @@ -10,7 +10,7 @@ function warning_config() % SPECIAL REQUIREMENTS % none -% Copyright (C) 2008-2013 Dynare Team +% Copyright (C) 2008-2015 Dynare Team % % This file is part of Dynare. % @@ -34,7 +34,11 @@ warning('on', 'backtrace'); if isoctave warning('off', 'Octave:separator-insert'); - warning('off', 'Octave:matlab-incompatible'); + if octave_ver_less_than('4.0') + warning('off', 'Octave:matlab-incompatible'); + else + warning('off', 'Octave:language-extension'); + end warning('off', 'Octave:single-quote-string'); warning('off', 'Octave:missing-semicolon'); warning('off', 'Octave:empty-list-elements'); From aa1acec3082caba9ab4da1b7a995f8d9f7b9abae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 17 Mar 2015 18:01:36 +0100 Subject: [PATCH 29/50] Remove obsolete warning code for Octave < 3.6. --- matlab/warning_config.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/matlab/warning_config.m b/matlab/warning_config.m index 6b19b83b6..3b9f45d63 100644 --- a/matlab/warning_config.m +++ b/matlab/warning_config.m @@ -47,11 +47,7 @@ if isoctave warning('off', 'Octave:str-to-num'); warning('off', 'Octave:array-as-scalar'); warning('off', 'Octave:array-as-vector'); - if octave_ver_less_than('3.6') - warning('off', 'Octave:string-concat'); - else - warning('off', 'Octave:mixed-string-concat'); - end + warning('off', 'Octave:mixed-string-concat'); warning('off', 'Octave:variable-switch-label'); warning('off', 'Octave:fortran-indexing'); else From bbbbeb839f927171e3fff678f1d3354e5267ca88 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 18 Mar 2015 13:32:04 +0100 Subject: [PATCH 30/50] Change call to test.m to fataltest.m Necessary after a988418668cb8d8441c5c483700f03bea9c685f9 to prevent crashes --- tests/deterministic_simulations/rbc_det_exo_lag_2b.mod | 2 +- tests/deterministic_simulations/rbc_det_exo_lag_2c.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod b/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod index 08cdb5473..d59a8e613 100644 --- a/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod +++ b/tests/deterministic_simulations/rbc_det_exo_lag_2b.mod @@ -77,4 +77,4 @@ rplot Capital; O=load('rbc_det_exo_lag_2a_results'); -test(oo_.endo_simul(:,2:end),O.oo_.endo_simul); \ No newline at end of file +fataltest(oo_.endo_simul(:,2:end),O.oo_.endo_simul); \ No newline at end of file diff --git a/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod b/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod index 654446c8c..fd7024109 100644 --- a/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod +++ b/tests/deterministic_simulations/rbc_det_exo_lag_2c.mod @@ -77,4 +77,4 @@ rplot Capital; O=load('rbc_det_exo_lag_2a_results'); -test(oo_.endo_simul(:,2:end),O.oo_.endo_simul); \ No newline at end of file +fataltest(oo_.endo_simul(:,2:end),O.oo_.endo_simul); \ No newline at end of file From 80f512b90bc85fe4208085b5d7ef8ed58d58a303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 18 Mar 2015 16:03:41 +0100 Subject: [PATCH 31/50] ilu function has been implemented in Octave 4.0. --- matlab/dynare_config.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 9426c7d76..352ab95c8 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -90,8 +90,8 @@ if isoctave addpath([dynareroot '/missing/ordeig']) end -% ilu is missing in Octave -if isoctave +% ilu is missing in Octave < 4.0 +if isoctave && octave_ver_less_than('4.0') addpath([dynareroot '/missing/ilu']) end From 39a2dcd70fe6fb5263a60a546b98a1afc680d2a1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 19 Mar 2015 15:32:50 +0100 Subject: [PATCH 32/50] preprocessor: bug fix for Windows 7 in joint parameters syntax. Closes #855 --- preprocessor/DynareFlex.ll | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 793de8c0e..994aaa421 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -851,6 +851,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 string token; yylval->vector_string_val = new vector; + bool dynare_statement = true; + while(getline(ss, token, ',')) if (driver.symbol_exists_and_is_not_modfile_local_or_external_function(token.c_str())) yylval->vector_string_val->push_back(new string(token)); @@ -862,9 +864,10 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 delete yylval->vector_string_val; BEGIN NATIVE; yyless(0); + dynare_statement = false; break; } - if (yylval->vector_string_val->size() > 0) + if (dynare_statement) { BEGIN DYNARE_STATEMENT; return token::SYMBOL_VEC; From 781e2806102f505652eab955e226639a666b89c9 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 25 Mar 2015 09:42:59 +0100 Subject: [PATCH 33/50] Prevent crash if steady state cannot be computed If e.g. the log of the steady state cannot be computed, the field oo_.dr.ys does not exist --- matlab/stoch_simul.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/stoch_simul.m b/matlab/stoch_simul.m index c90bc1a5e..e9a4e5e2d 100644 --- a/matlab/stoch_simul.m +++ b/matlab/stoch_simul.m @@ -82,7 +82,7 @@ else [oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); end -if options_.loglinear %log steady state for correct display of decision rules and simulations +if options_.loglinear && isfield(oo_.dr,'ys') %log steady state for correct display of decision rules and simulations oo_.dr.ys=log(oo_.dr.ys); oo_.steady_state=log(oo_.steady_state); options_old.logged_steady_state = 1; From 7ca36832812e1e1525d5d75e4aecd1cfe0491b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Sedna=29?= Date: Wed, 25 Mar 2015 14:37:58 +0100 Subject: [PATCH 34/50] Fixed bug. Uninitialized memory reads because the code was working with a std::map, which was volatile. --- dynare++/src/forw_subst_builder.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/dynare++/src/forw_subst_builder.cpp b/dynare++/src/forw_subst_builder.cpp index 5f85f0fab..e2fa6cf55 100644 --- a/dynare++/src/forw_subst_builder.cpp +++ b/dynare++/src/forw_subst_builder.cpp @@ -1,5 +1,6 @@ // Copyright (C) 2006-2011, Ondra Kamenik + #include "forw_subst_builder.h" using namespace ogdyn; @@ -47,18 +48,20 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j) // first make lagsubst be substitution setting f(x(+4)) to f(x(+1)) // this is lag = -3 (1-mlead) map lagsubst; - model.variable_shift_map(model.eqs.nulary_of_term(t), 1-mlead, lagsubst); + unordered_set nult = model.eqs.nulary_of_term(t);// make copy of nult! + model.variable_shift_map(nult, 1-mlead, lagsubst); int lagt = model.eqs.add_substitution(t, lagsubst); - // now maxlead of lagt is +1 - // add AUXLD_*_*_1 = f(x(+1)) to the model - char name[100]; - sprintf(name, "AUXLD_%d_%d_%d", i, j, 1); - model.atoms.register_uniq_endo(name); - info.num_aux_variables++; - const char* ss = model.atoms.get_name_storage().query(name); - int auxt = model.eqs.add_nulary(name); - model.eqs.add_formula(model.eqs.add_binary(ogp::MINUS, auxt, lagt)); - aux_map.insert(Tsubstmap::value_type(ss, lagt)); + + // now maxlead of lagt is +1 + // add AUXLD_*_*_1 = f(x(+1)) to the model + char name[100]; + sprintf(name, "AUXLD_%d_%d_%d", i, j, 1); + model.atoms.register_uniq_endo(name); + info.num_aux_variables++; + const char* ss = model.atoms.get_name_storage().query(name); + int auxt = model.eqs.add_nulary(name); + model.eqs.add_formula(model.eqs.add_binary(ogp::MINUS, auxt, lagt)); + aux_map.insert(Tsubstmap::value_type(ss, lagt)); // now add variables and equations // AUXLD_*_*_2 = AUXLD_*_*_1(+1) through // AUXLD_*_*_{mlead-1} = AUXLD_*_*_{mlead-2}(+1) @@ -82,7 +85,9 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j) aux_map.insert(Tsubstmap::value_type(ss, lagt)); } - // now we have to substitute AUXLEAD_*_*{mlead-1}(+1) for t + // now we have to substitute AUXLD_*_*{mlead-1}(+1) for t + sprintf(name, "AUXLD_%d_%d_%d", i, j, mlead-1); + ss = model.atoms.get_name_storage().query(name); model.substitute_atom_for_term(ss, +1, t); } } From 64346de401c74a57929f51c723cd8462bdef0e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Sedna=29?= Date: Wed, 25 Mar 2015 14:45:09 +0100 Subject: [PATCH 35/50] Initial guess for Lagrange multipliers solved by SVD decomposition to improve conditioning. --- dynare++/src/planner_builder.cpp | 10 ++-- dynare++/sylv/cc/GeneralMatrix.cpp | 73 ++++++++++++++++++++++++++++++ dynare++/sylv/cc/GeneralMatrix.h | 36 +++++++++++++++ 3 files changed, 114 insertions(+), 5 deletions(-) diff --git a/dynare++/src/planner_builder.cpp b/dynare++/src/planner_builder.cpp index d2a38dfd4..6958a8ab6 100644 --- a/dynare++/src/planner_builder.cpp +++ b/dynare++/src/planner_builder.cpp @@ -327,11 +327,11 @@ MultInitSS::MultInitSS(const PlannerBuilder& pb, const Vector& pvals, Vector& yy ogp::FormulaCustomEvaluator fe(builder.static_tree, terms); fe.eval(dssav, *this); - // solve overdetermined system b+F*lambda=0 => lambda=-(F^T*F)^{-1}*F^T*b - GeneralMatrix FtF(F, "transpose", F); - Vector lambda(builder.diff_f_static.dim2()); - F.multVecTrans(0.0, lambda, -1.0, b); - ConstGeneralMatrix(FtF).multInvLeft(lambda); + // solve overdetermined system b+F*lambda=0 using SVD decomposition + SVDDecomp decomp(F); + Vector lambda(builder.diff_f_static.dim2()); + decomp.solve(b, lambda); + lambda.mult(-1); // take values of lambda and put it to yy for (int fi = 0; fi < builder.diff_f_static.dim2(); fi++) { diff --git a/dynare++/sylv/cc/GeneralMatrix.cpp b/dynare++/sylv/cc/GeneralMatrix.cpp index b50b3ed4f..75834f522 100644 --- a/dynare++/sylv/cc/GeneralMatrix.cpp +++ b/dynare++/sylv/cc/GeneralMatrix.cpp @@ -481,3 +481,76 @@ void ConstGeneralMatrix::print() const printf("\n"); } } + +void SVDDecomp::construct(const GeneralMatrix& A) +{ + // quick exit if empty matrix + if (minmn == 0) { + U.unit(); + VT.unit(); + conv = true; + return; + } + + // make copy of the matrix + GeneralMatrix AA(A); + + lapack_int m = AA.numRows(); + lapack_int n = AA.numCols(); + double* a = AA.base(); + lapack_int lda = AA.getLD(); + double* s = sigma.base(); + double* u = U.base(); + lapack_int ldu = U.getLD(); + double* vt = VT.base(); + lapack_int ldvt = VT.getLD(); + double tmpwork; + lapack_int lwork = -1; + lapack_int info; + + lapack_int* iwork = new lapack_int[8*minmn]; + // query for optimal lwork + dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, &tmpwork, + &lwork, iwork, &info); + lwork = (lapack_int)tmpwork; + Vector work(lwork); + // do the decomposition + dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work.base(), + &lwork, iwork, &info); + delete [] iwork; + if (info < 0) + throw SYLV_MES_EXCEPTION("Internal error in SVDDecomp constructor"); + if (info == 0) + conv = true; +} + +void SVDDecomp::solve(const GeneralMatrix& B, GeneralMatrix& X) const +{ + if (B.numRows() != U.numRows()) + throw SYLV_MES_EXCEPTION("Incompatible number of rows "); + + // reciprocal condition number for determination of zeros in the + // end of sigma + double rcond = 1e-13; + + // solve U: B = U^T*B + GeneralMatrix UTB(U, "trans", B); + // determine nz=number of zeros in the end of sigma + int nz = 0; + while (nz < minmn && sigma[minmn-1-nz] < rcond*sigma[0]) + nz++; + // take relevant B for sigma inversion + int m = U.numRows(); + int n = VT.numCols(); + GeneralMatrix Bprime(UTB, m-minmn, 0, minmn-nz, B.numCols()); + // solve sigma + for (int i = 0; i < minmn-nz; i++) + Vector(i, Bprime).mult(1.0/sigma[i]); + // solve VT + X.zeros(); + //- copy Bprime to right place of X + for (int i = 0; i < minmn-nz; i++) + Vector(n-minmn+i, X) = ConstVector(i, Bprime); + //- multiply with VT + X.multLeftTrans(VT); +} diff --git a/dynare++/sylv/cc/GeneralMatrix.h b/dynare++/sylv/cc/GeneralMatrix.h index 18413b762..d24c11cad 100644 --- a/dynare++/sylv/cc/GeneralMatrix.h +++ b/dynare++/sylv/cc/GeneralMatrix.h @@ -7,6 +7,8 @@ #include "Vector.h" +#include + class GeneralMatrix; class ConstGeneralMatrix { @@ -272,6 +274,40 @@ private: static int md_length; }; +class SVDDecomp { +protected: + /** Minimum of number of rows and columns of the decomposed + * matrix. */ + const int minmn; + /** Singular values. */ + Vector sigma; + /** Orthogonal matrix U. */ + GeneralMatrix U; + /** Orthogonal matrix V^T. */ + GeneralMatrix VT; + /** Convered flag. */ + bool conv; +public: + SVDDecomp(const GeneralMatrix& A) + : minmn(std::min(A.numRows(), A.numCols())), + sigma(minmn), + U(A.numRows(), A.numRows()), + VT(A.numCols(), A.numCols()), + conv(false) + {construct(A);} + const GeneralMatrix& getU() const + {return U;} + const GeneralMatrix& getVT() const + {return VT;} + void solve(const GeneralMatrix& B, GeneralMatrix& X) const; + void solve(const Vector& b, Vector& x) const + { + GeneralMatrix xmat(x.base(), x.length(), 1); + solve(GeneralMatrix(b.base(), b.length(), 1), xmat); + } +private: + void construct(const GeneralMatrix& A); +}; From a97973d01f715efac8fbfe06b877ffc1e105eca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Sedna=29?= Date: Wed, 25 Mar 2015 14:52:28 +0100 Subject: [PATCH 36/50] Added method for recognizing unreferenced atoms. Call to this method replace catching the exception used before to recognize that an atom is not referenced. --- dynare++/parser/cc/dynamic_atoms.cpp | 6 ++++++ dynare++/parser/cc/dynamic_atoms.h | 3 +++ dynare++/parser/cc/static_atoms.cpp | 7 +++---- dynare++/src/dynare_atoms.cpp | 14 +++----------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dynare++/parser/cc/dynamic_atoms.cpp b/dynare++/parser/cc/dynamic_atoms.cpp index f02b580af..ca6b6dcd2 100644 --- a/dynare++/parser/cc/dynamic_atoms.cpp +++ b/dynare++/parser/cc/dynamic_atoms.cpp @@ -341,6 +341,12 @@ int DynamicAtoms::index(const char* name, int ll) const return -1; } +bool DynamicAtoms::is_referenced(const char* name) const +{ + Tvarmap::const_iterator it = vars.find(name); + return it != vars.end(); +} + const DynamicAtoms::Tlagmap& DynamicAtoms::lagmap(const char* name) const { Tvarmap::const_iterator it = vars.find(name); diff --git a/dynare++/parser/cc/dynamic_atoms.h b/dynare++/parser/cc/dynamic_atoms.h index 03cb0411f..7d44d6dcc 100644 --- a/dynare++/parser/cc/dynamic_atoms.h +++ b/dynare++/parser/cc/dynamic_atoms.h @@ -182,6 +182,9 @@ namespace ogp { /** Return index of the variable described by the variable * name and lag/lead. If it doesn't exist, return -1. */ int index(const char* name, int ll) const; + /** Return true if a variable is referenced, i.e. it has lag + * map. */ + bool is_referenced(const char* name) const; /** Return the lag map for the variable name. */ const Tlagmap& lagmap(const char* name) const; /** Return the variable name for the tree index. It throws an diff --git a/dynare++/parser/cc/static_atoms.cpp b/dynare++/parser/cc/static_atoms.cpp index 0151cade6..7276cc0c9 100644 --- a/dynare++/parser/cc/static_atoms.cpp +++ b/dynare++/parser/cc/static_atoms.cpp @@ -41,15 +41,14 @@ void StaticAtoms::import_atoms(const DynamicAtoms& da, OperationTree& otree, Tin register_name(name); int tnew = otree.add_nulary(); assign(name, tnew); - try { - const DynamicAtoms::Tlagmap& lmap = da.lagmap(name); + if (da.is_referenced(name)) { + const DynamicAtoms::Tlagmap& lmap = da.lagmap(name); for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { int told = (*it).second; tmap.insert(Tintintmap::value_type(told, tnew)); } - } catch (const ogu::Exception& e) { - } + } } } diff --git a/dynare++/src/dynare_atoms.cpp b/dynare++/src/dynare_atoms.cpp index e0121d530..c1ae58bc4 100644 --- a/dynare++/src/dynare_atoms.cpp +++ b/dynare++/src/dynare_atoms.cpp @@ -135,22 +135,19 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const // set parameteres for (unsigned int i = 0; i < atoms.get_params().size(); i++) { - try { + if (atoms.is_referenced(atoms.get_params()[i])) { const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_params()[i]); for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { int t = (*it).second; et.set_nulary(t, paramvals[i]); } - } catch (const ogu::Exception& e) { - // ignore non-referenced parameters; there is no - // lagmap for them } } // set endogenous for (unsigned int outer_i = 0; outer_i < atoms.get_endovars().size(); outer_i++) { - try { + if (atoms.is_referenced(atoms.get_endovars()[outer_i])) { const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_endovars()[outer_i]); for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { @@ -165,15 +162,12 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const else et.set_nulary(t, yyp[i-atoms.nstat()-atoms.npred()]); } - } catch (const ogu::Exception& e) { - // ignore non-referenced endogenous variables; there is no - // lagmap for them } } // set exogenous for (unsigned int outer_i = 0; outer_i < atoms.get_exovars().size(); outer_i++) { - try { + if (atoms.is_referenced(atoms.get_exovars()[outer_i])) { const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_exovars()[outer_i]); for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin(); it != lmap.end(); ++it) { @@ -184,8 +178,6 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const et.set_nulary(t, xx[i]); } } - } catch (const ogu::Exception& e) { - // ignore non-referenced variables } } } From 82bd6bcdf367d9fdc90689c57fa7ecbdd74e49dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Sedna=29?= Date: Wed, 25 Mar 2015 14:54:32 +0100 Subject: [PATCH 37/50] Fixed c++ warnings. --- dynare++/parser/cc/tree.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dynare++/parser/cc/tree.cpp b/dynare++/parser/cc/tree.cpp index 08c90fae6..8ff4267c6 100644 --- a/dynare++/parser/cc/tree.cpp +++ b/dynare++/parser/cc/tree.cpp @@ -1,5 +1,6 @@ // Copyright (C) 2005-2011, Ondra Kamenik + #include "utils/cc/exception.h" #include "tree.h" @@ -55,7 +56,7 @@ int OperationTree::add_unary(code_t code, int op) code == SQRT || code == ERF)) return zero; - if (op == zero && code == LOG || op == nan) + if ((op == zero && code == LOG) || op == nan) return nan; if (op == zero && (code == EXP || code == COS || @@ -86,39 +87,43 @@ int OperationTree::add_binary(code_t code, int op1, int op2) if (op1 == nan || op2 == nan) return nan; // for plus - if (code == PLUS) + if (code == PLUS) { if (op1 == zero && op2 == zero) return zero; else if (op1 == zero) return op2; else if (op2 == zero) return op1; + } // for minus - if (code == MINUS) + if (code == MINUS) { if (op1 == zero && op2 == zero) return zero; else if (op1 == zero) return add_unary(UMINUS, op2); else if (op2 == zero) return op1; + } // for times - if (code == TIMES) + if (code == TIMES) { if (op1 == zero || op2 == zero) return zero; else if (op1 == one) return op2; else if (op2 == one) return op1; + } // for divide - if (code == DIVIDE) + if (code == DIVIDE) { if (op1 == op2) return one; else if (op1 == zero) return zero; else if (op2 == zero) return nan; + } // for power - if (code == POWER) + if (code == POWER) { if (op1 == zero && op2 == zero) return nan; else if (op1 == zero) @@ -129,6 +134,7 @@ int OperationTree::add_binary(code_t code, int op1, int op2) return one; else if (op2 == one) return op1; + } // order operands of commutative operations if (code == TIMES || code == PLUS) From d7c253ae59fb193600e9976c44a6f4dbb3feb998 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 26 Mar 2015 19:08:30 +0100 Subject: [PATCH 38/50] support 64-bit preprocessor, #862 --- .gitignore | 2 ++ matlab/dynare.m | 18 ++++++++++++++++-- preprocessor/Makefile.am | 7 ++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6feb45057..367fb3503 100644 --- a/.gitignore +++ b/.gitignore @@ -97,6 +97,8 @@ mex/build/matlab/run_m2html.m # Preprocessor /preprocessor/dynare_m /preprocessor/dynare_m.exe +/preprocessor/dynare_m64 +/preprocessor/dynare_m64.exe /preprocessor/DynareBison.cc /preprocessor/DynareBison.hh /preprocessor/FlexLexer.h diff --git a/matlab/dynare.m b/matlab/dynare.m index d72d20787..299b073e9 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -16,7 +16,7 @@ function dynare(fname, varargin) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2001-2014 Dynare Team +% Copyright (C) 2001-2015 Dynare Team % % This file is part of Dynare. % @@ -145,7 +145,21 @@ if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') run([fname(1:end-4) filesep 'hooks/priorprocessing']) end -command = ['"' dynareroot 'dynare_m" ' fname] ; +if ispc + [junk, arch] = getenv('PROCESSOR_ARCHITECTURE'); +else + [junk, arch] = system('uname -m'); +end + +if isempty(strfind(arch, '64')) + arch_ext64 = ''; + disp('Using 32-bit preprocessor'); +else + arch_ext64 = '64'; + disp('Using 64-bit preprocessor'); +end + +command = ['"' dynareroot 'dynare_m' arch_ext64 '" ' fname] ; for i=2:nargin command = [command ' ' varargin{i-1}]; end diff --git a/preprocessor/Makefile.am b/preprocessor/Makefile.am index aea2e45a7..bce3bbe68 100644 --- a/preprocessor/Makefile.am +++ b/preprocessor/Makefile.am @@ -69,7 +69,12 @@ DynareBison.cc DynareBison.hh location.hh stack.hh position.hh: DynareBison.yy $(YACC) -o DynareBison.cc DynareBison.yy all-local: - cd ../matlab && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS) + if [ -z "`file $(PROGRAMS) | grep x86.64`" ]; then \ + ARCH=""; \ + else \ + ARCH="64"; \ + fi; \ + cd ../matlab && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS)$$ARCH if HAVE_DOXYGEN html-local: From 510c6641c918864c1f91dc5c164ee12c308b091c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 27 Mar 2015 10:54:42 +0100 Subject: [PATCH 39/50] Fixed compilation failure on Windows. --- dynare++/kord/journal.cweb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynare++/kord/journal.cweb b/dynare++/kord/journal.cweb index 9b7d658cd..b43b27bcc 100644 --- a/dynare++/kord/journal.cweb +++ b/dynare++/kord/journal.cweb @@ -101,7 +101,7 @@ void SystemResources::getRUS(double& load_avg, long int& pg_avail, majflt = -1; #endif -#if !defined(__MINGW32__) && !defined(__CYGWIN32__) +#if !defined(__MINGW32__) && !defined(__CYGWIN32__) && !defined(__CYGWIN__) && !defined(__MINGW64__) && !defined(__CYGWIN64__) getloadavg(&load_avg, 1); #else load_avg = -1.0; From 90e00b38712ebc226ce7a6774c998f01ce7ef779 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 27 Mar 2015 17:10:00 +0100 Subject: [PATCH 40/50] fixes for windows --- .gitignore | 5 +---- matlab/dynare.m | 6 +++--- preprocessor/Makefile.am | 5 +++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 367fb3503..ff09453b7 100644 --- a/.gitignore +++ b/.gitignore @@ -97,8 +97,6 @@ mex/build/matlab/run_m2html.m # Preprocessor /preprocessor/dynare_m /preprocessor/dynare_m.exe -/preprocessor/dynare_m64 -/preprocessor/dynare_m64.exe /preprocessor/DynareBison.cc /preprocessor/DynareBison.hh /preprocessor/FlexLexer.h @@ -115,8 +113,7 @@ mex/build/matlab/run_m2html.m /preprocessor/doc/ # MATLAB dir -/matlab/dynare_m -/matlab/dynare_m.exe +/matlab/preprocessor* /matlab/dynare_version.m # DLL rules diff --git a/matlab/dynare.m b/matlab/dynare.m index 299b073e9..9cdf8bf37 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -152,14 +152,14 @@ else end if isempty(strfind(arch, '64')) - arch_ext64 = ''; + arch_ext = '32'; disp('Using 32-bit preprocessor'); else - arch_ext64 = '64'; + arch_ext = '64'; disp('Using 64-bit preprocessor'); end -command = ['"' dynareroot 'dynare_m' arch_ext64 '" ' fname] ; +command = ['"' dynareroot 'preprocessor' arch_ext filesep 'dynare_m" ' fname] ; for i=2:nargin command = [command ' ' varargin{i-1}]; end diff --git a/preprocessor/Makefile.am b/preprocessor/Makefile.am index bce3bbe68..804282738 100644 --- a/preprocessor/Makefile.am +++ b/preprocessor/Makefile.am @@ -70,11 +70,12 @@ DynareBison.cc DynareBison.hh location.hh stack.hh position.hh: DynareBison.yy all-local: if [ -z "`file $(PROGRAMS) | grep x86.64`" ]; then \ - ARCH=""; \ + ARCH="32"; \ else \ ARCH="64"; \ fi; \ - cd ../matlab && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS)$$ARCH + mkdir -p ../matlab/preprocessor$$ARCH ; \ + cd ../matlab/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS) if HAVE_DOXYGEN html-local: From 575cbfe679580758804600154d887d94af57fd22 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 27 Mar 2015 18:41:31 +0100 Subject: [PATCH 41/50] build system: modify windows.nsi for 32 & 64 bit preprocessor --- windows/dynare.nsi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/windows/dynare.nsi b/windows/dynare.nsi index c6f062a1c..c76bb5175 100644 --- a/windows/dynare.nsi +++ b/windows/dynare.nsi @@ -58,7 +58,12 @@ Section "Dynare core (preprocessor and M-files)" SetOutPath $INSTDIR\matlab File /r ..\matlab\*.m - File ..\matlab\dynare_m.exe + + SetOutPath $INSTDIR\matlab\preprocessor32 + File ..\matlab\preprocessor32\dynare_m.exe + + SetOutPath $INSTDIR\matlab\preprocessor64 + File ..\matlab\preprocessor64\dynare_m.exe SetOutPath $INSTDIR\contrib File /r ..\contrib\*.m From 34c871b53c253366397f196fa943a86b8f7b57e8 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 27 Mar 2015 18:58:35 +0100 Subject: [PATCH 42/50] getenv provides one output on windows --- matlab/dynare.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 9cdf8bf37..778ba5b75 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -146,7 +146,7 @@ if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') end if ispc - [junk, arch] = getenv('PROCESSOR_ARCHITECTURE'); + arch = getenv('PROCESSOR_ARCHITECTURE'); else [junk, arch] = system('uname -m'); end From e10ea545b89519b32d56b461a41cbdc6c6b1b77d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 30 Mar 2015 11:06:58 +0200 Subject: [PATCH 43/50] build system: fix preprocessor clean, #862 --- preprocessor/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor/Makefile.am b/preprocessor/Makefile.am index 804282738..12157780e 100644 --- a/preprocessor/Makefile.am +++ b/preprocessor/Makefile.am @@ -83,7 +83,7 @@ html-local: endif clean-local: - cd ../matlab && rm -f $(PROGRAMS) + rm -rf ../matlab/preprocessor* rm -rf doc/html/ EXTRA_DIST = $(BUILT_SOURCES) Doxyfile From 600715127c3235dd35c9ec5be322c0e41ea34928 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 30 Mar 2015 11:14:44 +0200 Subject: [PATCH 44/50] build system: changes for #862 broke preprocessor parallel build --- preprocessor/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preprocessor/Makefile.am b/preprocessor/Makefile.am index 12157780e..4ea6bf6f0 100644 --- a/preprocessor/Makefile.am +++ b/preprocessor/Makefile.am @@ -68,7 +68,7 @@ DynareFlex.cc FlexLexer.h: DynareFlex.ll DynareBison.cc DynareBison.hh location.hh stack.hh position.hh: DynareBison.yy $(YACC) -o DynareBison.cc DynareBison.yy -all-local: +all-local: $(PROGRAMS) if [ -z "`file $(PROGRAMS) | grep x86.64`" ]; then \ ARCH="32"; \ else \ From 923f75df861a9fe6baaea5f37b0df5d4ebf881b9 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 30 Mar 2015 13:04:39 +0200 Subject: [PATCH 45/50] build system: fix make install following changes to #862 --- Makefile.am | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index d14a0f351..7b23cec88 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,17 +35,25 @@ EXTRA_DIST = \ dist-hook: rm -rf `find $(distdir)/matlab $(distdir)/examples -name *~` - rm -f $(distdir)/matlab/dynare_m$(EXEEXT) $(distdir)/matlab/dynare_version.m + rm -rf $(distdir)/matlab/preprocessor* $(distdir)/matlab/dynare_version.m $(MKDIR_P) $(distdir)/mex/matlab $(distdir)/mex/octave rm -rf `find $(distdir)/contrib -name '.git*'` install-exec-local: $(MKDIR_P) $(DESTDIR)$(pkglibdir)/contrib/ms-sbvar/TZcode + cp -r contrib/ms-sbvar/TZcode/MatlabFiles $(DESTDIR)$(pkglibdir)/contrib/ms-sbvar/TZcode cp -r examples $(DESTDIR)$(pkglibdir) cp -r matlab $(DESTDIR)$(pkglibdir) - rm -f $(DESTDIR)$(pkglibdir)/matlab/dynare_m - cp preprocessor/dynare_m $(DESTDIR)$(pkglibdir)/matlab - cp -r contrib/ms-sbvar/TZcode/MatlabFiles $(DESTDIR)$(pkglibdir)/contrib/ms-sbvar/TZcode + rm -rf $(DESTDIR)$(pkglibdir)/matlab/preprocessor* + { \ + if [ -z "`file preprocessor/dynare_m | grep x86.64`" ]; then \ + ARCH="32"; \ + else \ + ARCH="64"; \ + fi; \ + mkdir -p $(DESTDIR)$(pkglibdir)/matlab/preprocessor$$ARCH; \ + cp preprocessor/dynare_m $(DESTDIR)$(pkglibdir)/matlab/preprocessor$$ARCH; \ + } uninstall-local: rm -f $(DESTDIR)$(bindir)/dynare++ From 0e1dd779b953971bcdc4b7318bb0ff1d48eff528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 30 Mar 2015 14:54:14 +0200 Subject: [PATCH 46/50] Check that Dynare's routines are not overridden by other routines. By default Dynare will temporarly change Matlab/Octave's path. Added an option to force Dynare to keep the current path. Also check that the user did not put dynare/matlab directory with all the subfolders in the path. With this patch, we do not need to prefix Dynare routines with dyn_ or dynare_ anymore. --- doc/dynare.texi | 9 ++ matlab/add_path_to_mex_files.m | 89 +++++++++++++++++++ matlab/check_matlab_path.m | 150 +++++++++++++++++++++++++++++++++ matlab/dynare.m | 25 ++++-- matlab/dynare_config.m | 46 +--------- 5 files changed, 270 insertions(+), 49 deletions(-) create mode 100644 matlab/add_path_to_mex_files.m create mode 100644 matlab/check_matlab_path.m diff --git a/doc/dynare.texi b/doc/dynare.texi index 291df087d..95f017b28 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -793,6 +793,15 @@ graph @item nointeractive Instructs Dynare to not request user input +@item nopathchange +By default Dynare will change Matlab/Octave's path if +@file{dynare/matlab} directory is not on top and if Dynare's routines +are overriden by routines provided in other toolboxes. If one wishes to +override Dynare's routines, the @code{nopathchange} options can be +used. Alternatively, the path can be temporarly modified by the user at +the top of the @file{*.mod} file (using Matlab/Octave's @code{addpath} +command). + @item cygwin Tells Dynare that your MATLAB is configured for compiling MEX files with Cygwin (@pxref{Software requirements}). This option is only available diff --git a/matlab/add_path_to_mex_files.m b/matlab/add_path_to_mex_files.m new file mode 100644 index 000000000..279babb8f --- /dev/null +++ b/matlab/add_path_to_mex_files.m @@ -0,0 +1,89 @@ +function mexpath = add_path_to_mex_files(dynareroot, modifypath) + +% Copyright (C) 2015 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 . + +if nargin<2 + modifypath = true; +end + +if isoctave + mexpath = {[dynareroot '../mex/octave/']}; + if modifypath + addpath(mexpath{1}); + end +else + % Add win32 specific paths for Dynare Windows package + if strcmp(computer, 'PCWIN') + tmp = [dynareroot '../mex/matlab/win32-7.5-8.4/']; + if exist(tmp, 'dir') + mexpath = tmp; + if modifypath + addpath(mexpath); + end + end + end + % Add win64 specific paths for Dynare Windows package + if strcmp(computer, 'PCWIN64') + if matlab_ver_less_than('7.8') + tmp = [dynareroot '../mex/matlab/win64-7.5-7.7/']; + if exist(tmp, 'dir') + mexpath = tmp; + if modifypath + addpath(mexpath); + end + end + else + tmp = [dynareroot '../mex/matlab/win64-7.8-8.4/']; + if exist(tmp, 'dir') + mexpath = tmp; + if modifypath + addpath(mexpath); + end + end + end + end + % Add OS X 32bits specific paths for Dynare Mac package + if strcmp(computer, 'MACI') + tmp = [dynareroot '../mex/matlab/osx32-7.5-7.11/']; + if exist(tmp, 'dir') + mexpath = tmp; + if modifypath && exist(mexpath, 'dir') + addpath(mexpath); + end + end + end + % Add OS X 64bits specific paths for Dynare Mac package + if strcmp(computer, 'MACI64') + tmp = [dynareroot '../mex/matlab/osx64/']; + if exist(tmp, 'dir') + mexpath = tmp; + if modifypath && exist(mexpath, 'dir') + addpath(mexpath); + end + end + end + % Add generic MATLAB path (with higher priority than the previous ones) + if exist('mexpath') + mexpath = { mexpath, [dynareroot '../mex/matlab/'] }; + else + mexpath = { [dynareroot '../mex/matlab/'] }; + end + if modifypath + addpath([dynareroot '../mex/matlab/']); + end +end \ No newline at end of file diff --git a/matlab/check_matlab_path.m b/matlab/check_matlab_path.m new file mode 100644 index 000000000..ccd9d6308 --- /dev/null +++ b/matlab/check_matlab_path.m @@ -0,0 +1,150 @@ +function check_matlab_path(change_path_flag) + +% Copyright (C) 2015 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 . + +if ~nargin || isempty(change_path_flag) + change_path_flag = true; +end + +% Get path to dynare/matlab folder. +DYNARE_PATH = strrep(which('dynare'),'dynare.m',''); + +if isempty(DYNARE_PATH) + % Nothing to do here (this case should not happen) + disp('dynare.m is not in the Matlab''s path.') + return +else + % Removes trailing slash. + DYNARE_PATH = DYNARE_PATH(1:end-1); +end + +% Get matlab path +MATLAB_PATH = path(); + +% Position of DYNARE_PATH in MATLAB_PATH +idDYNARE = strfind(MATLAB_PATH,DYNARE_PATH); + +if isempty(idDYNARE) + disp('dynare.m is not in the Matlab''s path.') + return +else + if isequal(length(idDYNARE),1) + if isequal(idDYNARE, 1) + % Dynare is on top of matlab's path! Nothing to do here... + return + else + str0 = sprintf('Dynare is not on top of matlab''s path!'); + % Check that this will not create a problem + MATLAB_PATH_ = path2cell(MATLAB_PATH); + DYNARE_ROUTINES = getallroutinenames(DYNARE_PATH, getalldirectories(DYNARE_PATH)); + MATLAB_ROUTINES = {}; + for i=1:position(idDYNARE, MATLAB_PATH) + TMP_MATLAB_ROUTINES = getallroutinenames(MATLAB_PATH_{i}); + MATLAB_ROUTINES = { MATLAB_ROUTINES{:} TMP_MATLAB_ROUTINES{:} }; + end + COMMON_ROUTINES = intersect(MATLAB_ROUTINES, DYNARE_ROUTINES); + if ~isempty(COMMON_ROUTINES) + warning off backtrace + skipline() + if length(COMMON_ROUTINES)==1 + warning(sprintf('%s This can cause problems because the Dynare version of %s will be overriden.', str0, COMMON_ROUTINES{1})); + else + str1 = repmat('%s, ', 1, length(COMMON_ROUTINES)-1); + str2 = 'and %s '; + str3 = sprintf(['%s This can cause problems because the Dynare versions of ' str1, str2, 'will be overriden.'], str0, COMMON_ROUTINES{:}); + warning(str3); + end + if change_path_flag + skipline() + msg = sprintf('I put %s on top of your matlab''s path. Note that this is a', DYNARE_PATH); + msg = sprintf(' %s a temporary change (ie will not affect future matlab''s session).', msg); + msg = sprintf(' %s If the ordering was intentional, ie if you really want to override the routines distributed with Dynare,', msg); + msg = sprintf(' %s you can change this behaviour using option nopathchange (see the reference manual).', msg); + warning(msg); + skipline() + rmpath(DYNARE_PATH) + addpath(DYNARE_PATH) + end + warning on backtrace + end + end + else + % Check that the user did not put all the subfolders in the path. + % => If DYNARE_PATH/qz is in the path while mjdgges dll is available + % it most likely means that user wrongly put all subfolders in the + % matlab's path! + mexpath = add_path_to_mex_files([DYNARE_PATH filesep], false); + MATLAB_PATH = path2cell(MATLAB_PATH); + for i=1:length(mexpath) + if exist([mexpath{i} filesep 'mjdgges.' mexext],'file') && ismember([DYNARE_PATH filesep 'qz'],MATLAB_PATH) + msg = sprintf(['You put all the dynare/matlab subfolders in matlab''s path! Only ' ... + 'the dynare/matlab folder (without subfolders)\nshould be in the ' ... + 'path, Dynare will automatically add any required subfolders in the ' ... + 'path.']); + error(msg) + end + end + end +end + +function q = path2cell(p) + % Converts the output of path() to a cell + s = strfind(p,pathsep); + n = length(s)+1; + q = cell(n,1); + q(1) = {p(1:s(1)-1)}; + q(n) = {p(s(end)+1:end)}; + for i=2:n-1 + q(i) = {p(s(i-1)+1:s(i)-1)}; + end + +function flist = getallroutinenames(p, excludedsubfolders) + if nargin<2 + excludedsubfolders = {}; + end + dd = dir(p); + flist = {}; + for f=1:length(dd) + if ~(isequal(dd(f).name,'.') || isequal(dd(f).name,'..')) + if dd(f).isdir + if ~ismember(dd(f).name, excludedsubfolders) + r = getallroutinenames([ p filesep dd(f).name]); + flist = { flist{:} r{:} }; + end + else + % Filter out files without m extension. + if isequal(dd(f).name(end-1:end),'.m') + flist{length(flist)+1} = [dd(f).name]; + end + end + end + end + +function dlist = getalldirectories(p) + dd = dir(p); + dlist = {}; + for f = 1:length(dd) + if ~(isequal(dd(f).name,'.') || isequal(dd(f).name,'..')) + if dd(f).isdir + dlist{length(dlist)+1} = [dd(f).name]; + end + end + end + +function n = position(i, currentpath) + n = length(strfind(currentpath(1:i), pathsep)); \ No newline at end of file diff --git a/matlab/dynare.m b/matlab/dynare.m index 778ba5b75..026670af9 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -44,7 +44,22 @@ if strcmpi(fname,'help') return end -% detect if MEX files are present; if not, use alternative M-files +% Set default local options +change_path_flag = true; + +% Filter out some options. +if nargin>1 + id = strfind(varargin,'nopathchange'); + if ~isempty(id) + change_path_flag = false; + varargin(id{1}) = []; + end +end + +% Check matlab path +check_matlab_path(change_path_flag); + +% Detect if MEX files are present; if not, use alternative M-files dynareroot = dynare_config; warning_config() @@ -160,8 +175,8 @@ else end command = ['"' dynareroot 'preprocessor' arch_ext filesep 'dynare_m" ' fname] ; -for i=2:nargin - command = [command ' ' varargin{i-1}]; +for i=1:length(varargin) + command = [command ' ' varargin{i}]; end [status, result] = system(command); @@ -178,8 +193,8 @@ end % Save preprocessor result in logfile (if `no_log' option not present) no_log = 0; -for i=2:nargin - no_log = no_log || strcmp(varargin{i-1}, 'nolog'); +for i=1:length(varargin) + no_log = no_log || strcmp(varargin{i}, 'nolog'); end if ~no_log logname = [fname(1:end-4) '.log']; diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 352ab95c8..62bb0a5d0 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -35,6 +35,7 @@ function dynareroot = dynare_config(path_to_dynare,verbose) if nargin && ~isempty(path_to_dynare) addpath(path_to_dynare); end + dynareroot = strrep(which('dynare'),'dynare.m',''); origin = pwd(); @@ -44,7 +45,6 @@ if ~nargin || nargin==1 verbose = 1; end - addpath([dynareroot '/distributions/']) addpath([dynareroot '/kalman/']) addpath([dynareroot '/kalman/likelihood']) @@ -114,49 +114,7 @@ if (isoctave && ~user_has_octave_forge_package('statistics')) ... end % Add path to MEX files -if isoctave - addpath([dynareroot '../mex/octave/']); -else - % Add win32 specific paths for Dynare Windows package - if strcmp(computer, 'PCWIN') - mexpath = [dynareroot '../mex/matlab/win32-7.5-8.5']; - if exist(mexpath, 'dir') - addpath(mexpath) - end - end - - % Add win64 specific paths for Dynare Windows package - if strcmp(computer, 'PCWIN64') - if matlab_ver_less_than('7.8') - mexpath = [dynareroot '../mex/matlab/win64-7.5-7.7']; - if exist(mexpath, 'dir') - addpath(mexpath) - end - else - mexpath = [dynareroot '../mex/matlab/win64-7.8-8.5']; - if exist(mexpath, 'dir') - addpath(mexpath) - end - end - end - - if strcmp(computer, 'MACI') - mexpath = [dynareroot '../mex/matlab/osx32-7.5-7.11']; - if exist(mexpath, 'dir') - addpath(mexpath) - end - end - - if strcmp(computer, 'MACI64') - mexpath = [dynareroot '../mex/matlab/osx64']; - if exist(mexpath, 'dir') - addpath(mexpath) - end - end - - % Add generic MATLAB path (with higher priority than the previous ones) - addpath([dynareroot '../mex/matlab/']); -end +add_path_to_mex_files(dynareroot); %% Set mex routine names mex_status = cell(1,3); From 7544d8c97e234c5ce03c23b60e9bf4d3d3aabaa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Tue, 31 Mar 2015 00:43:59 +0200 Subject: [PATCH 47/50] Fixed typos in reference manual. --- doc/dynare.texi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 757132283..0e60bdf3e 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -4995,8 +4995,8 @@ Maximum number of iterations. Default: @code{1000} @item 'Hessian' Triggers three types of Hessian computations. @code{0}: outer product gradient; @code{1} default DYNARE Hessian routine; @code{2} 'mixed' outer product gradient, where diagonal elements are obtained using second order derivation formula and outer product is used for correlation structure. -Both @{0} and @{2} options require univariate filters, to ensure using maximum number of individual densities and a positive definite Hessian. -Both @{0} and @{2} are quicker than default DYNARE numeric Hessian, but provide decent starting values for Metropolis for large models (option @{2} being more accurate than @{0}). +Both @{0@} and @{2@} options require univariate filters, to ensure using maximum number of individual densities and a positive definite Hessian. +Both @{0@} and @{2@} are quicker than default DYNARE numeric Hessian, but provide decent starting values for Metropolis for large models (option @{2@} being more accurate than @{0@}). Default: @code{1}. @item 'TolFun' @@ -5585,7 +5585,7 @@ and end of the sample for which no forecasts can be made, e.g. entries (1,5,1) a the variables will be ordered in the order of declaration after the estimation command (or in general declaration order if no variables are specified here). In case of running the classical smoother, the variables will always be ordered in general -declaration order. If the @xref{selected_variables_only} option is specified with the classical smoother, +declaration order. If the @ref{selected_variables_only} option is specified with the classical smoother, non-requested variables will be simply left out in this order. @end defvr From 4f1725455a30984e3c41e79ff0e03123c9c47f5f Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Tue, 31 Mar 2015 15:47:04 +0200 Subject: [PATCH 48/50] fixing bug in treatment of temporary terms for blocks with *.m files --- preprocessor/DynamicModel.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 645fa6469..1de6bc8ca 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -187,6 +187,10 @@ DynamicModel::computeTemporaryTermsOrdered() it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); for (derivative_t::const_iterator it = derivative_other_endo[block].begin(); it != derivative_other_endo[block].end(); it++) it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); + for (derivative_t::const_iterator it = derivative_exo[block].begin(); it != derivative_exo[block].end(); it++) + it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); + for (derivative_t::const_iterator it = derivative_exo_det[block].begin(); it != derivative_exo_det[block].end(); it++) + it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block); v_temporary_terms_inuse[block] = temporary_terms_in_use; } computeTemporaryTermsMapping(); From b4a8ad8aa4b992c49638c90207871a9feaa18c3c Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 1 Apr 2015 14:43:52 +0200 Subject: [PATCH 49/50] Fix mex path for win64 bit --- matlab/add_path_to_mex_files.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/add_path_to_mex_files.m b/matlab/add_path_to_mex_files.m index 279babb8f..ea9065a51 100644 --- a/matlab/add_path_to_mex_files.m +++ b/matlab/add_path_to_mex_files.m @@ -48,7 +48,7 @@ else end end else - tmp = [dynareroot '../mex/matlab/win64-7.8-8.4/']; + tmp = [dynareroot '../mex/matlab/win64-7.8-8.5/']; if exist(tmp, 'dir') mexpath = tmp; if modifypath From 86d6e2145036ee37d1a6a580bbd9446a181bc5a6 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 15:17:08 +0200 Subject: [PATCH 50/50] preprocessor: remove unnecessary options_list argument to rplot --- preprocessor/ComputingTasks.cc | 7 ++----- preprocessor/ComputingTasks.hh | 4 +--- preprocessor/ParsingDriver.cc | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index e16d11354..31545e5e3 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -518,17 +518,14 @@ DynareSensitivityStatement::writeOutput(ostream &output, const string &basename) output << "dynare_sensitivity(options_gsa);" << endl; } -RplotStatement::RplotStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg) : - symbol_list(symbol_list_arg), - options_list(options_list_arg) +RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) : + symbol_list(symbol_list_arg) { } void RplotStatement::writeOutput(ostream &output, const string &basename) const { - options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); output << "rplot(var_list_);" << endl; } diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index d19f3e4c2..037ce9b69 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -150,10 +150,8 @@ class RplotStatement : public Statement { private: const SymbolList symbol_list; - const OptionsList options_list; public: - RplotStatement(const SymbolList &symbol_list_arg, - const OptionsList &options_list_arg); + RplotStatement(const SymbolList &symbol_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; }; diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index cd9b0101c..67c4be456 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1186,8 +1186,7 @@ ParsingDriver::add_in_symbol_list(string *tmp_var) void ParsingDriver::rplot() { - mod_file->addStatement(new RplotStatement(symbol_list, options_list)); - options_list.clear(); + mod_file->addStatement(new RplotStatement(symbol_list)); symbol_list.clear(); }