From 6d7c8ef9637e77c74203bc4e5baea174b654399f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 27 Nov 2014 09:08:57 +0100 Subject: [PATCH 001/210] 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 002/210] 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 003/210] 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 004/210] 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 005/210] 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+SjO(F#ed-}=bjw;}btGb@gj#xj>&Py5 z#&)!&MsV~C4_V`YL{->J&<0{`V%CEA^m$~E8Epp1zwt7W z<7S|FB0kU@E3e0h#_#kioF+;C$V}Lo=46vFE6v$i3{*(A=<7EyR(xmk9)7=H;XIju z1GAgR)Dkv!p&4l=o5;Dc$0MZ&YJRkwr_1BH(%`vYVXYZq$}>4V zR|dgFFbwQc-$yOHuMUIndG0Qgp`31W7w(QsZteAg?kgmfXbicQ@a#3>5;IDA(bCas zTwBk3ZmVT)fLc-aUzlz(V~qK)RNVRNKJAY~FY@&N^xn$rKc#=bMkFfJk7%erUub=& z@a|y$r}ZZ@=#OR4pUR-`$)G=-L4P8HerE=KTLwK-dotO7-m!z#v=g7{ez+@x?zV^P zyX|59fedz@&7i-KL4PxYetic0l?-}Y+w-Dhr^M@@ou#Gw`tR#+3U@hr%%|Vh;kFK* zUL;A@>CbOlObz- zPv@WJ($XFsdPw_sx9aVzb`B#u?tD4i(?ji)HN0!*S7wpCOz&4|P?z0w_qU7cad|0b zLwd-5SFOKHUiS9t7s*k_*8fFv%(Cg-JUb!#-93G0O^rM5d*hp9-OOeTeEKon^ca8X zn_FUI%$9(T3Q^NZ@_d23ieR(#0CAXP{wM>e(k8%NKDWUG8qy{Yg>3~8Qf=~poY5wr zq^$r3rA;0%P1^)u{{QHYmtE9}1m`lBhw* z;j945t}U^!5u}bBj35j%8$q7Q!3aV#vk@ep9E>1bGaEtX$-xLhII|I?sT_FIG*+-{eZbq_?j;sWH9V;95-N`;WaiKKqVIy#S_4*|H=nTlsNcPbgn2Ql( zvX9Q7+>B%&ox!;o$v!$max;>BbcW_;B>U(L%gsn|bZ!Y9cZQ3R66d&s^-@JeMT+7C zZ+!F3Hz_YYmdLTltBfl!IGvCAH1~SLxpJ9H>s30nD&^vsYGT%TY>9;%H9~Z4)E~E) z+#9uZ>(*4bQP9GTf);KRwAMCBFNIgEBjv5EhxG7Xj0)^UMa2gDUZh&?psxM-_TrS# zc#oDw6=q&%U~I7t_RmI)t*3ci%iS|3-93m6rz?XC`tV|9tW;y65#wYrPPF|2)u}`T~OWKGxX`XxTIf_qc z;rN6Wj!$S})_HJOl!@M^t|%8k2cX#$+Xo=^LAC*y81Rbj@aK;RuTdwZy`pj$i28%g zOE_#~axO+v75*q@BS+<8B)n`0X9avxrM*tO!(NY0dqs#)Zu1gpsxgv|9Ukjr0$wQq z8927Bz|=J0M6v|4e_ZAKJUl0+37~UAHUfbV_2$Hb4?dXQFKa=m$HZsUZc5ZQOlXQNG)*{^wmu?-{ZfaSGC6~an;}xh zNSR@3%_jMfq~0{h2TF*`i0Nob3KKO4zWh2>gx5|lo750oo`9!P@>Is224?kyDckC) zC{gpxfxowV>O!8%+0)Rhp4_?a>{D@~=67HJ#_p*rd78+cMrQSdgwVQAC5f7Y|M0JN zPux#`C7)Gkr;{a3%Xd+GsC6Aux4 z{l(M7oMNw~>gAS$c27OYlO^^BW%cBby_TvkU*2o?)Qdb>VsBVhPyX0zsrtKvuiHHx zL7ptJH!7N-TtpP6!$GkG?Vgz3Vu;(czBK_3KtGuTC_@E)I@< zw7X+;y;)~g$thm7EU~am#G$lE&Sh{}0gEfV#!AjfGQ|?Oo)D4B{;gPGt6gAgNAz&{ zXi+|Hn3+f>R;;dHU%#p;wl&nA9;xPIR%L7z7U+Ri;mlTBjQO+^!ZkXG(THTN;DKY)82>LnhXo zHTCwc?IvA2M_4qUyB3!fv}-r~)Sc)gpBl;wA^^6`nBsm)z4W{(b< zjr2|xn7I-YfZb&*LJ=1sJVUrr(Q2sBjB6~Ak&Oq96ctG26U|x~Rg5bh7|rn*%>{|| z4awzoH2We)%4jZ-cEfeji3WcIa6Q6nK(k!5Xl+1yIa!fwo(tACtl88QTN!Ldw7nn; zq!|q|7@MRKMd^8mD-+%{!&LMDQQs8X7V5X2(r?;Bap^f6?vv7gNqJr4`1BwAaVf|N2&D`j_$aAw8EtP*uWQVJrAzLhic(L?-Mn4ddm7v}1{^btHBsKwDND(8{2FSr^dCcgK2} z-M-ej*OFk#nET~!{`-CJf!rCYF`rI}N*B79;c<;oq>WN)rL0KFk|$=O z(lXo!u_D$(3T(KK9<6_)W|#Qc<$Gu5KS#_S(f0T>v1hi6w%w<}0Pf*%zje?#@U4Rm zQGA}@KK@GnJRsN38sy^S=2^yEStYhkF=ppE#x%&x?uOl{n|-%*}d$_-3-T`JE; zdMswXd-UtSonO7E;#@}`>FA@J=gS?X(djMM*ASU2#*B_!Chxpe*iBw{mvV(u`%33| zsMM};9$!`r^SvG}ug{$L)JH4JzN#4Edws8*#lT`j+7yxANAHw7k6%`Je;Z75Y^W5e znBg%MY0i0^BCU{Ki^{x|2l@snLqKZ;d;0QC#<2b!WwR*32W%Vu;$+S670V& zmU>++8saBx5AhV%Fqgubds9cyuX~S1P;+m&2x{&f6hY0sAtI=`_csK!zLvJQcOL}n z^$*qi-kHnJ?St};yA_eSh`@8VqRz}T=F(_;N5u&IdqsgnGG@l%=A_!)7d2l#qS94R zd&fU5_-fgfZ!16`W?}6d=Y7oZAQ6=sK>`u2KCtEv5(Pvc-jygMqL2v81|_f#4*HNw z`l9&v19L?Qe2*ze6cd4&qy)}!gG31tm}g4Fh>)x<@B3SYS*S!iBH9swIjRIkG}tPP zSkMP%uo4}J=s*PKw-OzRK)w(9!0cC|6A?I01PSB@B@m0j{lK@vf&^+SftU;uIQ|3) z5rHFv68(wjA0R$6v(3wr zuL<}JUb4H1wL<}VYGfIhJL<}PW z^G%82L<}bavr&l=M2sK;b5)6vMBscgI3AeEN{k``=cYjd^IVD1M2sc^SwM*~M2sN< zIYNoCM2sb3T!0uy#5f|5U)0BVBE}Pe?4!g4A|?=l+@wSq5oJUmb15NT)0Hj%j4CGr zc}cL`)(AIZ+Au#&W1tlZimaRN^Qijv@m2REa4>Od$f3sg;ng5X+W-JdPy-d0dI9L`)?DSzd{0L`)+B#{ebd+tr~~O(z0J2qh|r zs0a{P2km#(K|g*C1QP3@O7R>%uFbG$GcDRIi#FS$&9P|5S+uzp?Rbke&!U}R(N45z zRTgc&MO$Fe7Fx7L7VRX9cCtlVY|)ljv{NkFsTOUiMLW%+oo><2uxMvmw6iSQ*%s{_ zi*{~E!>XoIG>!a9iu}qzVhC1w*bn+VJb zCFT$@hX~9WC5|KFI3h5kl$cAzTp}>vlsKM<B$qr^!>oJ0h2 zlM*KraWWCeTuLk^VlffOYf3C3VhIt*dPacl{l4%Q;9&vRAMO+ONl@} zRpK-vP9p-@R*BPzIGqUOVkOQX;tV2?sg*dBh%<>m9#`TlBF-WLSzd{=i8z}G90Qa% zhlq2Cz!5@;bBVy`aysTe=Q?Pacn+_FmRq!Hi?+g|t+Z$fi&kUNR#~*w7Hy41JI|uk zTC_TgcD_Zcw`glE+65NvLW`EPXzMImgGF0!(KcALi!9nki*~U^+hox$v1pqu+7^p; zsYTlw(y*#oCYnb6GK&0Vfyf7e=u~1k5zC1{>?%=BL^TnJY$a9@v4RN1y%H;lSV;tC zg%SxO5=3CmC{aU14H1}8N~|Jc6%m+kN~|VgH4&JNN~|Gb4H1~DN}NZ;c|>3)D^W{C zEfJXKO4JciM+CBf66X_fJ`ubhBm$XBiFHJ*BLaC%i3TDXh(Oj;Vm%S-i9k+NVgnHyh(N|v;vyn0A_DnTiH$^T zBm&u1iHnK2mu{A*aoa>-Q@f==Xxl8>c8hj{ zMZ3|W-DJ^jwrIClv?hzT!=ml9Xt!FlT^8*&i*~z3yThXGwrG1STC+vF)1uvF(e4gu zSk*L&rjg%Bk>41Id=Q9EB`zZZ_vh(30|>;f5|gBH|_@kYCit%|zTx1hS73w-9j) z5y(wSG!fB61TvQrJBZjp1oD~^JBipy1hSqIw-RwH5y**3>>^?p5y+TI+(yK0L?E9k zaXS&W6M<~2#2rN3K?HKK61$1mO$0Kv5_^c)Lj>};63s+36M-zR#GORkNd%4oO58=n zT}0prp~T%p+#Mi(&UMf|;yJtyy4RxJXVLDrXb)Jl2QAt|7VTk+_J~D$)S^9R(H^&G zPgt}kE!tBS?P-hlj759aqCIEPp0{W(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: Wed, 3 Dec 2014 13:35:06 +0100 Subject: [PATCH 006/210] Add missing abs to unit root check in model_diagnostics.m --- matlab/model_diagnostics.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m index 62ec92054..21b7d7d71 100644 --- a/matlab/model_diagnostics.m +++ b/matlab/model_diagnostics.m @@ -173,7 +173,7 @@ if singularity_problem options_check=options; options_check.noprint=1; [eigenvalues_] = check(M, options_check, oo); - if any((abs(eigenvalues_)-1)<1e-6) + if any(abs(abs(eigenvalues_)-1)<1e-6) fprintf('MODEL_DIAGNOSTICS: The singularity seems to be (partly) caused by the presence of a unit root\n') fprintf('MODEL_DIAGNOSTICS: as the absolute value of one eigenvalue is in the range of +-1e-6 to 1.\n') fprintf('MODEL_DIAGNOSTICS: If the model is actually supposed to feature unit root behavior, such a warning is expected,\n') From dd6f8c182ce3c9caa560d886ee5517a1d07633b8 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 4 Dec 2014 09:18:33 +0100 Subject: [PATCH 007/210] Move call to optimizers in mode-computing to separate file to allow other function to access all integrated optimizers - also moves several options to subfields of options structure - allows setting options of newrat - requires newrat to have compatible kalman_algo specified in order for it to not change options_ - explicitly disallows using analytical derivation with numerical gradient (before the numerical gradient request was overwritten) - always outputs hessian returned by optimizer (empty matrix if not computed) and deletes subsequent overwriting if cova_compute=0 --- matlab/dynare_estimation_1.m | 437 +++------------------------- matlab/dynare_minimize_objective.m | 443 +++++++++++++++++++++++++++++ matlab/global_initialization.m | 16 +- 3 files changed, 494 insertions(+), 402 deletions(-) create mode 100644 matlab/dynare_minimize_objective.m diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 111a11814..ffa76d89d 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -239,414 +239,57 @@ end % Estimation of the posterior mode or likelihood mode if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation - switch options_.mode_compute - case 1 - if isoctave - error('Option mode_compute=1 is not available under Octave') - elseif ~user_has_matlab_license('optimization_toolbox') - error('Option mode_compute=1 requires the Optimization Toolbox') - end - % Set default optimization options for fmincon. - optim_options = optimset('display','iter', 'LargeScale','off', 'MaxFunEvals',100000, 'TolFun',1e-8, 'TolX',1e-6); - if isfield(options_,'optim_opt') - eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); - end - if options_.analytic_derivation, - optim_options = optimset(optim_options,'GradObj','on','TolX',1e-7); - end - [xparam1,fval,exitflag,output,lamdba,grad,hessian_fmincon] = ... - fmincon(objective_function,xparam1,[],[],[],[],bounds.lb,bounds.ub,[],optim_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); - fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); - case 2 - error('ESTIMATION: mode_compute=2 option (Lester Ingber''s Adaptive Simulated Annealing) is no longer available') - case 3 - if isoctave && ~user_has_octave_forge_package('optim') - error('Option mode_compute=3 requires the optim package') - elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox') - error('Option mode_compute=3 requires the Optimization Toolbox') - end - % Set default optimization options for fminunc. - optim_options = optimset('display','iter','MaxFunEvals',100000,'TolFun',1e-8,'TolX',1e-6); - if isfield(options_,'optim_opt') - eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); - end - if options_.analytic_derivation, - optim_options = optimset(optim_options,'GradObj','on'); - end - if ~isoctave - [xparam1,fval,exitflag] = fminunc(objective_function,xparam1,optim_options,dataset_,dataset_info_,options_,M_,estim_params_,bayestopt_,bounds,oo_); - else - % Under Octave, use a wrapper, since fminunc() does not have a 4th arg - func = @(x) objective_function(x, dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); - [xparam1,fval,exitflag] = fminunc(func,xparam1,optim_options); - end - fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); - case 4 - % Set default options. - H0 = 1e-4*eye(nx); - crit = 1e-7; - nit = 1000; - numgrad = options_.gradient_method; - epsilon = options_.gradient_epsilon; - % Change some options. + %prepare settings for newrat + if options_.mode_compute==5 + %get whether analytical Hessian with non-analytical mode-finding is requested + newratflag=[]; if isfield(options_,'optim_opt') options_list = read_key_value_string(options_.optim_opt); for i=1:rows(options_list) - switch options_list{i,1} - case 'MaxIter' - nit = options_list{i,2}; - case 'InitialInverseHessian' - H0 = eval(options_list{i,2}); - case 'TolFun' - crit = options_list{i,2}; - case 'NumgradAlgorithm' - numgrad = options_list{i,2}; - case 'NumgradEpsilon' - epsilon = options_list{i,2}; - otherwise - warning(['csminwel: Unknown option (' options_list{i,1} ')!']) + if strcmp(options_list{i,1},'Hessian') + newratflag=options_list{i,2}; end end end - % Set flag for analytical gradient. - if options_.analytic_derivation - analytic_grad=1; - else - analytic_grad=[]; - end - % Call csminwell. - [fval,xparam1,grad,hessian_csminwel,itct,fcount,retcodehat] = ... - csminwel1(objective_function, xparam1, H0, analytic_grad, crit, nit, numgrad, epsilon, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_,bounds, oo_); - % Disp value at the mode. - fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); - case 5 - if isfield(options_,'hess') - flag = options_.hess; - else - flag = 1; - end - if isfield(options_,'ftol') - crit = options_.ftol; - else - crit = 1.e-5; - end if options_.analytic_derivation, - analytic_grad=1; - ana_deriv = options_.analytic_derivation; + options_analytic_derivation_old = options_.analytic_derivation; options_.analytic_derivation = -1; - crit = 1.e-7; - flag = 0; - else - analytic_grad=0; - end - if isfield(options_,'nit') - nit = options_.nit; - else - nit=1000; - end - [xparam1,hh,gg,fval,invhess] = newrat(objective_function,xparam1,analytic_grad,crit,nit,0,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_); - if options_.analytic_derivation, - options_.analytic_derivation = ana_deriv; - else - if flag ==0, - options_.cova_compute = 1; - kalman_algo0 = options_.kalman_algo; - if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)), - options_.kalman_algo=2; - if options_.lik_init == 3, - options_.kalman_algo=4; - end - end - hh = reshape(mr_hessian(0,xparam1,objective_function,1,crit,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_), nx, nx); - options_.kalman_algo = kalman_algo0; + if ~isempty(newratflag) && newratflag~=0 %gradient explicitly specified + error('newrat: analytic_derivation is incompatible with numerical Hessian.') + else %use default + newratflag=0; %use analytical gradient end - end - parameter_names = bayestopt_.name; - save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names'); - fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); - case 6 - % Set default options - gmhmaxlikOptions = options_.gmhmaxlik; - if ~isempty(hh); - gmhmaxlikOptions.varinit = 'previous'; - else - gmhmaxlikOptions.varinit = 'prior'; - end - if isfield(options_,'optim_opt') - options_list = read_key_value_string(options_.optim_opt); - for i=1:rows(options_list) - switch options_list{i,1} - case 'NumberOfMh' - gmhmaxlikOptions.iterations = options_list{i,2}; - case 'ncov-mh' - gmhmaxlikOptions.number = options_list{i,2}; - case 'nscale' - gmhmaxlikOptions.nscale = options_list{i,2}; - case 'nclimb' - gmhmaxlikOptions.nclimb = options_list{i,2}; - case 'InitialCovarianceMatrix' - switch options_list{i,2} - case 'previous' - if isempty(hh) - error('gmhmaxlik: No previous estimate of the Hessian matrix available!') - else - gmhmaxlikOptions.varinit = 'previous' - end - case {'prior', 'identity'} - gmhmaxlikOptions.varinit = options_list{i,2}; - otherwise - error('gmhmaxlik: Unknown value for option ''InitialCovarianceMatrix''!') - end - case 'AcceptanceRateTarget' - gmhmaxlikOptions.target = options_list{i,2}; - if gmhmaxlikOptions.target>1 || gmhmaxlikOptions.target1 - flag = ''; - else - flag = 'LastCall'; - end - [xparam1,PostVar,Scale,PostMean] = ... - gmhmaxlik(objective_function,xparam1,[bounds.lb bounds.ub],gmhmaxlikOptions,Scale,flag,MeanPar,CovJump,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); - fval = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); - options_.mh_jscale = Scale; - mouvement = max(max(abs(PostVar-OldPostVar))); - skipline() - disp('========================================================== ') - disp([' Change in the covariance matrix = ' num2str(mouvement) '.']) - disp([' Mode improvement = ' num2str(abs(OldMode-fval))]) - disp([' New value of jscale = ' num2str(Scale)]) - disp('========================================================== ') - OldMode = fval; - else - OldPostVar = PostVar; - if i 0) && ~options_.mh_posterior_mode_estimation oo_=display_estimation_results_table(xparam1,stdh,M_,options_,estim_params_,bayestopt_,oo_,pnames,'Maximum Likelihood','mle'); end -OutputDirectoryName = CheckPath('Output',M_.dname); - if np > 0 pindx = estim_params_.param_vals(:,1); save([M_.fname '_params.mat'],'pindx'); @@ -805,14 +442,14 @@ if (any(bayestopt_.pshape >0 ) && options_.mh_replic) || ... if options_.load_mh_file && options_.use_mh_covariance_matrix invhess = compute_mh_covariance_matrix; end - ana_deriv = options_.analytic_derivation; + ana_deriv_old = options_.analytic_derivation; options_.analytic_derivation = 0; if options_.cova_compute feval(options_.posterior_sampling_method,objective_function,options_.proposal_distribution,xparam1,invhess,bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_); else error('I Cannot start the MCMC because the Hessian of the posterior kernel at the mode was not computed.') end - options_.analytic_derivation = ana_deriv; + options_.analytic_derivation = ana_deriv_old; end if options_.mh_posterior_mode_estimation CutSample(M_, options_, estim_params_); diff --git a/matlab/dynare_minimize_objective.m b/matlab/dynare_minimize_objective.m new file mode 100644 index 000000000..85c9f8fa2 --- /dev/null +++ b/matlab/dynare_minimize_objective.m @@ -0,0 +1,443 @@ +function [opt_par_values,fval,exitflag,hessian_mat,options_,Scale]=dynare_minimize_objective(start_par_value,minimizer_algorithm,objective_function,options_,bounds,parameter_names,prior_information,Initial_Hessian,varargin) +% function [opt_par_values,fval,exitflag,hessian_mat,Scale]=dynare_minimize_objective(start_par_value,minimizer_algorithm,objective_function,options_,bounds,parameter_names,prior_information,Initial_Hessian,varargin) +% Calls a minimizer +% +% INPUTS +% start_par_value [n_params by 1] vector of doubles starting values for the parameters +% minimizer_algorithm [scalar double] code of the optimizer algorithm +% objective_function [function handle] handle to the objective function +% options_ [matlab structure] Dynare options structure +% bounds [n_params by 2] vector of doubles 2 row vectors containing lower and upper bound for parameters +% parameter_names [n_params by 1] cell array strings containing the parameters names +% prior_information [matlab structure] Dynare prior information structure (bayestopt_) provided for algorithm 6 +% Initial_Hessian [n_params by n_params] matrix initial hessian matrix provided for algorithm 6 +% varargin [cell array] Input arguments for objective function +% +% OUTPUTS +% opt_par_values [n_params by 1] vector of doubles optimal parameter values minimizing the objective +% fval [scalar double] value of the objective function at the minimum +% exitflag [scalar double] return code of the respective optimizer +% hessian_mat [n_params by n_params] matrix hessian matrix at the mode returned by optimizer +% options_ [matlab structure] Dynare options structure (to return options set by algorithms 5) +% Scale [scalar double] scaling parameter returned by algorith 6 +% +% SPECIAL REQUIREMENTS +% none. +% +% +% Copyright (C) 2014 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 . + + +%% set bounds and parameter names if not already set +n_params=size(start_par_value,1); +if isempty(bounds) + if minimizer_algorithm==10 + error('Algorithm 10 (simpsa) requires upper and lower bounds') + else + bounds=[-Inf(n_params,1) Inf(n_params,1)]; + end +end + +if minimizer_algorithm==10 && any(any(isinf(bounds))) + error('Algorithm 10 (simpsa) requires finite upper and lower bounds') +end + +if isempty(parameter_names) + parameter_names=[repmat('parameter ',n_params,1),num2str((1:n_params)')]; +end + +%% initialize function outputs +hessian_mat=[]; +Scale=[]; +exitflag=1; +fval=NaN; +opt_par_values=NaN(size(start_par_value)); + + +switch minimizer_algorithm + case 1 + if isoctave + error('Optimization algorithm 1 is not available under Octave') + elseif ~user_has_matlab_license('optimization_toolbox') + error('Optimization algorithm 1 requires the Optimization Toolbox') + end + % Set default optimization options for fmincon. + optim_options = optimset('display','iter', 'LargeScale','off', 'MaxFunEvals',100000, 'TolFun',1e-8, 'TolX',1e-6); + if isfield(options_,'optim_opt') + eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); + end + if options_.analytic_derivation, + optim_options = optimset(optim_options,'GradObj','on','TolX',1e-7); + end + [opt_par_values,fval,exitflag,output,lamdba,grad,hessian_mat] = ... + fmincon(objective_function,start_par_value,[],[],[],[],bounds(:,1),bounds(:,2),[],optim_options,varargin{:}); + case 2 + error('Optimization algorithm 1 option (Lester Ingber''s Adaptive Simulated Annealing) is no longer available') + case 3 + if isoctave && ~user_has_octave_forge_package('optim') + error('Optimization algorithm 3 requires the optim package') + elseif ~isoctave && ~user_has_matlab_license('optimization_toolbox') + error('Optimization algorithm 3 requires the Optimization Toolbox') + end + % Set default optimization options for fminunc. + optim_options = optimset('display','iter','MaxFunEvals',100000,'TolFun',1e-8,'TolX',1e-6); + if isfield(options_,'optim_opt') + eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); + end + if options_.analytic_derivation, + optim_options = optimset(optim_options,'GradObj','on'); + end + if ~isoctave + [opt_par_values,fval,exitflag] = fminunc(objective_function,start_par_value,optim_options,varargin{:}); + else + % Under Octave, use a wrapper, since fminunc() does not have a 4th arg + func = @(x) objective_function(x,varargin{:}); + [opt_par_values,fval,exitflag] = fminunc(func,start_par_value,optim_options); + end + case 4 + % Set default options. + H0 = 1e-4*eye(n_params); + crit = options_.csminwel.tolerance.f; + nit = options_.csminwel.maxiter; + numgrad = options_.gradient_method; + epsilon = options_.gradient_epsilon; + % Change some options. + if isfield(options_,'optim_opt') + options_list = read_key_value_string(options_.optim_opt); + for i=1:rows(options_list) + switch options_list{i,1} + case 'MaxIter' + nit = options_list{i,2}; + case 'InitialInverseHessian' + H0 = eval(options_list{i,2}); + case 'TolFun' + crit = options_list{i,2}; + case 'NumgradAlgorithm' + numgrad = options_list{i,2}; + case 'NumgradEpsilon' + epsilon = options_list{i,2}; + otherwise + warning(['csminwel: Unknown option (' options_list{i,1} ')!']) + end + end + end + % Set flag for analytical gradient. + if options_.analytic_derivation + analytic_grad=1; + else + analytic_grad=[]; + end + % Call csminwell. + [fval,opt_par_values,grad,hessian_mat,itct,fcount,exitflag] = ... + csminwel1(objective_function, start_par_value, H0, analytic_grad, crit, nit, numgrad, epsilon, varargin{:}); + case 5 + if options_.analytic_derivation==-1 %set outside as code for use of analytic derivation + analytic_grad=1; + crit = options_.newrat.tolerance.f_analytic; + newratflag = 0; %analytical Hessian + else + analytic_grad=0; + crit=options_.newrat.tolerance.f; + newratflag = options_.newrat.hess; %default + end + nit=options_.newrat.maxiter; + + if isfield(options_,'optim_opt') + options_list = read_key_value_string(options_.optim_opt); + for i=1:rows(options_list) + switch options_list{i,1} + case 'MaxIter' + nit = options_list{i,2}; + case 'Hessian' + flag=options_list{i,2}; + if options_.analytic_derivation && flag~=0 + error('newrat: analytic_derivation is incompatible with numerical Hessian. Using analytic Hessian') + else + newratflag=flag; + end + case 'TolFun' + crit = options_list{i,2}; + otherwise + warning(['newrat: Unknown option (' options_list{i,1} ')!']) + end + end + end + [opt_par_values,hessian_mat,gg,fval,invhess] = newrat(objective_function,start_par_value,analytic_grad,crit,nit,0,varargin{:}); + 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 + % Set default options + gmhmaxlikOptions = options_.gmhmaxlik; + if ~isempty(Initial_Hessian); + gmhmaxlikOptions.varinit = 'previous'; + else + gmhmaxlikOptions.varinit = 'prior'; + end + if isfield(options_,'optim_opt') + options_list = read_key_value_string(options_.optim_opt); + for i=1:rows(options_list) + switch options_list{i,1} + case 'NumberOfMh' + gmhmaxlikOptions.iterations = options_list{i,2}; + case 'ncov-mh' + gmhmaxlikOptions.number = options_list{i,2}; + case 'nscale' + gmhmaxlikOptions.nscale = options_list{i,2}; + case 'nclimb' + gmhmaxlikOptions.nclimb = options_list{i,2}; + case 'InitialCovarianceMatrix' + switch options_list{i,2} + case 'previous' + if isempty(Initial_Hessian) + error('gmhmaxlik: No previous estimate of the Hessian matrix available! You cannot use the InitialCovarianceMatrix option!') + else + gmhmaxlikOptions.varinit = 'previous'; + end + case {'prior', 'identity'} + gmhmaxlikOptions.varinit = options_list{i,2}; + otherwise + error('gmhmaxlik: Unknown value for option ''InitialCovarianceMatrix''!') + end + case 'AcceptanceRateTarget' + gmhmaxlikOptions.target = options_list{i,2}; + if gmhmaxlikOptions.target>1 || gmhmaxlikOptions.target1 + flag = ''; + else + flag = 'LastCall'; + end + [opt_par_values,PostVar,Scale,PostMean] = ... + gmhmaxlik(objective_function,start_par_value,bounds,gmhmaxlikOptions,Scale,flag,MeanPar,CovJump,varargin{:}); + fval = feval(objective_function,opt_par_values,varargin{:}); + mouvement = max(max(abs(PostVar-OldPostVar))); + skipline() + disp('========================================================== ') + disp([' Change in the covariance matrix = ' num2str(mouvement) '.']) + disp([' Mode improvement = ' num2str(abs(OldMode-fval))]) + disp([' New value of jscale = ' num2str(Scale)]) + disp('========================================================== ') + OldMode = fval; + else + OldPostVar = PostVar; + if i Date: Thu, 4 Dec 2014 20:04:36 +0100 Subject: [PATCH 008/210] Integrate error from negative steady state with loglinear model into print_info.m Prevents crashes during estimation. Instead of directly crashing, error handling is done via print_info.m so that penalizing the error during estimation is possible --- matlab/dsge_likelihood.m | 4 +++- matlab/print_info.m | 2 ++ matlab/resol.m | 36 ++++++++++++++++++++---------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index 585b7e97a..7ac811416 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -70,6 +70,8 @@ function [fval,DLIK,Hess,exit_flag,SteadyState,trend_coeff,info,Model,DynareOpti %! M_.params has been updated in the steadystate routine and has complex valued scalars. %! @item info==24 %! M_.params has been updated in the steadystate routine and has some NaNs. +%! @item info==26 +%! M_.params has been updated in the steadystate routine and has negative/0 values in loglinear model. %! @item info==30 %! Ergodic variance can't be computed. %! @item info==41 @@ -266,7 +268,7 @@ if info(1) == 1 || info(1) == 2 || info(1) == 5 || info(1) == 7 || info(1) == 8 DLIK=ones(length(xparam1),1); end return -elseif info(1) == 3 || info(1) == 4 || info(1)==6 || info(1) == 20 || info(1) == 21 || info(1) == 23 +elseif info(1) == 3 || info(1) == 4 || info(1)==6 || info(1) == 20 || info(1) == 21 || info(1) == 23 || info(1)==26 fval = objective_function_penalty_base+info(2); info = info(1); exit_flag = 0; diff --git a/matlab/print_info.m b/matlab/print_info.m index 0ec5e3788..91c2100c0 100644 --- a/matlab/print_info.m +++ b/matlab/print_info.m @@ -88,6 +88,8 @@ if ~noprint error('Some updated params contain NaN or Inf') case 25 error('The solution to the static equations is not a steady state of the dynamic model: verify that the equations tagged by [static] and [dynamic] are consistent') + case 26 + error('The loglinearization of the model cannot be performed, because the steady state is not strictly positive.') case 30 error('Variance can''t be computed') case 41 diff --git a/matlab/resol.m b/matlab/resol.m index 92c775806..1a0685fe0 100644 --- a/matlab/resol.m +++ b/matlab/resol.m @@ -111,23 +111,27 @@ if options.loglinear % Find variables with non positive steady state. idx = find(dr.ys<1e-9); if length(idx) - variables_with_non_positive_steady_state = M.endo_names(idx,:); - skipline() - fprintf('You are attempting to simulate/estimate a loglinear approximation of a model, but\n') - fprintf('the steady state level of the following variables is not strictly positive:\n') - for var_iter=1:length(idx) - fprintf(' - %s (%s)\n',deblank(variables_with_non_positive_steady_state(var_iter,:)), num2str(dr.ys(idx(var_iter)))) + if options.debug + variables_with_non_positive_steady_state = M.endo_names(idx,:); + skipline() + fprintf('You are attempting to simulate/estimate a loglinear approximation of a model, but\n') + fprintf('the steady state level of the following variables is not strictly positive:\n') + for var_iter=1:length(idx) + fprintf(' - %s (%s)\n',deblank(variables_with_non_positive_steady_state(var_iter,:)), num2str(dr.ys(idx(var_iter)))) + end + if isestimation() + fprintf('You should check that the priors and/or bounds over the deep parameters are such\n') + fprintf('that the steady state levels of all the variables are strictly positive, or consider\n') + fprintf('a linearization of the model instead of a log linearization.\n') + else + fprintf('You should check that the calibration of the deep parameters is such that the\n') + fprintf('steady state levels of all the variables are strictly positive, or consider\n') + fprintf('a linearization of the model instead of a log linearization.\n') + end end - if isestimation() - fprintf('You should check that the priors and/or bounds over the deep parameters are such\n') - fprintf('that the steady state levels of all the variables are strictly positive, or consider\n') - fprintf('a linearization of the model instead of a log linearization.\n') - else - fprintf('You should check that the calibration of the deep parameters is such that the\n') - fprintf('steady state levels of all the variables are strictly positive, or consider\n') - fprintf('a linearization of the model instead of a log linearization.\n') - end - error('stoch_simul::resol: The loglinearization of the model cannot be performed, because the steady state is not strictly positive!') + info(1)=26; + info(2)=sum(dr.ys(dr.ys<1e-9).^2); + return end end From e60157e9b86b203ba2bbea39e5e7612ccf1ed457 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 4 Dec 2014 18:15:39 +0100 Subject: [PATCH 009/210] Add unit test for newrat with analytic derivatives and various Kalman algos --- tests/Makefile.am | 2 + .../fs2000_analytic_derivation.mod | 78 ++ tests/analytic_derivatives/fsdat_simul.m | 828 ++++++++++++++++++ 3 files changed, 908 insertions(+) create mode 100644 tests/analytic_derivatives/fs2000_analytic_derivation.mod create mode 100644 tests/analytic_derivatives/fsdat_simul.m diff --git a/tests/Makefile.am b/tests/Makefile.am index b13370853..e99be6f97 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -79,6 +79,7 @@ MODFILES = \ arima/mod2b.mod \ arima/mod2c.mod \ data/mod1a.mod \ + analytic_derivatives/fs2000_analytic_derivation.mod \ fs2000/fs2000.mod \ fs2000/fs2000a.mod \ fs2000/fs2000c.mod \ @@ -319,6 +320,7 @@ EXTRA_DIST = \ expectations/expectation_ss_old_steadystate.m \ steady_state/walsh1_old_ss_steadystate.m \ data/test.xls \ + analytic_derivatives/fsdat_simul.m \ fs2000/fs2000a_steadystate.m \ fs2000/fsdat_simul.m \ k_order_perturbation/run_fs2000kplusplus.m \ diff --git a/tests/analytic_derivatives/fs2000_analytic_derivation.mod b/tests/analytic_derivatives/fs2000_analytic_derivation.mod new file mode 100644 index 000000000..c4f2a7479 --- /dev/null +++ b/tests/analytic_derivatives/fs2000_analytic_derivation.mod @@ -0,0 +1,78 @@ +// Tests the analytic_derivation option + +var m P c e W R k d n l gy_obs gp_obs y dA; +varexo e_a e_m; + +parameters alp bet gam mst rho psi del; + +alp = 0.33; +bet = 0.99; +gam = 0.003; +mst = 1.011; +rho = 0.7; +psi = 0.787; +del = 0.02; + +model; +dA = exp(gam+e_a); +log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; +-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; +W = l/n; +-(psi/(1-psi))*(c*P/(1-n))+l/n = 0; +R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; +1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; +c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); +P*c = m; +m-1+d = l; +e = exp(e_a); +y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); +gy_obs = dA*y/y(-1); +gp_obs = (P/P(-1))*m(-1)/dA; +end; + +initval; +k = 6; +m = mst; +P = 2.25; +c = 0.45; +e = 1; +W = 4; +R = 1.02; +d = 0.85; +n = 0.19; +l = 0.86; +y = 0.6; +gy_obs = exp(gam); +gp_obs = exp(-gam); +dA = exp(gam); +end; + +shocks; +var e_a; stderr 0.014; +var e_m; stderr 0.005; +end; + +steady; + +check; + +estimated_params; +alp, beta_pdf, 0.356, 0.02; +bet, beta_pdf, 0.993, 0.002; +gam, normal_pdf, 0.0085, 0.003; +mst, normal_pdf, 1.0002, 0.007; +rho, beta_pdf, 0.129, 0.223; +psi, beta_pdf, 0.65, 0.05; +del, beta_pdf, 0.01, 0.005; +stderr e_a, inv_gamma_pdf, 0.035449, inf; +stderr e_m, inv_gamma_pdf, 0.008862, inf; +end; + +varobs gp_obs gy_obs; + +options_.solve_tolf = 1e-12; + +estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=1,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); +estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=2,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); +estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=3,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); +estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=4,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); \ No newline at end of file diff --git a/tests/analytic_derivatives/fsdat_simul.m b/tests/analytic_derivatives/fsdat_simul.m new file mode 100644 index 000000000..d4f4a8066 --- /dev/null +++ b/tests/analytic_derivatives/fsdat_simul.m @@ -0,0 +1,828 @@ +gy_obs =[ + 1.0030045 + 0.99990934 + 1.0172778 + 0.99464043 + 1.0253423 + 1.0150215 + 0.97772557 + 0.97832186 + 1.0159561 + 1.0085937 + 1.0102649 + 1.0007604 + 1.0112596 + 1.0163279 + 1.0173204 + 1.0103896 + 1.0006493 + 0.99447124 + 1.0196405 + 1.0089304 + 0.99650737 + 1.0139707 + 0.97865842 + 1.0192225 + 0.99139628 + 1.0141362 + 1.0196612 + 0.97483476 + 0.99686151 + 0.99594464 + 1.0000642 + 1.0172243 + 1.0025773 + 0.97199728 + 1.0217815 + 1.0219949 + 0.99490252 + 1.0190728 + 1.0111337 + 1.0003792 + 0.98969164 + 1.010438 + 1.0216309 + 1.0016671 + 1.0357588 + 0.98803787 + 1.0093457 + 1.0177035 + 0.98548204 + 1.0274294 + 1.0141377 + 1.0091174 + 0.96427632 + 1.0083272 + 1.0007882 + 0.99038262 + 1.0031336 + 0.99500213 + 0.98203716 + 0.9889452 + 1.011632 + 0.99451949 + 0.97291047 + 0.98750871 + 0.99992418 + 0.97657318 + 0.99930448 + 1.0008515 + 1.0044064 + 0.98133792 + 1.0091702 + 1.0087023 + 1.0119876 + 1.0143019 + 1.0311061 + 0.99340471 + 1.0057428 + 0.99197259 + 1.0071019 + 0.99448853 + 1.0061819 + 1.0070088 + 0.9950913 + 1.0302318 + 0.9817693 + 1.0072885 + 0.97355282 + 0.98782586 + 1.0136674 + 0.99863956 + 1.0205668 + 0.99611384 + 1.0073805 + 0.99691529 + 1.0089194 + 1.0030467 + 1.0112006 + 1.0260523 + 0.97803331 + 0.99423374 + 1.0043727 + 1.0140173 + 1.0111473 + 0.99524348 + 0.99775943 + 0.9958619 + 0.9982344 + 1.0210212 + 1.0022288 + 1.0014801 + 1.011456 + 1.0124871 + 0.99843599 + 0.99324886 + 0.99912838 + 1.003327 + 1.0072071 + 1.0115223 + 1.009266 + 1.0070554 + 1.0129916 + 1.0053413 + 1.0051638 + 0.99212952 + 1.0214422 + 0.98716707 + 0.99905788 + 0.98877357 + 0.98568476 + 0.99767393 + 1.0061791 + 0.98423439 + 0.99492949 + 0.98786999 + 0.99754239 + 1.0168619 + 0.99472384 + 1.0041658 + 0.98123181 + 1.0112882 + 0.99245422 + 1.0010255 + 1.0017799 + 1.0089968 + 1.0072824 + 0.99768475 + 1.0044726 + 1.0118678 + 1.0056385 + 1.0276965 + 1.0025122 + 1.0065161 + 1.0234338 + 0.99760167 + 0.98922272 + 1.0101918 + 1.011615 + 1.0085286 + 1.0074455 + 0.98866757 + 0.99959012 + 1.0129881 + 0.99127881 + 0.97971901 + 1.0185314 + 1.020054 + 1.0132605 + 0.98063643 + 0.99490253 + 1.0101531 + 1.0004526 + 1.0059109 + 0.98974491 + 1.0062391 + 1.0216488 + 0.99398446 + 0.97786609 + 1.0019274 + 0.99587153 + 1.0095881 + 1.0111887 + 0.99457649 + 0.97896734 + 1.000172 + 1.0142951 + 1.0034224 + 1.0037242 + 1.0016059 + 1.016556 + 0.99687023 + 1.0117844 + 1.0059212 + 0.98083159 + 0.98638851 + 1.0128713 + 1.0096232 + 1.0115891 + 1.0011213 + 1.0147105 + 1.0066344 + 1.0164429 + 0.99825038 + 0.99403411 + +]; + +gp_obs =[ + 1.0079715 + 1.0074573 + 1.0153107 + 1.0152677 + 1.0011653 + 0.99950061 + 1.0328311 + 1.0192317 + 1.009827 + 0.99588916 + 1.007474 + 1.0113061 + 0.98696624 + 0.99978663 + 0.98240542 + 0.98861723 + 0.99008763 + 1.0185076 + 1.0052452 + 0.99447194 + 1.0092685 + 1.01208 + 1.0105237 + 0.98513875 + 1.0165628 + 0.99485934 + 1.0050255 + 1.0140756 + 1.0093128 + 1.0155868 + 1.0107023 + 0.99212762 + 1.0095465 + 1.0028435 + 1.0069437 + 1.0070473 + 1.0145902 + 1.0186922 + 1.0059917 + 1.0113072 + 1.0107386 + 0.99769196 + 0.99793444 + 1.0050791 + 0.98307821 + 1.0107594 + 0.99689982 + 0.98667064 + 0.9991662 + 0.98274722 + 0.98422032 + 0.99393016 + 1.0118567 + 0.99912781 + 1.0023744 + 1.0086662 + 1.0164773 + 1.0169327 + 1.0372478 + 1.0314242 + 1.0004256 + 1.0110541 + 1.0076575 + 1.0119851 + 1.0055188 + 1.0213959 + 1.0234416 + 1.0264917 + 1.0292725 + 1.0385184 + 1.0200999 + 1.0107697 + 1.008583 + 1.0200332 + 1.0030413 + 1.0108659 + 1.0185145 + 1.0168619 + 1.0180462 + 1.0239657 + 1.0205509 + 1.0189973 + 1.0246446 + 1.0135089 + 1.0352973 + 1.0099289 + 1.0266474 + 1.0279829 + 1.0101653 + 1.041216 + 1.0103861 + 1.0114727 + 1.0054605 + 1.0190722 + 1.0114837 + 1.0179213 + 1.006082 + 1.0049696 + 1.0143629 + 0.9971036 + 1.0005602 + 1.0078403 + 1.0240222 + 1.0195063 + 1.0355136 + 1.0218743 + 1.0171331 + 1.0049817 + 1.0140974 + 1.0168431 + 1.0049966 + 1.0045568 + 1.0156414 + 1.0273055 + 1.0197653 + 1.0030624 + 1.0154993 + 0.99782084 + 0.99711648 + 1.014408 + 1.0057417 + 0.99936837 + 1.0096934 + 1.0095138 + 1.0057734 + 1.0114497 + 1.0059784 + 1.0328889 + 1.0098032 + 1.0041114 + 1.0101247 + 1.0181588 + 1.0115712 + 1.0227509 + 1.0065104 + 1.0110902 + 1.0298169 + 1.0089532 + 1.0368733 + 1.0123033 + 1.0060763 + 1.0150937 + 1.0239325 + 0.99555536 + 0.99861271 + 1.0076201 + 0.99941535 + 1.0119522 + 1.0129183 + 0.99288924 + 1.0260784 + 1.0144982 + 1.0121985 + 1.0234916 + 1.02215 + 1.0190118 + 1.0172679 + 1.0118398 + 1.0002123 + 1.0092124 + 1.0071943 + 0.99508468 + 1.0019303 + 1.0030733 + 0.9964198 + 1.0027298 + 0.99797614 + 1.006942 + 0.99793928 + 1.0083214 + 1.0283732 + 1.0111102 + 1.016936 + 1.0229061 + 0.98846454 + 1.0015387 + 1.0201769 + 1.0079822 + 1.0064007 + 1.0095543 + 1.0092207 + 1.0135485 + 1.0198974 + 1.0140252 + 1.0128686 + 1.0092903 + 1.0141974 + 1.0023492 + 0.99731455 + 1.0026598 + 0.99303643 + 1.0036469 + 1.0160975 + 1.0368378 + 1.0139625 + 1.01493 + 1.0113531 + 1.0114548 + 0.99833441 + 0.99648401 + 0.97645361 + 1.0154053 + 1.01703 + +]; + +Y_obs =[ + 1 + 0.99690484 + 1.0111781 + 1.0028141 + 1.0251518 + 1.0371688 + 1.0118899 + 0.98720726 + 1.0001589 + 1.0057481 + 1.0130085 + 1.0107643 + 1.0190194 + 1.0323428 + 1.0466587 + 1.0540438 + 1.0516886 + 1.0431553 + 1.0597913 + 1.0657172 + 1.0592201 + 1.0701863 + 1.0458402 + 1.0620582 + 1.0504499 + 1.0615817 + 1.0782384 + 1.0500687 + 1.0439257 + 1.0368658 + 1.0339255 + 1.0481453 + 1.0477181 + 1.0167109 + 1.0354878 + 1.0544782 + 1.0463762 + 1.0624445 + 1.0705737 + 1.0679484 + 1.0546356 + 1.0620691 + 1.0806955 + 1.0793581 + 1.1121124 + 1.0971458 + 1.1034869 + 1.1181859 + 1.1006634 + 1.1250883 + 1.1362214 + 1.1423343 + 1.1036061 + 1.1089288 + 1.1067125 + 1.0940906 + 1.0942197 + 1.0862174 + 1.06525 + 1.0511907 + 1.0598182 + 1.0513331 + 1.0212391 + 1.0057433 + 1.002663 + 0.97623167 + 0.97253165 + 0.97037865 + 0.97178055 + 0.95011397 + 0.95627969 + 0.96197747 + 0.97096053 + 0.98225794 + 1.0103595 + 1.0007597 + 1.003498 + 0.99246608 + 0.99656347 + 0.98804749 + 0.99122491 + 0.99522926 + 0.98731605 + 1.0145434 + 0.99330816 + 0.99759216 + 0.96814048 + 0.95296183 + 0.96362471 + 0.95925977 + 0.97682205 + 0.96993138 + 0.9743074 + 0.96821818 + 0.97413308 + 0.9741753 + 0.98237142 + 1.0054193 + 0.98044807 + 0.9716773 + 0.9730455 + 0.98405828 + 0.99220103 + 0.98444001 + 0.97919493 + 0.97205233 + 0.96728223 + 0.98529893 + 0.98452324 + 0.98299888 + 0.99145042 + 1.000933 + 0.99636447 + 0.98660883 + 0.98273271 + 0.98305518 + 0.98725774 + 0.99577549 + 1.002037 + 1.0060879 + 1.016075 + 1.0184118 + 1.0205711 + 1.0096961 + 1.0281337 + 1.0122963 + 1.0083497 + 0.99411874 + 0.976799 + 0.97146842 + 0.97464304 + 0.95587292 + 0.94779791 + 0.93266339 + 0.92720128 + 0.94105864 + 0.93277798 + 0.93393927 + 0.91216657 + 0.92045028 + 0.9099 + 0.90792098 + 0.90669634 + 0.91268867 + 0.91696661 + 0.91164685 + 0.91311495 + 0.92197825 + 0.92461222 + 0.94930422 + 0.9488119 + 0.95232353 + 0.97275278 + 0.96734995 + 0.95356817 + 0.96075548 + 0.96936594 + 0.97489002 + 0.97933106 + 0.96499412 + 0.96157973 + 0.97156334 + 0.95983765 + 0.93655215 + 0.95207909 + 0.96912862 + 0.97938462 + 0.95701655 + 0.94891457 + 0.95606317 + 0.95351125 + 0.95641767 + 0.94315807 + 0.94639265 + 0.96503697 + 0.95601693 + 0.93087851 + 0.92980141 + 0.92266844 + 0.92925206 + 0.93743628 + 0.92900826 + 0.9049711 + 0.90213859 + 0.91342916 + 0.91384707 + 0.91456681 + 0.91316822 + 0.92671976 + 0.92058549 + 0.92936541 + 0.93228212 + 0.91010921 + 0.89349322 + 0.90336005 + 0.90997873 + 0.91856328 + 0.91668007 + 0.92838606 + 0.932016 + 0.94545438 + 0.94070026 + 0.93172987 + +]; + +P_obs =[ + 1 + 0.99948573 + 1.0068249 + 1.0141211 + 1.0073149 + 0.99884398 + 1.0237035 + 1.0349636 + 1.036819 + 1.0247366 + 1.0242391 + 1.0275737 + 1.0065684 + 0.99838346 + 0.97281734 + 0.95346302 + 0.9355791 + 0.9461152 + 0.94338882 + 0.92988921 + 0.9311862 + 0.93529467 + 0.93784681 + 0.91501401 + 0.92360522 + 0.91049302 + 0.90754698 + 0.91365103 + 0.91499228 + 0.92260749 + 0.92533824 + 0.90949431 + 0.91106924 + 0.90594116 + 0.90491334 + 0.9039891 + 0.91060772 + 0.92132842 + 0.91934854 + 0.92268418 + 0.92545127 + 0.91517169 + 0.90513459 + 0.90224212 + 0.87734878 + 0.88013667 + 0.86906494 + 0.84776403 + 0.83895869 + 0.81373437 + 0.78998314 + 0.77594176 + 0.77982695 + 0.77098321 + 0.76538611 + 0.76608075 + 0.77458654 + 0.78354767 + 0.81282389 + 0.83627649 + 0.82873051 + 0.83181309 + 0.83149903 + 0.83551261 + 0.83305985 + 0.84648418 + 0.86195421 + 0.88047436 + 0.90177533 + 0.93232215 + 0.94445051 + 0.9472487 + 0.94786015 + 0.95992178 + 0.95499149 + 0.95788581 + 0.9684288 + 0.97731917 + 0.98739379 + 1.0033879 + 1.0159673 + 1.0269931 + 1.0436661 + 1.0492034 + 1.0765292 + 1.0784865 + 1.0971624 + 1.1171737 + 1.1193675 + 1.1526119 + 1.1550265 + 1.1585277 + 1.1560166 + 1.1671172 + 1.1706294 + 1.1805791 + 1.1786896 + 1.1756876 + 1.1820789 + 1.171211 + 1.1637997 + 1.1636684 + 1.179719 + 1.1912538 + 1.2187959 + 1.2326986 + 1.2418602 + 1.2388704 + 1.2449963 + 1.2538678 + 1.2508929 + 1.2474781 + 1.255148 + 1.274482 + 1.2862757 + 1.2813665 + 1.2888943 + 1.2787436 + 1.2678886 + 1.274325 + 1.2720952 + 1.263492 + 1.2652139 + 1.2667561 + 1.264558 + 1.2680362 + 1.2660431 + 1.2909605 + 1.2927921 + 1.288932 + 1.2910852 + 1.3012725 + 1.3048721 + 1.3196515 + 1.3181903 + 1.321309 + 1.3431543 + 1.344136 + 1.3730377 + 1.3773695 + 1.3754742 + 1.3825964 + 1.3985574 + 1.3861412 + 1.3767823 + 1.3764309 + 1.3678747 + 1.3718554 + 1.3768022 + 1.3617199 + 1.3798267 + 1.3863533 + 1.3905803 + 1.4061004 + 1.4202788 + 1.4313191 + 1.4406155 + 1.4444837 + 1.4367244 + 1.4379653 + 1.4371881 + 1.4243012 + 1.41826 + 1.4133617 + 1.40181 + 1.3965683 + 1.3865729 + 1.3855433 + 1.3755111 + 1.3758609 + 1.3962625 + 1.3994012 + 1.4083656 + 1.4233002 + 1.4037932 + 1.3973604 + 1.4095657 + 1.4095764 + 1.4080055 + 1.4095882 + 1.4108374 + 1.4164143 + 1.4283402 + 1.4343939 + 1.4392909 + 1.4406097 + 1.4468355 + 1.4412132 + 1.4305562 + 1.4252445 + 1.4103094 + 1.4059847 + 1.4141106 + 1.4429769 + 1.4489679 + 1.4559263 + 1.4593079 + 1.4627911 + 1.453154 + 1.4416665 + 1.4101485 + 1.4175823 + 1.4266407 + +]; + From 5865d46a745999274a77a5588a02fab4a776eef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sat, 21 Feb 2015 18:14:15 +0100 Subject: [PATCH 010/210] Fixed bug. Wrong number of returned arguments when calling dynare_minimize_objective (missing options_). --- matlab/dynare_estimation_1.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index ffa76d89d..c9d7468fc 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -271,7 +271,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation end end - [xparam1,fval,exitflag,hh,Scale]=dynare_minimize_objective(xparam1,options_.mode_compute,objective_function,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + [xparam1, fval, exitflag, hh, options_, Scale] = dynare_minimize_objective(xparam1,options_.mode_compute,objective_function,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); if options_.mode_compute==5 && options_.analytic_derivation==-1 %reset options changed by newrat From beb78263764531ac403921ef030ca370890e5411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 23 Feb 2015 14:26:07 +0100 Subject: [PATCH 011/210] Moved optimization related routines in a common subfolder. --- matlab/dynare_config.m | 1 + matlab/{ => optimization}/cmaes.m | 0 matlab/{ => optimization}/csminit1.m | 0 matlab/{ => optimization}/csminwel1.m | 0 matlab/{ => optimization}/dynare_minimize_objective.m | 0 matlab/{ => optimization}/gmhmaxlik.m | 0 matlab/{ => optimization}/mr_gstep.m | 0 matlab/{ => optimization}/mr_hessian.m | 0 matlab/{ => optimization}/numgrad2.m | 0 matlab/{ => optimization}/numgrad3.m | 0 matlab/{ => optimization}/numgrad3_.m | 0 matlab/{ => optimization}/numgrad5.m | 0 matlab/{ => optimization}/numgrad5_.m | 0 matlab/{ => optimization}/simplex_optimization_routine.m | 0 matlab/{ => optimization}/simpsa.m | 0 matlab/{ => optimization}/simpsaget.m | 0 matlab/{ => optimization}/simpsaset.m | 0 17 files changed, 1 insertion(+) rename matlab/{ => optimization}/cmaes.m (100%) rename matlab/{ => optimization}/csminit1.m (100%) rename matlab/{ => optimization}/csminwel1.m (100%) rename matlab/{ => optimization}/dynare_minimize_objective.m (100%) rename matlab/{ => optimization}/gmhmaxlik.m (100%) rename matlab/{ => optimization}/mr_gstep.m (100%) rename matlab/{ => optimization}/mr_hessian.m (100%) rename matlab/{ => optimization}/numgrad2.m (100%) rename matlab/{ => optimization}/numgrad3.m (100%) rename matlab/{ => optimization}/numgrad3_.m (100%) rename matlab/{ => optimization}/numgrad5.m (100%) rename matlab/{ => optimization}/numgrad5_.m (100%) rename matlab/{ => optimization}/simplex_optimization_routine.m (100%) rename matlab/{ => optimization}/simpsa.m (100%) rename matlab/{ => optimization}/simpsaget.m (100%) rename matlab/{ => optimization}/simpsaset.m (100%) diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index c0b5c4294..e4f9506d8 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -58,6 +58,7 @@ addpath([dynareroot '/particle/']) addpath([dynareroot '/gsa/']) addpath([dynareroot '/ep/']) addpath([dynareroot '/lmmcp/']) +addpath([dynareroot '/optimization/']) addpath([dynareroot '/modules/dates/src/']) addpath([dynareroot '/modules/dseries/src/']) addpath([dynareroot '/utilities/doc/']) diff --git a/matlab/cmaes.m b/matlab/optimization/cmaes.m similarity index 100% rename from matlab/cmaes.m rename to matlab/optimization/cmaes.m diff --git a/matlab/csminit1.m b/matlab/optimization/csminit1.m similarity index 100% rename from matlab/csminit1.m rename to matlab/optimization/csminit1.m diff --git a/matlab/csminwel1.m b/matlab/optimization/csminwel1.m similarity index 100% rename from matlab/csminwel1.m rename to matlab/optimization/csminwel1.m diff --git a/matlab/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m similarity index 100% rename from matlab/dynare_minimize_objective.m rename to matlab/optimization/dynare_minimize_objective.m diff --git a/matlab/gmhmaxlik.m b/matlab/optimization/gmhmaxlik.m similarity index 100% rename from matlab/gmhmaxlik.m rename to matlab/optimization/gmhmaxlik.m diff --git a/matlab/mr_gstep.m b/matlab/optimization/mr_gstep.m similarity index 100% rename from matlab/mr_gstep.m rename to matlab/optimization/mr_gstep.m diff --git a/matlab/mr_hessian.m b/matlab/optimization/mr_hessian.m similarity index 100% rename from matlab/mr_hessian.m rename to matlab/optimization/mr_hessian.m diff --git a/matlab/numgrad2.m b/matlab/optimization/numgrad2.m similarity index 100% rename from matlab/numgrad2.m rename to matlab/optimization/numgrad2.m diff --git a/matlab/numgrad3.m b/matlab/optimization/numgrad3.m similarity index 100% rename from matlab/numgrad3.m rename to matlab/optimization/numgrad3.m diff --git a/matlab/numgrad3_.m b/matlab/optimization/numgrad3_.m similarity index 100% rename from matlab/numgrad3_.m rename to matlab/optimization/numgrad3_.m diff --git a/matlab/numgrad5.m b/matlab/optimization/numgrad5.m similarity index 100% rename from matlab/numgrad5.m rename to matlab/optimization/numgrad5.m diff --git a/matlab/numgrad5_.m b/matlab/optimization/numgrad5_.m similarity index 100% rename from matlab/numgrad5_.m rename to matlab/optimization/numgrad5_.m diff --git a/matlab/simplex_optimization_routine.m b/matlab/optimization/simplex_optimization_routine.m similarity index 100% rename from matlab/simplex_optimization_routine.m rename to matlab/optimization/simplex_optimization_routine.m diff --git a/matlab/simpsa.m b/matlab/optimization/simpsa.m similarity index 100% rename from matlab/simpsa.m rename to matlab/optimization/simpsa.m diff --git a/matlab/simpsaget.m b/matlab/optimization/simpsaget.m similarity index 100% rename from matlab/simpsaget.m rename to matlab/optimization/simpsaget.m diff --git a/matlab/simpsaset.m b/matlab/optimization/simpsaset.m similarity index 100% rename from matlab/simpsaset.m rename to matlab/optimization/simpsaset.m From 0ffb9dd6e2c6a91d08c986314a390edf90520da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 23 Feb 2015 14:35:41 +0100 Subject: [PATCH 012/210] Changed order of the input arguments in dynare_mimimize_objective. It is more standard to have the name of the routine (defining the objective to be minimized) as a first argument. --- matlab/dynare_estimation_1.m | 4 ++-- matlab/optimization/dynare_minimize_objective.m | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index c9d7468fc..69169f7d6 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -12,7 +12,7 @@ function dynare_estimation_1(var_list_,dname) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2003-2013 Dynare Team +% Copyright (C) 2003-2015 Dynare Team % % This file is part of Dynare. % @@ -271,7 +271,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation end end - [xparam1, fval, exitflag, hh, options_, Scale] = dynare_minimize_objective(xparam1,options_.mode_compute,objective_function,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); + [xparam1, fval, exitflag, hh, options_, Scale] = dynare_minimize_objective(objective_function,xparam1,options_.mode_compute,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); if options_.mode_compute==5 && options_.analytic_derivation==-1 %reset options changed by newrat diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 85c9f8fa2..7323664c5 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -1,11 +1,11 @@ -function [opt_par_values,fval,exitflag,hessian_mat,options_,Scale]=dynare_minimize_objective(start_par_value,minimizer_algorithm,objective_function,options_,bounds,parameter_names,prior_information,Initial_Hessian,varargin) -% function [opt_par_values,fval,exitflag,hessian_mat,Scale]=dynare_minimize_objective(start_par_value,minimizer_algorithm,objective_function,options_,bounds,parameter_names,prior_information,Initial_Hessian,varargin) +function [opt_par_values,fval,exitflag,hessian_mat,options_,Scale]=dynare_minimize_objective(objective_function,start_par_value,minimizer_algorithm,options_,bounds,parameter_names,prior_information,Initial_Hessian,varargin) + % Calls a minimizer % % INPUTS +% objective_function [function handle] handle to the objective function % start_par_value [n_params by 1] vector of doubles starting values for the parameters % minimizer_algorithm [scalar double] code of the optimizer algorithm -% objective_function [function handle] handle to the objective function % options_ [matlab structure] Dynare options structure % bounds [n_params by 2] vector of doubles 2 row vectors containing lower and upper bound for parameters % parameter_names [n_params by 1] cell array strings containing the parameters names @@ -25,7 +25,7 @@ function [opt_par_values,fval,exitflag,hessian_mat,options_,Scale]=dynare_minimi % none. % % -% Copyright (C) 2014 Dynare Team +% Copyright (C) 2014-2015 Dynare Team % % This file is part of Dynare. % From 59c8fe4319f96d292a2a2a1c1bd2001c91352395 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 23 Feb 2015 16:50:14 +0100 Subject: [PATCH 013/210] test system: rename ramsey.mod as ramsey_.mod to avoid removal of ramsey directory when doing make clean --- tests/Makefile.am | 2 +- tests/optimal_policy/{ramsey.mod => ramsey_.mod} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/optimal_policy/{ramsey.mod => ramsey_.mod} (100%) diff --git a/tests/Makefile.am b/tests/Makefile.am index 5fbd246ba..200402436 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,7 +21,7 @@ MODFILES = \ optimal_policy/osr_example.mod \ optimal_policy/osr_example_objective_correctness.mod \ optimal_policy/osr_example_obj_corr_non_stat_vars.mod \ - optimal_policy/ramsey.mod \ + optimal_policy/ramsey_.mod \ optimal_policy/nk_ramsey.mod \ optimal_policy/nk_ramsey_model.mod \ optimal_policy/nk_ramsey_det.mod \ diff --git a/tests/optimal_policy/ramsey.mod b/tests/optimal_policy/ramsey_.mod similarity index 100% rename from tests/optimal_policy/ramsey.mod rename to tests/optimal_policy/ramsey_.mod From bd39ff34f642823d2ac70e61c42b339fe80e93ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 23 Feb 2015 18:24:57 +0100 Subject: [PATCH 014/210] Fixed bug in get_prior_info routine. lb and ub (lower and upper bounds for the priors) are no more fields of bayestopt_ structure. --- matlab/get_prior_info.m | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/matlab/get_prior_info.m b/matlab/get_prior_info.m index cea8ffe46..6a82442bf 100644 --- a/matlab/get_prior_info.m +++ b/matlab/get_prior_info.m @@ -53,6 +53,7 @@ order = options_.order; options_.order = 1; [xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_); + if plt_flag plot_priors(bayestopt_,M_,estim_params_,options_) end @@ -100,37 +101,37 @@ if size(M_.param_names,1)==size(M_.param_names_tex,1)% All the parameters have a case { 1 , 5 } LowerBound = bayestopt_.p3(i); UpperBound = bayestopt_.p4(i); - if ~isinf(bayestopt_.lb(i)) - LowerBound=max(LowerBound,bayestopt_.lb(i)); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); end - if ~isinf(bayestopt_.ub(i)) - UpperBound=min(UpperBound,bayestopt_.ub(i)); + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); end case { 2 , 4 , 6 } LowerBound = bayestopt_.p3(i); - if ~isinf(bayestopt_.lb(i)) - LowerBound=max(LowerBound,bayestopt_.lb(i)); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); end - if ~isinf(bayestopt_.ub(i)) - UpperBound=bayestopt_.ub(i); + if ~isinf(ub(i)) + UpperBound=ub(i); else UpperBound = '$\infty$'; end case 3 - if isinf(bayestopt_.p3(i)) && isinf(bayestopt_.lb(i)) + if isinf(bayestopt_.p3(i)) && isinf(lb(i)) LowerBound = '$-\infty$'; else LowerBound = bayestopt_.p3(i); - if ~isinf(bayestopt_.lb(i)) - LowerBound=max(LowerBound,bayestopt_.lb(i)); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); end end - if isinf(bayestopt_.p4(i)) && isinf(bayestopt_.ub(i)) + if isinf(bayestopt_.p4(i)) && isinf(ub(i)) UpperBound = '$\infty$'; else UpperBound = bayestopt_.p4(i); - if ~isinf(bayestopt_.ub(i)) - UpperBound=min(UpperBound,bayestopt_.ub(i)); + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); end end otherwise @@ -206,7 +207,7 @@ if info==2% Prior optimization. bayestopt_.p6, ... bayestopt_.p7, ... bayestopt_.p3, ... - bayestopt_.p4,options_,M_,estim_params_,oo_); + bayestopt_.p4,options_,M_,bayestopt_,estim_params_,oo_); % Display the results. skipline(2) disp('------------------') From fac1d206ab2c691d57f3f4da222d637d3e746aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 23 Feb 2015 18:26:34 +0100 Subject: [PATCH 015/210] Use new wrapper for optimization algorithms when maximizing the prior density. --- matlab/maximize_prior_density.m | 19 +++++++------------ .../optimization/dynare_minimize_objective.m | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/matlab/maximize_prior_density.m b/matlab/maximize_prior_density.m index 01e9ffc8d..131e0422d 100644 --- a/matlab/maximize_prior_density.m +++ b/matlab/maximize_prior_density.m @@ -1,5 +1,5 @@ function [xparams,lpd,hessian] = ... - maximize_prior_density(iparams, prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound,DynareOptions,DynareModel,EstimatedParams,DynareResults) + maximize_prior_density(iparams, prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound,DynareOptions,DynareModel,BayesInfo,EstimatedParams,DynareResults) % Maximizes the logged prior density using Chris Sims' optimization routine. % % INPUTS @@ -15,7 +15,7 @@ function [xparams,lpd,hessian] = ... % lpd [double] scalar, value of the logged prior density at the mode. % hessian [double] matrix, Hessian matrix at the prior mode. -% Copyright (C) 2009-2012 Dynare Team +% Copyright (C) 2009-2015 Dynare Team % % This file is part of Dynare. % @@ -32,15 +32,10 @@ function [xparams,lpd,hessian] = ... % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -number_of_estimated_parameters = length(iparams); -H0 = 1e-4*eye(number_of_estimated_parameters); -crit = 1e-7; -nit = 1000; -gradient_method = 2; -gradient_epsilon = 1e-6; - -[lpd,xparams,grad,hessian,itct,fcount,retcodehat] = ... - csminwel1('minus_logged_prior_density',iparams,H0,[],crit,nit,gradient_method, gradient_epsilon, ... - prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound,DynareOptions,DynareModel,EstimatedParams,DynareResults); +[xparams, lpd, exitflag, hessian]=dynare_minimize_objective('minus_logged_prior_density', ... + iparams, DynareOptions.mode_compute, DynareOptions, [prior_inf_bound, prior_sup_bound], ... + BayesInfo.name, BayesInfo, [], ... + prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound, ... + DynareOptions,DynareModel,EstimatedParams,DynareResults); lpd = -lpd; diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 7323664c5..68eef8fed 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -46,7 +46,7 @@ function [opt_par_values,fval,exitflag,hessian_mat,options_,Scale]=dynare_minimi %% set bounds and parameter names if not already set n_params=size(start_par_value,1); if isempty(bounds) - if minimizer_algorithm==10 + if minimizer_algorithm==10 error('Algorithm 10 (simpsa) requires upper and lower bounds') else bounds=[-Inf(n_params,1) Inf(n_params,1)]; From 2809afaa11ecbb049ae0a5251d37a82b335ba608 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 24 Feb 2015 14:41:29 +0100 Subject: [PATCH 016/210] macroprocessor: add support for passing macro values to @#include statement, closes #848 --- preprocessor/macro/MacroFlex.ll | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/preprocessor/macro/MacroFlex.ll b/preprocessor/macro/MacroFlex.ll index be908019c..3fede037e 100644 --- a/preprocessor/macro/MacroFlex.ll +++ b/preprocessor/macro/MacroFlex.ll @@ -84,6 +84,32 @@ CONT \\\\ BEGIN(INITIAL); } +^{SPC}*@#{SPC}*include{SPC}+[^\"\r\n]*{SPC}*{EOL} { + yylloc->lines(1); + yylloc->step(); + + // Get variable name + string *modvarname = new string(yytext); + int dblq_idx1 = modvarname->find("include"); + modvarname->erase(0, dblq_idx1 + 7); + modvarname->erase(0, modvarname->find_first_not_of(" \t")); + size_t p = modvarname->find_last_not_of(" \t\n\r"); + if (string::npos != p) + modvarname->erase(p+1); + + string *filename; + try + { + filename = new string(driver.get_variable(*modvarname)->toString()); + } + catch(MacroDriver::UnknownVariable(&e)) + { + driver.error(*yylloc, "Unknown variable: " + *modvarname); + } + create_include_context(filename, yylloc, driver); + BEGIN(INITIAL); + } + ^{SPC}*@# { yylloc->step(); BEGIN(STMT); } @\{ { yylloc->step(); BEGIN(EXPR); } From e19f03b4204f0e363f5a2c1b13833a1d8208eb65 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 24 Feb 2015 16:38:36 +0100 Subject: [PATCH 017/210] replace reporting code with submodule. closes #811 --- .gitmodules | 3 + matlab/dynare_config.m | 2 +- matlab/modules/reporting | 1 + matlab/reports/@graph/addSeries.m | 22 -- matlab/reports/@graph/display.m | 32 --- matlab/reports/@graph/end.m | 35 --- matlab/reports/@graph/graph.m | 219 -------------- matlab/reports/@graph/subsasgn.m | 49 ---- matlab/reports/@graph/subsref.m | 53 ---- matlab/reports/@graph/write.m | 39 --- matlab/reports/@graph/writeGraphFile.m | 271 ------------------ matlab/reports/@page/addSection.m | 34 --- matlab/reports/@page/display.m | 32 --- matlab/reports/@page/end.m | 35 --- matlab/reports/@page/numSections.m | 32 --- matlab/reports/@page/page.m | 101 ------- matlab/reports/@page/subsasgn.m | 46 --- matlab/reports/@page/subsref.m | 48 ---- matlab/reports/@page/write.m | 66 ----- matlab/reports/@paragraph/display.m | 32 --- matlab/reports/@paragraph/paragraph.m | 63 ---- matlab/reports/@paragraph/subsasgn.m | 50 ---- matlab/reports/@paragraph/subsref.m | 48 ---- matlab/reports/@paragraph/write.m | 70 ----- matlab/reports/@report/addGraph.m | 34 --- matlab/reports/@report/addPage.m | 37 --- matlab/reports/@report/addParagraph.m | 34 --- matlab/reports/@report/addSection.m | 33 --- matlab/reports/@report/addSeries.m | 38 --- matlab/reports/@report/addTable.m | 34 --- matlab/reports/@report/addVspace.m | 34 --- matlab/reports/@report/compile.m | 122 -------- matlab/reports/@report/display.m | 32 --- matlab/reports/@report/numPages.m | 32 --- matlab/reports/@report/report.m | 93 ------ matlab/reports/@report/subsasgn.m | 46 --- matlab/reports/@report/subsref.m | 48 ---- matlab/reports/@report/write.m | 98 ------- matlab/reports/@report_series/display.m | 32 --- .../reports/@report_series/getNameForLegend.m | 31 -- matlab/reports/@report_series/getRange.m | 27 -- matlab/reports/@report_series/getTexName.m | 29 -- matlab/reports/@report_series/printSeries.m | 57 ---- matlab/reports/@report_series/report_series.m | 107 ------- .../@report_series/setDataToZeroFromZeroTol.m | 28 -- matlab/reports/@report_series/subsasgn.m | 42 --- matlab/reports/@report_series/subsref.m | 46 --- .../@report_series/writeSeriesForGraph.m | 145 ---------- .../@report_series/writeSeriesForTable.m | 105 ------- matlab/reports/@report_series/ymax.m | 23 -- matlab/reports/@report_series/ymin.m | 23 -- matlab/reports/@report_table/addSeries.m | 22 -- matlab/reports/@report_table/display.m | 32 --- matlab/reports/@report_table/report_table.m | 145 ---------- matlab/reports/@report_table/subsasgn.m | 45 --- matlab/reports/@report_table/subsref.m | 46 --- matlab/reports/@report_table/write.m | 39 --- matlab/reports/@report_table/writeTableFile.m | 200 ------------- matlab/reports/@section/addGraph.m | 38 --- matlab/reports/@section/addParagraph.m | 42 --- matlab/reports/@section/addTable.m | 38 --- matlab/reports/@section/addVspace.m | 37 --- matlab/reports/@section/display.m | 32 --- matlab/reports/@section/end.m | 35 --- matlab/reports/@section/numElements.m | 22 -- matlab/reports/@section/section.m | 60 ---- matlab/reports/@section/subsasgn.m | 50 ---- matlab/reports/@section/subsref.m | 48 ---- matlab/reports/@section/write.m | 89 ------ matlab/reports/@vspace/display.m | 32 --- matlab/reports/@vspace/subsasgn.m | 49 ---- matlab/reports/@vspace/subsref.m | 48 ---- matlab/reports/@vspace/vspace.m | 67 ----- matlab/reports/@vspace/write.m | 44 --- matlab/reports/allCellsAreDates.m | 39 --- matlab/reports/allCellsAreDatesRange.m | 39 --- matlab/reports/areParensNext.m | 26 -- matlab/reports/display_reporting_object.m | 95 ------ matlab/reports/getMaxRange.m | 36 --- 79 files changed, 5 insertions(+), 4283 deletions(-) create mode 160000 matlab/modules/reporting delete mode 100644 matlab/reports/@graph/addSeries.m delete mode 100644 matlab/reports/@graph/display.m delete mode 100644 matlab/reports/@graph/end.m delete mode 100644 matlab/reports/@graph/graph.m delete mode 100644 matlab/reports/@graph/subsasgn.m delete mode 100644 matlab/reports/@graph/subsref.m delete mode 100644 matlab/reports/@graph/write.m delete mode 100644 matlab/reports/@graph/writeGraphFile.m delete mode 100644 matlab/reports/@page/addSection.m delete mode 100644 matlab/reports/@page/display.m delete mode 100644 matlab/reports/@page/end.m delete mode 100644 matlab/reports/@page/numSections.m delete mode 100644 matlab/reports/@page/page.m delete mode 100644 matlab/reports/@page/subsasgn.m delete mode 100644 matlab/reports/@page/subsref.m delete mode 100644 matlab/reports/@page/write.m delete mode 100644 matlab/reports/@paragraph/display.m delete mode 100644 matlab/reports/@paragraph/paragraph.m delete mode 100644 matlab/reports/@paragraph/subsasgn.m delete mode 100644 matlab/reports/@paragraph/subsref.m delete mode 100644 matlab/reports/@paragraph/write.m delete mode 100644 matlab/reports/@report/addGraph.m delete mode 100644 matlab/reports/@report/addPage.m delete mode 100644 matlab/reports/@report/addParagraph.m delete mode 100644 matlab/reports/@report/addSection.m delete mode 100644 matlab/reports/@report/addSeries.m delete mode 100644 matlab/reports/@report/addTable.m delete mode 100644 matlab/reports/@report/addVspace.m delete mode 100644 matlab/reports/@report/compile.m delete mode 100644 matlab/reports/@report/display.m delete mode 100644 matlab/reports/@report/numPages.m delete mode 100644 matlab/reports/@report/report.m delete mode 100644 matlab/reports/@report/subsasgn.m delete mode 100644 matlab/reports/@report/subsref.m delete mode 100644 matlab/reports/@report/write.m delete mode 100644 matlab/reports/@report_series/display.m delete mode 100644 matlab/reports/@report_series/getNameForLegend.m delete mode 100644 matlab/reports/@report_series/getRange.m delete mode 100644 matlab/reports/@report_series/getTexName.m delete mode 100644 matlab/reports/@report_series/printSeries.m delete mode 100644 matlab/reports/@report_series/report_series.m delete mode 100644 matlab/reports/@report_series/setDataToZeroFromZeroTol.m delete mode 100644 matlab/reports/@report_series/subsasgn.m delete mode 100644 matlab/reports/@report_series/subsref.m delete mode 100644 matlab/reports/@report_series/writeSeriesForGraph.m delete mode 100644 matlab/reports/@report_series/writeSeriesForTable.m delete mode 100644 matlab/reports/@report_series/ymax.m delete mode 100644 matlab/reports/@report_series/ymin.m delete mode 100644 matlab/reports/@report_table/addSeries.m delete mode 100644 matlab/reports/@report_table/display.m delete mode 100644 matlab/reports/@report_table/report_table.m delete mode 100644 matlab/reports/@report_table/subsasgn.m delete mode 100644 matlab/reports/@report_table/subsref.m delete mode 100644 matlab/reports/@report_table/write.m delete mode 100644 matlab/reports/@report_table/writeTableFile.m delete mode 100644 matlab/reports/@section/addGraph.m delete mode 100644 matlab/reports/@section/addParagraph.m delete mode 100644 matlab/reports/@section/addTable.m delete mode 100644 matlab/reports/@section/addVspace.m delete mode 100644 matlab/reports/@section/display.m delete mode 100644 matlab/reports/@section/end.m delete mode 100644 matlab/reports/@section/numElements.m delete mode 100644 matlab/reports/@section/section.m delete mode 100644 matlab/reports/@section/subsasgn.m delete mode 100644 matlab/reports/@section/subsref.m delete mode 100644 matlab/reports/@section/write.m delete mode 100644 matlab/reports/@vspace/display.m delete mode 100644 matlab/reports/@vspace/subsasgn.m delete mode 100644 matlab/reports/@vspace/subsref.m delete mode 100644 matlab/reports/@vspace/vspace.m delete mode 100644 matlab/reports/@vspace/write.m delete mode 100644 matlab/reports/allCellsAreDates.m delete mode 100644 matlab/reports/allCellsAreDatesRange.m delete mode 100644 matlab/reports/areParensNext.m delete mode 100644 matlab/reports/display_reporting_object.m delete mode 100644 matlab/reports/getMaxRange.m diff --git a/.gitmodules b/.gitmodules index 3c608c798..7f1ae195c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -21,3 +21,6 @@ path = matlab/modules/dseries url = https://github.com/DynareTeam/dseries.git branch = old-oop-style +[submodule "matlab/modules/reporting"] + path = matlab/modules/reporting + url = https://github.com/DynareTeam/reporting.git diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index b2544d9b1..9a8ca5bb4 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -66,7 +66,7 @@ addpath([dynareroot '/utilities/doc/']) addpath([dynareroot '/utilities/tests/src/']) addpath([dynareroot '/utilities/dataset/']) addpath([dynareroot '/utilities/general/']) -addpath([dynareroot '/reports/']) +addpath([dynareroot '/modules/reporting/src/']) % For functions that exist only under some Octave versions % or some MATLAB versions, and for which we provide some replacement functions diff --git a/matlab/modules/reporting b/matlab/modules/reporting new file mode 160000 index 000000000..d242c9249 --- /dev/null +++ b/matlab/modules/reporting @@ -0,0 +1 @@ +Subproject commit d242c92493693a8dc3b369f36b8762d8c31179fd diff --git a/matlab/reports/@graph/addSeries.m b/matlab/reports/@graph/addSeries.m deleted file mode 100644 index 6a0f6d23e..000000000 --- a/matlab/reports/@graph/addSeries.m +++ /dev/null @@ -1,22 +0,0 @@ -function o = addSeries(o, varargin) -% function o = addSeries(o, varargin) - -% Copyright (C) 2013-2014 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 . - -o.series{end+1} = report_series(varargin{:}); -end \ No newline at end of file diff --git a/matlab/reports/@graph/display.m b/matlab/reports/@graph/display.m deleted file mode 100644 index 02ad369e4..000000000 --- a/matlab/reports/@graph/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Graph object -% -% INPUTS -% o [graph] graph object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@graph/end.m b/matlab/reports/@graph/end.m deleted file mode 100644 index 9fd4da3a1..000000000 --- a/matlab/reports/@graph/end.m +++ /dev/null @@ -1,35 +0,0 @@ -function lastIndex = end(o, k, n) -% function lastIndex = end(o, k, n) -% End keyword -% -% INPUTS -% o [graph] graph object -% k [integer] index where end appears -% n [integer] number of indices -% -% OUTPUTS -% lastIndex [integer] last graph index -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -assert(k==1 && n==1, '@graph/end: graph only has one dimension'); -lastIndex = length(o.series); -end \ No newline at end of file diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m deleted file mode 100644 index d33b80ed0..000000000 --- a/matlab/reports/@graph/graph.m +++ /dev/null @@ -1,219 +0,0 @@ -function o = graph(varargin) -%function o = graph(varargin) -% Graph Class Constructor -% -% INPUTS -% varargin 0 args : empty graph object -% 1 arg : must be graph object (return a copy of arg) -% > 1 args: option/value pairs (see structure below for -% options) -% -% OUTPUTS -% o [graph] graph object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o = struct; - -o.series = {}; - -o.title = ''; -o.titleFormat = ''; -o.titleFontSize = 'normalsize'; -o.ylabel = ''; -o.xlabel = ''; - -o.axisShape = 'box'; - -o.graphDirName = 'tmpRepDir'; -o.graphName = ''; -o.data = ''; -o.seriesToUse = ''; -o.xrange = ''; -o.xAxisTight = true; -o.yrange = ''; -o.yAxisTight = false; - -o.shade = ''; -o.shadeColor = 'green'; -o.shadeOpacity = 20; - -o.showGrid = true; - -o.showLegend = false; -o.legendAt = []; -o.showLegendBox = false; -o.legendLocation = 'south east'; -o.legendOrientation = 'horizontal'; -o.legendFontSize = 'tiny'; - -o.showZeroline = false; -o.zeroLineColor = 'black'; - -o.xTicks = []; -o.xTickLabels = {}; -o.xTickLabelRotation = 0; -o.xTickLabelAnchor = 'east'; - -o.yTickLabelScaled = true; -o.yTickLabelPrecision = 0; -o.yTickLabelFixed = true; -o.yTickLabelZeroFill = true; - -o.tickFontSize = 'normalsize'; - -o.width = 6; -o.height = 4.5; - -o.miscTikzPictureOptions = ''; -o.miscTikzAxisOptions = ''; - -o.writeCSV = false; - -if nargin == 1 - assert(isa(varargin{1}, 'graph'),['@graph.graph: with one arg you ' ... - 'must pass a graph object']); - o = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['@graph.graph: options must be supplied in name/value ' ... - 'pairs.']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('@graph.graph: %s is not a recognized option.', pair{1}); - end - end -end - -% Check options provided by user -if ischar(o.title) - o.title = {o.title}; -end -assert(iscellstr(o.title), '@graph.graph: title must be a cell array of string(s)'); -assert(ischar(o.titleFormat), '@graph.graph: titleFormat file must be a string'); -assert(ischar(o.xlabel), '@graph.graph: xlabel file must be a string'); -assert(ischar(o.ylabel), '@graph.graph: ylabel file must be a string'); -assert(ischar(o.miscTikzPictureOptions), '@graph.graph: miscTikzPictureOptions file must be a string'); -assert(ischar(o.miscTikzAxisOptions), '@graph.graph: miscTikzAxisOptions file must be a string'); -assert(ischar(o.graphName), '@graph.graph: graphName must be a string'); -assert(ischar(o.graphDirName), '@graph.graph: graphDirName must be a string'); -assert(islogical(o.showGrid), '@graph.graph: showGrid must be either true or false'); -assert(islogical(o.xAxisTight), '@graph.graph: xAxisTight must be either true or false'); -assert(islogical(o.yAxisTight), '@graph.graph: yAxisTight must be either true or false'); -assert(islogical(o.showLegend), '@graph.graph: showLegend must be either true or false'); -assert(isempty(o.legendAt) || (isfloat(o.legendAt) && length(o.legendAt)==2), ... - '@graph.graph: legendAt must be a double array of size two'); -assert(islogical(o.showLegendBox), '@graph.graph: showLegendBox must be either true or false'); -assert(islogical(o.showZeroline), '@graph.graph: showZeroline must be either true or false'); -assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ... - o.shadeOpacity >= 0 && o.shadeOpacity <= 100, ... - '@graph.graph: o.shadeOpacity must be a real in [0 100]'); -assert(isfloat(o.width), '@graph.graph: o.width must be a real number'); -assert(isfloat(o.height), '@graph.graph: o.height must be a real number'); -assert(isfloat(o.xTickLabelRotation), '@graph.graph: o.xTickLabelRotation must be a real number'); -assert(ischar(o.xTickLabelAnchor), '@graph.graph: xTickLabelAnchor must be a string'); -assert(isint(o.yTickLabelPrecision), '@graph.graph: o.yTickLabelPrecision must be an integer'); -assert(islogical(o.yTickLabelFixed), '@graph.graph: yTickLabelFixed must be either true or false'); -assert(islogical(o.yTickLabelZeroFill), '@graph.graph: yTickLabelZeroFill must be either true or false'); -assert(islogical(o.yTickLabelScaled), '@graph.graph: yTickLabelScaled must be either true or false'); -assert(islogical(o.writeCSV), '@graph.graph: writeCSV must be either true or false'); -assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string'); -assert(ischar(o.zeroLineColor), '@graph.graph: zeroLineColor must be a string'); -assert(any(strcmp(o.axisShape, {'box', 'L'})), ['@graph.graph: axisShape ' ... - 'must be one of ''box'' or ''L''']); -valid_legend_locations = ... - {'south west','south east','north west','north east','outer north east'}; -assert(any(strcmp(o.legendLocation, valid_legend_locations)), ... - ['@graph.graph: legendLocation must be one of ' strjoin(valid_legend_locations, ' ')]); - -valid_font_sizes = {'tiny', 'scriptsize', 'footnotesize', 'small', ... - 'normalsize', 'large', 'Large', 'LARGE', 'huge', 'Huge'}; -assert(any(strcmp(o.legendFontSize, valid_font_sizes)), ... - ['@graph.graph: legendFontSize must be one of ' strjoin(valid_font_sizes)]); -assert(any(strcmp(o.titleFontSize, valid_font_sizes)), ... - ['@graph.graph: titleFontSize must be one of ' strjoin(valid_font_sizes)]); -assert(any(strcmp(o.tickFontSize, valid_font_sizes)), ... - ['@graph.graph: tickFontSize must be one of ' strjoin(valid_font_sizes)]); - -valid_legend_orientations = {'vertical', 'horizontal'}; -assert(any(strcmp(o.legendOrientation, valid_legend_orientations)), ... - ['@graph.graph: legendOrientation must be one of ' strjoin(valid_legend_orientations, ' ')]); - -assert(isempty(o.shade) || (isdates(o.shade) && o.shade.ndat >= 2), ... - ['@graph.graph: shade is specified as a dates range, e.g. ' ... - '''dates(''1999q1''):dates(''1999q3'')''.']); -assert(isempty(o.xrange) || (isdates(o.xrange) && o.xrange.ndat >= 2), ... - ['@graph.graph: xrange is specified as a dates range, e.g. ' ... - '''dates(''1999q1''):dates(''1999q3'')''.']); -assert(isempty(o.yrange) || (isfloat(o.yrange) && length(o.yrange) == 2 && ... - o.yrange(1) < o.yrange(2)), ... - ['@graph.graph: yrange is specified an array with two float entries, ' ... - 'the lower bound and upper bound.']); -assert(isempty(o.data) || isdseries(o.data), ['@graph.graph: data must ' ... - 'be a dseries']); -assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ['@graph.graph: ' ... - 'seriesToUse must be a cell array of string(s)']); -assert(isempty(o.xTicks) || isfloat(o.xTicks),... - '@graph.graph: xTicks must be a numerical array'); -assert(iscellstr(o.xTickLabels) || (ischar(o.xTickLabels) && strcmpi(o.xTickLabels, 'ALL')), ... - ['@graph.graph: xTickLabels must be a cell array of strings or ' ... - 'equivalent to the string ''ALL''']); -if ~isempty(o.xTickLabels) - assert((ischar(o.xTickLabels) && strcmpi(o.xTickLabels, 'ALL')) || ... - ~isempty(o.xTicks), ['@graph.graph: if you set xTickLabels and ' ... - 'it''s not equal to ''ALL'', you must set xTicks']); -end -if ~isempty(o.xTicks) - assert(~isempty(o.xTickLabels), '@graph.graph: if you set xTicks, you must set xTickLabels'); -end - -% using o.seriesToUse, create series objects and put them in o.series -if ~isempty(o.data) - if isempty(o.seriesToUse) - for i=1:o.data.vobs - o.series{end+1} = report_series('data', o.data{o.data.name{i}}); - end - else - for i=1:length(o.seriesToUse) - o.series{end+1} = report_series('data', o.data{o.seriesToUse{i}}); - end - end -end -o = rmfield(o, 'seriesToUse'); -o = rmfield(o, 'data'); - -if ~exist(o.graphDirName, 'file') - mkdir(o.graphDirName); -end - -% Create graph object -o = class(o, 'graph'); -end \ No newline at end of file diff --git a/matlab/reports/@graph/subsasgn.m b/matlab/reports/@graph/subsasgn.m deleted file mode 100644 index 2048ab408..000000000 --- a/matlab/reports/@graph/subsasgn.m +++ /dev/null @@ -1,49 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2013-2014 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '()' - index = S.subs{:}; - assert(isnumeric(index)); - B.series{index} = V; - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@graph.subsasgn: field ' S.subs 'does not exist']); - end - case '{}' - assert(isint(S.subs{1})); - B{S.subs{1}} = V; - otherwise - error('@graph.subsasgn: syntax error'); -end -end \ No newline at end of file diff --git a/matlab/reports/@graph/subsref.m b/matlab/reports/@graph/subsref.m deleted file mode 100644 index 6643f3f56..000000000 --- a/matlab/reports/@graph/subsref.m +++ /dev/null @@ -1,53 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2013-2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@graph.subsref: unknown field or method: ' S(1).subs]); - end - case '()' - if isempty(S(1).subs{:}) - A = A.series; - else - assert(isnumeric(S(1).subs{:})); - A = A.series{S(1).subs{:}}; - end - case '{}' - A = A.series{S(1).subs{:}}; - otherwise - error('@graph.subsref: impossible case') -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@graph/write.m b/matlab/reports/@graph/write.m deleted file mode 100644 index bdb91a117..000000000 --- a/matlab/reports/@graph/write.m +++ /dev/null @@ -1,39 +0,0 @@ -function o = write(o, fid, pg, sec, row, col) -%function o = write(o, fid, pg, sec, row, col) -% Write a Graph object -% -% INPUTS -% o [graph] graph object -% fid [integer] file id -% pg [integer] this page number -% sec [integer] this section number -% row [integer] this row number -% col [integer] this col number -% -% OUTPUTS -% o [graph] graph object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -assert(fid ~= -1); -o = writeGraphFile(o, pg, sec, row, col); -fprintf(fid, '\\input{%s}', o.graphName); -end \ No newline at end of file diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m deleted file mode 100644 index 0e53fe0d1..000000000 --- a/matlab/reports/@graph/writeGraphFile.m +++ /dev/null @@ -1,271 +0,0 @@ -function o = writeGraphFile(o, pg, sec, row, col) -%function o = writeGraphFile(o, pg, sec, row, col) -% Write the tikz file that contains the graph -% -% INPUTS -% o [graph] graph object -% pg [integer] this page number -% sec [integer] this section number -% row [integer] this row number -% col [integer] this col number -% -% OUTPUTS -% o [graph] graph object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -ne = length(o.series); -if ne < 1 - warning('@graph.writeGraphFile: no series to plot, returning'); - return; -end - -if isempty(o.graphName) - o.graphName = sprintf('%s/graph_pg%d_sec%d_row%d_col%d.tex', o.graphDirName, pg, sec, row, col); -else - o.graphName = [o.graphDirName '/' o.graphName]; -end - -[fid, msg] = fopen(o.graphName, 'w'); -if fid == -1 - error(['@graph.writeGraphFile: ' msg]); -end - -fprintf(fid, '\\begin{tikzpicture}[baseline'); -if ~isempty(o.miscTikzPictureOptions) - fprintf(fid, ',%s', o.miscTikzPictureOptions); -end -fprintf(fid, ']'); - -if isempty(o.xrange) - dd = getMaxRange(o.series); -else - dd = o.xrange; -end - -fprintf(fid, '\\begin{axis}[%%\n'); -% set tick labels -if isempty(o.xTickLabels) - stringsdd = strings(dd); - if ~isempty(o.shade) - x1 = find(strcmpi(date2string(o.shade(1)), stringsdd)); - x2 = find(strcmpi(date2string(o.shade(end)), stringsdd)); - if x1 == 1 - x = [1 x2 dd.ndat]; - xTickLabels = [stringsdd(1) stringsdd(x2) stringsdd(end)]; - elseif x2 == dd.ndat - x = [1 x1 dd.ndat]; - xTickLabels = [stringsdd(1) stringsdd(x1) stringsdd(end)]; - else - x = [1 x1 x2 dd.ndat]; - xTickLabels = [stringsdd(1) stringsdd(x1) stringsdd(x2) stringsdd(end)]; - end - else - x = [1 dd.ndat]; - xTickLabels = [stringsdd(1) stringsdd(end)]; - end - fprintf(fid, 'xminorticks=true,\nyminorticks=true,\n'); -elseif iscell(o.xTickLabels) - fprintf(fid,'minor xtick,\n'); - x = o.xTicks; - xTickLabels = o.xTickLabels; -else - x = [1:dd.ndat]; - xTickLabels = strings(dd); -end -fprintf(fid, 'xticklabels={'); -xlen = length(x); -for i = 1:xlen - fprintf(fid,'%s,',lower(xTickLabels{i})); -end -fprintf(fid, '},\nxtick={'); -for i = 1:xlen - fprintf(fid, '%d',x(i)); - if i ~= length(x) - fprintf(fid,','); - end -end -fprintf(fid, '},\ny tick label style={\n/pgf/number format/.cd,\n'); -if o.yTickLabelFixed - fprintf(fid, 'fixed,\n'); -end -if o.yTickLabelZeroFill - fprintf(fid, 'zerofill,\n'); -end -fprintf(fid, 'precision=%d,\n/tikz/.cd\n},\n', o.yTickLabelPrecision); -fprintf(fid, 'x tick label style={rotate=%f', o.xTickLabelRotation); -if o.xTickLabelRotation ~= 0 - fprintf(fid, ',anchor=%s', o.xTickLabelAnchor); -end -fprintf(fid, ['},\n',... - 'width=%fin,\n'... - 'height=%fin,\n'... - 'scale only axis,\n'... - 'unbounded coords=jump,\n'], o.width, o.height); - -if strcmpi(o.axisShape, 'box') - fprintf(fid, 'axis lines=box,\n'); -elseif strcmpi(o.axisShape, 'L') - fprintf(fid, 'axis x line=bottom,\naxis y line=left,\n'); -end - -if ~isempty(o.title{1}) - fprintf(fid, 'title style={align=center'); - if ~isempty(o.titleFormat) - fprintf(fid, ',font=%s', o.titleFormat); - end - fprintf(fid, '},\ntitle='); - nt = length(o.title); - for i=1:nt - fprintf(fid, '%s', o.title{i}); - if i ~= nt - fprintf(fid, '\\\\'); - end - end - fprintf(fid, ',\n'); -end - -if o.xAxisTight - fprintf(fid, 'enlarge x limits=false,\n'); -else - fprintf(fid, 'enlarge x limits=true,\n'); -end - -if isempty(o.yrange) - if o.yAxisTight - fprintf(fid, 'enlarge y limits=false,\n'); - else - fprintf(fid, 'enlarge y limits=true,\n'); - end -else - fprintf(fid, 'ymin=%f,\nymax=%f,\n',o.yrange(1),o.yrange(2)); -end -fprintf(fid, 'xmin = 1,\nxmax = %d,\n', length(dd)); - -if o.showLegend - fprintf(fid, 'legend style={'); - if ~o.showLegendBox - fprintf(fid, 'draw=none,'); - end - fprintf(fid, 'font=\\%s,', o.legendFontSize); - if strcmp(o.legendOrientation, 'horizontal') - fprintf(fid,'legend columns=-1,'); - end - if isempty(o.legendAt) - fprintf(fid, '},\nlegend pos=%s,\n', o.legendLocation); - else - fprintf(fid, 'at={(%f,%f)}},\n',o.legendAt(1),o.legendAt(2)); - end -end - -fprintf(fid, 'tick label style={font=\\%s},\n', o.tickFontSize); - -if o.showGrid - fprintf(fid, 'xmajorgrids=true,\nymajorgrids=true,\n'); -end - -if ~isempty(o.xlabel) - fprintf(fid, 'xlabel=%s,\n', o.xlabel); -end - -if ~isempty(o.ylabel) - fprintf(fid, 'ylabel=%s,\n', o.ylabel); -end - -if ~o.yTickLabelScaled - fprintf(fid, 'scaled y ticks = false,\n'); -end - -if ~isempty(o.miscTikzAxisOptions) - fprintf(fid, '%s', o.miscTikzAxisOptions); -end -fprintf(fid, ']\n'); - -if ~isempty(o.title{1}) - fprintf(fid, '\\pgfplotsset{every axis title/.append style={}}=[font=\\%s]\n', o.titleFontSize); -end - -if ~isempty(o.shade) - fprintf(fid, '%%shading\n'); - stringsdd = strings(dd); - x1 = find(strcmpi(date2string(o.shade(1)), stringsdd)); - x2 = find(strcmpi(date2string(o.shade(end)), stringsdd)); - assert(~isempty(x1) && ~isempty(x2), ['@graph.writeGraphFile: either ' ... - date2string(o.shade(1)) ' or ' date2string(o.shade(end)) ' is not in the date ' ... - 'range of data selected.']); - if x1 == 1 - fprintf(fid,['\\begin{pgfonlayer}{background0}\n\\fill[%s!%f]\n(axis ' ... - 'cs:\\pgfkeysvalueof{/pgfplots/xmin},\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ... - 'cs:%f,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ... - o.shadeColor, o.shadeOpacity, x2); - elseif x2 == dd.ndat - fprintf(fid,['\\begin{pgfonlayer}{background0}\n\\fill[%s!%f]\n(axis ' ... - 'cs:%f,\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ... - 'cs:\\pgfkeysvalueof{/pgfplots/xmax},\\pgfkeysvalueof{/' ... - 'pgfplots/ymax});\n\\end{pgfonlayer}\n'], ... - o.shadeColor, o.shadeOpacity, x1); - else - fprintf(fid,['\\begin{pgfonlayer}{background0}\n\\fill[%s!%f]\n(axis ' ... - 'cs:%f,\\pgfkeysvalueof{/pgfplots/ymin})\nrectangle (axis ' ... - 'cs:%f,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ... - o.shadeColor, o.shadeOpacity, x1, x2); - end -end - -if o.showZeroline - fprintf(fid, '%%zeroline\n\\addplot[%s,line width=.5,forget plot] coordinates {(1,0)(%d,0)};\n', ... - o.zeroLineColor, dd.ndat); -end - -if o.writeCSV - csvseries = dseries(); -end -for i=1:ne - o.series{i}.writeSeriesForGraph(fid, dd); - if o.writeCSV - csvseries = [csvseries ... - o.series{i}.data(dd).set_names([... - o.series{i}.data.name{:} '_' ... - o.series{i}.graphLegendName '_' ... - o.series{i}.graphLineColor '_' ... - o.series{i}.graphLineStyle '_' ... - num2str(o.series{i}.graphLineWidth) '_' ... - o.series{i}.graphMarker '_' ... - o.series{i}.graphMarkerEdgeColor '_' ... - o.series{i}.graphMarkerFaceColor '_' ... - num2str(o.series{i}.graphMarkerSize)]) ... - ]; - end - if o.showLegend - le = o.series{i}.getNameForLegend(); - if ~isempty(le) - fprintf(fid, '\\addlegendentry{%s}\n', le); - end - end -end -if o.writeCSV - csvseries.save(strrep(o.graphName, '.tex', ''), 'csv'); -end -fprintf(fid, '\\end{axis}\n\\end{tikzpicture}%%'); -if fclose(fid) == -1 - error('@graph.writeGraphFile: closing %s\n', o.filename); -end -end \ No newline at end of file diff --git a/matlab/reports/@page/addSection.m b/matlab/reports/@page/addSection.m deleted file mode 100644 index a99ffc22a..000000000 --- a/matlab/reports/@page/addSection.m +++ /dev/null @@ -1,34 +0,0 @@ -function p = addSection(p, varargin) -%function p = addSection(p, varargin) -% Add a section to the Cell Array of sections in the report -% -% INPUTS -% 1 args => add empty section -% 2 args => add given section -% 3 args => add section at index -% -% OUTPUTS -% updated page object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -p.sections{end+1} = section(varargin{:}); -end diff --git a/matlab/reports/@page/display.m b/matlab/reports/@page/display.m deleted file mode 100644 index 19595ba5e..000000000 --- a/matlab/reports/@page/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Page object -% -% INPUTS -% o [page] page object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@page/end.m b/matlab/reports/@page/end.m deleted file mode 100644 index 073a271b4..000000000 --- a/matlab/reports/@page/end.m +++ /dev/null @@ -1,35 +0,0 @@ -function lastIndex = end(o, k, n) -% function lastIndex = end(o, k, n) -% End keyword -% -% INPUTS -% o [page] page object -% k [integer] index where end appears -% n [integer] number of indices -% -% OUTPUTS -% lastIndex [integer] last sections index -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013 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 . - -assert(k==1 && n==1, '@page/end: page only has one dimension'); -lastIndex = numSections(o); -end \ No newline at end of file diff --git a/matlab/reports/@page/numSections.m b/matlab/reports/@page/numSections.m deleted file mode 100644 index aa0b0a1be..000000000 --- a/matlab/reports/@page/numSections.m +++ /dev/null @@ -1,32 +0,0 @@ -function ns = numSections(p) -%function ns = numSections(p) -% return the number of sections currently in the page -% -% INPUTS -% none -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -ns = length(p.sections); -end \ No newline at end of file diff --git a/matlab/reports/@page/page.m b/matlab/reports/@page/page.m deleted file mode 100644 index 290d9caaa..000000000 --- a/matlab/reports/@page/page.m +++ /dev/null @@ -1,101 +0,0 @@ -function o = page(varargin) -%function o = page(varargin) -% Page Class Constructor -% -% INPUTS -% 0 args => empty page -% 1 arg (page class) => copy object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-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 . - -o = struct; -o.paper = ''; -o.title = {''}; -titleFormatDefalut = {'\large\bfseries'}; -o.titleFormat = titleFormatDefalut; -o.titleTruncate = ''; -o.orientation = ''; -o.footnote = {}; -o.sections = {}; - -if nargin == 1 - assert(isa(varargin{1}, 'page'), ['@page.page: with one arg to Page ' ... - 'constructor, you must pass a page object']); - o = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['@page.page: options must be supplied in name/value ' ... - 'pairs.']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('@page.page: %s is not a recognized option.', pair{1}); - end - end -end - -% Check options provided by user -if ischar(o.title) - o.title = {o.title}; -end -if ischar(o.titleFormat) - o.titleFormat = {o.titleFormat}; -end -if length(o.title) ~= length(o.titleFormat) - o.titleFormat = repmat(titleFormatDefalut, 1, length(o.title)); -end -assert(iscellstr(o.title), ... - '@page.page: title must be a cell array of strings'); -assert(iscellstr(o.titleFormat), ... - '@page.page: titleFormat must be a cell array of strings'); -assert((ischar(o.titleTruncate) && isempty(o.titleTruncate)) || ... - isint(o.titleTruncate), ... - '@page.page: titleTruncate must be empty or an integer.'); - -valid_paper = {'a4', 'letter'}; -assert(any(strcmp(o.paper, valid_paper)), ... - ['@page.page: paper must be one of ' strjoin(valid_paper, ' ')]); - -valid_orientation = {'portrait', 'landscape'}; -assert(any(strcmp(o.orientation, valid_orientation)), ... - ['@page.page: orientation must be one of ' strjoin(valid_orientation, ' ')]); - -if ischar(o.footnote) - o.footnote = {o.footnote}; -end -assert(iscellstr(o.footnote), ... - '@page.page: footnote must be a cell array of string(s)'); - -% Create page object -o = class(o, 'page'); -end diff --git a/matlab/reports/@page/subsasgn.m b/matlab/reports/@page/subsasgn.m deleted file mode 100644 index 00e85ae2d..000000000 --- a/matlab/reports/@page/subsasgn.m +++ /dev/null @@ -1,46 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2013 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '()' - index = S.subs{:}; - assert(isnumeric(index)); - B{index} = V; - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@page.subsasgn: field ' S.subs 'does not exist']); - end - otherwise - error('@page.subsasgn: syntax error'); -end -end \ No newline at end of file diff --git a/matlab/reports/@page/subsref.m b/matlab/reports/@page/subsref.m deleted file mode 100644 index 7ad0befc8..000000000 --- a/matlab/reports/@page/subsref.m +++ /dev/null @@ -1,48 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2013-2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@page.subsref: unknown field or method: ' S(1).subs]); - end - case '()' - A = getSections(A, S(1).subs{:}); - case '{}' - error(['@page.subsref: ' S(1).type ' indexing not supported.']); - otherwise - error('@page.subsref: impossible case') -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@page/write.m b/matlab/reports/@page/write.m deleted file mode 100644 index 6a66fd69a..000000000 --- a/matlab/reports/@page/write.m +++ /dev/null @@ -1,66 +0,0 @@ -function o = write(o, fid, pg) -%function o = write(o, fid, pg) -% Write a Page object -% -% INPUTS -% o [page] page object -% fid [integer] file id -% pg [integer] this page number -% -% OUTPUTS -% o [page] page object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-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 . - -assert(fid ~= -1); - -fprintf(fid, '\n%% Page Object\n'); -if strcmpi(o.orientation, 'landscape') - fprintf(fid, '\\begin{landscape}\n'); -end - -for i=1:length(o.footnote) - fprintf(fid, '\\blfootnote{\\tiny %d. %s}', i, o.footnote{i}); -end -fprintf(fid,'\n'); - -fprintf(fid, '\\begin{tabular}[t]{c}\n'); -for i=1:length(o.title) - if isint(o.titleTruncate) - if length(o.title{i}) > o.titleTruncate - o.title{i} = o.title{i}(1:o.titleTruncate); - end - end - fprintf(fid,'\\multicolumn{1}{c}{%s %s}\\\\\n', o.titleFormat{i}, o.title{i}); -end - -nps = length(o.sections); -for i=1:nps - o.sections{i}.write(fid, pg, i); -end - -fprintf(fid, '\\end{tabular}\n'); -if strcmpi(o.orientation, 'landscape') - fprintf(fid, '\\end{landscape}\n'); -end -fprintf(fid, '\\clearpage\n'); -fprintf(fid, '%% End Page Object\n\n'); -end \ No newline at end of file diff --git a/matlab/reports/@paragraph/display.m b/matlab/reports/@paragraph/display.m deleted file mode 100644 index f731c9c5d..000000000 --- a/matlab/reports/@paragraph/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Paragraph object -% -% INPUTS -% o [paragraph] paragraph object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@paragraph/paragraph.m b/matlab/reports/@paragraph/paragraph.m deleted file mode 100644 index 4cf6106b2..000000000 --- a/matlab/reports/@paragraph/paragraph.m +++ /dev/null @@ -1,63 +0,0 @@ -function o = paragraph(varargin) -%function o = paragraph(varargin) -% Instantiates a paragraph object - -% Copyright (C) 2014 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 . - -o = struct; - -o.balancedCols = false; -o.cols = 1; -o.heading = ''; -o.indent = true; -o.text = ''; - -if nargin == 1 - assert(isa(varargin{1}, 'paragraph'),['With one arg to Paragraph constructor, ' ... - 'you must pass a paragraph object']); - o = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['@paragraph.paragraph: options must be supplied in name/value ' ... - 'pairs.']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('@paragraph.paragraph: %s is not a recognized option.', pair{1}); - end - end -end - -assert(islogical(o.indent), '@paragraph.paragraph: indent must be either true or false'); -assert(islogical(o.balancedCols), '@paragraph.paragraph: balancedCols must be either true or false'); -assert(isint(o.cols), '@paragraph.paragraph: cols must be an integer'); -assert(ischar(o.text), '@paragraph.paragraph: text must be a string'); -assert(ischar(o.heading), '@paragraph.paragraph: heading must be a string'); - -% Create paragraph object -o = class(o, 'paragraph'); -end diff --git a/matlab/reports/@paragraph/subsasgn.m b/matlab/reports/@paragraph/subsasgn.m deleted file mode 100644 index 429c48ccd..000000000 --- a/matlab/reports/@paragraph/subsasgn.m +++ /dev/null @@ -1,50 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2014 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '()' - index = S.subs{:}; - assert(isnumeric(index)); - B.elements{index} = V; - case '{}' - index = S.subs{:}; - assert(isnumeric(index)); - B{index} = V; - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@paragraph.subsasgn: field ' S.subs 'does not exist']); - end - otherwise - error('@paragraph.subsasgn: syntax error'); -end -end \ No newline at end of file diff --git a/matlab/reports/@paragraph/subsref.m b/matlab/reports/@paragraph/subsref.m deleted file mode 100644 index f3dd2c55b..000000000 --- a/matlab/reports/@paragraph/subsref.m +++ /dev/null @@ -1,48 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@paragraph.subsref: unknown field or method: ' S(1).subs]); - end - case '()' - A = A.elements{S(1).subs{:}}; - case '{}' - error(['@paragraph.subsref: ' S(1).type ' indexing not supported.']); - otherwise - error('@paragraph.subsref: impossible case') -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@paragraph/write.m b/matlab/reports/@paragraph/write.m deleted file mode 100644 index 3397b44a1..000000000 --- a/matlab/reports/@paragraph/write.m +++ /dev/null @@ -1,70 +0,0 @@ -function o = write(o, fid) -%function o = write(o, fid) -% Write Paragraph object -% -% INPUTS -% o [paragraph] paragraph object -% fid [integer] file id -% -% OUTPUTS -% o [paragraph] paragraph object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2014 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 . - -assert(fid ~= -1); -fprintf(fid, '%% Paragraph Object\n\\multicolumn{1}{p{\\textwidth}}{%%\n'); -if o.cols ~= 1 - bc = ''; - if o.balancedCols - bc = '*'; - end - fprintf(fid, '\\begin{multicols%s}{%d}%%\n', bc, o.cols); -end - -if ~isempty(o.heading) - if o.cols ~= 1 - fprintf(fid, '[%s\n]\n', o.heading); - else - fprintf(fid, '%s\\newline \\newline\n', o.heading); - end -end - -if o.indent - fprintf(fid, '\\hspace{4ex}'); -end - -fprintf(fid, '%s', o.text); - -if o.cols ~= 1 - fprintf(fid, '\\end{multicols%s}\n', bc); -end -fprintf(fid, '}\n%% End Paragraph Object\n\n'); -end - - -%\multicolumn{1}{p{\textwidth}} -%{\begin{multicols}{2} -%Hello, here is some text without a meaning. This text should show what -%a printed text will look like at this place. -%\columnbreak -%If you read this text, you will get no information. Really? Is there -%no information? Is there... -%\end{multicols}}\\ \ No newline at end of file diff --git a/matlab/reports/@report/addGraph.m b/matlab/reports/@report/addGraph.m deleted file mode 100644 index 9e0e691e8..000000000 --- a/matlab/reports/@report/addGraph.m +++ /dev/null @@ -1,34 +0,0 @@ -function o = addGraph(o, varargin) -%function o = addGraph(o, varargin) -% Add a graph to the current section of the current page in the report -% -% INPUTS -% o [report] report object -% varargin arguments to @section/addGraph.m -% -% OUTPUTS -% o [report] updated report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o.pages{end}.sections{end} = ... - o.pages{end}.sections{end}.addGraph(varargin{:}); -end diff --git a/matlab/reports/@report/addPage.m b/matlab/reports/@report/addPage.m deleted file mode 100644 index 0fd7aa481..000000000 --- a/matlab/reports/@report/addPage.m +++ /dev/null @@ -1,37 +0,0 @@ -function o = addPage(o, varargin) -%function o = addPage(o, varargin) -% Add a page to the report -% -% INPUTS -% o [report] report object -% varargin arguments to @section/addGraph.m -% -% OUTPUTS -% o [report] updated report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -np = length(o.pages) + 1; -if o.showOutput - fprintf(1, 'Adding Page: %d\n', np); -end -o.pages{np} = page('orientation', o.orientation, 'paper', o.paper, varargin{:}); -end diff --git a/matlab/reports/@report/addParagraph.m b/matlab/reports/@report/addParagraph.m deleted file mode 100644 index 4ec7209a3..000000000 --- a/matlab/reports/@report/addParagraph.m +++ /dev/null @@ -1,34 +0,0 @@ -function o = addParagraph(o, varargin) -%function o = addParagraph(o, varargin) -% Add a paragraph to the current section of the current page in the report -% -% INPUTS -% o [report] report object -% varargin arguments to @section/addGraph.m -% -% OUTPUTS -% o [report] updated report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o.pages{end}.sections{end} = ... - o.pages{end}.sections{end}.addParagraph(varargin{:}); -end diff --git a/matlab/reports/@report/addSection.m b/matlab/reports/@report/addSection.m deleted file mode 100644 index 3387b9466..000000000 --- a/matlab/reports/@report/addSection.m +++ /dev/null @@ -1,33 +0,0 @@ -function o = addSection(o, varargin) -%function o = addSection(o, varargin) -% Add a section to the current page in the report -% -% INPUTS -% o [report] report object -% varargin arguments to @section/addGraph.m -% -% OUTPUTS -% o [report] updated report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o.pages{end} = o.pages{end}.addSection(varargin{:}); -end diff --git a/matlab/reports/@report/addSeries.m b/matlab/reports/@report/addSeries.m deleted file mode 100644 index 459230bfe..000000000 --- a/matlab/reports/@report/addSeries.m +++ /dev/null @@ -1,38 +0,0 @@ -function o = addSeries(o, varargin) -%function o = addSeries(o, varargin) -% Add a graph to the current section of the current page in the report -% -% INPUTS -% o [report] report object -% varargin arguments to @graph/addSeries -% -% OUTPUTS -% o [report] updated report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -assert(isa(o.pages{end}.sections{end}.elements{end}, 'graph') || ... - isa(o.pages{end}.sections{end}.elements{end}, 'report_table'), ... - '@report.addSeries: you can only add a series to a report_table or graph object'); - -o.pages{end}.sections{end}.elements{end} = ... - o.pages{end}.sections{end}.elements{end}.addSeries(varargin{:}); -end diff --git a/matlab/reports/@report/addTable.m b/matlab/reports/@report/addTable.m deleted file mode 100644 index 4b1f8c0d4..000000000 --- a/matlab/reports/@report/addTable.m +++ /dev/null @@ -1,34 +0,0 @@ -function o = addTable(o, varargin) -%function o = addTable(o, varargin) -% Add a table to the current section of the current page in the report -% -% INPUTS -% o [report] report object -% varargin arguments to @section/addTable.m -% -% OUTPUTS -% o [report] updated report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o.pages{end}.sections{end} = ... - o.pages{end}.sections{end}.addTable(varargin{:}); -end diff --git a/matlab/reports/@report/addVspace.m b/matlab/reports/@report/addVspace.m deleted file mode 100644 index f4ca186d6..000000000 --- a/matlab/reports/@report/addVspace.m +++ /dev/null @@ -1,34 +0,0 @@ -function o = addVspace(o, varargin) -%function o = addVspace(o, varargin) -% Add a vspace to the current section of the current page in the report -% -% INPUTS -% o [report] report object -% varargin arguments to @section/addVspace.m -% -% OUTPUTS -% o [report] updated report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o.pages{end}.sections{end} = ... - o.pages{end}.sections{end}.addVspace(varargin{:}); -end diff --git a/matlab/reports/@report/compile.m b/matlab/reports/@report/compile.m deleted file mode 100644 index e187a7781..000000000 --- a/matlab/reports/@report/compile.m +++ /dev/null @@ -1,122 +0,0 @@ -function o = compile(o, varargin) -%function o = compile(o) -% Compile Report Object -% -% INPUTS -% o [report] report object -% varargin [char] allows user to change report compiler for a -% given run of compile. -% -% OUTPUTS -% o [report] report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-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 . - -opts.compiler = o.compiler; -opts.showReport = true; -opts.showOutput = o.showOutput; - -if nargin > 1 - if round((nargin-1)/2) ~= (nargin-1)/2 - error('@report.compile: options must be supplied in name/value pairs'); - end - - optNames = fieldnames(opts); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - opts.(optNames{ind}) = pair{2}; - else - error('@report.compile: %s is not a recognized option.', pair{1}); - end - end -end - -assert(ischar(opts.compiler), '@report.compile: compiler file must be a string'); -assert(islogical(opts.showReport), '@report.compile: showReport must be either true or false'); -assert(islogical(opts.showOutput), '@report.compile: showOutput must be either true or false'); - -if ~exist(o.fileName, 'file') - o.write(); -end - -middle = ' ./'; -options = '-synctex=1 -halt-on-error'; -if isoctave - echo = 1; -else - echo = '-echo'; -end -if isempty(opts.compiler) - if strncmp(computer, 'MACI', 4) || ~isempty(regexpi(computer, '.*apple.*', 'once')) - % Add most likely places for pdflatex to exist outside of default $PATH - if opts.showOutput - [status, opts.compiler] = ... - system(['PATH=$PATH:/usr/texbin:/usr/local/bin:/usr/local/sbin;' ... - 'which pdflatex'], echo); - else - [status, opts.compiler] = ... - system('PATH=$PATH:/usr/texbin:/usr/local/bin:/usr/local/sbin;which pdflatex'); - end - elseif strcmp(computer, 'PCWIN') || strcmp(computer, 'PCWIN64') - if opts.showOutput - [status, opts.compiler] = system('findtexmf --file-type=exe pdflatex', echo); - else - [status, opts.compiler] = system('findtexmf --file-type=exe pdflatex'); - end - middle = ' '; - opts.compiler = ['"' strtrim(opts.compiler) '"']; - else % gnu/linux - if opts.showOutput - [status, opts.compiler] = system('which pdflatex', echo); - else - [status, opts.compiler] = system('which pdflatex'); - end - end - assert(status == 0, ... - '@report.compile: Could not find a tex compiler on your system'); - opts.compiler = strtrim(opts.compiler); - o.compiler = opts.compiler; -end - -if opts.showOutput - status = system([opts.compiler ' ' options middle o.fileName], echo); -else - [status, junk] = system([opts.compiler ' -interaction=batchmode ' options middle o.fileName]); -end -[junk, rfn, junk] = fileparts(o.fileName); - -if status ~= 0 - error(['@report.compile: There was an error in compiling ' rfn '.pdf.' ... - ' ' compiler ' returned the error code: ' num2str(status)]); -end -if o.showOutput || opts.showOutput - fprintf(1, 'Done.\n'); - disp('Your compiled report is located here:'); - disp([' ' pwd filesep rfn '.pdf']); -end -if opts.showReport && ~isoctave - open([pwd filesep rfn '.pdf']); -end -end diff --git a/matlab/reports/@report/display.m b/matlab/reports/@report/display.m deleted file mode 100644 index 1f4a535c5..000000000 --- a/matlab/reports/@report/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Report object -% -% INPUTS -% o [report] report object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@report/numPages.m b/matlab/reports/@report/numPages.m deleted file mode 100644 index 98f4b8900..000000000 --- a/matlab/reports/@report/numPages.m +++ /dev/null @@ -1,32 +0,0 @@ -function n = numPages(o) -%function n = numPages(o) -% return the number of pages currently in the report -% -% INPUTS -% o [report] report object -% -% OUTPUTS -% n [integer] number of pages in the report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -n = length(o.pages); -end \ No newline at end of file diff --git a/matlab/reports/@report/report.m b/matlab/reports/@report/report.m deleted file mode 100644 index cf4a61603..000000000 --- a/matlab/reports/@report/report.m +++ /dev/null @@ -1,93 +0,0 @@ -function o = report(varargin) -%function o = report(varargin) -% Report Class Constructor -% -% INPUTS -% varargin 0 args : empty report object -% 1 arg : must be report object (return a copy of arg) -% > 1 args: option/value pairs (see structure below for options) -% -% OUTPUTS -% o [report] report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -% default values -o = struct; -o.title = ''; -o.orientation = 'portrait'; -o.paper = 'a4'; -o.margin = 2.5; -o.marginUnit = 'cm'; -o.pages = {}; -o.fileName = 'report.tex'; -o.showDate = true; -o.compiler = ''; -o.showOutput = true; - -if nargin == 1 - assert(isa(varargin{1}, 'report'), ['@report.report: with one arg, ' ... - 'you must pass a report object']); - r = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['@report.report: options must be supplied in name/value ' ... - 'pairs']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('@report.report: %s is not a recognized option.', pair{1}); - end - end -end - -% Check options provided by user -assert(ischar(o.title), '@report.report: title must be a string'); -assert(ischar(o.fileName), '@report.report: fileName must be a string'); -assert(ischar(o.compiler), '@report.report: compiler file must be a string'); -assert(islogical(o.showDate), '@report.report: showDate must be either true or false'); -assert(islogical(o.showOutput), '@report.report: showOutput must be either true or false'); -assert(isfloat(o.margin) && o.margin > 0, '@report.report: margin must be a float > 0.'); - -valid_margin_unit = {'cm', 'in'}; -assert(any(strcmp(o.marginUnit, valid_margin_unit)), ... - ['@report.report: marginUnit must be one of ' strjoin(valid_margin_unit, ' ')]); - -valid_paper = {'a4', 'letter'}; -assert(any(strcmp(o.paper, valid_paper)), ... - ['@report.report: paper must be one of ' strjoin(valid_paper, ' ')]); - -valid_orientation = {'portrait', 'landscape'}; -assert(any(strcmp(o.orientation, valid_orientation)), ... - ['@report.report: orientation must be one of ' strjoin(valid_orientation, ' ')]); - -% Create report object -o = class(o, 'report'); -end \ No newline at end of file diff --git a/matlab/reports/@report/subsasgn.m b/matlab/reports/@report/subsasgn.m deleted file mode 100644 index 515a1ded9..000000000 --- a/matlab/reports/@report/subsasgn.m +++ /dev/null @@ -1,46 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2013-2014 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '()' - index = S.subs{:}; - assert(isnumeric(index)); - B.pages{index} = V; - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@report.subsasgn: field ' S.subs 'does not exist']); - end - otherwise - error('@report.subsasgn: syntax error'); -end -end \ No newline at end of file diff --git a/matlab/reports/@report/subsref.m b/matlab/reports/@report/subsref.m deleted file mode 100644 index 29b7156be..000000000 --- a/matlab/reports/@report/subsref.m +++ /dev/null @@ -1,48 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2013-2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@report.subsasgn: unknown field or method: ' S(1).subs]); - end - case '()' - A = A.pages{S(1).subs{:}}; - case '{}' - error(['@report.subsasgn: ' S(1).type ' indexing not supported.']); - otherwise - error('@report.subsasgn: impossible case'); -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@report/write.m b/matlab/reports/@report/write.m deleted file mode 100644 index fce1a2e7a..000000000 --- a/matlab/reports/@report/write.m +++ /dev/null @@ -1,98 +0,0 @@ -function o = write(o) -%function o = write(o) -% Write Report object -% -% INPUTS -% o [report] report object -% -% OUTPUTS -% o [report] report object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -[fid, msg] = fopen(o.fileName, 'w'); -if fid == -1 - error(['@report.write: ' msg]); -end - -fprintf(fid, '%% Report Object\n'); -fprintf(fid, '\\documentclass[11pt]{article}\n'); - -fprintf(fid, '\\usepackage[%spaper,margin=%f%s', o.paper, o.margin, o.marginUnit); -if strcmpi(o.orientation, 'landscape') - fprintf(fid, ',landscape'); -end -fprintf(fid, ']{geometry}\n'); -fprintf(fid, '\\usepackage{pdflscape, booktabs, pgfplots, colortbl, adjustbox, multicol}\n'); -fprintf(fid, '\\pgfplotsset{compat=1.5.1}'); -fprintf(fid, ['\\makeatletter\n' ... - '\\def\\blfootnote{\\gdef\\@thefnmark{}\\@footnotetext}\n' ... - '\\makeatother\n']); - -if isoctave && isempty(regexpi(computer, '.*apple.*', 'once')) - fprintf(fid, '\\usepackage[T1]{fontenc}\n'); - fprintf(fid, '\\usepackage[utf8x]{inputenc}\n'); - fprintf(fid, '\\usepackage{gnuplot-lua-tikz}\n'); -end - -fprintf(fid, '\\definecolor{LightCyan}{rgb}{0.88,1,1}\n'); -fprintf(fid, '\\definecolor{Gray}{gray}{0.9}\n'); -if o.showDate - fprintf(fid, '\\usepackage{fancyhdr, datetime}\n'); - fprintf(fid, '\\newdateformat{reportdate}{\\THEDAY\\ \\shortmonthname\\ \\THEYEAR}\n'); - fprintf(fid, '\\pagestyle{fancy}\n'); - fprintf(fid, '\\renewcommand{\\headrulewidth}{0pt}\n'); - fprintf(fid, '\\renewcommand{\\footrulewidth}{0.5pt}\n'); - fprintf(fid, '\\rfoot{\\scriptsize\\reportdate\\today\\ -- \\currenttime}\n'); -end - -% May not need these..... -fprintf(fid, '\\renewcommand{\\textfraction}{0.05}\n'); -fprintf(fid, '\\renewcommand{\\topfraction}{0.8}\n'); -fprintf(fid, '\\renewcommand{\\bottomfraction}{0.8}\n'); -fprintf(fid, '\\setlength{\\parindent}{0in}\n'); -fprintf(fid, '\\setlength{\\tabcolsep}{1em}\n'); -fprintf(fid, '\\newlength\\sectionheight\n'); -fprintf(fid, '\\begin{document}\n'); -fprintf(fid, '\\pgfdeclarelayer{background0}\n'); -fprintf(fid, '\\pgfdeclarelayer{background1}\n'); -fprintf(fid, '\\pgfsetlayers{background0,background1,main}\n'); -fprintf(fid, '\\pgfplotsset{tick scale binop={\\times},\ntrim axis left}\n'); -fprintf(fid, '\\centering\n'); - -nps = length(o.pages); -for i=1:nps - if o.showOutput - fprintf(1, 'Writing Page: %d\n', i); - end - o.pages{i}.write(fid, i); -end - -fprintf(fid, '\\end{document}\n'); -fprintf(fid, '%% End Report Object\n'); -status = fclose(fid); -if status == -1 - error('@report.write: closing %s\n', o.fileName); -end -if o.showOutput - disp('Finished Writing Report!'); -end -end diff --git a/matlab/reports/@report_series/display.m b/matlab/reports/@report_series/display.m deleted file mode 100644 index d4e0ba5e6..000000000 --- a/matlab/reports/@report_series/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Report_Series object -% -% INPUTS -% o [report_series] report_series object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@report_series/getNameForLegend.m b/matlab/reports/@report_series/getNameForLegend.m deleted file mode 100644 index 0748a8de2..000000000 --- a/matlab/reports/@report_series/getNameForLegend.m +++ /dev/null @@ -1,31 +0,0 @@ -function s = getNameForLegend(o) -%function s = getNameForLegend(o) - -% Copyright (C) 2014 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 isempty(o.data) || ~o.graphShowInLegend - % for the case when there is no data in the series - % e.g. graphVline was passed - % or when the user does not want this series shown in - % the legend - s = ''; -else - assert(size(o.data,2) == 1); - s = o.data.tex{:}; -end -end \ No newline at end of file diff --git a/matlab/reports/@report_series/getRange.m b/matlab/reports/@report_series/getRange.m deleted file mode 100644 index a0d1fd807..000000000 --- a/matlab/reports/@report_series/getRange.m +++ /dev/null @@ -1,27 +0,0 @@ -function dd = getRange(o) -%function dd = getRange(o) - -% Copyright (C) 2013 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 isempty(o.data) - dd = dates(); -else - assert(size(o.data, 2) == 1); - dd = o.data.dates; -end -end \ No newline at end of file diff --git a/matlab/reports/@report_series/getTexName.m b/matlab/reports/@report_series/getTexName.m deleted file mode 100644 index 0672508f9..000000000 --- a/matlab/reports/@report_series/getTexName.m +++ /dev/null @@ -1,29 +0,0 @@ -function s = getTexName(o) -%function s = getTexName(o) - -% Copyright (C) 2013-2014 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 isempty(o.data) - % for the case when there is no data in the series - % e.g. graphVline was passed - s = ''; -else - assert(size(o.data,2) == 1); - s = o.data.tex{:}; -end -end \ No newline at end of file diff --git a/matlab/reports/@report_series/printSeries.m b/matlab/reports/@report_series/printSeries.m deleted file mode 100644 index e1a6f0b49..000000000 --- a/matlab/reports/@report_series/printSeries.m +++ /dev/null @@ -1,57 +0,0 @@ -function o = printSeries(o, fid, dser, dates, precision) -%function printSeries(o, fid, dser, dates, precision) -% function to print a row of data, contained in dser -% -% INPUTS -% fid [int] file id -% dser [string] name of data series to be printed -% dates [dates] dates for report_series slice -% precision [float] precision with which to print the data -% -% -% OUTPUTS -% o [report_series] report_series object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2014 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 . - -dataString = sprintf('%%.%df', precision); -precision = 10^precision; - -data = dser(dates); -data = setDataToZeroFromZeroTol(o, data); -for i=1:size(data,1) - fprintf(fid, '&'); - if o.tableShowMarkers - if data(i) < -o.tableMarkerLimit - fprintf(fid, '\\color{%s}', o.tableNegColor); - elseif data(i) > o.tableMarkerLimit - fprintf(fid, '\\color{%s}', o.tablePosColor); - end - fprintf(fid, '['); - end - - fprintf(fid, dataString, round(data(i)*precision)/precision); - - if o.tableShowMarkers - fprintf(fid, ']'); - end -end -end \ No newline at end of file diff --git a/matlab/reports/@report_series/report_series.m b/matlab/reports/@report_series/report_series.m deleted file mode 100644 index 0ce1d92da..000000000 --- a/matlab/reports/@report_series/report_series.m +++ /dev/null @@ -1,107 +0,0 @@ -function o = report_series(varargin) -%function o = report_series(varargin) -% Report_Series Class Constructor -% -% INPUTS -% varargin 0 args : empty report_series object -% 1 arg : must be report_series object (return a copy of arg) -% > 1 args: option/value pairs (see structure below for -% options) -% -% OUTPUTS -% o [report_series] report_series object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o = struct; - -o.data = ''; - -o.graphLegendName = ''; - -o.graphLineColor = 'black'; -o.graphLineStyle = 'solid'; -o.graphLineWidth = 0.5; - -o.graphShowInLegend = true; - -o.graphMarker = ''; -o.graphMarkerEdgeColor = ''; -o.graphMarkerFaceColor = ''; -o.graphMarkerSize = 1; - -o.graphMiscTikzAddPlotOptions = ''; - -o.graphHline = {}; -o.graphVline = dates(); - -o.graphBar = false; -o.graphBarColor = 'black'; -o.graphBarFillColor = 'black'; -o.graphBarWidth = 2; - -o.tableShowMarkers = false; -o.tableNegColor = 'red'; -o.tablePosColor = 'blue'; -o.tableMarkerLimit = 1e-4; - -o.tableSubSectionHeader = ''; -o.tableAlignRight = false; - -o.tableRowColor = 'white'; -o.tableRowIndent = 0; - -o.tableDataRhs = ''; - -o.zeroTol = 1e-6; - -if nargin == 1 - assert(isa(varargin{1}, 'report_series'),['@report_series.report_series: with one arg you ' ... - 'must pass a report_series object']); - o = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['@report_series.report_series: options must be supplied in name/value ' ... - 'pairs.']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('@report_series.report_series: %s is not a recognized option.', pair{1}); - end - end -end - -if ~isempty(o.graphLegendName) - o.data = o.data.tex_rename(o.graphLegendName); -end - -% Create report_series object -o = class(o, 'report_series'); -end \ No newline at end of file diff --git a/matlab/reports/@report_series/setDataToZeroFromZeroTol.m b/matlab/reports/@report_series/setDataToZeroFromZeroTol.m deleted file mode 100644 index 25daeb15f..000000000 --- a/matlab/reports/@report_series/setDataToZeroFromZeroTol.m +++ /dev/null @@ -1,28 +0,0 @@ -function d = setDataToZeroFromZeroTol(o, ds) -%function d = setDataToZeroFromZeroTol(o, ds) - -% Copyright (C) 2014 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 . - -d = ds.data; -stz = bsxfun(@and, ... - bsxfun(@lt, d, o.zeroTol), ... - bsxfun(@gt, d, -o.zeroTol)); -if any(stz) - d(stz) = 0; -end -end \ No newline at end of file diff --git a/matlab/reports/@report_series/subsasgn.m b/matlab/reports/@report_series/subsasgn.m deleted file mode 100644 index fdf0f7db5..000000000 --- a/matlab/reports/@report_series/subsasgn.m +++ /dev/null @@ -1,42 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2013 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@report_series.subsasgn: field ' S.subs 'does not exist']); - end - otherwise - error('@report_series.subsasgn: syntax error'); -end -end \ No newline at end of file diff --git a/matlab/reports/@report_series/subsref.m b/matlab/reports/@report_series/subsref.m deleted file mode 100644 index 938b9f4b7..000000000 --- a/matlab/reports/@report_series/subsref.m +++ /dev/null @@ -1,46 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2013-2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@report_series.subsref: unknown field or method: ' S(1).subs]); - end - case {'()', '{}'} - error(['@report_series.subsref: ' S(1).type ' indexing not supported.']); - otherwise - error('@report_series.subsref: impossible case') -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@report_series/writeSeriesForGraph.m b/matlab/reports/@report_series/writeSeriesForGraph.m deleted file mode 100644 index 2242953b5..000000000 --- a/matlab/reports/@report_series/writeSeriesForGraph.m +++ /dev/null @@ -1,145 +0,0 @@ -function o = writeSeriesForGraph(o, fid, xrange) -%function o = writeSeriesForGraph(o, fid, xrange) -% Print a TikZ line -% -% INPUTS -% o [report_series] series object -% xrange [dates] range of x values for line -% -% OUTPUTS -% NONE -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2014 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 . - -%% Validate options provided by user -if isempty(o.graphVline) && isempty(o.graphHline) - assert(~isempty(o.data) && isdseries(o.data), ['@report_series.writeSeriesForGraph: must ' ... - 'provide data as a dseries']); -end - -assert(ischar(o.graphMiscTikzAddPlotOptions), ['@report_series.writeSeriesForGraph: ' ... - 'graphMiscTikzAddPlotOptions file must be a string']); -assert(islogical(o.graphShowInLegend), ['@report_series.writeSeriesForGraph: ' ... - 'graphShowInLegend must be either true or false']); - -% Line -assert(ischar(o.graphLineColor), '@report_series.writeSeriesForGraph: graphLineColor must be a string'); -assert(ischar(o.graphLineStyle), '@report_series.writeSeriesForGraph: graphLineStyle must be a string'); -assert(isfloat(o.graphLineWidth) && o.graphLineWidth > 0, ... - '@report_series.writeSeriesForGraph: graphLineWidth must be a positive number'); - -% Bar -assert(islogical(o.graphBar), '@report_series.writeSeriesForGraph: graphBar must be either true or false'); -assert(ischar(o.graphBarColor), '@report_series.writeSeriesForGraph: graphBarColor must be a string'); -assert(ischar(o.graphBarFillColor), '@report_series.writeSeriesForGraph: graphBarFillColor must be a string'); -assert(isfloat(o.graphBarWidth) && o.graphBarWidth > 0, ... - '@report_series.writeSeriesForGraph: graphbarWidth must be a positive number'); - -% GraphMarker -valid_graphMarker = {'x', '+', '-', '|', 'o', 'asterisk', 'star', '10-pointed star', 'oplus', ... - 'oplus*', 'otimes', 'otimes*', 'square', 'square*', 'triangle', 'triangle*', 'diamond', ... - 'diamond*', 'halfdiamond*', 'halfsquare*', 'halfsquare right*', ... - 'halfsquare left*','Mercedes star','Mercedes star flipped','halfcircle',... - 'halfcircle*','pentagon','pentagon star'}; -assert(isempty(o.graphMarker) || any(strcmp(o.graphMarker, valid_graphMarker)), ... - ['@report_series.writeSeriesForGraph: graphMarker must be one of ' strjoin(valid_graphMarker)]); - -assert(ischar(o.graphMarkerEdgeColor), '@report_series.writeSeriesForGraph: graphMarkerEdgeColor must be a string'); -assert(ischar(o.graphMarkerFaceColor), '@report_series.writeSeriesForGraph: graphMarkerFaceColor must be a string'); -assert(isfloat(o.graphMarkerSize) && o.graphMarkerSize > 0, ... - '@report_series.writeSeriesForGraph: graphMarkerSize must be a positive number'); - -% Marker & Line -assert(~(strcmp(o.graphLineStyle, 'none') && isempty(o.graphMarker)), ['@report_series.writeSeriesForGraph: ' ... - 'you must provide at least one of graphLineStyle and graphMarker']); - -% Validate graphVline -assert(isempty(o.graphVline) || (isdates(o.graphVline) && o.graphVline.ndat == 1), ... - '@report_series.writeSeriesForGraph: graphVline must be a dates of size one'); -assert(isempty(o.graphHline) || isnumeric(o.graphHline), ... - '@report_series.writeSeriesForGraph: graphHline must a single numeric value'); - -% Zero tolerance -assert(isfloat(o.zeroTol), '@report_series.write: zeroTol must be a float'); - -%% graphVline && graphHline -if ~isempty(o.graphVline) - fprintf(fid, '%%Vertical Line\n\\begin{pgfonlayer}{background1}\n\\draw'); - writeLineOptions(o, fid); - stringsdd = strings(xrange); - x = find(strcmpi(date2string(o.graphVline), stringsdd)); - fprintf(fid, ['(axis cs:%d,\\pgfkeysvalueof{/pgfplots/ymin}) -- (axis ' ... - 'cs:%d,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ... - x, x); -end -if ~isempty(o.graphHline) - fprintf(fid, '%%Horizontal Line\n\\begin{pgfonlayer}{background1}\n\\addplot'); - writeLineOptions(o, fid); - fprintf(fid, ['coordinates {(\\pgfkeysvalueof{/pgfplots/xmin},%f)' ... - '(\\pgfkeysvalueof{/pgfplots/xmax},%f)};\n\\end{pgfonlayer}\n'], ... - o.graphHline, o.graphHline); -end -if ~isempty(o.graphVline) || ~isempty(o.graphHline) - % return since the code below assumes that o.data exists - return -end - -%% -if isempty(xrange) || all(xrange == o.data.dates) - ds = o.data; -else - ds = o.data(xrange); -end - -thedata = setDataToZeroFromZeroTol(o, ds); -fprintf(fid, '%%series %s\n\\addplot', o.data.name{:}); -writeLineOptions(o, fid); -fprintf(fid,'\ntable[row sep=crcr]{\nx y\\\\\n'); -for i=1:ds.dates.ndat - fprintf(fid, '%d %f\\\\\n', i, thedata(i)); -end -fprintf(fid,'};\n'); -end - -function writeLineOptions(o, fid) -if o.graphBar - fprintf(fid, '[ybar,ybar legend,color=%s,fill=%s,line width=%fpt',... - o.graphBarColor, o.graphBarFillColor, o.graphBarWidth); -else - fprintf(fid, '[color=%s,%s,line width=%fpt,line join=round',... - o.graphLineColor, o.graphLineStyle, o.graphLineWidth); - - if ~isempty(o.graphMarker) - if isempty(o.graphMarkerEdgeColor) - o.graphMarkerEdgeColor = o.graphLineColor; - end - if isempty(o.graphMarkerFaceColor) - o.graphMarkerFaceColor = o.graphLineColor; - end - fprintf(fid, ',mark=%s,mark size=%f,every mark/.append style={draw=%s,fill=%s}',... - o.graphMarker,o.graphMarkerSize,o.graphMarkerEdgeColor,o.graphMarkerFaceColor); - end -end -if ~isempty(o.graphMiscTikzAddPlotOptions) - fprintf(fid, ',%s', o.graphMiscTikzAddPlotOptions); -end -fprintf(fid,']'); -end diff --git a/matlab/reports/@report_series/writeSeriesForTable.m b/matlab/reports/@report_series/writeSeriesForTable.m deleted file mode 100644 index 77bc82a3b..000000000 --- a/matlab/reports/@report_series/writeSeriesForTable.m +++ /dev/null @@ -1,105 +0,0 @@ -function o = writeSeriesForTable(o, fid, dates, precision, ncols, rowcolor) -%function o = writeSeriesForTable(o, fid, dates, precision, ncols, rowcolor) -% Write Table Row -% -% INPUTS -% o [report_series] report_series object -% fid [int] file id -% dates [dates] dates for report_series slice -% precision [float] precision with which to print the data -% ncols [int] total number of columns in table -% rowcolor [string] string to color this row -% -% -% OUTPUTS -% o [report_series] report_series object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -%% Validate options passed to function -assert(fid ~= -1); -for i=1:length(dates) - assert(isdates(dates{i})); -end -assert(isint(precision)); - -%% Validate options provided by user -assert(ischar(o.tableSubSectionHeader), '@report_series.writeSeriesForTable: tableSubSectionHeader must be a string'); -if isempty(o.tableSubSectionHeader) - assert(~isempty(o.data) && isdseries(o.data), ... - '@report_series.writeSeriesForTable: must provide data as a dseries'); - - if ~isempty(o.tableDataRhs) - assert(~isempty(o.tableDataRhs) && isdseries(o.tableDataRhs), ... - '@report_series.writeSeriesForTable: must provide tableDataRhs as a dseries'); - assert(iscell(dates) && length(dates) == 2, ... - '@report_series.writeSeriesForTable: must provide second range with tableDataRhs'); - end -end - -assert(ischar(o.tableNegColor), '@report_series.writeSeriesForTable: tableNegColor must be a string'); -assert(ischar(o.tablePosColor), '@report_series.writeSeriesForTable: tablePosColor must be a string'); -assert(ischar(o.tableRowColor), '@report_series.writeSeriesForTable: tableRowColor must be a string'); -assert(isint(o.tableRowIndent) && o.tableRowIndent >= 0, ... - '@report_series.writeSeriesForTable: tableRowIndent must be an integer >= 0'); -assert(islogical(o.tableShowMarkers), '@report_series.writeSeriesForTable: tableShowMarkers must be true or false'); -assert(islogical(o.tableAlignRight), '@report_series.writeSeriesForTable: tableAlignRight must be true or false'); -assert(isfloat(o.tableMarkerLimit), '@report_series.writeSeriesForTable: tableMarkerLimit must be a float'); - -%% Write Output -fprintf(fid, '%% Table Row (report_series)\n'); -if ~isempty(o.tableRowColor) && ~strcmpi(o.tableRowColor, 'white') - fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); -elseif ~isempty(rowcolor) - fprintf(fid, '\\rowcolor{%s}', rowcolor); -else - fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); -end -if ~isempty(o.tableSubSectionHeader) - fprintf(fid, '\\textbf{%s}', o.tableSubSectionHeader); - for i=1:ncols-1 - fprintf(fid, ' &'); - end - fprintf(fid, '\\\\%%\n'); - return; -end -if o.tableAlignRight - fprintf(fid, '\\multicolumn{1}{r}{'); -end -if o.tableRowIndent == 0 - fprintf(fid, '\\noindent'); -else - for i=1:o.tableRowIndent - fprintf(fid,'\\indent'); - end -end -fprintf(fid, ' %s', o.data.tex{:}); -if o.tableAlignRight - fprintf(fid, '}'); -end - -printSeries(o, fid, o.data, dates{1}, precision); -if ~isempty(o.tableDataRhs) - printSeries(o, fid, o.tableDataRhs, dates{2}, precision); -end - -fprintf(fid, '\\\\%%\n'); -end diff --git a/matlab/reports/@report_series/ymax.m b/matlab/reports/@report_series/ymax.m deleted file mode 100644 index eac0aaad1..000000000 --- a/matlab/reports/@report_series/ymax.m +++ /dev/null @@ -1,23 +0,0 @@ -function ymax = ymax(o, dd) -%function ymax = ymax(o, dd) - -% Copyright (C) 2014 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 . - -assert(~isempty(o.data) && size(o.data, 2) == 1); -ymax = max(o.data(dd).data); -end \ No newline at end of file diff --git a/matlab/reports/@report_series/ymin.m b/matlab/reports/@report_series/ymin.m deleted file mode 100644 index 217546047..000000000 --- a/matlab/reports/@report_series/ymin.m +++ /dev/null @@ -1,23 +0,0 @@ -function ymin = ymin(o, dd) -%function ymin = ymin(o, dd) - -% Copyright (C) 2014 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 . - -assert(~isempty(o.data) && size(o.data, 2) == 1); -ymin = min(o.data(dd).data); -end \ No newline at end of file diff --git a/matlab/reports/@report_table/addSeries.m b/matlab/reports/@report_table/addSeries.m deleted file mode 100644 index 6a0f6d23e..000000000 --- a/matlab/reports/@report_table/addSeries.m +++ /dev/null @@ -1,22 +0,0 @@ -function o = addSeries(o, varargin) -% function o = addSeries(o, varargin) - -% Copyright (C) 2013-2014 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 . - -o.series{end+1} = report_series(varargin{:}); -end \ No newline at end of file diff --git a/matlab/reports/@report_table/display.m b/matlab/reports/@report_table/display.m deleted file mode 100644 index f5bcf888c..000000000 --- a/matlab/reports/@report_table/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Report_Table object -% -% INPUTS -% o [report_table] report_table object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@report_table/report_table.m b/matlab/reports/@report_table/report_table.m deleted file mode 100644 index effd07e51..000000000 --- a/matlab/reports/@report_table/report_table.m +++ /dev/null @@ -1,145 +0,0 @@ -function o = report_table(varargin) -%function o = report_table(varargin) -% Report_Table Class Constructor -% -% INPUTS -% 0 args => empty report_table -% 1 arg (report_table class) => copy object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o = struct; - -o.tableDirName = 'tmpRepDir'; -o.tableName = ''; - -o.series = {}; - -o.title = {''}; -titleFormatDefalut = {'\large'}; -o.titleFormat = titleFormatDefalut; - -o.showHlines = false; -o.showVlines = false; -o.vlineAfter = ''; -o.vlineAfterEndOfPeriod = false; - -o.data = ''; -o.seriesToUse = ''; -o.range = {}; -o.precision = 1; -o.writeCSV = false; - -o.highlightRows = {''}; - -if nargin == 1 - assert(isa(varargin{1}, 'report_table'),['With one arg to Report_Table constructor, ' ... - 'you must pass a report_table object']); - o = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['Options to Report_Table constructor must be supplied in name/value ' ... - 'pairs.']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('%s is not a recognized option to the Report_Table constructor.', pair{1}); - end - end -end -if ~iscell(o.range) - o.range = {o.range}; -end - -if isdates(o.vlineAfter) - o.vlineAfter = {o.vlineAfter}; -end - -% Check options provided by user -if ischar(o.title) - o.title = {o.title}; -end -if ischar(o.titleFormat) - o.titleFormat = {o.titleFormat}; -end -if length(o.title) ~= length(o.titleFormat) - o.titleFormat = repmat(titleFormatDefalut, 1, length(o.title)); -end -assert(islogical(o.showHlines), '@report_table.report_table: showHlines must be true or false'); -assert(islogical(o.showVlines), '@report_table.report_table: showVlines must be true or false'); -assert(isint(o.precision), '@report_table.report_table: precision must be an int'); -assert(isempty(o.range) || length(o.range) <=2 && allCellsAreDatesRange(o.range), ... - ['@report_table.report_table: range is specified as a dates range, e.g. ' ... - '''dates(''1999q1''):dates(''1999q3'')''.']); -assert(isempty(o.data) || isdseries(o.data), ... - '@report_table.report_table: data must be a dseries'); -assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ... - '@report_table.report_table: seriesToUse must be a cell array of string(s)'); -assert(isempty(o.vlineAfter) || allCellsAreDates(o.vlineAfter), ... - '@report_table.report_table: vlineAfter must be a dates'); -if o.showVlines - o.vlineAfter = ''; -end -assert(islogical(o.vlineAfterEndOfPeriod), ... - '@report_table.report_table: vlineAfterEndOfPeriod must be true or false'); -assert(iscellstr(o.title), ... - '@report_table.report_table: title must be a cell array of string(s)'); -assert(iscellstr(o.titleFormat), ... - '@report_table.report_table: titleFormat must be a cell array of string(s)'); -assert(ischar(o.tableName), '@report_table.report_table: tableName must be a string'); -assert(ischar(o.tableDirName), '@report_table.report_table: tableDirName must be a string'); -assert(islogical(o.writeCSV), '@report_table.report_table: writeCSV must be either true or false'); -assert(iscellstr(o.highlightRows), '@report_table.report_table: highlightRowsmust be a cell string'); - -% using o.seriesToUse, create series objects and put them in o.series -if ~isempty(o.data) - if isempty(o.seriesToUse) - for i=1:o.data.vobs - o.series{end+1} = report_series('data', o.data{o.data.name{i}}); - end - else - for i=1:length(o.seriesToUse) - o.series{end+1} = report_series('data', o.data{o.seriesToUse{i}}); - end - end -end -o = rmfield(o, 'seriesToUse'); -o = rmfield(o, 'data'); - -if ~exist(o.tableDirName, 'file') - mkdir(o.tableDirName); -end - -% Create report_table object -o = class(o, 'report_table'); -end \ No newline at end of file diff --git a/matlab/reports/@report_table/subsasgn.m b/matlab/reports/@report_table/subsasgn.m deleted file mode 100644 index 9ea3b0b76..000000000 --- a/matlab/reports/@report_table/subsasgn.m +++ /dev/null @@ -1,45 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2013 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@report_table.subsasgn: field ' S.subs 'does not exist in the report_table class']) - end - case '{}' - assert(isint(S.subs{1})); - B{S.subs{1}} = V; - otherwise - error('@report_table.subsasgn: syntax error') -end -end \ No newline at end of file diff --git a/matlab/reports/@report_table/subsref.m b/matlab/reports/@report_table/subsref.m deleted file mode 100644 index 97962ec41..000000000 --- a/matlab/reports/@report_table/subsref.m +++ /dev/null @@ -1,46 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2013-2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@report_table.subsref: unknown field or method: ' S(1).subs]); - end - case {'()', '{}'} - error(['@report_table.subsref: ' S(1).type ' indexing not supported.']); - otherwise - error('@report_table.subsref: subsref.m impossible case') -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@report_table/write.m b/matlab/reports/@report_table/write.m deleted file mode 100644 index adc6dd968..000000000 --- a/matlab/reports/@report_table/write.m +++ /dev/null @@ -1,39 +0,0 @@ -function o = write(o, fid, pg, sec, row, col) -%function o = write(o, fid, pg, sec, row, col) -% Write a Table object -% -% INPUTS -% o [table] table object -% fid [integer] file id -% pg [integer] this page number -% sec [integer] this section number -% row [integer] this row number -% col [integer] this col number -% -% OUTPUTS -% o [table] table object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -assert(fid ~= -1); -o = writeTableFile(o, pg, sec, row, col); -fprintf(fid, '\\input{%s}', o.tableName); -end diff --git a/matlab/reports/@report_table/writeTableFile.m b/matlab/reports/@report_table/writeTableFile.m deleted file mode 100644 index 01e04adaa..000000000 --- a/matlab/reports/@report_table/writeTableFile.m +++ /dev/null @@ -1,200 +0,0 @@ -function o = writeTableFile(o, pg, sec, row, col) -%function o = writeTableFile(o, pg, sec, row, col) -% Write a Report_Table object -% -% INPUTS -% o [report_table] report_table object -% pg [integer] this page number -% sec [integer] this section number -% row [integer] this row number -% col [integer] this col number -% -% OUTPUTS -% o [report_table] report_table object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -ne = length(o.series); -if ne == 0 - warning('@report_table.write: no series to plot, returning'); - return; -end - -if isempty(o.tableName) - o.tableName = sprintf('%s/table_pg%d_sec%d_row%d_col%d.tex', o.tableDirName, pg, sec, row, col); -else - o.tableName = [o.tableDirName '/' o.tableName]; -end - -[fid, msg] = fopen(o.tableName, 'w'); -if fid == -1 - error(['@report_table.writeTableFile: ' msg]); -end - -%number of left-hand columns, 1 until we allow the user to group data, -% e.g.: GDP Europe -% GDP France -% GDP Germany -% this example would be two lh columns, with GDP Europe spanning both -nlhc = 1; - -if isempty(o.range) - dates = getMaxRange(o.series); - o.range = {dates}; -else - dates = o.range{1}; -end -ndates = dates.ndat; - -fprintf(fid, '%% Report_Table Object\n'); -fprintf(fid, '\\setlength{\\parindent}{6pt}\n'); -fprintf(fid, '\\setlength{\\tabcolsep}{4pt}\n'); -fprintf(fid, '\\begin{tabular}{@{}l'); - -for i=1:ndates - fprintf(fid, 'r'); - if o.showVlines - fprintf(fid, '|'); - elseif o.vlineAfterEndOfPeriod && dates(i).time(2) == dates(i).freq - fprintf(fid, '|'); - elseif ~isempty(o.vlineAfter) - for j=1:length(o.vlineAfter) - if dates(i) == o.vlineAfter{j} - fprintf(fid, '|'); - end - end - end -end -datedata = dates.time; -years = unique(datedata(:, 1)); -if length(o.range) > 1 - rhscols = strings(o.range{2}); - if o.range{2}.freq == 1 - rhscols = strrep(rhscols, 'Y', ''); - end -else - rhscols = {}; -end -for i=1:length(rhscols) - fprintf(fid, 'r'); - if o.showVlines - fprintf(fid, '|'); - end -end -nrhc = length(rhscols); -ncols = ndates+nlhc+nrhc; -fprintf(fid, '@{}}%%\n'); -for i=1:length(o.title) - if ~isempty(o.title{i}) - fprintf(fid, '\\multicolumn{%d}{c}{%s %s}\\\\\n', ... - ncols, o.titleFormat{i}, o.title{i}); - end -end -fprintf(fid, '\\toprule%%\n'); - -% Column Headers -thdr = num2cell(years, size(years, 1)); -if dates.freq == 1 - for i=1:size(thdr, 1) - fprintf(fid, ' & %d', thdr{i, 1}); - end - for i=1:length(rhscols) - fprintf(fid, ' & %s', rhscols{i}); - end -else - thdr{1, 2} = datedata(:, 2)'; - if size(thdr, 1) > 1 - for i=2:size(thdr, 1) - split = find(thdr{i-1, 2} == dates.freq, 1, 'first'); - assert(~isempty(split), '@report_table.writeTableFile: Shouldn''t arrive here'); - thdr{i, 2} = thdr{i-1, 2}(split+1:end); - thdr{i-1, 2} = thdr{i-1, 2}(1:split); - end - end - for i=1:size(thdr, 1) - fprintf(fid, ' & \\multicolumn{%d}{c}{%d}', size(thdr{i,2}, 2), thdr{i,1}); - end - for i=1:length(rhscols) - fprintf(fid, ' & %s', rhscols{i}); - end - fprintf(fid, '\\\\\n'); - switch dates.freq - case 4 - sep = 'Q'; - case 12 - sep = 'M'; - case 52 - sep = 'W'; - otherwise - error('@report_table.writeTableFile: Invalid frequency.'); - end - for i=1:size(thdr, 1) - period = thdr{i, 2}; - for j=1:size(period, 2) - fprintf(fid, ' & \\multicolumn{1}{c'); - if o.showVlines - fprintf(fid, '|'); - elseif o.vlineAfterEndOfPeriod && j == size(period, 2) - fprintf(fid, '|'); - elseif ~isempty(o.vlineAfter) - for k=1:length(o.vlineAfter) - if o.vlineAfter{k}.time(1) == thdr{i} && ... - o.vlineAfter{k}.time(2) == period(j) - fprintf(fid, '|'); - end - end - end - fprintf(fid, '}{%s%d}', sep, period(j)); - end - end -end -fprintf(fid, '\\\\[-2pt]%%\n'); -fprintf(fid, '\\hline%%\n'); -fprintf(fid, '%%\n'); - -% Write Report_Table Data -if o.writeCSV - csvseries = dseries(); -end -for i=1:ne - o.series{i}.writeSeriesForTable(fid, o.range, o.precision, ncols, o.highlightRows{mod(i,length(o.highlightRows))+1}); - if o.writeCSV - if isempty(o.series{i}.tableSubSectionHeader) - csvseries = [csvseries ... - o.series{i}.data(dates).set_names([... - num2str(i) '_' ... - o.series{i}.data.name{:}])]; - end - end - if o.showHlines - fprintf(fid, '\\hline\n'); - end -end -if o.writeCSV - csvseries.save(strrep(o.tableName, '.tex', ''), 'csv'); -end -fprintf(fid, '\\bottomrule\n'); -fprintf(fid, '\\end{tabular}\\setlength{\\parindent}{0pt}\n \\par \\medskip\n\n'); -fprintf(fid, '%% End Report_Table Object\n'); -if fclose(fid) == -1 - error('@report_table.writeTableFile: closing %s\n', o.filename); -end -end diff --git a/matlab/reports/@section/addGraph.m b/matlab/reports/@section/addGraph.m deleted file mode 100644 index c3675764f..000000000 --- a/matlab/reports/@section/addGraph.m +++ /dev/null @@ -1,38 +0,0 @@ -function o = addGraph(o, varargin) -%function o = addGraph(o, varargin) -% Add a graph to the Cell Array of graphs in the report -% -% INPUTS -% 1 args => add empty graph -% 2 args => add given graph -% 3 args => add graph at index -% -% OUTPUTS -% updated section object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -for i=1:length(o.elements) - assert(~isa(o.elements{i}, 'paragraph'), ... - '@addGraph: A Section that contains a Paragraph cannot contain a Graph'); -end -o.elements{end+1} = graph(varargin{:}); -end diff --git a/matlab/reports/@section/addParagraph.m b/matlab/reports/@section/addParagraph.m deleted file mode 100644 index 11c228de2..000000000 --- a/matlab/reports/@section/addParagraph.m +++ /dev/null @@ -1,42 +0,0 @@ -function o = addParagraph(o, varargin) -%function o = addParagraph(o, varargin) -% Add a paragraph to the Cell Array of elements in this section -% -% INPUTS -% 1 args => add empty paragraph -% 2 args => add given paragraph -% 3 args => add paragraph at index -% -% OUTPUTS -% updated page object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2014 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 . - -assert(o.cols == 1, ... - ['@addParagraph: you can only add a paragraph to a Section that ' ... - 'contains one column']); -for i=1:length(o.elements) - assert(isa(o.elements{i}, 'paragraph'), ... - ['@addParagraph: you can only add a paragraph to a Section that ' ... - 'contains only paragraphs']); -end -o.elements{end+1} = paragraph(varargin{:}); -end diff --git a/matlab/reports/@section/addTable.m b/matlab/reports/@section/addTable.m deleted file mode 100644 index 30f79c73d..000000000 --- a/matlab/reports/@section/addTable.m +++ /dev/null @@ -1,38 +0,0 @@ -function o = addTable(o, varargin) -%function o = addTable(o, varargin) -% Add a report_table to the Cell Array of report_tables in the report -% -% INPUTS -% 1 args => add empty report_table -% 2 args => add given report_table -% 3 args => add report_table at index -% -% OUTPUTS -% updated section object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -for i=1:length(o.elements) - assert(~isa(o.elements{i}, 'paragraph'), ... - '@addTable: A Section that contains a Paratable cannot contain a Table'); -end -o.elements{end+1} = report_table(varargin{:}); -end diff --git a/matlab/reports/@section/addVspace.m b/matlab/reports/@section/addVspace.m deleted file mode 100644 index be40daab2..000000000 --- a/matlab/reports/@section/addVspace.m +++ /dev/null @@ -1,37 +0,0 @@ -function o = addVspace(o, varargin) -%function o = addVspace(o, varargin) -% Add a vspace to the Cell Array of vspaces in the report -% -% INPUTS -% 1 args => add empty vspace -% 2 args => add given vspace -% -% OUTPUTS -% updated section object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -for i=1:length(o.elements) - assert(~isa(o.elements{i}, 'paragraph'), ... - '@addVspace: A Section that contains a Paragraph cannot contain a Vspace'); -end -o.elements{end+1} = vspace(varargin{:}); -end diff --git a/matlab/reports/@section/display.m b/matlab/reports/@section/display.m deleted file mode 100644 index 476d6a119..000000000 --- a/matlab/reports/@section/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Section object -% -% INPUTS -% o [section] section object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@section/end.m b/matlab/reports/@section/end.m deleted file mode 100644 index 0017c4b31..000000000 --- a/matlab/reports/@section/end.m +++ /dev/null @@ -1,35 +0,0 @@ -function lastIndex = end(o, k, n) -% function lastIndex = end(o, k, n) -% End keyword -% -% INPUTS -% o [section] section object -% k [integer] index where end appears -% n [integer] number of indices -% -% OUTPUTS -% lastIndex [integer] last section index -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013 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 . - -assert(k==1 && n==1, '@section/end: section only has one dimension'); -lastIndex = numElements(o); -end \ No newline at end of file diff --git a/matlab/reports/@section/numElements.m b/matlab/reports/@section/numElements.m deleted file mode 100644 index b72393015..000000000 --- a/matlab/reports/@section/numElements.m +++ /dev/null @@ -1,22 +0,0 @@ -function n = numElements(o) -% function n = numElements(o) - -% Copyright (C) 2013-2014 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 . - -n = length(o.elements); -end \ No newline at end of file diff --git a/matlab/reports/@section/section.m b/matlab/reports/@section/section.m deleted file mode 100644 index 5042d94d0..000000000 --- a/matlab/reports/@section/section.m +++ /dev/null @@ -1,60 +0,0 @@ -function o = section(varargin) -%function o = section(varargin) - -% Section produces a latex minipage - -% Copyright (C) 2013-2014 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 . - -o = struct; -o.elements = {}; -o.cols = 1; -o.height = ''; - -if nargin == 1 - assert(isa(varargin{1}, 'section'),['With one arg to Section constructor, ' ... - 'you must pass a section object']); - o = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['@section.section: options must be supplied in name/value ' ... - 'pairs.']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('@section.section: %s is not a recognized option.', pair{1}); - end - end -end - -% Check options provided by user -assert(isint(o.cols), '@section.section: cols must be an integer'); -assert(isempty(o.height) || ischar(o.height), ... - '@section.section: cols must be a string'); - -% Create section object -o = class(o, 'section'); -end diff --git a/matlab/reports/@section/subsasgn.m b/matlab/reports/@section/subsasgn.m deleted file mode 100644 index 24dc92fbc..000000000 --- a/matlab/reports/@section/subsasgn.m +++ /dev/null @@ -1,50 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2013-2014 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '()' - index = S.subs{:}; - assert(isnumeric(index)); - B.elements{index} = V; - case '{}' - index = S.subs{:}; - assert(isnumeric(index)); - B{index} = V; - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@section.subsasgn: field ' S.subs 'does not exist']); - end - otherwise - error('@section.subsasgn: syntax error'); -end -end \ No newline at end of file diff --git a/matlab/reports/@section/subsref.m b/matlab/reports/@section/subsref.m deleted file mode 100644 index 74573e564..000000000 --- a/matlab/reports/@section/subsref.m +++ /dev/null @@ -1,48 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2013-2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@section.subsref: unknown field or method: ' S(1).subs]); - end - case '()' - A = A.elements{S(1).subs{:}}; - case '{}' - error(['@section.subsref: ' S(1).type ' indexing not supported.']); - otherwise - error('@section.subsref: impossible case') -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@section/write.m b/matlab/reports/@section/write.m deleted file mode 100644 index 00a34f75c..000000000 --- a/matlab/reports/@section/write.m +++ /dev/null @@ -1,89 +0,0 @@ -function o = write(o, fid, pg, sec) -%function o = write(o, fid, pg, sec) -% Write Section object -% -% INPUTS -% o [section] section object -% fid [integer] file id -% pg [integer] this page number -% sec [integer] this section number -% -% OUTPUTS -% o [section] section object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -assert(fid ~= -1); -fprintf(fid, '%% Section Object\n'); - -if ~isempty(o.height) - fprintf(fid, '\\setlength\\sectionheight{%s}%%\n', o.height); -end -fprintf(fid, '\\maxsizebox{\\textwidth}{'); -if isempty(o.height) - fprintf(fid, '!'); -else - fprintf(fid, '\\sectionheight'); -end -fprintf(fid, '}{%%\n'); -fprintf(fid, '\\begin{tabular}[t]{'); -for i=1:o.cols - if ~isa(o.elements{1}, 'paragraph') - % if one element is a paragraph, they all are - % due to check in add*.m functions - fprintf(fid, 'l'); - else - fprintf(fid, 'c'); - end -end -fprintf(fid, '}\n'); - -ne = numElements(o); -row = 1; -col = 1; -for i=1:ne - if isa(o.elements{i}, 'vspace') - o.elements{i}.write(fid); - fprintf(fid, '\\\\\n'); - if col ~= o.cols - fprintf(fid, '\\end{tabular}}\\\\\n'); - fprintf(fid, '%% End Section Object\n\n'); - return; - end - else - if isa(o.elements{i}, 'paragraph') - o.elements{i}.write(fid); - else - o.elements{i}.write(fid, pg, sec, row, col); - end - if col ~= o.cols - fprintf(fid, ' & '); - col = col + 1; - else - fprintf(fid, '\\\\\n'); - row = row + 1; - col = 1; - end - end -end -fprintf(fid, '\\end{tabular}}\\\\\n'); -fprintf(fid, '%% End Section Object\n\n'); -end \ No newline at end of file diff --git a/matlab/reports/@vspace/display.m b/matlab/reports/@vspace/display.m deleted file mode 100644 index 9d22a5f41..000000000 --- a/matlab/reports/@vspace/display.m +++ /dev/null @@ -1,32 +0,0 @@ -function display(o) -%function display(o) -% Display a Vspace object -% -% INPUTS -% o [vspace] vspace object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -display_reporting_object(o); -end \ No newline at end of file diff --git a/matlab/reports/@vspace/subsasgn.m b/matlab/reports/@vspace/subsasgn.m deleted file mode 100644 index 3b9cbe82f..000000000 --- a/matlab/reports/@vspace/subsasgn.m +++ /dev/null @@ -1,49 +0,0 @@ -function B = subsasgn(A, S, V) -% function B = subsasgn(A, S, V) - -% Copyright (C) 2013 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 . - -B = A; -if length(S) > 1 - for i=1:(length(S)-1) - B = subsref(B, S(i)); - end - B = subsasgn(B, S(end), V); - B = subsasgn(A, S(1:(end-1)), B); - return -end - -switch S.type - case '()' - index = S.subs{:}; - assert(isnumeric(index)); - B{index} = V; - case '.' - switch S.subs - case fieldnames(A) - B.(S.subs) = V; - otherwise - error(['@vspace.subsasgn: field ' S.subs 'does not exist']); - end - case '{}' - assert(isint(S.subs{1})); - B{S.subs{1}} = V; - otherwise - error('@vspace.subsasgn: syntax error'); -end -end \ No newline at end of file diff --git a/matlab/reports/@vspace/subsref.m b/matlab/reports/@vspace/subsref.m deleted file mode 100644 index 618b985ff..000000000 --- a/matlab/reports/@vspace/subsref.m +++ /dev/null @@ -1,48 +0,0 @@ -function A = subsref(A, S) -%function A = subsref(A, S) - -% Copyright (C) 2013-2014 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 . - -switch S(1).type - case '.' - switch S(1).subs - case fieldnames(A) - A = A.(S(1).subs); - case methods(A) - if areParensNext(S) - A = feval(S(1).subs, A, S(2).subs{:}); - S = shiftS(S,1); - else - A = feval(S(1).subs, A); - end - otherwise - error(['@vspace.subsref: unknown field or method: ' S(1).subs]); - end - case '()' - A = getSections(A, S(1).subs{:}); - case '{}' - error(['@vspace.subsref: ' S(1).type ' indexing not supported.']); - otherwise - error('@vspace.subsref: impossible case') -end - -S = shiftS(S,1); -if length(S) >= 1 - A = subsref(A, S); -end -end diff --git a/matlab/reports/@vspace/vspace.m b/matlab/reports/@vspace/vspace.m deleted file mode 100644 index a3aa809da..000000000 --- a/matlab/reports/@vspace/vspace.m +++ /dev/null @@ -1,67 +0,0 @@ -function o = vspace(varargin) -%function o = vspace(varargin) -% Vspace Class Constructor -% -% INPUTS -% 0 args => empty vspace -% 1 arg (vspace class) => copy object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -o = struct; -o.number = 1; -o.hline = 0; - -if nargin == 1 - assert(isa(varargin{1}, 'vspace'), ['@vspace.vspace: with one arg to Vspace ' ... - 'constructor, you must pass a vspace object']); - o = varargin{1}; - return; -elseif nargin > 1 - if round(nargin/2) ~= nargin/2 - error(['@vspace.vspace: options must be supplied in name/value ' ... - 'pairs.']); - end - - optNames = fieldnames(o); - - % overwrite default values - for pair = reshape(varargin, 2, []) - ind = find(strcmpi(optNames, pair{1})); - assert(isempty(ind) || length(ind) == 1); - if ~isempty(ind) - o.(optNames{ind}) = pair{2}; - else - error('@vspace.vspace: %s is not a recognized option.', pair{1}); - end - end -end - -% Check options provided by user -assert(isint(o.number), '@vspace.vspace: number must be an integer'); -assert(isint(o.hline), '@vspace.vspace: hline must be an integer'); - -% Create vspace object -o = class(o, 'vspace'); -end diff --git a/matlab/reports/@vspace/write.m b/matlab/reports/@vspace/write.m deleted file mode 100644 index 4ea1d2e23..000000000 --- a/matlab/reports/@vspace/write.m +++ /dev/null @@ -1,44 +0,0 @@ -function o = write(o, fid) -%function o = write(o, fid) -% Write a Vspace object -% -% INPUTS -% o [vspace] vspace object -% fid [integer] file id -% -% OUTPUTS -% o [vspace] vspace object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -assert(fid ~= -1); - -for i=1:o.number - fprintf(fid, ' \\par \\medskip '); -end - -if o.hline > 0 - fprintf(fid, '\\\\\n'); - for i=1:o.hline - fprintf(fid, '\\midrule'); - end -end -end \ No newline at end of file diff --git a/matlab/reports/allCellsAreDates.m b/matlab/reports/allCellsAreDates.m deleted file mode 100644 index 7beca1b00..000000000 --- a/matlab/reports/allCellsAreDates.m +++ /dev/null @@ -1,39 +0,0 @@ -function tf = allCellsAreDates(dcell) -%function tf = allCellsAreDates(dcell) -% Determines if all the elements of dcell are dates objects -% -% INPUTS -% dcell cell of dates objects -% -% OUTPUTS -% tf true if every entry of dcell is a dates object -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2014 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 . - -assert(iscell(dcell)); -tf = true; -for i=1:length(dcell) - if ~isdates(dcell{i}) - tf = false; - return; - end -end -end \ No newline at end of file diff --git a/matlab/reports/allCellsAreDatesRange.m b/matlab/reports/allCellsAreDatesRange.m deleted file mode 100644 index fd3e111d8..000000000 --- a/matlab/reports/allCellsAreDatesRange.m +++ /dev/null @@ -1,39 +0,0 @@ -function tf = allCellsAreDatesRange(dcell) -%function tf = allCellsAreDatesRange(dcell) -% Determines if all the elements of dcell are a range of dates -% -% INPUTS -% dcell cell of dates -% -% OUTPUTS -% tf true if every entry of dcell is a range of dates -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2014 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 . - -assert(iscell(dcell)); -tf = true; -for i=1:length(dcell) - if ~(isdates(dcell{i}) && dcell{i}.ndat >= 2) - tf = false; - return; - end -end -end \ No newline at end of file diff --git a/matlab/reports/areParensNext.m b/matlab/reports/areParensNext.m deleted file mode 100644 index eb485d762..000000000 --- a/matlab/reports/areParensNext.m +++ /dev/null @@ -1,26 +0,0 @@ -function tf = areParensNext(S) -%function tf = areParensNext(S) - -% Copyright (C) 2013 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 length(S) > 1 && strcmp(S(2).type, '()') - tf = true; -else - tf = false; -end -end \ No newline at end of file diff --git a/matlab/reports/display_reporting_object.m b/matlab/reports/display_reporting_object.m deleted file mode 100644 index fc7ba46d0..000000000 --- a/matlab/reports/display_reporting_object.m +++ /dev/null @@ -1,95 +0,0 @@ -function display_reporting_object(o) -%function display_reporting_object(o) -% Display a Reporting Object -% i.e., one of: graph -% page -% report -% report_series -% report_table -% section -% vspace -% -% INPUTS -% o [object] reporting object -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2013-2014 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 . - -fprintf('\n%s Object = \n\n', upper(class(o))); -fields = fieldnames(o); -for i=1:length(fields) - fprintf(' %s: ', fields{i}); - val = o.(fields{i}); - if iscell(val) - fprintf('{'); - for j=1:length(val) - if ischar(val{j}); - fprintf('''%s''', val{j}); - if j~=length(val) - fprintf(', '); - end - else - if strcmp(fields{i}, 'pages') || strcmp(fields{i}, 'sections') - fprintf('%d', length(val)); - break; - else - fprintf('fix this'); - end - end - end - fprintf('}'); - elseif ischar(val) - fprintf('''%s''', val); - elseif isnumeric(val) - fprintf('%s', num2str(val)); - elseif islogical(val) - if val - fprintf('true'); - else - fprintf('false'); - end - elseif isobject(val) - if isdates(val) - if isempty(val) - fprintf(''); - else - fprintf('', ... - date2string(val(1)), date2string(val(end))); - end - elseif isdseries(val) - if numel(val) == 1 - fprintf('', val.name{1}); - else - fprintf('%s', class(val)); - end - else - cl = class(val); - fprintf('%d', val.(['num' upper(cl(1)) cl(2:end)])); - end - else - fprintf('fix this'); - end - fprintf('\n'); -end -fprintf('\n'); -end \ No newline at end of file diff --git a/matlab/reports/getMaxRange.m b/matlab/reports/getMaxRange.m deleted file mode 100644 index 1a578083c..000000000 --- a/matlab/reports/getMaxRange.m +++ /dev/null @@ -1,36 +0,0 @@ -function dd = getMaxRange(cellser) -% function dd = getMaxRange(cellser) - -% Copyright (C) 2013-2014 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 . - -ddmin = dates(); -ddmax = dates(); -ne = length(cellser); -for i=1:ne - ddt = cellser{i}.getRange(); - if ~isempty(ddt) - if isempty(ddmin) - ddmin = ddt(1); - ddmax = ddt(end); - else - ddmin = min(ddt(1), ddmin); - ddmax = max(ddt(end), ddmax); - end - end -end -dd = ddmin:ddmax; \ No newline at end of file From 5ef340b8cfe672ba404095f92f0f72c0095bf9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 24 Feb 2015 20:34:35 +0100 Subject: [PATCH 018/210] Rewrote gmhmaxlik routine (mode_compute==6). --- matlab/global_initialization.m | 4 + .../optimization/dynare_minimize_objective.m | 112 +----------------- .../{gmhmaxlik.m => gmhmaxlik_core.m} | 5 +- 3 files changed, 7 insertions(+), 114 deletions(-) rename matlab/optimization/{gmhmaxlik.m => gmhmaxlik_core.m} (97%) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 5eb4e635c..71c40e035 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -103,6 +103,10 @@ options_.bvar_prior_omega = 1; options_.bvar_prior_flat = 0; options_.bvar_prior_train = 0; +% Initialize the field that will contain the optimization algorigthm's options declared in the +% estimation command (if anny). +options_.optim_opt = []; + % Optimization algorithm [6] gmhmaxlik gmhmaxlik.iterations = 3; gmhmaxlik.number = 20000; diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 68eef8fed..452c6304a 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -184,116 +184,8 @@ switch minimizer_algorithm hessian_mat = reshape(mr_hessian(0,opt_par_values,objective_function,1,crit,varargin{:}), n_params, n_params); end case 6 - % Set default options - gmhmaxlikOptions = options_.gmhmaxlik; - if ~isempty(Initial_Hessian); - gmhmaxlikOptions.varinit = 'previous'; - else - gmhmaxlikOptions.varinit = 'prior'; - end - if isfield(options_,'optim_opt') - options_list = read_key_value_string(options_.optim_opt); - for i=1:rows(options_list) - switch options_list{i,1} - case 'NumberOfMh' - gmhmaxlikOptions.iterations = options_list{i,2}; - case 'ncov-mh' - gmhmaxlikOptions.number = options_list{i,2}; - case 'nscale' - gmhmaxlikOptions.nscale = options_list{i,2}; - case 'nclimb' - gmhmaxlikOptions.nclimb = options_list{i,2}; - case 'InitialCovarianceMatrix' - switch options_list{i,2} - case 'previous' - if isempty(Initial_Hessian) - error('gmhmaxlik: No previous estimate of the Hessian matrix available! You cannot use the InitialCovarianceMatrix option!') - else - gmhmaxlikOptions.varinit = 'previous'; - end - case {'prior', 'identity'} - gmhmaxlikOptions.varinit = options_list{i,2}; - otherwise - error('gmhmaxlik: Unknown value for option ''InitialCovarianceMatrix''!') - end - case 'AcceptanceRateTarget' - gmhmaxlikOptions.target = options_list{i,2}; - if gmhmaxlikOptions.target>1 || gmhmaxlikOptions.target1 - flag = ''; - else - flag = 'LastCall'; - end - [opt_par_values,PostVar,Scale,PostMean] = ... - gmhmaxlik(objective_function,start_par_value,bounds,gmhmaxlikOptions,Scale,flag,MeanPar,CovJump,varargin{:}); - fval = feval(objective_function,opt_par_values,varargin{:}); - mouvement = max(max(abs(PostVar-OldPostVar))); - skipline() - disp('========================================================== ') - disp([' Change in the covariance matrix = ' num2str(mouvement) '.']) - disp([' Mode improvement = ' num2str(abs(OldMode-fval))]) - disp([' New value of jscale = ' num2str(Scale)]) - disp('========================================================== ') - OldMode = fval; - else - OldPostVar = PostVar; - if i Date: Tue, 24 Feb 2015 20:42:19 +0100 Subject: [PATCH 019/210] Added missing routine and fixed licence header. --- matlab/optimization/gmhmaxlik.m | 120 +++++++++++++++++++++++++++ matlab/optimization/gmhmaxlik_core.m | 2 +- 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 matlab/optimization/gmhmaxlik.m diff --git a/matlab/optimization/gmhmaxlik.m b/matlab/optimization/gmhmaxlik.m new file mode 100644 index 000000000..4501f845c --- /dev/null +++ b/matlab/optimization/gmhmaxlik.m @@ -0,0 +1,120 @@ +function [PostMode, HessianMatrix, Scale, ModeValue] = gmhmaxlik(fun, xinit, Hinit, iscale, bounds, priorstd, gmhmaxlikOptions, OptimizationOptions, varargin) + +% Copyright (C) 2006-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 . + +% Set default options + +if ~isempty(Hinit); + gmhmaxlikOptionsptions.varinit = 'previous'; +else + gmhmaxlikOptions.varinit = 'prior'; +end + +if ~isempty(OptimizationOptions) + DynareOptionslist = read_key_value_string(OptimizationOptions); + for i=1:rows(DynareOptionslist) + switch DynareOptionslist{i,1} + case 'NumberOfMh' + gmhmaxlikOptions.iterations = DynareOptionslist{i,2}; + case 'ncov-mh' + gmhmaxlikOptions.number = DynareOptionslist{i,2}; + case 'nscale' + gmhmaxlikOptions.nscale = DynareOptionslist{i,2}; + case 'nclimb' + gmhmaxlikOptions.nclimb = DynareOptionslist{i,2}; + case 'InitialCovarianceMatrix' + switch DynareOptionslist{i,2} + case 'previous' + if isempty(Hinit) + error('gmhmaxlik: No previous estimate of the Hessian matrix available! You cannot use the InitialCovarianceMatrix option!') + else + gmhmaxlikOptions.varinit = 'previous'; + end + case {'prior', 'identity'} + gmhmaxlikOptions.varinit = DynareOptionslist{i,2}; + otherwise + error('gmhmaxlik: Unknown value for option ''InitialCovarianceMatrix''!') + end + case 'AcceptanceRateTarget' + gmhmaxlikOptions.target = DynareOptionslist{i,2}; + if gmhmaxlikOptions.target>1 || gmhmaxlikOptions.target Date: Thu, 26 Feb 2015 12:07:40 +0100 Subject: [PATCH 023/210] Beta prior. Do not return the prior mean of the prior density has two modes (return the first mode). --- matlab/set_prior.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/set_prior.m b/matlab/set_prior.m index 9fcbd10b3..7bc3cc83d 100644 --- a/matlab/set_prior.m +++ b/matlab/set_prior.m @@ -179,7 +179,7 @@ for i=1:length(k) bayestopt_.p5(k(i)) = m; else disp(['Prior distribution for parameter ' bayestopt_.name{k(i)} ' has two modes!']) - bayestopt_.p5(k(i)) = bayestopt_.p1(k(i)) ; + bayestopt_.p5(k(i)) = m(1); end end From 4979f33f8b6ab09368d322f0828dac7b554e35d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 26 Feb 2015 16:10:44 +0100 Subject: [PATCH 024/210] Added the possibility to return the generated line in a variable. --- matlab/printline.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/matlab/printline.m b/matlab/printline.m index e7d6276a3..21b8cdaef 100644 --- a/matlab/printline.m +++ b/matlab/printline.m @@ -1,4 +1,4 @@ -function printline(n, s, fid) +function varargout = printline(n, s, fid) % This function print a line formed by replicating a symbol s. % % INPUTS @@ -43,4 +43,8 @@ for i=2:n S = sprintf('%s%s',S,s); end -fprintf(f,sprintf('%s\n',S)) \ No newline at end of file +if nargout + varargout(1) = { sprintf('%s\n',S) }; +else + fprintf(f,sprintf('%s\n',S)) +end \ No newline at end of file From eec1e77140080d27770526f7d63de275800180bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 26 Feb 2015 16:18:33 +0100 Subject: [PATCH 025/210] Removed last character if string is renurned in a variable. --- matlab/printline.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/printline.m b/matlab/printline.m index 21b8cdaef..c60d0906a 100644 --- a/matlab/printline.m +++ b/matlab/printline.m @@ -44,7 +44,7 @@ for i=2:n end if nargout - varargout(1) = { sprintf('%s\n',S) }; + varargout(1) = { sprintf('%s',S) }; else fprintf(f,sprintf('%s\n',S)) end \ No newline at end of file From daaed377820ca13e627feca55f60ad6887822161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 27 Feb 2015 17:05:11 +0100 Subject: [PATCH 026/210] Added new routines. --- matlab/optimize_prior.m | 74 +++++++++++++++++ matlab/print_table_prior.m | 158 +++++++++++++++++++++++++++++++++++++ matlab/write_table_prior.m | 142 +++++++++++++++++++++++++++++++++ 3 files changed, 374 insertions(+) create mode 100644 matlab/optimize_prior.m create mode 100644 matlab/print_table_prior.m create mode 100644 matlab/write_table_prior.m diff --git a/matlab/optimize_prior.m b/matlab/optimize_prior.m new file mode 100644 index 000000000..a3595d0f6 --- /dev/null +++ b/matlab/optimize_prior.m @@ -0,0 +1,74 @@ +function optimize_prior(DynareOptions, ModelInfo, DynareResults, BayesInfo, EstimationInfo) + +% This routine computes the mode of the prior density using an optimization algorithm. + +% 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 . + +% Initialize to the prior mean +DynareResults.dr = set_state_space(DynareResults.dr,ModelInfo,DynareOptions); +xparam1 = BayesInfo.p1; + +% Pertubation of the initial condition. +look_for_admissible_initial_condition = 1; scale = 1.0; iter = 0; +while look_for_admissible_initial_condition + xinit = xparam1+scale*randn(size(xparam1)); + if all(xinit(:)>BayesInfo.p3) && all(xinit(:). + +PriorNames = 'Beta'; +PriorNames = strvcat(PriorNames,'Gamma'); +PriorNames = strvcat(PriorNames,'Gaussian'); +PriorNames = strvcat(PriorNames,'Inverted Gamma'); +PriorNames = strvcat(PriorNames,'Uniform'); +PriorNames = strvcat(PriorNames,'Inverted Gamma -- 2'); + +n = size(BayesInfo.name,1); % Numbe rof estimated parameters. + +l1 = printline(10, '-'); +T1 = strvcat(l1, 'PARAMETER '); +T1 = strvcat(T1, l1); + +l2 = printline(133, '-'); +T2 = strvcat(l2, sprintf('Prior shape \t Prior mean \t Prior mode \t Prior std. \t Prior lb \t Prior ub \t Prior HPD lb \t Prior HPH ub')); +T2 = strvcat(T2, l2); + +prior_trunc_backup = DynareOptions.prior_trunc ; +DynareOptions.prior_trunc = (1-DynareOptions.prior_interval)/2 ; +PriorIntervals = prior_bounds(BayesInfo,DynareOptions) ; +DynareOptions.prior_trunc = prior_trunc_backup ; + +RESIZE = false; + +for i=1:size(BayesInfo.name,1) + [Name,tmp] = get_the_name(i,1,ModelInfo,EstimationInfo,DynareOptions); + if length(Name)>size(T1,2) + resize = true; + else + resize = false; + end + T1 = strvcat(T1, Name); + if resize + RESIZE = true; + l1 = printline(length(Name)); + T1(1,:) = l1; + T1(3,:) = l1; + end + PriorShape = PriorNames(BayesInfo.pshape(i),:); + PriorMean = BayesInfo.p1(i); + PriorMode = BayesInfo.p5(i); + PriorStandardDeviation = BayesInfo.p2(i); + switch BayesInfo.pshape(i) + case { 1 , 5 } + LowerBound = BayesInfo.p3(i); + UpperBound = BayesInfo.p4(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); + end + case { 2 , 4 , 6 } + LowerBound = BayesInfo.p3(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=ub(i); + else + UpperBound = Inf; + end + case 3 + if isinf(BayesInfo.p3(i)) && isinf(lb(i)) + LowerBound = -Inf; + else + LowerBound = BayesInfo.p3(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + end + if isinf(BayesInfo.p4(i)) && isinf(ub(i)) + UpperBound = Inf; + else + UpperBound = BayesInfo.p4(i); + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); + end + end + otherwise + error('get_prior_info:: Dynare bug!') + end + format_string = build_format_string(PriorMode, PriorStandardDeviation,LowerBound,UpperBound); + str = sprintf(format_string, ... + PriorShape, ... + PriorMean, ... + PriorMode, ... + PriorStandardDeviation, ... + LowerBound, ... + UpperBound, ... + PriorIntervals.lb(i), ... + PriorIntervals.ub(i) ); + T2 = strvcat(T2, str); +end + +T1 = strvcat(T1, l1); +T2 = strvcat(T2, l2); + +skipline(2) + +if RESIZE + l0 = printline(2); + T0 = strvcat(l0,' '); + T0 = strvcat(T0, l0); + T0 = strvcat(T0, repmat(' ', n, 1)); + T0 = strvcat(T0, l0); + disp([T1, T0, T2]) +else + disp([T1, T2]) +end + +skipline(2) + + +function format_string = build_format_string(PriorMode,PriorStandardDeviation,LowerBound,UpperBound) + format_string = ['%s \t %6.4f \t']; + if isnan(PriorMode) + format_string = [ format_string , ' %s \t']; + else + format_string = [ format_string , ' %6.4f \t']; + end + if ~isnumeric(PriorStandardDeviation) + format_string = [ format_string , ' %s \t']; + else + format_string = [ format_string , ' %6.4f \t']; + end + if ~isnumeric(LowerBound) + format_string = [ format_string , ' %s \t']; + else + format_string = [ format_string , ' %6.4f \t']; + end + if ~isnumeric(UpperBound) + format_string = [ format_string , ' %s \t']; + else + format_string = [ format_string , ' %6.4f \t']; + end + format_string = [ format_string , ' %6.4f \t %6.4f']; \ No newline at end of file diff --git a/matlab/write_table_prior.m b/matlab/write_table_prior.m new file mode 100644 index 000000000..3c6c847c6 --- /dev/null +++ b/matlab/write_table_prior.m @@ -0,0 +1,142 @@ +function write_table_prior(lb, ub, DynareOptions, ModelInfo, BayesInfo, EstimationInfo) + +% This routine builds a latex table with some descriptive statistics about the prior distribution. + +% 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 . + +PriorNames = { 'Beta' , 'Gamma' , 'Gaussian' , 'Inverted Gamma' , 'Uniform' , 'Inverted Gamma -- 2' }; + +if size(ModelInfo.param_names,1)==size(ModelInfo.param_names_tex,1)% All the parameters have a TeX name. + fidTeX = fopen('priors_data.tex','w+'); + fprintf(fidTeX,'%% TeX-table generated by Dynare.\n'); + fprintf(fidTeX,'%% Prior Information\n'); + fprintf(fidTeX,['%% ' datestr(now,0)]); + fprintf(fidTeX,' \n'); + fprintf(fidTeX,' \n'); + fprintf(fidTeX,'\\begin{center}\n'); + fprintf(fidTeX,'\\begin{longtable}{l|cccccccc} \n'); + fprintf(fidTeX,'\\caption{Prior information (parameters)}\\\\\n '); + fprintf(fidTeX,'\\label{Table:Prior}\\\\\n'); + fprintf(fidTeX,'\\hline\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior mode & Prior s.d. & Lower Bound & Upper Bound & LB Untrunc. 80\\%% HPDI & UB Untrunc. 80\\%% HPDI \\\\ \n'); + fprintf(fidTeX,'\\hline \\endfirsthead \n'); + fprintf(fidTeX,'\\caption{(continued)}\\\\\n '); + fprintf(fidTeX,'\\hline\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior mode & Prior s.d. & Lower Bound & Upper Bound & LB Untrunc. 80\\%% HPDI & UB Untrunc. 80\\%% HPDI \\\\ \n'); + fprintf(fidTeX,'\\hline \\endhead \n'); + fprintf(fidTeX,'\\hline \\multicolumn{9}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); + fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); + % Column 1: a string for the name of the prior distribution. + % Column 2: the prior mean. + % Column 3: the prior mode. + % Column 4: the prior standard deviation. + % Column 5: the lower bound of the prior density support. + % Column 6: the upper bound of the prior density support. + % Column 7: the lower bound of the interval containing 80% of the prior mass. + % Column 8: the upper bound of the interval containing 80% of the prior mass. + prior_trunc_backup = DynareOptions.prior_trunc ; + DynareOptions.prior_trunc = (1-DynareOptions.prior_interval)/2 ; + PriorIntervals = prior_bounds(BayesInfo,DynareOptions) ; + DynareOptions.prior_trunc = prior_trunc_backup ; + for i=1:size(BayesInfo.name,1) + [tmp,TexName] = get_the_name(i,1,ModelInfo,EstimationInfo,DynareOptions); + PriorShape = PriorNames{ BayesInfo.pshape(i) }; + PriorMean = BayesInfo.p1(i); + PriorMode = BayesInfo.p5(i); + PriorStandardDeviation = BayesInfo.p2(i); + switch BayesInfo.pshape(i) + case { 1 , 5 } + LowerBound = BayesInfo.p3(i); + UpperBound = BayesInfo.p4(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); + end + case { 2 , 4 , 6 } + LowerBound = BayesInfo.p3(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + if ~isinf(ub(i)) + UpperBound=ub(i); + else + UpperBound = '$\infty$'; + end + case 3 + if isinf(BayesInfo.p3(i)) && isinf(lb(i)) + LowerBound = '$-\infty$'; + else + LowerBound = BayesInfo.p3(i); + if ~isinf(lb(i)) + LowerBound=max(LowerBound,lb(i)); + end + end + if isinf(BayesInfo.p4(i)) && isinf(ub(i)) + UpperBound = '$\infty$'; + else + UpperBound = BayesInfo.p4(i); + if ~isinf(ub(i)) + UpperBound=min(UpperBound,ub(i)); + end + end + otherwise + error('get_prior_info:: Dynare bug!') + end + format_string = build_format_string(PriorMode, PriorStandardDeviation,LowerBound,UpperBound); + fprintf(fidTeX,format_string, ... + TexName, ... + PriorShape, ... + PriorMean, ... + PriorMode, ... + PriorStandardDeviation, ... + LowerBound, ... + UpperBound, ... + PriorIntervals.lb(i), ... + PriorIntervals.ub(i) ); + end + fprintf(fidTeX,'\\end{longtable}\n '); + fprintf(fidTeX,'\\end{center}\n'); + fprintf(fidTeX,'%% End of TeX file.\n'); + fclose(fidTeX); +end + +function format_string = build_format_string(PriorMode,PriorStandardDeviation,LowerBound,UpperBound) +format_string = ['%s & %s & %6.4f &']; +if isnan(PriorMode) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(PriorStandardDeviation) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(LowerBound) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(UpperBound) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n']; \ No newline at end of file From 73cdaa3091b109564c55bd538f8769461bf94fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 27 Feb 2015 17:12:04 +0100 Subject: [PATCH 027/210] Replaced get_prior_info routine by prior routine. This new routine gives the possibility to obtain a description of the prior from the command line. >> prior table will display a table with the prior mean, prior mode, prior std, prior bounds and prior HPD interval. >> prior plot will plot the prior densities. >> prior optimize will trigger the maximization of the prior density and display the results (often, because of BK conditions or other issues, Dynare is even not able to get the prior mode). >> prior moments will display the moments of the endogenous variables at the prior mode. >> prior simulate will run a Monte-Carlo, by sampling from the prior and discarding vector of parameters such that the steady state does not exist or the BK conditions are not met, and return an estimate of the effective prior mass. --- matlab/cli/prior.m | 129 ++++++++++++++++++++ matlab/dynare_config.m | 1 + matlab/get_prior_info.m | 253 ---------------------------------------- 3 files changed, 130 insertions(+), 253 deletions(-) create mode 100644 matlab/cli/prior.m delete mode 100644 matlab/get_prior_info.m diff --git a/matlab/cli/prior.m b/matlab/cli/prior.m new file mode 100644 index 000000000..f490a570b --- /dev/null +++ b/matlab/cli/prior.m @@ -0,0 +1,129 @@ +function varargout = prior(varargin) + +% Computes various prior statistics and display them in the command window. +% +% INPUTS +% 'table', 'moments', 'optimize', 'simulate', 'plot' +% +% OUTPUTS +% none +% +% 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 . + +global options_ M_ estim_params_ bayestopt_ oo_ objective_function_penalty_base + +donesomething = false; + +% Temporarly change qz_criterium option value +changed_qz_criterium_flag = 0; +if isempty(options_.qz_criterium) + options_.qz_criterium = 1+1e-9; + changed_qz_criterium_flag = 1; +end + +M_.dname = M_.fname; + +% Temporarly set options_.order equal to one +order = options_.order; +options_.order = 1; + +[xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_); + +if ismember('plot', varargin) + plot_priors(bayestopt_,M_,estim_params_,options_) + donesomething = true; +end + +if ismember('table', varargin) + print_table_prior(lb, ub, options_, M_, bayestopt_, estim_params_); + donesomething = true; +end + +if ismember('simulate', varargin) % Prior simulations (BK). + results = prior_sampler(0,M_,bayestopt_,options_,oo_,estim_params_); + % Display prior mass info + skipline(2) + disp(['Prior mass = ' num2str(results.prior.mass)]) + disp(['BK indeterminacy share = ' num2str(results.bk.indeterminacy_share)]) + disp(['BK unstability share = ' num2str(results.bk.unstability_share)]) + disp(['BK singularity share = ' num2str(results.bk.singularity_share)]) + disp(['Complex jacobian share = ' num2str(results.jacobian.problem_share)]) + disp(['mjdgges crash share = ' num2str(results.dll.problem_share)]) + disp(['Steady state problem share = ' num2str(results.ss.problem_share)]) + disp(['Complex steady state share = ' num2str(results.ss.complex_share)]) + disp(['Analytical steady state problem share = ' num2str(results.ass.problem_share)]) + skipline(2) + donesomething = true; +end + +if ismember('optimize', varargin) % Prior optimization. + optimize_prior(options_, M_, oo_, bayestopt_, estim_params_); + donesomething = true; +end + +if ismember('moments', varargin) % Prior simulations (2nd order moments). + % Set estimated parameters to the prior mode... + xparam1 = bayestopt_.p5; + % ... Except for uniform priors! + k = find(isnan(xparam1)); + xparam1(k) = bayestopt_.p5(k); + % Update vector of parameters and covariance matrices + M_ = set_all_parameters(xparam1,estim_params_,M_); + % Check model. + check_model(M_); + % Compute state space representation of the model. + oo_.dr=set_state_space(oo_.dr, M_, options_); + % Solve model + [dr,info, M_ ,options_ , oo_] = resol(0, M_ , options_ ,oo_); + % Compute and display second order moments + disp_th_moments(oo_.dr,[]); + skipline(2) + donesomething = true; +end + +if changed_qz_criterium_flag + options_.qz_criterium = []; +end + +options_.order = order; + +if ~donesomething + error('prior: Unexpected arguments!') +end + +function format_string = build_format_string(PriorStandardDeviation,LowerBound,UpperBound) +format_string = ['%s & %s & %6.4f &']; +if ~isnumeric(PriorStandardDeviation) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(LowerBound) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +if ~isnumeric(UpperBound) + format_string = [ format_string , ' %s &']; +else + format_string = [ format_string , ' %6.4f &']; +end +format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n']; \ No newline at end of file diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index 24543ddcd..160cd6222 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -58,6 +58,7 @@ addpath([dynareroot '/parallel/']) addpath([dynareroot '/particle/']) addpath([dynareroot '/gsa/']) addpath([dynareroot '/ep/']) +addpath([dynareroot '/cli/']) addpath([dynareroot '/lmmcp/']) addpath([dynareroot '/optimization/']) addpath([dynareroot '/modules/dates/src/']) diff --git a/matlab/get_prior_info.m b/matlab/get_prior_info.m deleted file mode 100644 index 6a82442bf..000000000 --- a/matlab/get_prior_info.m +++ /dev/null @@ -1,253 +0,0 @@ -function results = get_prior_info(info,plt_flag) -% Computes various prior statistics. -% -% INPUTS -% info [integer] scalar specifying what has to be done. -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2009-2012 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . -global options_ M_ estim_params_ oo_ objective_function_penalty_base - -if ~nargin - info = 0; - plt_flag = 0; -end - -if nargin==1 - plt_flag = 1; -end - -% Initialize returned variable. -results = []; - -changed_qz_criterium_flag = 0; -if isempty(options_.qz_criterium) - options_.qz_criterium = 1+1e-9; - changed_qz_criterium_flag = 1; -end - -M_.dname = M_.fname; - -% Temporarly set options_.order equal to one -order = options_.order; -options_.order = 1; - -[xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_); - -if plt_flag - plot_priors(bayestopt_,M_,estim_params_,options_) -end - -PriorNames = { 'Beta' , 'Gamma' , 'Gaussian' , 'Inverted Gamma' , 'Uniform' , 'Inverted Gamma -- 2' }; - -if size(M_.param_names,1)==size(M_.param_names_tex,1)% All the parameters have a TeX name. - fidTeX = fopen('priors_data.tex','w+'); - fprintf(fidTeX,'%% TeX-table generated by get_prior_info (Dynare).\n'); - fprintf(fidTeX,'%% Prior Information\n'); - fprintf(fidTeX,['%% ' datestr(now,0)]); - fprintf(fidTeX,' \n'); - fprintf(fidTeX,' \n'); - fprintf(fidTeX,'\\begin{center}\n'); - fprintf(fidTeX,'\\begin{longtable}{l|ccccccc} \n'); - fprintf(fidTeX,'\\caption{Prior information (parameters)}\\\\\n '); - fprintf(fidTeX,'\\label{Table:Prior}\\\\\n'); - fprintf(fidTeX,'\\hline\\hline \\\\ \n'); - fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Lower Bound & Upper Bound & LB Untrunc. 80\\%% HPDI & UB Untrunc. 80\\%% HPDI \\\\ \n'); - fprintf(fidTeX,'\\hline \\endfirsthead \n'); - fprintf(fidTeX,'\\caption{(continued)}\\\\\n '); - fprintf(fidTeX,'\\hline\\hline \\\\ \n'); - fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Lower Bound & Upper Bound & LB Untrunc. 80\\%% HPDI & UB Untrunc. 80\\%% HPDI \\\\ \n'); - fprintf(fidTeX,'\\hline \\endhead \n'); - fprintf(fidTeX,'\\hline \\multicolumn{8}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); - fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); - - % Column 1: a string for the name of the prior distribution. - % Column 2: the prior mean. - % Column 3: the prior standard deviation. - % Column 4: the lower bound of the prior density support. - % Column 5: the upper bound of the prior density support. - % Column 6: the lower bound of the interval containing 80% of the prior mass. - % Column 7: the upper bound of the interval containing 80% of the prior mass. - prior_trunc_backup = options_.prior_trunc ; - options_.prior_trunc = (1-options_.prior_interval)/2 ; - PriorIntervals = prior_bounds(bayestopt_,options_) ; - options_.prior_trunc = prior_trunc_backup ; - for i=1:size(bayestopt_.name,1) - [tmp,TexName] = get_the_name(i,1,M_,estim_params_,options_); - PriorShape = PriorNames{ bayestopt_.pshape(i) }; - PriorMean = bayestopt_.p1(i); - PriorStandardDeviation = bayestopt_.p2(i); - switch bayestopt_.pshape(i) - case { 1 , 5 } - LowerBound = bayestopt_.p3(i); - UpperBound = bayestopt_.p4(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - if ~isinf(ub(i)) - UpperBound=min(UpperBound,ub(i)); - end - case { 2 , 4 , 6 } - LowerBound = bayestopt_.p3(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - if ~isinf(ub(i)) - UpperBound=ub(i); - else - UpperBound = '$\infty$'; - end - case 3 - if isinf(bayestopt_.p3(i)) && isinf(lb(i)) - LowerBound = '$-\infty$'; - else - LowerBound = bayestopt_.p3(i); - if ~isinf(lb(i)) - LowerBound=max(LowerBound,lb(i)); - end - end - if isinf(bayestopt_.p4(i)) && isinf(ub(i)) - UpperBound = '$\infty$'; - else - UpperBound = bayestopt_.p4(i); - if ~isinf(ub(i)) - UpperBound=min(UpperBound,ub(i)); - end - end - otherwise - error('get_prior_info:: Dynare bug!') - end - format_string = build_format_string(PriorStandardDeviation,LowerBound,UpperBound); - fprintf(fidTeX,format_string, ... - TexName, ... - PriorShape, ... - PriorMean, ... - PriorStandardDeviation, ... - LowerBound, ... - UpperBound, ... - PriorIntervals.lb(i), ... - PriorIntervals.ub(i) ); - end - fprintf(fidTeX,'\\end{longtable}\n '); - fprintf(fidTeX,'\\end{center}\n'); - fprintf(fidTeX,'%% End of TeX file.\n'); - fclose(fidTeX); -end - -M_.dname = M_.fname; - -if info==1% Prior simulations (BK). - results = prior_sampler(0,M_,bayestopt_,options_,oo_,estim_params_); - % Display prior mass info - disp(['Prior mass = ' num2str(results.prior.mass)]) - disp(['BK indeterminacy share = ' num2str(results.bk.indeterminacy_share)]) - disp(['BK unstability share = ' num2str(results.bk.unstability_share)]) - disp(['BK singularity share = ' num2str(results.bk.singularity_share)]) - disp(['Complex jacobian share = ' num2str(results.jacobian.problem_share)]) - disp(['mjdgges crash share = ' num2str(results.dll.problem_share)]) - disp(['Steady state problem share = ' num2str(results.ss.problem_share)]) - disp(['Complex steady state share = ' num2str(results.ss.complex_share)]) - disp(['Analytical steady state problem share = ' num2str(results.ass.problem_share)]) -end - -if info==2% Prior optimization. - % Initialize to the prior mode if possible - oo_.dr=set_state_space(oo_.dr,M_,options_); - k = find(~isnan(bayestopt_.p5)); - xparam1(k) = bayestopt_.p5(k); - % Pertubation of the initial condition. - look_for_admissible_initial_condition = 1; - scale = 1.0; - iter = 0; - while look_for_admissible_initial_condition - xinit = xparam1+scale*randn(size(xparam1)); - if all(xinit(:)>bayestopt_.p3) && all(xinit(:) Date: Fri, 27 Feb 2015 18:52:41 +0100 Subject: [PATCH 028/210] Removed three unused routines. --- matlab/PosteriorFilterSmootherAndForecast.m | 275 -------------------- matlab/forcst_unc.m | 152 ----------- matlab/rndprior.m | 57 ---- 3 files changed, 484 deletions(-) delete mode 100644 matlab/PosteriorFilterSmootherAndForecast.m delete mode 100644 matlab/forcst_unc.m delete mode 100644 matlab/rndprior.m diff --git a/matlab/PosteriorFilterSmootherAndForecast.m b/matlab/PosteriorFilterSmootherAndForecast.m deleted file mode 100644 index b63656563..000000000 --- a/matlab/PosteriorFilterSmootherAndForecast.m +++ /dev/null @@ -1,275 +0,0 @@ -function PosteriorFilterSmootherAndForecast(Y,gend, type,data_index) - -% function PosteriorFilterSmootherAndForecast(Y,gend, type) -% Computes posterior filter smoother and forecasts -% -% INPUTS -% Y: data -% gend: number of observations -% type: posterior -% prior -% gsa -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2005-2012 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -global options_ estim_params_ oo_ M_ bayestopt_ - -nvx = estim_params_.nvx; -nvn = estim_params_.nvn; -ncx = estim_params_.ncx; -ncn = estim_params_.ncn; -np = estim_params_.np ; -npar = nvx+nvn+ncx+ncn+np; -offset = npar-np; -naK = length(options_.filter_step_ahead); - -MaxNumberOfPlotPerFigure = 4;% The square root must be an integer! -MaxNumberOfBytes=options_.MaxNumberOfBytes; -endo_nbr=M_.endo_nbr; -exo_nbr=M_.exo_nbr; -nvobs = length(options_.varobs); -nn = sqrt(MaxNumberOfPlotPerFigure); -iendo = 1:endo_nbr; -i_last_obs = gend+(1-M_.maximum_endo_lag:0); -horizon = options_.forecast; -maxlag = M_.maximum_endo_lag; - -CheckPath('Plots/',M_.dname); -MetropolisFolder = CheckPath('metropolis',M_.dname); -ModelName = M_.fname; -BaseName = [MetropolisFolder filesep Model_name]; - -load_last_mh_history_file(MetropolisFolder,ModelName); - -FirstMhFile = record.KeepedDraws.FirstMhFile; -FirstLine = record.KeepedDraws.FirstLine; -TotalNumberOfMhFiles = sum(record.MhDraws(:,2)); LastMhFile = TotalNumberOfMhFiles; -TotalNumberOfMhDraws = sum(record.MhDraws(:,1)); -NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws); - -B = min(1200, round(0.25*NumberOfDraws)); -B = 200; - -MAX_nruns = min(B,ceil(options_.MaxNumberOfBytes/(npar+2)/8)); -MAX_nsmoo = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*gend)/8)); -MAX_ninno = min(B,ceil(MaxNumberOfBytes/(exo_nbr*gend)/8)); -MAX_nerro = min(B,ceil(MaxNumberOfBytes/(length(options_.varobs)*gend)/8)); -if naK - MAX_naK = min(B,ceil(MaxNumberOfBytes/(length(options_.varobs)* ... - length(options_.filter_step_ahead)*gend)/8)); -end -if horizon - MAX_nforc1 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*(horizon+maxlag))/8)); - MAX_nforc2 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*(horizon+maxlag))/ ... - 8)); - IdObs = bayestopt_.mfys; - -end - -varlist = options_.varlist; -if isempty(varlist) - varlist = M_.endo_names; - SelecVariables = transpose(1:M_.endo_nbr); - nvar = M_.endo_nbr; -else - nvar = size(varlist,1); - SelecVariables = []; - for i=1:nvar - if ~isempty(strmatch(varlist(i,:),M_.endo_names,'exact')) - SelecVariables = [SelecVariables;strmatch(varlist(i,:),M_.endo_names,'exact')]; - end - end -end - -irun1 = 1; -irun2 = 1; -irun3 = 1; -irun4 = 1; -irun5 = 1; -irun6 = 1; -irun7 = 1; -ifil1 = 0; -ifil2 = 0; -ifil3 = 0; -ifil4 = 0; -ifil5 = 0; -ifil6 = 0; -ifil7 = 0; - -h = waitbar(0,'Bayesian smoother...'); - -stock_param = zeros(MAX_nruns, npar); -stock_logpo = zeros(MAX_nruns,1); -stock_ys = zeros(MAX_nruns,endo_nbr); -if options_.smoother - stock_smooth = zeros(endo_nbr,gend,MAX_nsmoo); - stock_innov = zeros(exo_nbr,gend,B); - stock_error = zeros(nvobs,gend,MAX_nerro); -end -if options_.filter_step_ahead - stock_filter = zeros(naK,endo_nbr,gend+options_.filter_step_ahead(end),MAX_naK); -end -if options_.forecast - stock_forcst_mean = zeros(endo_nbr,horizon+maxlag,MAX_nforc1); - stock_forcst_total = zeros(endo_nbr,horizon+maxlag,MAX_nforc2); -end - -for b=1:B - [deep, logpo] = GetOneDraw(type); - M_ = set_all_parameters(deep,estim_params_,M_); - [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = ... - DsgeSmoother(deep,gend,Y,data_index); - - if options_.loglinear - stock_smooth(dr.order_var,:,irun1) = alphahat(1:endo_nbr,:)+ ... - repmat(log(dr.ys(dr.order_var)),1,gend); - else - stock_smooth(dr.order_var,:,irun1) = alphahat(1:endo_nbr,:)+ ... - repmat(dr.ys(dr.order_var),1,gend); - end - if nvx - stock_innov(:,:,irun2) = etahat; - end - if nvn - stock_error(:,:,irun3) = epsilonhat; - end - if naK - stock_filter(:,dr.order_var,:,irun4) = aK(options_.filter_step_ahead,1:endo_nbr,:); - end - stock_param(irun5,:) = deep; - stock_logpo(irun5,1) = logpo; - stock_ys(irun5,:) = SteadyState'; - - if horizon - yyyy = alphahat(iendo,i_last_obs); - yf = forcst2a(yyyy,dr,zeros(horizon,exo_nbr)); - if options_.prefilter == 1 - yf(:,IdObs) = yf(:,IdObs)+repmat(bayestopt_.mean_varobs', ... - horizon+maxlag,1); - end - yf(:,IdObs) = yf(:,IdObs)+(gend+[1-maxlag:horizon]')*trend_coeff'; - if options_.loglinear - yf = yf+repmat(log(SteadyState'),horizon+maxlag,1); - else - yf = yf+repmat(SteadyState',horizon+maxlag,1); - end - yf1 = forcst2(yyyy,horizon,dr,1); - if options_.prefilter - yf1(:,IdObs,:) = yf1(:,IdObs,:)+ ... - repmat(bayestopt_.mean_varobs',[horizon+maxlag,1,1]); - end - yf1(:,IdObs,:) = yf1(:,IdObs,:)+repmat((gend+[1-maxlag:horizon]')* ... - trend_coeff',[1,1,1]); - if options_.loglinear - yf1 = yf1 + repmat(log(SteadyState'),[horizon+maxlag,1,1]); - else - yf1 = yf1 + repmat(SteadyState',[horizon+maxlag,1,1]); - end - - stock_forcst_mean(:,:,irun6) = yf'; - stock_forcst_total(:,:,irun7) = yf1'; - end - - irun1 = irun1 + 1; - irun2 = irun2 + 1; - irun3 = irun3 + 1; - irun4 = irun4 + 1; - irun5 = irun5 + 1; - irun6 = irun6 + 1; - irun7 = irun7 + 1; - - if irun1 > MAX_nsmoo || b == B - stock = stock_smooth(:,:,1:irun1-1); - ifil1 = ifil1 + 1; - save([BaseName '_smooth' int2str(ifil1) '.mat'],'stock'); - irun1 = 1; - end - - if nvx && (irun2 > MAX_ninno || b == B) - stock = stock_innov(:,:,1:irun2-1); - ifil2 = ifil2 + 1; - save([BaseName '_inno' int2str(ifil2) '.mat'],'stock'); - irun2 = 1; - end - - if nvn && (irun3 > MAX_error || b == B) - stock = stock_error(:,:,1:irun3-1); - ifil3 = ifil3 + 1; - save([BaseName '_error' int2str(ifil3) '.mat'],'stock'); - irun3 = 1; - end - - if naK && (irun4 > MAX_naK || b == B) - stock = stock_filter(:,:,:,1:irun4-1); - ifil4 = ifil4 + 1; - save([BaseName '_filter' int2str(ifil4) '.mat'],'stock'); - irun4 = 1; - end - - if irun5 > MAX_nruns || b == B - stock = stock_param(1:irun5-1,:); - ifil5 = ifil5 + 1; - save([BaseName '_param' int2str(ifil5) '.mat'],'stock','stock_logpo','stock_ys'); - irun5 = 1; - end - - if horizon && (irun6 > MAX_nforc1 || b == B) - stock = stock_forcst_mean(:,:,1:irun6-1); - ifil6 = ifil6 + 1; - save([BaseName '_forc_mean' int2str(ifil6) '.mat'],'stock'); - irun6 = 1; - end - - if horizon && (irun7 > MAX_nforc2 || b == B) - stock = stock_forcst_total(:,:,1:irun7-1); - ifil7 = ifil7 + 1; - save([BaseName '_forc_total' int2str(ifil7) '.mat'],'stock'); - irun7 = 1; - end - - waitbar(b/B,h); - -end -close(h) - -% ?????? -stock_gend=gend; -stock_data=Y; -save([BaseName '_data.mat'],'stock_gend','stock_data'); - -if options_.smoother - pm3(endo_nbr,gend,ifil1,B,'Smoothed variables',... - M_.endo_names(SelecVariables),M_.endo_names,'tit_tex',M_.endo_names,... - 'names2','smooth',MetropolisFolder,'_smooth') -end - -if options_.forecast - pm3(endo_nbr,horizon+maxlag,ifil6,B,'Forecasted variables (mean)',... - M_.endo_names(SelecVariables),M_.endo_names,'tit_tex',M_.endo_names,... - 'names2','smooth',MetropolisFolder,'_forc_mean') - pm3(endo_nbr,horizon+maxlag,ifil6,B,'Forecasted variables (total)',... - M_.endo_names(SelecVariables),M_.endo_names,'tit_tex',M_.endo_names,... - 'names2','smooth',MetropolisFolder,'_forc_total') -end diff --git a/matlab/forcst_unc.m b/matlab/forcst_unc.m deleted file mode 100644 index 139b09f91..000000000 --- a/matlab/forcst_unc.m +++ /dev/null @@ -1,152 +0,0 @@ -function forcst_unc(y0,var_list) -% function [mean,intval1,intval2]=forcst_unc(y0,var_list) -% computes forecasts with parameter uncertainty -% -% INPUTS -% y0: matrix of initial values -% var_list: list of variables to be forecasted -% -% OUTPUTS -% none -% -% ALGORITHM -% uses antithetic draws for the shocks -% -% SPECIAL REQUIREMENTS -% None. - -% Copyright (C) 2006-2013 Dynare Team -% -% This file is part of Dynare. -% -% Dynare is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% Dynare is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with Dynare. If not, see . - -global M_ options_ oo_ estim_params_ bayestopt_ - -% setting up estim_params_ -[xparam1,estim_params_,bayestopt_,lb,ub] = set_prior(estim_params_,M_); - -options_.TeX = 0; -options_.nograph = 0; -plot_priors(bayestopt_,M_,options_); - -% workspace initialization -if isempty(var_list) - var_list = M_.endo_names(1:M_.orig_endo_nbr,:); -end -n = size(var_list,1); - -periods = options_.forecast; -exo_nbr = M_.exo_nbr; -replic = options_.replic; -order = options_.order; -maximum_lag = M_.maximum_lag; -% params = prior_draw(1); -params = rndprior(bayestopt_); -set_parameters(params); -% eliminate shocks with 0 variance -i_exo_var = setdiff([1:exo_nbr],find(diag(M_.Sigma_e) == 0)); -nx = length(i_exo_var); - -ex0 = zeros(periods,exo_nbr); -yf1 = zeros(periods+M_.maximum_lag,n,replic); - -% loops on parameter values -m1 = 0; -m2 = 0; -for i=1:replic - % draw parameter values from the prior - % params = prior_draw(0); - params = rndprior(bayestopt_); - set_parameters(params); - % solve the model - [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); - % discard problematic cases - if info - continue - end - % compute forecast with zero shocks - m1 = m1+1; - yf1(:,:,m1) = simult_(y0,dr,ex0,order)'; - % compute forecast with antithetic shocks - chol_S = chol(M_.Sigma_e(i_exo_var,i_exo_var)); - ex(:,i_exo_var) = randn(periods,nx)*chol_S; - m2 = m2+1; - yf2(:,:,m2) = simult_(y0,dr,ex,order)'; - m2 = m2+1; - yf2(:,:,m2) = simult_(y0,dr,-ex,order)'; -end - -oo_.forecast.accept_rate = (replic-m1)/replic; - -if options_.noprint == 0 && m1 < replic - skipline(2) - disp('FORECASTING WITH PARAMETER UNCERTAINTY:') - disp(sprintf(['The model couldn''t be solved for %f%% of the parameter' ... - ' values'],100*oo_.forecast.accept_rate)) - skipline(2) -end - -% compute moments -yf1 = yf1(:,:,1:m1); -yf2 = yf2(:,:,1:m2); - -yf_mean = mean(yf1,3); - -yf1 = sort(yf1,3); -yf2 = sort(yf2,3); - -sig_lev = options_.conf_sig; -k1 = round((0.5+[-sig_lev, sig_lev]/2)*replic); -% make sure that lower bound is at least the first element -if k1(2) == 0 - k1(2) = 1; -end -k2 = round((1+[-sig_lev, sig_lev])*replic); -% make sure that lower bound is at least the first element -if k2(2) == 0 - k2(2) = 1; -end - -% compute shock uncertainty around forecast with mean prior -set_parameters(bayestopt_.p1); -[dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); -[yf3,yf3_intv] = forcst(dr,y0,periods,var_list); -yf3_1 = yf3'-[zeros(maximum_lag,n); yf3_intv]; -yf3_2 = yf3'+[zeros(maximum_lag,n); yf3_intv]; - -% graphs -OutputDirectoryName = CheckPath('graphs',M_.fname); - -dyn_graph=dynare_graph_init('Forecasts type I',n,{'b-' 'g-' 'g-' 'r-' 'r-'}); -for i=1:n - dynare_graph(dyn_graph,[yf_mean(:,i) squeeze(yf1(:,i,k1)) squeeze(yf2(:,i,k2))],... - var_list(i,:)); -end -dyn_saveas(dyn_graph.fh,[OutputDirectoryName '/' M_.fname '_forecast_param_uncert_',num2str(nlags)],options_) - -dyn_graph=dynare_graph_init('Forecasts type II',n,{'b-' 'k-' 'k-' 'r-' 'r-'}); -for i=1:n - dynare_graph(dyn_graph,[yf_mean(:,i) yf3_1(:,i) yf3_2(:,i) squeeze(yf2(:,i,k2))],... - var_list(i,:)); -end -dyn_saveas(dyn_graph.fh,[OutputDirectoryName '/' M_.fname '_forecast_param_shock_uncert_',num2str(nlags)],options_) - - -% saving results -save_results(yf_mean,'oo_.forecast.Mean.',var_list); -save_results(yf1(:,:,k1(1)),'oo_.forecast.HPDinf.',var_list); -save_results(yf1(:,:,k1(2)),'oo_.forecast.HPDsup.',var_list); -save_results(yf2(:,:,k2(1)),'oo_.forecast.HPDTotalinf.',var_list); -save_results(yf2(:,:,k2(2)),'oo_.forecast.HPDTotalsup.',var_list); \ No newline at end of file diff --git a/matlab/rndprior.m b/matlab/rndprior.m deleted file mode 100644 index 3ff7f6e0b..000000000 --- a/matlab/rndprior.m +++ /dev/null @@ -1,57 +0,0 @@ -function y = rndprior(bayestopt_) -% function y = rndprior(bayestopt_) -% Draws random number from the prior density -% -% INPUTS -% bayestopt_: structure characterizing priors -% -% OUTPUTS -% y: drawn numbers vector -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2003-2009 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 . - -pshape=bayestopt_.pshape; -p3=bayestopt_.p3; -p4=bayestopt_.p4; -p6=bayestopt_.p6; -p7=bayestopt_.p7; - -y = NaN(1,length(pshape)); - -for i=1:length(pshape) - switch pshape(i) - case 1 % Beta - y(i) = betarnd(p6(i),p7(i)); - y(i) = y(1,i) * (p4(i)-p3(i)) + p3(i); - case 2 % Generalized gamma - y(i) = gamrnd(p6(i),p7(i)) + p3(i); - case 3 % Gaussian - y(i) = randn*p7(i) + p6(i) ; - case 4 % Inverse-gamma type 1 - y(i) = 1/sqrt(gamrnd(p7(i)/2, 2/p6(i))) + p3(i); - case 5 % Uniform - y(i) = rand*(p4(i)-p3(i)) + p3(i); - case 6 % Inverse-gamma type 2 - y(i) = 1/gamrnd(p7(i)/2, 2/p6(i)) + p3(i); - otherwise - error(sprintf('rndprior: unknown distribution shape (index %d, type %d)', i, pshape(i))); - end -end \ No newline at end of file From 0ef7524977e4b3a92b81b418ee0c74be6bc6f86d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 28 Feb 2015 20:37:10 +0100 Subject: [PATCH 029/210] Use dynare_minimize_objective for OSR computations --- matlab/global_initialization.m | 3 +-- matlab/osr1.m | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index dec79b27b..36a0ccf9f 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -639,8 +639,7 @@ options_.endogenous_prior_restrictions.irf={}; options_.endogenous_prior_restrictions.moment={}; % OSR Optimal Simple Rules -options_.osr.tolf=1e-7; -options_.osr.maxit=1000; +options_.osr.opt_algo=4; % use GPU options_.gpu = 0; diff --git a/matlab/osr1.m b/matlab/osr1.m index eb23312ff..a96c618fb 100644 --- a/matlab/osr1.m +++ b/matlab/osr1.m @@ -73,9 +73,6 @@ t0 = M_.params(i_params); inv_order_var = oo_.dr.inv_order_var; -H0 = 1e-4*eye(np); -crit=options_.osr.tolf; -nit=options_.osr.maxit; %extract unique entries of covariance i_var=unique(i_var); @@ -93,20 +90,25 @@ if isinf(loss) error('OSR: Initial likelihood is infinite') end + +if isequal(options_.osr.opt_algo,5) + error('OSR: OSR does not support opt_algo=5.') +elseif isequal(options_.osr.opt_algo,6) + error('OSR: OSR does not support opt_algo=6.') +elseif isequal(options_.osr.opt_algo,10) + error('OSR: OSR does not support opt_algo=10.') +else %%do actual optimization -[f,p]=csminwel1('osr_obj',t0,H0,[],crit,nit,options_.gradient_method,options_.gradient_epsilon,i_params,... +[p, f, exitflag] = dynare_minimize_objective(str2func('osr_obj'),t0,options_.osr.opt_algo,options_,[],cellstr(M_.param_names(i_params,:)),[],[], i_params,... inv_order_var(i_var),weights(i_var,i_var)); +end + osr_res.objective_function = f; M_.params(i_params)=p; %make sure optimal parameters are set (and not the last draw used in csminwel) for i=1:length(i_params) osr_res.optim_params.(deblank(M_.param_names(i_params(i),:))) = p(i); end -% options = optimset('fminunc'); -% options = optimset('display','iter'); -% [p,f]=fminunc(@osr_obj,t0,options,i_params,... -% inv_order_var(i_var),weights(i_var,i_var)); - skipline() disp('OPTIMAL VALUE OF THE PARAMETERS:') skipline() From 49c32da83b94bc458dd00e93e57c2201fd57ffd5 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 28 Feb 2015 20:42:46 +0100 Subject: [PATCH 030/210] Add unit tests for different OSR algorithms --- tests/Makefile.am | 6 + .../OSR/osr_obj_corr_algo_1.mod | 109 +++++++++++++++++ .../OSR/osr_obj_corr_algo_3.mod | 109 +++++++++++++++++ .../OSR/osr_obj_corr_algo_4.mod | 110 ++++++++++++++++++ .../OSR/osr_obj_corr_algo_7.mod | 109 +++++++++++++++++ .../OSR/osr_obj_corr_algo_8.mod | 109 +++++++++++++++++ .../OSR/osr_obj_corr_algo_9.mod | 109 +++++++++++++++++ 7 files changed, 661 insertions(+) create mode 100644 tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod create mode 100644 tests/optimal_policy/OSR/osr_obj_corr_algo_3.mod create mode 100644 tests/optimal_policy/OSR/osr_obj_corr_algo_4.mod create mode 100644 tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod create mode 100644 tests/optimal_policy/OSR/osr_obj_corr_algo_8.mod create mode 100644 tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 200402436..734945b24 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,6 +21,12 @@ MODFILES = \ optimal_policy/osr_example.mod \ optimal_policy/osr_example_objective_correctness.mod \ optimal_policy/osr_example_obj_corr_non_stat_vars.mod \ + optimal_policy/OSR/osr_obj_corr_algo_1.mod \ + optimal_policy/OSR/osr_obj_corr_algo_3.mod \ + optimal_policy/OSR/osr_obj_corr_algo_4.mod \ + optimal_policy/OSR/osr_obj_corr_algo_7.mod \ + optimal_policy/OSR/osr_obj_corr_algo_8.mod \ + optimal_policy/OSR/osr_obj_corr_algo_9.mod \ optimal_policy/ramsey_.mod \ optimal_policy/nk_ramsey.mod \ optimal_policy/nk_ramsey_model.mod \ diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod new file mode 100644 index 000000000..65dcf6991 --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_1.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=4 +var y inflation r dummy_var; +varexo y_ inf_; + +parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_; + +delta = 0.44; +kappa = 0.18; +alpha = 0.48; +sigma = -0.06; + + +model(linear); +y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; +inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_; +dummy_var=0.9*dummy_var(-1)+0.01*y; +r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_; +end; + +shocks; +var y_; +stderr 0.63; +var inf_; +stderr 0.4; +end; + +options_.nograph=1; +options_.nocorr=1; +osr_params gammax0 gammac0 gamma_y_ gamma_inf_; + + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +end; + + +gammax0 = 0.2; +gammac0 = 1.5; +gamma_y_ = 8; +gamma_inf_ = 3; + +osr(opt_algo=1); +%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')); + +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +%redo computation with covariance specified +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +gammax0=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%redo computation with double weight on one covariance +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 1; +end; + +osr; +%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'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +oo_covar_single=oo_; + +%redo computation with single weight on both covariances + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +inflation,y 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8 + error('Objective Function is wrong') +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 diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_3.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_3.mod new file mode 100644 index 000000000..a54224fc8 --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_3.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=4 +var y inflation r dummy_var; +varexo y_ inf_; + +parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_; + +delta = 0.44; +kappa = 0.18; +alpha = 0.48; +sigma = -0.06; + + +model(linear); +y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; +inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_; +dummy_var=0.9*dummy_var(-1)+0.01*y; +r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_; +end; + +shocks; +var y_; +stderr 0.63; +var inf_; +stderr 0.4; +end; + +options_.nograph=1; +options_.nocorr=1; +osr_params gammax0 gammac0 gamma_y_ gamma_inf_; + + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +end; + + +gammax0 = 0.2; +gammac0 = 1.5; +gamma_y_ = 8; +gamma_inf_ = 3; + +osr(opt_algo=3); +%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')); + +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +%redo computation with covariance specified +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +gammax0=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%redo computation with double weight on one covariance +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 1; +end; + +osr; +%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'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +oo_covar_single=oo_; + +%redo computation with single weight on both covariances + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +inflation,y 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8 + error('Objective Function is wrong') +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 diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_4.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_4.mod new file mode 100644 index 000000000..cbbabab6b --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_4.mod @@ -0,0 +1,110 @@ +// Example of optimal simple rule using opt_algo=4 +var y inflation r dummy_var; +varexo y_ inf_; + +parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_; + +delta = 0.44; +kappa = 0.18; +alpha = 0.48; +sigma = -0.06; + + +model(linear); +y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; +inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_; +dummy_var=0.9*dummy_var(-1)+0.01*y; +r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_; +end; + +shocks; +var y_; +stderr 0.63; +var inf_; +stderr 0.4; +end; + +options_.nograph=1; +options_.nocorr=1; +options_.osr.tolf=1e-20; +osr_params gammax0 gammac0 gamma_y_ gamma_inf_; + + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +end; + + +gammax0 = 0.2; +gammac0 = 1.5; +gamma_y_ = 8; +gamma_inf_ = 3; + +osr(opt_algo=4); +%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')); + +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +%redo computation with covariance specified +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +gammax0=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%redo computation with double weight on one covariance +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 1; +end; + +osr; +%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'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +oo_covar_single=oo_; + +%redo computation with single weight on both covariances + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +inflation,y 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8 + error('Objective Function is wrong') +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 diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod new file mode 100644 index 000000000..fea442457 --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_7.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=2 +var y inflation r dummy_var; +varexo y_ inf_; + +parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_; + +delta = 0.44; +kappa = 0.18; +alpha = 0.48; +sigma = -0.06; + + +model(linear); +y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; +inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_; +dummy_var=0.9*dummy_var(-1)+0.01*y; +r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_; +end; + +shocks; +var y_; +stderr 0.63; +var inf_; +stderr 0.4; +end; + +options_.nograph=1; +options_.nocorr=1; +osr_params gammax0 gammac0 gamma_y_ gamma_inf_; + + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +end; + + +gammax0 = 0.2; +gammac0 = 1.5; +gamma_y_ = 8; +gamma_inf_ = 3; + +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')); + +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +%redo computation with covariance specified +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +gammax0=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%redo computation with double weight on one covariance +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 1; +end; + +osr; +%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'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +oo_covar_single=oo_; + +%redo computation with single weight on both covariances + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +inflation,y 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8 + error('Objective Function is wrong') +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 diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_8.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_8.mod new file mode 100644 index 000000000..77d014d2f --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_8.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=2 +var y inflation r dummy_var; +varexo y_ inf_; + +parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_; + +delta = 0.44; +kappa = 0.18; +alpha = 0.48; +sigma = -0.06; + + +model(linear); +y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; +inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_; +dummy_var=0.9*dummy_var(-1)+0.01*y; +r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_; +end; + +shocks; +var y_; +stderr 0.63; +var inf_; +stderr 0.4; +end; + +options_.nograph=1; +options_.nocorr=1; +osr_params gammax0 gammac0 gamma_y_ gamma_inf_; + + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +end; + + +gammax0 = 0.2; +gammac0 = 1.5; +gamma_y_ = 8; +gamma_inf_ = 3; + +osr(opt_algo=8); +%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')); + +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +%redo computation with covariance specified +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +gammax0=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%redo computation with double weight on one covariance +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 1; +end; + +osr; +%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'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +oo_covar_single=oo_; + +%redo computation with single weight on both covariances + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +inflation,y 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8 + error('Objective Function is wrong') +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 diff --git a/tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod b/tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod new file mode 100644 index 000000000..59a2fa250 --- /dev/null +++ b/tests/optimal_policy/OSR/osr_obj_corr_algo_9.mod @@ -0,0 +1,109 @@ +// Example of optimal simple rule using opt_algo=3 +var y inflation r dummy_var; +varexo y_ inf_; + +parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_; + +delta = 0.44; +kappa = 0.18; +alpha = 0.48; +sigma = -0.06; + + +model(linear); +y = delta * y(-1) + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; +inflation = alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_; +dummy_var=0.9*dummy_var(-1)+0.01*y; +r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_; +end; + +shocks; +var y_; +stderr 0.63; +var inf_; +stderr 0.4; +end; + +options_.nograph=1; +options_.nocorr=1; +osr_params gammax0 gammac0 gamma_y_ gamma_inf_; + + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +end; + + +gammax0 = 0.2; +gammac0 = 1.5; +gamma_y_ = 8; +gamma_inf_ = 3; + +osr(opt_algo=9); +%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')); + +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +%redo computation with covariance specified +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end + +gammax0=1.35533; +gammac0=1.39664; +gamma_y_=16.6667; +gamma_inf_=9.13199; + +%redo computation with double weight on one covariance +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 1; +end; + +osr; +%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'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +oo_covar_single=oo_; + +%redo computation with single weight on both covariances + +optim_weights; +inflation 1; +y 1; +dummy_var 1; +y,inflation 0.5; +inflation,y 0.5; +end; + +osr; +%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'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact')); +if abs(oo_.osr.objective_function-objective)>1e-8 + error('Objective Function is wrong') +end +if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8 + error('Objective Function is wrong') +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 From f89108568c0c117eb1463888ad379bdd621d01a9 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 28 Feb 2015 20:43:30 +0100 Subject: [PATCH 031/210] Document osr option --- doc/dynare.texi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 993c3b2c4..c7ff4cf2d 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -4944,6 +4944,7 @@ Metropolis-Hastings simulations instead of starting from scratch. Shouldn't be used together with @code{mh_recover} @item optim = (@var{NAME}, @var{VALUE}, ...) +@anchor{optim} A list of @var{NAME} and @var{VALUE} pairs. Can be used to set options for the optimization routines. The set of available options depends on the selected optimization routine (ie on the value of option @ref{mode_compute}): @table @code @@ -6498,9 +6499,8 @@ is specified in the @code{optim_weights}-block. By attaching weights to endogenous variables, the subset of endogenous variables entering the objective function, @math{y}, is implicitly specified. -The linear quadratic problem is solved using the numerical optimizer -@code{csminwel} of Chris Sims. +The linear quadratic problem is solved using the numerical optimizer specified with @ref{opt_algo}. @optionshead @@ -6511,12 +6511,12 @@ by listing them after the command, as @code{stoch_simul} @table @code -@item maxit = @var{INTEGER} Determines the maximum number of iterations -used in the non-linear solver. Default: @code{1000} +@item opt_algo = @var{INTEGER} +@anchor{opt_algo} +Specifies the optimizer for minimizing the objective function. The same solvers as for @code{mode_compute} (@pxref{mode_compute}) are available, except for 5,6, and 10. -@item tolf = @var{DOUBLE} Convergence criterion for termination based on -the function value. Iteration will cease when it proves impossible to -improve the function value by more than tolf. Default: @code{1e-7} +@item optim = (@var{NAME}, @var{VALUE}, ...) +A list of @var{NAME} and @var{VALUE} pairs. Can be used to set options for the optimization routines. The set of available options depends on the selected optimization routine (i.e. on the value of option @ref{opt_algo}). @xref{optim}. @end table From fe938c902af6ee35f92c488fc5d1470125c7e3b1 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 1 Mar 2015 13:34:39 +0100 Subject: [PATCH 032/210] Fixed another bug related to options_.optim_opt being now initialized as an empty array Finalizes 392486273e29a3a5617c6f0580231c0bb7163fd8 --- matlab/dynare_estimation_1.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 589a5010b..f64960504 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -235,7 +235,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation if options_.mode_compute==5 %get whether analytical Hessian with non-analytical mode-finding is requested newratflag=[]; - if isfield(options_,'optim_opt') + if ~isempty(options_.optim_opt) options_list = read_key_value_string(options_.optim_opt); for i=1:rows(options_list) if strcmp(options_list{i,1},'Hessian') From a7f380d8c07da86e132f61886c068cc2422d3e51 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 1 Mar 2015 13:36:21 +0100 Subject: [PATCH 033/210] Condition check for changed parameters on whether parameters are estimated in the first place Fixes crash in master unit test --- matlab/initial_estimation_checks.m | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index b78b50b7e..54af16f7b 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -49,20 +49,22 @@ old_steady_params=Model.params; %save initial parameters for check if steady sta % % check if steady state solves static model (except if diffuse_filter == 1) [DynareResults.steady_state, new_steady_params] = evaluate_steady_state(DynareResults.steady_state,Model,DynareOptions,DynareResults,DynareOptions.diffuse_filter==0); -%check whether steady state file changes estimated parameters -Model_par_varied=Model; %store Model structure -Model_par_varied.params(EstimatedParameters.param_vals(:,1))=Model_par_varied.params(EstimatedParameters.param_vals(:,1))*1.01; %vary parameters -[junk, new_steady_params_2] = evaluate_steady_state(DynareResults.steady_state,Model_par_varied,DynareOptions,DynareResults,DynareOptions.diffuse_filter==0); +if ~isempty(EstimatedParameters.param_vals) + %check whether steady state file changes estimated parameters + Model_par_varied=Model; %store Model structure + Model_par_varied.params(EstimatedParameters.param_vals(:,1))=Model_par_varied.params(EstimatedParameters.param_vals(:,1))*1.01; %vary parameters + [junk, new_steady_params_2] = evaluate_steady_state(DynareResults.steady_state,Model_par_varied,DynareOptions,DynareResults,DynareOptions.diffuse_filter==0); -changed_par_indices=find((old_steady_params(EstimatedParameters.param_vals(:,1))-new_steady_params(EstimatedParameters.param_vals(:,1))) ... - | (Model_par_varied.params(EstimatedParameters.param_vals(:,1))-new_steady_params_2(EstimatedParameters.param_vals(:,1)))); + changed_par_indices=find((old_steady_params(EstimatedParameters.param_vals(:,1))-new_steady_params(EstimatedParameters.param_vals(:,1))) ... + | (Model_par_varied.params(EstimatedParameters.param_vals(:,1))-new_steady_params_2(EstimatedParameters.param_vals(:,1)))); -if ~isempty(changed_par_indices) - fprintf('\nThe steady state file internally changed the values of the following estimated parameters:\n') - disp(Model.param_names(changed_par_indices,:)); - fprintf('This will override the parameter values drawn from the proposal density and may lead to wrong results.\n') - fprintf('Check whether this is really intended.\n') - warning('The steady state file internally changes the values of the estimated parameters.') + if ~isempty(changed_par_indices) + fprintf('\nThe steady state file internally changed the values of the following estimated parameters:\n') + disp(Model.param_names(changed_par_indices,:)); + fprintf('This will override the parameter values drawn from the proposal density and may lead to wrong results.\n') + fprintf('Check whether this is really intended.\n') + warning('The steady state file internally changes the values of the estimated parameters.') + end end if any(BayesInfo.pshape) % if Bayesian estimation From 30428aeb17162db8328d941491162fe3a6895041 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 3 Mar 2015 15:08:33 +0100 Subject: [PATCH 034/210] preprocessor: add joint prior syntax, #824 --- matlab/global_initialization.m | 2 + preprocessor/ComputingTasks.cc | 109 +++++++++++++++++++++++++++++++++ preprocessor/ComputingTasks.hh | 16 +++++ preprocessor/DynareBison.yy | 21 +++++++ preprocessor/DynareFlex.ll | 32 ++++++++++ preprocessor/ParsingDriver.cc | 20 ++++++ preprocessor/ParsingDriver.hh | 6 ++ tests/ms-dsge/test_ms_dsge.mod | 4 +- 8 files changed, 209 insertions(+), 1 deletion(-) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 36a0ccf9f..bcd3cff40 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -362,6 +362,8 @@ estimation_info.measurement_error_corr.range_index = {}; 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)); options_.initial_period = NaN; %dates(1,1); options_.dataset.file = []; options_.dataset.series = []; diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 2c0c5d297..2d7b1ffc3 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2082,6 +2082,115 @@ SubsamplesEqualStatement::writeOutput(ostream &output, const string &basename) c << endl; } +JointPriorStatement::JointPriorStatement(const vector joint_parameters_arg, + const PriorDistributions &prior_shape_arg, + const OptionsList &options_list_arg) : + joint_parameters(joint_parameters_arg), + prior_shape(prior_shape_arg), + options_list(options_list_arg) +{ +} + +void +JointPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) +{ + if (joint_parameters.size() < 2) + { + cerr << "ERROR: you must pass at least two parameters to the joint prior statement" << endl; + exit(EXIT_FAILURE); + } + + if (prior_shape == eNoShape) + { + cerr << "ERROR: You must pass the shape option to the prior statement." << endl; + exit(EXIT_FAILURE); + } + + if (options_list.num_options.find("mean") == options_list.num_options.end() && + options_list.num_options.find("mode") == options_list.num_options.end()) + { + cerr << "ERROR: You must pass at least one of mean and mode to the prior statement." << endl; + exit(EXIT_FAILURE); + } + + OptionsList::num_options_t::const_iterator it_num = options_list.num_options.find("domain"); + if (it_num != options_list.num_options.end()) + { + using namespace boost; + vector tokenizedDomain; + split(tokenizedDomain, it_num->second, is_any_of("[ ]"), token_compress_on); + if (tokenizedDomain.size() != 4) + { + cerr << "ERROR: You must pass exactly two values to the domain option." << endl; + exit(EXIT_FAILURE); + } + } +} + +void +JointPriorStatement::writeOutput(ostream &output, const string &basename) const +{ + for (vector::const_iterator it = joint_parameters.begin() ; it != joint_parameters.end(); it++) + output << "eifind = get_new_or_existing_ei_index('joint_parameter_prior_index', '" + << *it << "', '');" << endl + << "estimation_info.joint_parameter_prior_index(eifind) = {'" << *it << "'};" << endl; + + output << "key = {["; + for (vector::const_iterator it = joint_parameters.begin() ; it != joint_parameters.end(); it++) + output << "get_new_or_existing_ei_index('joint_parameter_prior_index', '" << *it << "', '') ..." + << endl << " "; + output << "]};" << endl; + + string lhs_field("estimation_info.joint_parameter_tmp"); + + writeOutputHelper(output, "domain", lhs_field); + writeOutputHelper(output, "interval", lhs_field); + writeOutputHelper(output, "mean", lhs_field); + writeOutputHelper(output, "median", lhs_field); + writeOutputHelper(output, "mode", lhs_field); + + assert(prior_shape != eNoShape); + output << lhs_field << ".shape = " << prior_shape << ";" << endl; + + writeOutputHelper(output, "shift", lhs_field); + writeOutputHelper(output, "stdev", lhs_field); + writeOutputHelper(output, "truncate", lhs_field); + writeOutputHelper(output, "variance", lhs_field); + + output << "estimation_info.joint_parameter_tmp = table(key, ..." << endl + << " " << lhs_field << ".domain , ..." << endl + << " " << lhs_field << ".interval , ..." << endl + << " " << lhs_field << ".mean , ..." << endl + << " " << lhs_field << ".median , ..." << endl + << " " << lhs_field << ".mode , ..." << endl + << " " << lhs_field << ".shape , ..." << endl + << " " << 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; +} + +void +JointPriorStatement::writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const +{ + OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field); + output << lhs_field << "." << field << " = {"; + if (itn != options_list.num_options.end()) + output << itn->second; + else + output << "{}"; + output << "};" << endl; +} + + BasicPriorStatement::~BasicPriorStatement() { } diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index 36732cc24..d19f3e4c2 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -679,6 +679,22 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; }; +class JointPriorStatement : public Statement +{ +private: + const vector joint_parameters; + const PriorDistributions prior_shape; + const OptionsList options_list; +public: + JointPriorStatement(const vector joint_parameters_arg, + const PriorDistributions &prior_shape_arg, + const OptionsList &options_list_arg); + virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); + virtual void writeOutput(ostream &output, const string &basename) const; + void writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const; +}; + + class BasicPriorStatement : public Statement { public: diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 3760a46ed..748cd7804 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -171,6 +171,7 @@ class ParsingDriver; %token PARAMETER_CONVERGENCE_CRITERION NUMBER_OF_LARGE_PERTURBATIONS NUMBER_OF_SMALL_PERTURBATIONS %token NUMBER_OF_POSTERIOR_DRAWS_AFTER_PERTURBATION MAX_NUMBER_OF_STAGES %token RANDOM_FUNCTION_CONVERGENCE_CRITERION RANDOM_PARAMETER_CONVERGENCE_CRITERION +%token SYMBOL_VEC %type expression expression_or_empty %type equation hand_side @@ -1422,6 +1423,8 @@ prior : symbol '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNo { driver.set_prior($1, new string ("")); } | symbol '.' symbol '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';' { driver.set_prior($1, $3); } + | SYMBOL_VEC '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' joint_prior_options_list ')' ';' + { driver.set_joint_prior($1); } | STD '(' symbol ')' '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';' { driver.set_std_prior($3, new string ("")); } | STD '(' symbol ')' '.' symbol '.' PRIOR { driver.set_prior_variance(); driver.prior_shape = eNoShape; } '(' prior_options_list ')' ';' @@ -1448,6 +1451,22 @@ prior_options : o_shift | o_domain ; +joint_prior_options_list : joint_prior_options_list COMMA joint_prior_options + | joint_prior_options + ; + +joint_prior_options : o_shift + | o_mean_vec + | o_median + | o_stdev + | o_truncate + | o_variance_mat + | o_mode + | o_interval + | o_shape + | o_domain + ; + prior_eq : prior_eq_opt EQUAL prior_eq_opt ';' { driver.copy_prior($1->at(0), $1->at(1), $1->at(2), $1->at(3), @@ -2544,6 +2563,7 @@ o_shift : SHIFT EQUAL signed_number { driver.option_num("shift", $3); }; o_shape : SHAPE EQUAL prior_distribution { driver.prior_shape = $3; }; o_mode : MODE EQUAL signed_number { driver.option_num("mode", $3); }; o_mean : MEAN EQUAL signed_number { driver.option_num("mean", $3); }; +o_mean_vec : MEAN EQUAL vec_value { driver.option_num("mean", $3); }; o_truncate : TRUNCATE EQUAL vec_value { driver.option_num("truncate", $3); }; o_stdev : STDEV EQUAL non_negative_number { driver.option_num("stdev", $3); }; o_jscale : JSCALE EQUAL non_negative_number { driver.option_num("jscale", $3); }; @@ -2552,6 +2572,7 @@ o_bounds : BOUNDS EQUAL vec_value_w_inf { driver.option_num("bounds", $3); }; o_domain : DOMAINN EQUAL vec_value { driver.option_num("domain", $3); }; o_interval : INTERVAL EQUAL vec_value { driver.option_num("interval", $3); }; o_variance : VARIANCE EQUAL expression { driver.set_prior_variance($3); } +o_variance_mat : VARIANCE EQUAL vec_of_vec_value { driver.option_num("variance",$3); } o_prefilter : PREFILTER EQUAL INT_NUMBER { driver.option_num("prefilter", $3); }; o_presample : PRESAMPLE EQUAL INT_NUMBER { driver.option_num("presample", $3); }; o_lik_algo : LIK_ALGO EQUAL INT_NUMBER { driver.option_num("lik_algo", $3); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index cf65ff855..793de8c0e 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -839,6 +839,38 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 } } + /* For joint prior statement, match [symbol, symbol, ...] + If no match, begin native and push everything back on stack + */ +\[([[:space:]]*[A-Za-z_][A-Za-z0-9_]*[[:space:]]*,{1}[[:space:]]*)*([[:space:]]*[A-Za-z_][A-Za-z0-9_]*[[:space:]]*){1}\] { + string yytextcpy = string(yytext); + yytextcpy.erase(remove(yytextcpy.begin(), yytextcpy.end(), '['), yytextcpy.end()); + yytextcpy.erase(remove(yytextcpy.begin(), yytextcpy.end(), ']'), yytextcpy.end()); + yytextcpy.erase(remove(yytextcpy.begin(), yytextcpy.end(), ' '), yytextcpy.end()); + istringstream ss(yytextcpy); + string token; + yylval->vector_string_val = new vector; + + 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)); + else + { + for (vector::iterator it=yylval->vector_string_val->begin(); + it != yylval->vector_string_val->end(); it++) + delete *it; + delete yylval->vector_string_val; + BEGIN NATIVE; + yyless(0); + break; + } + if (yylval->vector_string_val->size() > 0) + { + BEGIN DYNARE_STATEMENT; + return token::SYMBOL_VEC; + } +} + /* Enter a native block */ . { BEGIN NATIVE; yyless(0); } diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index acf0c8a91..cd9b0101c 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1410,6 +1410,26 @@ ParsingDriver::set_prior(string *name, string *subsample_name) delete subsample_name; } +void +ParsingDriver::set_joint_prior(vector*symbol_vec) +{ + for (vector::const_iterator it=symbol_vec->begin(); it != symbol_vec->end(); it++) + add_joint_parameter(*it); + mod_file->addStatement(new JointPriorStatement(joint_parameters, prior_shape, options_list)); + joint_parameters.clear(); + options_list.clear(); + prior_shape = eNoShape; + delete symbol_vec; +} + +void +ParsingDriver::add_joint_parameter(string *name) +{ + check_symbol_is_parameter(name); + joint_parameters.push_back(*name); + delete name; +} + void ParsingDriver::set_prior_variance(expr_t variance) { diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index ace9d1223..d4ebc05dc 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -186,6 +186,8 @@ private: //! Temporary storage for argument list of external function stack > stack_external_function_args; + //! Temporary storage for parameters in joint prior statement + vector joint_parameters; //! Temporary storage for the symb_id associated with the "name" symbol of the current external_function statement int current_external_function_id; //! Temporary storage for option list provided to external_function() @@ -411,6 +413,10 @@ public: void estimation_data(); //! Sets the prior for a parameter void set_prior(string *arg1, string *arg2); + //! Sets the joint prior for a set of parameters + void set_joint_prior(vector*symbol_vec); + //! Adds a parameters to the list of joint parameters + void add_joint_parameter(string *name); //! Adds the variance option to its temporary holding place void set_prior_variance(expr_t variance=NULL); //! Copies the prior from_name to_name diff --git a/tests/ms-dsge/test_ms_dsge.mod b/tests/ms-dsge/test_ms_dsge.mod index e11715b3e..51b132adf 100644 --- a/tests/ms-dsge/test_ms_dsge.mod +++ b/tests/ms-dsge/test_ms_dsge.mod @@ -35,4 +35,6 @@ alpha.options(init=1); rho.options(init=1); beta.options(init=0.2); std(u).options(init=3); -corr(y,c).options(init=.02); \ No newline at end of file +corr(y,c).options(init=.02); + +[alpha , beta , rho].prior(shape=beta, mean=[2 3 4], variance=[[1 2 3],[2 3 4]]); \ No newline at end of file From 9ab6be8995b5b9b0746dfc01a961e9dff385c5f5 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 6 Mar 2015 09:49:11 +0100 Subject: [PATCH 035/210] preprocessor: bug fix; warning should be issued if there is at least one unused exo not more than one --- preprocessor/ModFile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 265970c1c90fc044ce1af68c54b35c67a3ff13ee Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sun, 22 Feb 2015 21:54:39 +0100 Subject: [PATCH 036/210] 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 037/210] 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 038/210] 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` zMJt_pH#pA&o#(^kIb!xY%;%0W!Spi+q<+lYjBpqCC6QTXxv4X2OtneM^PgIcc86$b z#8jBq(Ty4RC1NHXqJ}Zk59uX#2pdt;^AI+SjO(F#ed-}=bjw;}btGb@gj#xj>&Py5 z#&)!&MsV~C4_V`YL{->J&<0{`V%CEA^m$~E8Epp1zwt7W z<7S|FB0kU@E3e0h#_#kioF+;C$V}Lo=46vFE6v$i3{*(A=<7EyR(xmk9)7=H;XIju z1GAgR)Dkv!p&4l=o5;Dc$0MZ&YJRkwr_1BH(%`vYVXYZq$}>4V zR|dgFFbwQc-$yOHuMUIndG0Qgp`31W7w(QsZteAg?kgmfXbicQ@a#3>5;IDA(bCas zTwBk3ZmVT)fLc-aUzlz(V~qK)RNVRNKJAY~FY@&N^xn$rKc#=bMkFfJk7%erUub=& z@a|y$r}ZZ@=#OR4pUR-`$)G=-L4P8HerE=KTLwK-dotO7-m!z#v=g7{ez+@x?zV^P zyX|59fedz@&7i-KL4PxYetic0l?-}Y+w-Dhr^M@@ou#Gw`tR#+3U@hr%%|Vh;kFK* zUL;A@>CbOlObz- zPv@WJ($XFsdPw_sx9aVzb`B#u?tD4i(?ji)HN0!*S7wpCOz&4|P?z0w_qU7cad|0b zLwd-5SFOKHUiS9t7s*k_*8fFv%(Cg-JUb!#-93G0O^rM5d*hp9-OOeTeEKon^ca8X zn_FUI%$9(T3Q^NZ@_d23ieR(#0CAXP{wM>e(k8%NKDWUG8qy{Yg>3~8Qf=~poY5wr zq^$r3rA;0%P1^)u{{QHYmtE9}1m`lBhw* z;j945t}U^!5u}bBj35j%8$q7Q!3aV#vk@ep9E>1bGaEtX$-xLhII|I?sT_FIG*+-{eZbq_?j;sWH9V;95-N`;WaiKKqVIy#S_4*|H=nTlsNcPbgn2Ql( zvX9Q7+>B%&ox!;o$v!$max;>BbcW_;B>U(L%gsn|bZ!Y9cZQ3R66d&s^-@JeMT+7C zZ+!F3Hz_YYmdLTltBfl!IGvCAH1~SLxpJ9H>s30nD&^vsYGT%TY>9;%H9~Z4)E~E) z+#9uZ>(*4bQP9GTf);KRwAMCBFNIgEBjv5EhxG7Xj0)^UMa2gDUZh&?psxM-_TrS# zc#oDw6=q&%U~I7t_RmI)t*3ci%iS|3-93m6rz?XC`tV|9tW;y65#wYrPPF|2)u}`T~OWKGxX`XxTIf_qc z;rN6Wj!$S})_HJOl!@M^t|%8k2cX#$+Xo=^LAC*y81Rbj@aK;RuTdwZy`pj$i28%g zOE_#~axO+v75*q@BS+<8B)n`0X9avxrM*tO!(NY0dqs#)Zu1gpsxgv|9Ukjr0$wQq z8927Bz|=J0M6v|4e_ZAKJUl0+37~UAHUfbV_2$Hb4?dXQFKa=m$HZsUZc5ZQOlXQNG)*{^wmu?-{ZfaSGC6~an;}xh zNSR@3%_jMfq~0{h2TF*`i0Nob3KKO4zWh2>gx5|lo750oo`9!P@>Is224?kyDckC) zC{gpxfxowV>O!8%+0)Rhp4_?a>{D@~=67HJ#_p*rd78+cMrQSdgwVQAC5f7Y|M0JN zPux#`C7)Gkr;{a3%Xd+GsC6Aux4 z{l(M7oMNw~>gAS$c27OYlO^^BW%cBby_TvkU*2o?)Qdb>VsBVhPyX0zsrtKvuiHHx zL7ptJH!7N-TtpP6!$GkG?Vgz3Vu;(czBK_3KtGuTC_@E)I@< zw7X+;y;)~g$thm7EU~am#G$lE&Sh{}0gEfV#!AjfGQ|?Oo)D4B{;gPGt6gAgNAz&{ zXi+|Hn3+f>R;;dHU%#p;wl&nA9;xPIR%L7z7U+Ri;mlTBjQO+^!ZkXG(THTN;DKY)82>LnhXo zHTCwc?IvA2M_4qUyB3!fv}-r~)Sc)gpBl;wA^^6`nBsm)z4W{(b< zjr2|xn7I-YfZb&*LJ=1sJVUrr(Q2sBjB6~Ak&Oq96ctG26U|x~Rg5bh7|rn*%>{|| z4awzoH2We)%4jZ-cEfeji3WcIa6Q6nK(k!5Xl+1yIa!fwo(tACtl88QTN!Ldw7nn; zq!|q|7@MRKMd^8mD-+%{!&LMDQQs8X7V5X2(r?;Bap^f6?vv7gNqJr4`1BwAaVf|N2&D`j_$aAw8EtP*uWQVJrAzLhic(L?-Mn4ddm7v}1{^btHBsKwDND(8{2FSr^dCcgK2} z-M-ej*OFk#nET~!{`-CJf!rCYF`rI}N*B79;c<;oq>WN)rL0KFk|$=O z(lXo!u_D$(3T(KK9<6_)W|#Qc<$Gu5KS#_S(f0T>v1hi6w%w<}0Pf*%zje?#@U4Rm zQGA}@KK@GnJRsN38sy^S=2^yEStYhkF=ppE#x%&x?uOl{n|-%*}d$_-3-T`JE; zdMswXd-UtSonO7E;#@}`>FA@J=gS?X(djMM*ASU2#*B_!Chxpe*iBw{mvV(u`%33| zsMM};9$!`r^SvG}ug{$L)JH4JzN#4Edws8*#lT`j+7yxANAHw7k6%`Je;Z75Y^W5e znBg%MY0i0^BCU{Ki^{x|2l@snLqKZ;d;0QC#<2b!WwR*32W%Vu;$+S670V& zmU>++8saBx5AhV%Fqgubds9cyuX~S1P;+m&2x{&f6hY0sAtI=`_csK!zLvJQcOL}n z^$*qi-kHnJ?St};yA_eSh`@8VqRz}T=F(_;N5u&IdqsgnGG@l%=A_!)7d2l#qS94R zd&fU5_-fgfZ!16`W?}6d=Y7oZAQ6=sK>`u2KCtEv5(Pvc-jygMqL2v81|_f#4*HNw z`l9&v19L?Qe2*ze6cd4&qy)}!gG31tm}g4Fh>)x<@B3SYS*S!iBH9swIjRIkG}tPP zSkMP%uo4}J=s*PKw-OzRK)w(9!0cC|6A?I01PSB@B@m0j{lK@vf&^+SftU;uIQ|3) z5rHFv68(wjA0R$6v(3wr zuL<}JUb4H1wL<}VYGfIhJL<}PW z^G%82L<}bavr&l=M2sK;b5)6vMBscgI3AeEN{k``=cYjd^IVD1M2sc^SwM*~M2sN< zIYNoCM2sb3T!0uy#5f|5U)0BVBE}Pe?4!g4A|?=l+@wSq5oJUmb15NT)0Hj%j4CGr zc}cL`)(AIZ+Au#&W1tlZimaRN^Qijv@m2REa4>Od$f3sg;ng5X+W-JdPy-d0dI9L`)?DSzd{0L`)+B#{ebd+tr~~O(z0J2qh|r zs0a{P2km#(K|g*C1QP3@O7R>%uFbG$GcDRIi#FS$&9P|5S+uzp?Rbke&!U}R(N45z zRTgc&MO$Fe7Fx7L7VRX9cCtlVY|)ljv{NkFsTOUiMLW%+oo><2uxMvmw6iSQ*%s{_ zi*{~E!>XoIG>!a9iu}qzVhC1w*bn+VJb zCFT$@hX~9WC5|KFI3h5kl$cAzTp}>vlsKM<B$qr^!>oJ0h2 zlM*KraWWCeTuLk^VlffOYf3C3VhIt*dPacl{l4%Q;9&vRAMO+ONl@} zRpK-vP9p-@R*BPzIGqUOVkOQX;tV2?sg*dBh%<>m9#`TlBF-WLSzd{=i8z}G90Qa% zhlq2Cz!5@;bBVy`aysTe=Q?Pacn+_FmRq!Hi?+g|t+Z$fi&kUNR#~*w7Hy41JI|uk zTC_TgcD_Zcw`glE+65NvLW`EPXzMImgGF0!(KcALi!9nki*~U^+hox$v1pqu+7^p; zsYTlw(y*#oCYnb6GK&0Vfyf7e=u~1k5zC1{>?%=BL^TnJY$a9@v4RN1y%H;lSV;tC zg%SxO5=3CmC{aU14H1}8N~|Jc6%m+kN~|VgH4&JNN~|Gb4H1~DN}NZ;c|>3)D^W{C zEfJXKO4JciM+CBf66X_fJ`ubhBm$XBiFHJ*BLaC%i3TDXh(Oj;Vm%S-i9k+NVgnHyh(N|v;vyn0A_DnTiH$^T zBm&u1iHnK2mu{A*aoa>-Q@f==Xxl8>c8hj{ zMZ3|W-DJ^jwrIClv?hzT!=ml9Xt!FlT^8*&i*~z3yThXGwrG1STC+vF)1uvF(e4gu zSk*L&rjg%Bk>41Id=Q9EB`zZZ_vh(30|>;f5|gBH|_@kYCit%|zTx1hS73w-9j) z5y(wSG!fB61TvQrJBZjp1oD~^JBipy1hSqIw-RwH5y**3>>^?p5y+TI+(yK0L?E9k zaXS&W6M<~2#2rN3K?HKK61$1mO$0Kv5_^c)Lj>};63s+36M-zR#GORkNd%4oO58=n zT}0prp~T%p+#Mi(&UMf|;yJtyy4RxJXVLDrXb)Jl2QAt|7VTk+_J~D$)S^9R(H^&G zPgt}kE!tBS?P-hlj759aqCIEPp0{W(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: Mon, 9 Mar 2015 17:13:03 +0100 Subject: [PATCH 039/210] =?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 040/210] 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 041/210] 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 042/210] 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 d4c07260266484b38eeb751ab883a92200c89ef8 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 11 Mar 2015 18:15:28 +0100 Subject: [PATCH 043/210] Fix size of filtered variables matrix Fixes crash occurring due to non-conformable matrices --- matlab/prior_posterior_statistics.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/matlab/prior_posterior_statistics.m b/matlab/prior_posterior_statistics.m index 35a0b481f..4908d6b64 100644 --- a/matlab/prior_posterior_statistics.m +++ b/matlab/prior_posterior_statistics.m @@ -98,13 +98,13 @@ MAX_ninno = min(B,ceil(MaxNumberOfBytes/(exo_nbr*gend)/8)); MAX_nerro = min(B,ceil(MaxNumberOfBytes/(size(options_.varobs,1)*gend)/8)); if naK - MAX_naK = min(B,ceil(MaxNumberOfBytes/(length(options_.varobs)* ... - length(options_.filter_step_ahead)*gend)/8)); + MAX_naK = min(B,ceil(MaxNumberOfBytes/(endo_nbr* ... + length(options_.filter_step_ahead)*(gend+max(options_.filter_step_ahead)))/8)); end if horizon - MAX_nforc1 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*horizon)/8)); - MAX_nforc2 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*horizon)/ ... + MAX_nforc1 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*(horizon+maxlag))/8)); + MAX_nforc2 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*(horizon+maxlag))/ ... 8)); IdObs = bayestopt_.mfys; From c881cfff17cadb1db437d5e07b60e75492473042 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 12 Mar 2015 17:24:21 +0100 Subject: [PATCH 044/210] 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 045/210] 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 046/210] 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 047/210] 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 048/210] 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 049/210] 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 050/210] 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 051/210] 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 052/210] 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 053/210] 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 054/210] 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 055/210] 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 056/210] 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 057/210] 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 058/210] 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 059/210] 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 060/210] 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 061/210] 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 062/210] 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 063/210] 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 064/210] 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 065/210] 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 066/210] 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 067/210] 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 068/210] 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 069/210] 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 070/210] 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 071/210] 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 072/210] 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 073/210] 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 074/210] 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 075/210] 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 076/210] 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 077/210] 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 078/210] 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 079/210] 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 214dc747237b8a3ddce4267039ada25d0ab2f0e6 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 1 Apr 2015 09:00:51 +0200 Subject: [PATCH 080/210] - Fixed bugs around analytic derivation. - Fixed test routine, eliminating diffuse filter. - Trapped incompatibility of diffuse filter with analytic derivation. --- matlab/dsge_likelihood.m | 2 +- matlab/dynare_estimation_init.m | 3 +++ matlab/optimization/dynare_minimize_objective.m | 3 --- tests/analytic_derivatives/fs2000_analytic_derivation.mod | 8 +++++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index 7ac811416..aae1224e4 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -631,7 +631,7 @@ if analytic_derivation, analytic_deriv_info={analytic_derivation,DT,DYss,DOm,DH,DP,asy_Hess}; else analytic_deriv_info={analytic_derivation,DT,DYss,DOm,DH,DP,D2T,D2Yss,D2Om,D2H,D2P}; - clear DT DYss DOm DH DP D2T D2Yss D2Om D2H D2P, + clear DT DYss DOm DP D2T D2Yss D2Om D2H D2P, end else analytic_deriv_info={0}; diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index e54618a7b..eab7b8b7e 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -442,6 +442,9 @@ else end; if options_.analytic_derivation, + if options_.lik_init == 3, + error('analytic derivation is incompatible with diffuse filter') + end options_.analytic_derivation = 1; if ~(exist('sylvester3','file')==2), dynareroot = strrep(which('dynare'),'dynare.m',''); diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index b345b8d55..4113bf119 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -178,9 +178,6 @@ switch minimizer_algorithm 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; - end case 6 [opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function, start_par_value, ... Initial_Hessian, options_.mh_jscale, bounds, prior_information.p2, options_.gmhmaxlik, options_.optim_opt, varargin{:}); diff --git a/tests/analytic_derivatives/fs2000_analytic_derivation.mod b/tests/analytic_derivatives/fs2000_analytic_derivation.mod index c4f2a7479..3dc8b7ad0 100644 --- a/tests/analytic_derivatives/fs2000_analytic_derivation.mod +++ b/tests/analytic_derivatives/fs2000_analytic_derivation.mod @@ -61,7 +61,7 @@ alp, beta_pdf, 0.356, 0.02; bet, beta_pdf, 0.993, 0.002; gam, normal_pdf, 0.0085, 0.003; mst, normal_pdf, 1.0002, 0.007; -rho, beta_pdf, 0.129, 0.223; +rho, beta_pdf, 0.129, 0.1; psi, beta_pdf, 0.65, 0.05; del, beta_pdf, 0.01, 0.005; stderr e_a, inv_gamma_pdf, 0.035449, inf; @@ -74,5 +74,7 @@ options_.solve_tolf = 1e-12; estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=1,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=2,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); -estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=3,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); -estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=4,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); \ No newline at end of file +estimation(order=1,mode_compute=4,analytic_derivation,kalman_algo=1,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); +estimation(order=1,mode_compute=4,analytic_derivation,kalman_algo=2,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); +//estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=3,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); +//estimation(order=1,mode_compute=5,analytic_derivation,kalman_algo=4,datafile=fsdat_simul,nobs=192,mh_replic=0,mh_nblocks=2,mh_jscale=0.8); \ No newline at end of file From b4a8ad8aa4b992c49638c90207871a9feaa18c3c Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 1 Apr 2015 14:43:52 +0200 Subject: [PATCH 081/210] 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 082/210] 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(); } From 9c3c0d727f7fe336c02e580c57b13f5ab9f29314 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 17 Sep 2014 20:06:57 +0200 Subject: [PATCH 083/210] Add check for point priors and force user to fix this parameter. Traps Inf-prior --- matlab/set_prior.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/matlab/set_prior.m b/matlab/set_prior.m index 7bc3cc83d..a72a6204d 100644 --- a/matlab/set_prior.m +++ b/matlab/set_prior.m @@ -155,6 +155,12 @@ end bayestopt_.p6 = NaN(size(bayestopt_.p1)) ; bayestopt_.p7 = bayestopt_.p6 ; +%% check for point priors and disallow them as they do not work with MCMC +if any(bayestopt_.p2 ==0) + error(sprintf(['Error in prior for %s: you cannot use a point prior in estimation. Either increase the prior standard deviation',... + ' or fix the parameter completely.'], bayestopt_.name{bayestopt_.p2 ==0})) +end + % generalized location parameters by default for beta distribution k = find(bayestopt_.pshape == 1); k1 = find(isnan(bayestopt_.p3(k))); From 27403fb2dd495e578325c8e57d58fe448e31ac25 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 17 Sep 2014 20:09:33 +0200 Subject: [PATCH 084/210] Add check whether initial prior is Inf Requires adding fourth output argument of priordens.m that stores position of problematic parameter. --- matlab/initial_estimation_checks.m | 8 +++++++- matlab/priordens.m | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 54af16f7b..7b1bf2380 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -89,8 +89,14 @@ if any(BayesInfo.pshape) % if Bayesian estimation end end -%% display warning if some parameters are still NaN +% display warning if some parameters are still NaN test_for_deep_parameters_calibration(Model); + +[lnprior, junk1,junk2,info]= priordens(xparam1,BayesInfo.pshape,BayesInfo.p6,BayesInfo.p7,BayesInfo.p3,BayesInfo.p4); +if info + fprintf('The prior density evaluated at the initial values is Inf for the following parameters: %s\n',BayesInfo.name{info,1}) + error('The initial value of the prior is -Inf') +end % Evaluate the likelihood. ana_deriv = DynareOptions.analytic_derivation; diff --git a/matlab/priordens.m b/matlab/priordens.m index 02ba5c698..f3e5fd619 100644 --- a/matlab/priordens.m +++ b/matlab/priordens.m @@ -1,4 +1,4 @@ -function [logged_prior_density, dlprior, d2lprior] = priordens(x, pshape, p6, p7, p3, p4,initialization) +function [logged_prior_density, dlprior, d2lprior, info] = priordens(x, pshape, p6, p7, p3, p4,initialization) % Computes a prior density for the structural parameters of DSGE models % % INPUTS @@ -12,6 +12,7 @@ function [logged_prior_density, dlprior, d2lprior] = priordens(x, pshape, p6, p7 % % OUTPUTS % logged_prior_density [double] scalar, log of the prior density evaluated at x. +% info [double] error code for index of Inf-prior parameter % % Copyright (C) 2003-2012 Dynare Team @@ -34,6 +35,8 @@ function [logged_prior_density, dlprior, d2lprior] = priordens(x, pshape, p6, p7 persistent id1 id2 id3 id4 id5 id6 persistent tt1 tt2 tt3 tt4 tt5 tt6 +info=0; + if nargin > 6 && initialization == 1 % Beta indices. tt1 = 1; @@ -81,6 +84,9 @@ d2lprior = 0.0; if tt1 logged_prior_density = logged_prior_density + sum(lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1))) ; if isinf(logged_prior_density) + if nargout ==4 + info=id1(isinf(lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1)))); + end return end if nargout == 2, @@ -93,6 +99,9 @@ end if tt2 logged_prior_density = logged_prior_density + sum(lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2))) ; if isinf(logged_prior_density) + if nargout ==4 + info=id2(isinf(lpdfgam(x(id2)-p3(id2),p6(id2),p7(id2)))); + end return end if nargout == 2, @@ -114,6 +123,9 @@ end if tt4 logged_prior_density = logged_prior_density + sum(lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4))) ; if isinf(logged_prior_density) + if nargout ==4 + info=id4(isinf(lpdfig1(x(id4)-p3(id4),p6(id4),p7(id4)))); + end return end if nargout == 2, @@ -126,6 +138,9 @@ end if tt5 if any(x(id5)-p3(id5)<0) || any(x(id5)-p4(id5)>0) logged_prior_density = -Inf ; + if nargout ==4 + info=id5((x(id5)-p3(id5)<0) || (x(id5)-p4(id5)>0)); + end return end logged_prior_density = logged_prior_density + sum(log(1./(p4(id5)-p3(id5)))) ; @@ -140,6 +155,9 @@ end if tt6 logged_prior_density = logged_prior_density + sum(lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6))) ; if isinf(logged_prior_density) + if nargout ==4 + info=id6(isinf(lpdfig2(x(id6)-p3(id6),p6(id6),p7(id6)))); + end return end if nargout == 2, From 8cc9fbd69a78290da3edd3b802d840ca2f8ae7ad Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 2 Apr 2015 20:52:49 +0200 Subject: [PATCH 085/210] Remove hard-coded coloring of legend in mode_check.m Now displays correct colors with new Matlab plot interface (>2014a) --- matlab/mode_check.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/matlab/mode_check.m b/matlab/mode_check.m index fd80782d7..180ba3592 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -149,7 +149,7 @@ for plt = 1:nbplt, y(i,2) = (y(i,1)+lnprior-dy); end end - plot(z,-y); + fighandle=plot(z,-y); hold on yl=get(gca,'ylim'); plot( [x(kk) x(kk)], yl, 'c', 'LineWidth', 1) @@ -173,8 +173,9 @@ for plt = 1:nbplt, else axes('position',[0.3 0.01 0.42 0.05],'box','on'), end - plot([0.48 0.68],[0.5 0.5],'color',[0 0.5 0]) - hold on, plot([0.04 0.24],[0.5 0.5],'b') + line_color=get(fighandle,'color'); + plot([0.48 0.68],[0.5 0.5],'color',line_color{2}) + hold on, plot([0.04 0.24],[0.5 0.5],'color',line_color{1}) set(gca,'xlim',[0 1],'ylim',[0 1],'xtick',[],'ytick',[]) text(0.25,0.5,'log-post') text(0.69,0.5,'log-lik kernel') From 7c838b133f11ce58101bf611b770de74feec48c5 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 1 Apr 2015 14:55:47 +0200 Subject: [PATCH 086/210] Use local variables for restrict var list, to avoid overwriting the global and messing likelihood evaluations later on. --- matlab/DsgeSmoother.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index f59236c69..ef38cf231 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -69,9 +69,10 @@ M_ = set_all_parameters(xparam1,estim_params_,M_); %------------------------------------------------------------------------------ % 2. call model setup & reduction program %------------------------------------------------------------------------------ -oo_.dr.restrict_var_list = bayestopt_.smoother_var_list; -oo_.dr.restrict_columns = bayestopt_.smoother_restrict_columns; -[T,R,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_); +DynareResults = oo_; +DynareResults.dr.restrict_var_list = bayestopt_.smoother_var_list; +DynareResults.dr.restrict_columns = bayestopt_.smoother_restrict_columns; +[T,R,SteadyState,info,M_,options_,DynareResults] = dynare_resolve(M_,options_,DynareResults); bayestopt_.mf = bayestopt_.smoother_mf; if options_.noconstant constant = zeros(vobs,1); From 52978365772b67a7e4ff78e59b00b89438dbefd4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 1 Apr 2015 14:58:10 +0200 Subject: [PATCH 087/210] Harmonize criteria for exiting diffuse steps in likelihood with the smoother. Since initial Pinf is well scaled to unity, crit1= 1.e-6 is used for smoother and should also apply to likelihood evaluations. --- matlab/kalman/likelihood/kalman_filter_d.m | 3 ++- .../likelihood/missing_observations_kalman_filter_d.m | 3 ++- matlab/kalman/likelihood/univariate_kalman_filter_d.m | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/matlab/kalman/likelihood/kalman_filter_d.m b/matlab/kalman/likelihood/kalman_filter_d.m index ced4d1305..bbec1fe7c 100644 --- a/matlab/kalman/likelihood/kalman_filter_d.m +++ b/matlab/kalman/likelihood/kalman_filter_d.m @@ -59,8 +59,9 @@ dlik = zeros(smpl,1); % Initialization of the vector gathering the densitie dLIK = Inf; % Default value of the log likelihood. oldK = Inf; s = 0; +crit1=1.e-6; -while rank(Pinf,kalman_tol) && (t<=last) +while rank(Pinf,crit1) && (t<=last) s = t-start+1; v = Y(:,t)-Z*a; Finf = Z*Pinf*Z'; diff --git a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m index 608a07b7d..c09194820 100644 --- a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m +++ b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m @@ -66,13 +66,14 @@ t = start; % Initialization of the time index. dlik = zeros(smpl,1); % Initialization of the vector gathering the densities. dLIK = Inf; % Default value of the log likelihood. oldK = Inf; +crit1=1.e-6; if isequal(H,0) H = zeros(pp,pp); end s = 0; -while rank(Pinf,kalman_tol) && (t<=last) +while rank(Pinf,crit1) && (t<=last) s = t-start+1; d_index = data_index{t}; if isempty(d_index) diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_d.m b/matlab/kalman/likelihood/univariate_kalman_filter_d.m index ba047a291..e3368a6c1 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter_d.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter_d.m @@ -110,7 +110,8 @@ dLIK = Inf; % Default value of the log likelihood. oldK = Inf; llik = zeros(smpl,pp); -newRank = rank(Pinf,kalman_tol); +crit1 = 1.e-6; +newRank = rank(Pinf,crit1); l2pi = log(2*pi); while newRank && (t<=last) @@ -138,7 +139,7 @@ while newRank && (t<=last) end end if newRank - oldRank = rank(Pinf,kalman_tol); + oldRank = rank(Pinf,crit1); else oldRank = 0; end @@ -146,7 +147,7 @@ while newRank && (t<=last) Pstar = T*Pstar*T'+QQ; Pinf = T*Pinf*T'; if newRank - newRank = rank(Pinf,kalman_tol); + newRank = rank(Pinf,crit1); end if oldRank ~= newRank disp('univariate_diffuse_kalman_filter:: T does influence the rank of Pinf!') From e97e5c340757098a2904b24aaeb5f8011812cdf3 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 1 Apr 2015 15:10:26 +0200 Subject: [PATCH 088/210] Exclude zero columns of T from Kitagawa transformation, since ordschur is extremely noisy for multiple zero eigenvalues. This can make a lot of difference for large models that have hundreds of definitions. --- matlab/schur_statespace_transformation.m | 61 +++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/matlab/schur_statespace_transformation.m b/matlab/schur_statespace_transformation.m index cef99ed78..c9bdec8a9 100644 --- a/matlab/schur_statespace_transformation.m +++ b/matlab/schur_statespace_transformation.m @@ -1,8 +1,15 @@ -function [Z,ST,R1,QT,Pstar,Pinf] = schur_statespace_transformation(mf,T,R,Q,qz_criterium) -% function [Z,ST,QT,R1,Pstar,Pinf] = schur_statespace(mf,T,R,Q,qz_criterium) +function [Z,ST,R1,QT,Pstar,Pinf] = schur_statespace_transformation(mf,T,R,Q,qz_criterium, restrict_columns) +% function [Z,ST,QT,R1,Pstar,Pinf] = schur_statespace_transformation(mf,T,R,Q,qz_criterium, restrict_columns) % Kitagawa transformation of state space system with a quasi-triangular -% transition matrix with unit roots at the top. Computation of Pstar and -% Pinf for Durbin and Koopman Diffuse filter +% transition matrix with unit roots at the top, but excluding zero columns of the transition matrix. +% Computation of Pstar and Pinf for Durbin and Koopman Diffuse filter +% +% The transformed state space is +% y = [ss; z; x]; +% s = static variables (zero columns of T) +% z = unit roots +% x = stable roots +% ss = s - z = stationarized static variables % % INPUTS % mf [integer] vector of indices of observed variables in @@ -44,6 +51,20 @@ function [Z,ST,R1,QT,Pstar,Pinf] = schur_statespace_transformation(mf,T,R,Q,qz_c % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . +np = size(T,1); +if nargin == 6, + indx = restrict_columns; + indx0=find(~ismember([1:np],indx)); +else + indx=(find(max(abs(T))>0)); + indx0=(find(max(abs(T))==0)); +end +T0=T(indx0,indx); %static variables vs. dynamic ones +R0=R(indx0,:); % matrix of shocks for static variables + +% perform Kitagawa transformation only for non-zero columns of T +T=T(indx,indx); +R=R(indx,:); np = size(T,1); [QT,ST] = schur(T); e1 = abs(ordeig(ST)) > 2-qz_criterium; @@ -93,14 +114,40 @@ if i == nk+1 Pstar(nk1,nk1)=(B(nk1,nk1)+c)/(1-ST(nk1,nk1)*ST(nk1,nk1)); end -Z = QT(mf,:); R1 = QT'*R; +ST1=ST; + +% now I recover stationarized static variables +% using +% ss = s-z and +% z-z(-1) (growth rates of unit roots) only depends on stationary variables +np0=length(indx0); +Pstar = blkdiag(zeros(np0),Pstar); +ST = [zeros(length(Pstar),length(indx0)) [T0*QT ;ST]]; +R1 = [R0; R1]; +ST0=ST; +ST0(:,1:np0+nk)=0; +ST0(np0+1:np0+nk,:)=0; +ST0(1:np0,np0+nk+1:end) = ST(1:np0,np0+nk+1:end)-ST(1:np0,np0+1:np0+nk)*ST(np0+1:np0+nk,np0+nk+1:end); +R10 = R1; +R10(np0+1:np0+nk,:)=0; +R10(1:np0,:) = R1(1:np0,:)-ST(1:np0,np0+1:np0+nk)*R1(np0+1:np0+nk,:); +Pstar = ... + ST0*Pstar*ST0'+ ... + R10*Q*R10'; +QT = blkdiag(eye(np0),QT); +QT(1:np0,np0+1:np0+nk) = QT(1:np0,np0+1:np0+nk)+ST(1:np0,np0+1:np0+nk); +% reorder QT entries +QT([indx0(:); indx(:)],:) = QT; +Z = QT(mf,:); +ST(1:np0,:) = ST0(1:np0,:); +R1(1:np0,:) = R10(1:np0,:); % stochastic trends with no influence on observed variables are % arbitrarily initialized to zero Pinf = zeros(np,np); Pinf(1:nk,1:nk) = eye(nk); -[QQ,RR,EE] = qr(Z*ST(:,1:nk),0); +[QQ,RR,EE] = qr(Z*ST(:,1+np0:nk+np0),0); k = find(abs(diag([RR; zeros(nk-size(Z,1),size(RR,2))])) < 1e-8); if length(k) > 0 k1 = EE(:,k); @@ -108,3 +155,5 @@ if length(k) > 0 dd(k1) = zeros(length(k1),1); Pinf(1:nk,1:nk) = diag(dd); end +Pinf = blkdiag(zeros(np0),Pinf); + From 090c4fedbd28dcd184fdcdaccc750d922ec4bf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 3 Apr 2015 17:48:25 +0200 Subject: [PATCH 089/210] Added new option (diffuse_kalman_tol) and fixed tolerance paremeters in diffuse smoother routines. --- doc/dynare.texi | 2 ++ matlab/DsgeSmoother.m | 5 +++-- matlab/global_initialization.m | 1 + matlab/missing_DiffuseKalmanSmootherH1_Z.m | 16 ++++++++-------- matlab/missing_DiffuseKalmanSmootherH3_Z.m | 14 +++++++------- preprocessor/DynareBison.yy | 4 +++- preprocessor/DynareFlex.ll | 1 + 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 0e60bdf3e..094089cb4 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -5221,6 +5221,8 @@ singularity is encountered, Dynare by default automatically switches to the univ @item kalman_tol = @var{DOUBLE} @anchor{kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors during the Kalman filter (minimum allowed reciprocal of the matrix condition number). Default value is @code{1e-10} +@item diffuse_kalman_tol = @var{DOUBLE} +@anchor{diffuse_kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors (@math{F_{\infty}}) and the rank of the covariance matrix of the state variables (@math{P_{\infty}}) during the Diffuse Kalman filter. Default value is @code{1e-8} @item filter_covariance @anchor{filter_covariance} Saves the series of one step ahead error of diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index ef38cf231..2dba85016 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -175,6 +175,7 @@ elseif options_.lik_init == 5 % Old diffuse Kalman filter only for th Pinf = []; end kalman_tol = options_.kalman_tol; +diffuse_kalman_tol = options_.diffuse_kalman_tol; riccati_tol = options_.riccati_tol; data1 = Y-trend; % ----------------------------------------------------------------------------- @@ -200,7 +201,7 @@ if kalman_algo == 1 || kalman_algo == 3 [alphahat,epsilonhat,etahat,ahat,P,aK,PK,decomp] = missing_DiffuseKalmanSmootherH1_Z(ST, ... Z,R1,Q,H,Pinf,Pstar, ... data1,vobs,np,smpl,data_index, ... - options_.nk,kalman_tol,options_.filter_decomposition); + options_.nk,kalman_tol,diffuse_kalman_tol,options_.filter_decomposition); if isinf(alphahat) if kalman_algo == 1 kalman_algo = 2; @@ -227,7 +228,7 @@ if kalman_algo == 2 || kalman_algo == 4 [alphahat,epsilonhat,etahat,ahat,P,aK,PK,decomp] = missing_DiffuseKalmanSmootherH3_Z(ST, ... Z,R1,Q,diag(H), ... Pinf,Pstar,data1,vobs,np,smpl,data_index, ... - options_.nk,kalman_tol,... + options_.nk,kalman_tol,diffuse_kalman_tol, ... options_.filter_decomposition); end diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 1470d533f..f169bfe6a 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -387,6 +387,7 @@ options_.nobs = NaN; options_.kalman_algo = 0; options_.fast_kalman = 0; options_.kalman_tol = 1e-10; +options_.diffuse_kalman_tol = 1e-8; options_.use_univariate_filters_if_singularity_is_detected = 1; options_.riccati_tol = 1e-6; options_.lik_algo = 1; diff --git a/matlab/missing_DiffuseKalmanSmootherH1_Z.m b/matlab/missing_DiffuseKalmanSmootherH1_Z.m index 4b5014771..9fc09eb30 100644 --- a/matlab/missing_DiffuseKalmanSmootherH1_Z.m +++ b/matlab/missing_DiffuseKalmanSmootherH1_Z.m @@ -1,6 +1,6 @@ -function [alphahat,epsilonhat,etahat,atilde,P,aK,PK,decomp] = missing_DiffuseKalmanSmootherH1_Z(T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,decomp_flag) +function [alphahat,epsilonhat,etahat,atilde,P,aK,PK,decomp] = missing_DiffuseKalmanSmootherH1_Z(T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,diffuse_kalman_tol,decomp_flag) -% function [alphahat,epsilonhat,etahat,a,aK,PK,decomp] = DiffuseKalmanSmoother1(T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,decomp_flag) +% function [alphahat,epsilonhat,etahat,a,aK,PK,decomp] = DiffuseKalmanSmoother1(T,Z,R,Q,H,Pinf1,Pstar1,Y,pp,mm,smpl,data_index,nk,kalman_tol,diffuse_kalman_tol,decomp_flag) % Computes the diffuse kalman smoother without measurement error, in the case of a non-singular var-cov matrix % % INPUTS @@ -18,6 +18,7 @@ function [alphahat,epsilonhat,etahat,atilde,P,aK,PK,decomp] = missing_DiffuseKal % data_index [cell] 1*smpl cell of column vectors of indices. % nk number of forecasting periods % kalman_tol tolerance for reciprocal condition number +% diffuse_kalman_tol tolerance for reciprocal condition number (for Finf) and the rank of Pinf % decomp_flag if true, compute filter decomposition % % OUTPUTS @@ -38,7 +39,7 @@ function [alphahat,epsilonhat,etahat,atilde,P,aK,PK,decomp] = missing_DiffuseKal % Models", S.J. Koopman and J. Durbin (2003, in Journal of Time Series % Analysis, vol. 24(1), pp. 85-98). -% Copyright (C) 2004-2011 Dynare Team +% Copyright (C) 2004-2015 Dynare Team % % This file is part of Dynare. % @@ -80,7 +81,6 @@ Kstar = zeros(mm,pp,smpl); P = zeros(mm,mm,smpl+1); Pstar = zeros(spstar(1),spstar(2),smpl+1); Pstar(:,:,1) = Pstar1; Pinf = zeros(spinf(1),spinf(2),smpl+1); Pinf(:,:,1) = Pinf1; -crit1 = 1.e-8; steady = smpl; rr = size(Q,1); QQ = R*Q*transpose(R); @@ -91,7 +91,7 @@ epsilonhat = zeros(rr,smpl); r = zeros(mm,smpl+1); t = 0; -while rank(Pinf(:,:,t+1),crit1) && t INT_NUMBER %token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION -%token KALMAN_ALGO KALMAN_TOL SUBSAMPLES OPTIONS TOLF +%token KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF %token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV %token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT %token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS @@ -1664,6 +1664,7 @@ estimation_options : o_datafile | o_filtered_vars | o_kalman_algo | o_kalman_tol + | o_diffuse_kalman_tol | o_xls_sheet | o_xls_range | o_filter_step_ahead @@ -2643,6 +2644,7 @@ o_filtered_vars : FILTERED_VARS { driver.option_num("filtered_vars", "1"); }; o_relative_irf : RELATIVE_IRF { driver.option_num("relative_irf", "1"); }; o_kalman_algo : KALMAN_ALGO EQUAL INT_NUMBER { driver.option_num("kalman_algo", $3); }; o_kalman_tol : KALMAN_TOL EQUAL non_negative_number { driver.option_num("kalman_tol", $3); }; +o_diffuse_kalman_tol : DIFFUSE_KALMAN_TOL EQUAL non_negative_number { driver.option_num("diffuse_kalman_tol", $3); }; o_marginal_density : MARGINAL_DENSITY EQUAL LAPLACE { driver.option_str("mc_marginal_density", "laplace"); } | MARGINAL_DENSITY EQUAL MODIFIEDHARMONICMEAN diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 994aaa421..0e7a31c16 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -288,6 +288,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 nodiagnostic {return token::NODIAGNOSTIC;} kalman_algo {return token::KALMAN_ALGO;} kalman_tol {return token::KALMAN_TOL;} +diffuse_kalman_tol {return token::DIFFUSE_KALMAN_TOL;} forecast {return token::FORECAST;} smoother {return token::SMOOTHER;} bayesian_irf {return token::BAYESIAN_IRF;} From 6aa5ceabb2de37ded2315fa9b143203170fbf403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 3 Apr 2015 17:59:51 +0200 Subject: [PATCH 090/210] Fixed bug introduced in 363c4a61222103fda22adff9bdb1115a6073428a. --- matlab/DsgeSmoother.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index 2dba85016..a692965f1 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -69,10 +69,16 @@ M_ = set_all_parameters(xparam1,estim_params_,M_); %------------------------------------------------------------------------------ % 2. call model setup & reduction program %------------------------------------------------------------------------------ -DynareResults = oo_; -DynareResults.dr.restrict_var_list = bayestopt_.smoother_var_list; -DynareResults.dr.restrict_columns = bayestopt_.smoother_restrict_columns; -[T,R,SteadyState,info,M_,options_,DynareResults] = dynare_resolve(M_,options_,DynareResults); +oldoo.restrict_var_list = oo_.dr.restrict_var_list; +oldoo.restrict_columns = oo_.dr.restrict_columns; +oo_.dr.restrict_var_list = bayestopt_.smoother_var_list; +oo_.dr.restrict_columns = bayestopt_.smoother_restrict_columns; + +[T,R,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_); + +oo_.dr.restrict_var_list = oldoo.restrict_var_list; +oo_.dr.restrict_columns = oldoo.restrict_columns; + bayestopt_.mf = bayestopt_.smoother_mf; if options_.noconstant constant = zeros(vobs,1); From c46b6cdfea04fc2c1618facfd4430081838f42c1 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 3 Apr 2015 18:19:38 +0200 Subject: [PATCH 091/210] Clarify Ramsey optimal policy --- doc/dynare.texi | 88 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 0e60bdf3e..bddef3b40 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -2331,7 +2331,7 @@ jump from t=200 to t=201. @end deffn @deffn Block histval ; - +@anchor{histval} @descriptionhead @customhead{In a deterministic perfect foresight context} @@ -2371,6 +2371,10 @@ affect the starting point for impulse response functions). As for the case of perfect foresight simulations, all not explicitly specified variables are set to 0. Moreover, as only states enter the recursive policy functions, all values specified for control variables will be ignored. +For @ref{Ramsey} policy, it also specifies the values of the endogenous states at +which the objective function of the planner is computed. Note that the initial values +of the Lagrange multipliers associated with the planner's problem cannot be set, @xref{planner_objective_value}. + @examplehead @example @@ -6457,7 +6461,7 @@ new, expanded model. Alternatively, you can either solve for optimal policy under commitment with @code{ramsey_policy}, for optimal policy under discretion with @code{discretionary_policy} or for optimal simple rule with -@code{osr}. +@code{osr} (also implying commitment). @anchor{osr} @@ -6647,7 +6651,7 @@ at the optimum, stored in fields of the form @descriptionhead This command computes the First Order Conditions for maximizing the policy maker objective function subject to the -constraints provided by the equilibrium path of the economy. +constraints provided by the equilibrium path of the private economy. The planner objective must be declared with the @code{planner_objective} command. @@ -6677,6 +6681,7 @@ under optimal policy. Requires a @code{steady_state_model} block or a @end table @customhead{Steady state} +@anchor{Ramsey steady state} Dynare takes advantage of the fact that the Lagrange multipliers appear linearly in the equations of the steady state of the model under optimal @@ -6701,12 +6706,32 @@ instrument. @deffn Command ramsey_policy [@var{VARIABLE_NAME}@dots{}]; @deffnx Command ramsey_policy (@var{OPTIONS}@dots{}) [@var{VARIABLE_NAME}@dots{}]; +@anchor{ramsey_policy} @descriptionhead This command computes the first order approximation of the policy that -maximizes the policy maker objective function submitted to the -constraints provided by the equilibrium path of the economy. +maximizes the policy maker's objective function subject to the +constraints provided by the equilibrium path of the private economy and under +commitment to this optimal policy. Following @cite{Woodford (1999)}, the Ramsey +policy is computed using a timeless perspective. That is, the government forgoes +its first-period advantage and does not exploit the preset privates sector expectations +(which are the source of the well-known time inconsistency that requires the +assumption of commitment). Rather, it acts as if the initial multipliers had +been set to 0 in the distant past, giving them time to converge to their steady +state value. Consequently, the optimal decision rules are computed around this steady state +of the endogenous variables and the Lagrange multipliers. + +This first order approximation to the optimal policy conducted by Dynare is not to be +confused with a naive linear quadratic approach to optimal policy that can lead to +spurious welfare rankings (see @cite{Kim and Kim (2003)}). In the latter, the optimal policy +would be computed subject to the first order approximated FOCs of the +private economy. In contrast, Dynare first computes the FOCs of the Ramsey planner's problem +subject to the nonlinear constraints that are the FOCs of the private economy +and only then approximates these FOCs of planner's problem to first order. Thereby, the second +order terms that are required for a second-order correct welfare evaluation are +preserved. + The planner objective must be declared with the @code{planner_objective} command. @@ -6730,36 +6755,34 @@ under optimal policy. Requires a @code{steady_state_model} block or a @end table -Note that only first order approximation is available (@i{i.e.} -@code{order=1} must be specified). +Note that only a first order approximation of the optimal Ramsey policy is +available, leading to a second-order accurate welfare ranking +(@i{i.e.} @code{order=1} must be specified). @outputhead -This command generates all the output variables of @code{stoch_simul}. +This command generates all the output variables of @code{stoch_simul}. For specifying +the initial values for the endogenous state variables (except for the Lagrange +multipliers}, @xref{histval} @vindex oo_.planner_objective_value +@anchor{planner_objective_value} + In addition, it stores the value of planner objective function under -Ramsey policy in @code{oo_.planner_objective_value}. +Ramsey policy in @code{oo_.planner_objective_value}, given the initial values +of the endogenous state variables. If not specified with @code{histval}, they are +taken to be at their steady state values. The result is a 1 by 2 +vector, where the first entry stores the value of the planner objective under +the timeless perspective to Ramsey policy, i.e. where the initial Lagrange +multipliers associated with the planner's problem are set to their steady state +values (@xref{ramsey_policy}). +In contrast, the second entry stores the value of the planner objective with +initial Lagrange multipliers of the planner's problem set to 0, i.e. it is assumed +that the planner succumbs to the temptation to exploit the preset private expecatations +in the first period (but not in later periods due to commitment). @customhead{Steady state} - -Dynare takes advantage of the fact that the Lagrange multipliers appear -linearly in the equations of the steady state of the model under optimal -policy. Nevertheless, it is in general very difficult to compute the -steady state with simply a numerical guess in @code{initval} for the -endogenous variables. - -It greatly facilitates the computation, if the user provides an -analytical solution for the steady state (in @code{steady_state_model} -block or in a @code{@dots{}_steadystate.m} file). In this case, it is -necessary to provide a steady state solution CONDITIONAL on the value -of the instruments in the optimal policy problem and declared with -option @code{instruments}. Note that choosing the instruments is -partly a matter of interpretation and you can choose instruments that -are handy from a mathematical point of view but different from the -instruments you would refer to in the analysis of the paper. A typical -example is choosing inflation or nominal interest rate as an -instrument. +@xref{Ramsey steady state} @end deffn @@ -12285,6 +12308,11 @@ Juillard, Michel (1996): ``Dynare: A program for the resolution and simulation of dynamic models with forward variables through the use of a relaxation algorithm,'' CEPREMAP, @i{Couverture Orange}, 9602 +@item +Kim, Jinill and Sunghyun Kim (2003): ``Spurious welfare reversals in +international business cycle models,'' @i{Journal of International +Economics}, 60, 471--500 + @item Kim, Jinill, Sunghyun Kim, Ernst Schaumburg, and Christopher A. Sims (2008): ``Calculating and using second-order accurate solutions of @@ -12355,6 +12383,12 @@ Villemot, Sébastien (2011): ``Solving rational expectations models at first order: what Dynare does,'' @i{Dynare Working Papers}, 2, CEPREMAP +@item +Woodford, Michael (2011): ``Commentary: How Should Monetary Policy Be +Conducted in an Era of Price Stability?'' @i{Proceedings - Economic Policy Symposium - Jackson Hole}, +277-316 + + @end itemize @node Command and Function Index From 405b1f7368882e1e4bf071c29b10bb07e2151fa1 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 6 Apr 2015 11:05:12 +0200 Subject: [PATCH 092/210] Add solvopt.m to Dynare optimizers Restores compatibility of mode_compute=101 --- matlab/global_initialization.m | 11 + matlab/optimization/apprgrdn.m | 73 ++ .../optimization/dynare_minimize_objective.m | 28 +- matlab/optimization/solvopt.m | 991 ++++++++++++++++++ 4 files changed, 1098 insertions(+), 5 deletions(-) create mode 100644 matlab/optimization/apprgrdn.m create mode 100644 matlab/optimization/solvopt.m diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index f169bfe6a..bd6f7140b 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -525,6 +525,17 @@ simpsa.MAX_FUN_EVALS = 20000; simpsa.DISPLAY = 'iter'; options_.simpsa = simpsa; +%solveopt optimizer +solveopt.minimizer_indicator=-1; %use minimizer +solveopt.TolX=1e-6; %accuracy of argument +solveopt.TolFun=1e-6; %accuracy of function +solveopt.MaxIter=15000; +solveopt.verbosity=1; +solveopt.TolXConstraint=1.e-8; +solveopt.SpaceDilation=2.5; +solveopt.LBGradientStep=1.e-11; +options_.solveopt=solveopt; + % prior analysis options_.prior_mc = 20000; options_.prior_analysis_endo_var_list = []; diff --git a/matlab/optimization/apprgrdn.m b/matlab/optimization/apprgrdn.m new file mode 100644 index 000000000..9f16e4466 --- /dev/null +++ b/matlab/optimization/apprgrdn.m @@ -0,0 +1,73 @@ +function g = apprgrdn(x,f,fun,deltax,obj,varargin) +% g = apprgrdn(x,f,fun,deltax,obj,varargin) +% Performs the finite difference approximation of the gradient at a +% point used in solveopt +% +% Inputs: +% x: point at which to evaluate gradient +% f: calculated function value at a point x; +% fun: Name of the Matlab function calculating the function values +% deltax: vector of the relative stepsizes, +% obj flag indicating whether the gradient of the objective +% function (1) or the constraint function (0) is to be calculated. +% +% Modified by Giovanni Lombardo and Johannes Pfeifer to accomodate Dynare +% structure +% +% +% Copyright (C) 1997-2008, Alexei Kuntsevich and Franz Kappel +% Copyright (C) 2008-2015 Giovanni Lombardo +% 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 . + +n=max(size(x)); ee=ones(size(x)); +di=abs(x); idx=find(di<5e-15); di(idx)=5e-15*ee(idx); +di=deltax.*di; +if obj + idx=find(abs(di)<2e-10); + di(idx)=2e-10*sign(di(idx)); +else + idx=find(abs(di)<5e-15); + di(idx)=5e-15*sign(di(idx)); +end +y=x; + +g=NaN(n,1); +for i=1:n + y(i)=x(i)+di(i); + fi=feval(fun,y,varargin{:}); + if obj + if fi==f, + for j=1:3 + di(i)=di(i)*10; y(i)=x(i)+di(i); + fi=feval(fun,y,varargin{:}); + if fi~=f + break + end + end + end + end + g(i)=(fi-f)/di(i); + if obj + if ~isempty(idx) && any(idx==i) + y(i)=x(i)-di(i); + fi=feval(fun,y,varargin{:}); + g(i)=.5*(g(i)+(f-fi)/di(i)); + end + end + y(i)=x(i); +end diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 4113bf119..773b6a9d0 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -278,11 +278,29 @@ switch minimizer_algorithm options_.cova_compute = 0 ; [opt_par_values,stdh,lb_95,ub_95,med_param] = online_auxiliary_filter(start_par_value,varargin{:}) ; case 101 - myoptions=soptions; - myoptions(2)=1e-6; %accuracy of argument - myoptions(3)=1e-6; %accuracy of function (see Solvopt p.29) - myoptions(5)= 1.0; - [opt_par_values,fval]=solvopt(start_par_value,objective_function,[],myoptions,varargin{:}); + solveoptoptions = options_.solveopt; + if ~isempty(options_.optim_opt) + options_list = read_key_value_string(options_.optim_opt); + for i=1:rows(options_list) + switch options_list{i,1} + case 'TolX' + solveoptoptions.TolX = options_list{i,2}; + case 'TolFun' + solveoptoptions.TolFun = options_list{i,2}; + case 'MaxIter' + solveoptoptions.MaxIter = options_list{i,2}; + case 'verbosity' + solveoptoptions.verbosity = options_list{i,2}; + case 'SpaceDilation' + solveoptoptions.SpaceDilation = options_list{i,2}; + case 'LBGradientStep' + solveoptoptions.LBGradientStep = options_list{i,2}; + otherwise + warning(['solveopt: Unknown option (' options_list{i,1} ')!']) + end + end + end + [opt_par_values,fval]=solvopt(start_par_value,objective_function,[],[],[],solveoptoptions,varargin{:}); case 102 %simulating annealing LB = start_par_value - 1; diff --git a/matlab/optimization/solvopt.m b/matlab/optimization/solvopt.m new file mode 100644 index 000000000..9e5aa6139 --- /dev/null +++ b/matlab/optimization/solvopt.m @@ -0,0 +1,991 @@ +function [x,f,exitflag,n_f_evals,n_grad_evals,n_constraint_evals,n_constraint_gradient_evals]=solvopt(x,fun,grad,func,gradc,optim,varargin) +% [x,f,options]=solvopt(x,fun,grad,func,gradc,options,varargin) +% +% The function SOLVOPT, developed by Alexei Kuntsevich and Franz Kappe, +% performs a modified version of Shor's r-algorithm in +% order to find a local minimum resp. maximum of a nonlinear function +% defined on the n-dimensional Euclidean space or % a solution of a nonlinear +% constrained problem: +% min { f(x): g(x) (<)= 0, g(x) in R(m), x in R(n) } +% +% Inputs: +% x n-vector (row or column) of the coordinates of the starting +% point, +% fun name of an M-file (M-function) which computes the value +% of the objective function at a point x, +% synopsis: f=fun(x) +% grad name of an M-file (M-function) which computes the gradient +% vector of the function at a point x, +% synopsis: g=grad(x) +% func name of an M-file (M-function) which computes the MAXIMAL +% RESIDUAL(!) for a set of constraints at a point x, +% synopsis: fc=func(x) +% gradc name of an M-file (M-function) which computes the gradient +% vector for the maximal residual constraint at a point x, +% synopsis: gc=gradc(x) +% optim Options structure with fields: +% optim.minimizer_indicator= H, where sign(H)=-1 resp. sign(H)=+1 means minimize +% resp. maximize (valid only for unconstrained problem) +% and H itself is a factor for the initial trial step size +% (optim.minimizer_indicator=-1 by default), +% optim.TolX= relative error for the argument in terms of the +% infinity-norm (1.e-4 by default), +% optim.TolFun= relative error for the function value (1.e-6 by default), +% optim.MaxIter= limit for the number of iterations (15000 by default), +% optim.verbosity= control of the display of intermediate results and error +% resp. warning messages (default value is 0, i.e., no intermediate +% output but error and warning messages, see more in the manual), +% optim.TolXConstraint= admissible maximal residual for a set of constraints +% (optim.TolXConstraint=1e-8 by default, see more in the manual), +% *optim.SpaceDilation= the coefficient of space dilation (2.5 by default), +% *optim.LBGradientStep= lower bound for the stepsize used for the difference +% approximation of gradients (1e-12 by default, see more in the manual). +% (* ... changes should be done with care) +% +% Outputs: +% x optimal parameter vector (row resp. column), +% f optimum function value +% exitflag: the number of iterations, if positive, +% or an abnormal stop code, if negative (see more in the manual), +% n_f_evals: number of objective evaluations +% n_grad_evals: number of gradient evaluations, +% n_constraint_evals: number of constraint function evaluations, +% n_constraint_gradient_evals number of constraint gradient evaluations. +% +% +% Algorithm: Kuntsevich, A.V., Kappel, F., The solver for local nonlinear optimization problems +% (version 1.1, Matlab, C, FORTRAN). University of Graz, Graz, 1997. +% +% +% Copyright (C) 1997-2008, Alexei Kuntsevich and Franz Kappel +% Copyright (C) 2008-2015 Giovanni Lombardo +% 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 . + + + +% strings: ----{ +errmes='SolvOpt error:'; +wrnmes='SolvOpt warning:'; +error1='No function name and/or starting point passed to the function.'; +error2='Argument X has to be a row or column vector of dimension > 1.'; +error30=' returns an empty string.'; +error31='Function value does not exist (NaN is returned).'; +error32='Function equals infinity at the point.'; +error40=' returns an improper matrix. Check the dimension.'; +error41='Gradient does not exist (NaN is returned by ).'; +error42='Gradient equals infinity at the starting point.'; +error43='Gradient equals zero at the starting point.'; +error50=' returns an empty string.'; +error51=' returns NaN at the point.'; +error52=' returns infinite value at the point.'; +error60=' returns an improper vector. Check the dimension'; +error61=' returns NaN at the point.'; +error62=' returns infinite vector at the point.'; +error63=' returns zero vector at an infeasible point.'; +error5='Function is unbounded.'; +error6='Choose another starting point.'; +warn1= 'Gradient is zero at the point, but stopping criteria are not fulfilled.'; +warn20='Normal re-setting of a transformation matrix.' ; +warn21='Re-setting due to the use of a new penalty coefficient.' ; +warn4= 'Iterations limit exceeded.'; +warn31='The function is flat in certain directions.'; +warn32='Trying to recover by shifting insensitive variables.'; +warn09='Re-run from recorded point.'; +warn08='Ravine with a flat bottom is detected.'; +termwarn0='SolvOpt: Normal termination.'; +termwarn1='SolvOpt: Termination warning:'; +appwarn='The above warning may be reasoned by inaccurate gradient approximation'; +endwarn=[... + 'Premature stop is possible. Try to re-run the routine from the obtained point. ';... + 'Result may not provide the optimum. The function apparently has many extremum points. ';... + 'Result may be inaccurate in the coordinates. The function is flat at the optimum. ';... + 'Result may be inaccurate in a function value. The function is extremely steep at the optimum.']; +% ----} + +% ARGUMENTS PASSED ----{ +if nargin<2 % Function and/or starting point are not specified + exitflag=-1; + disp(errmes); + disp(error1); + return +end +if nargin<3 + app=1; % No user-supplied gradients +elseif isempty(grad) + app=1; +else + app=0; % Exact gradients are supplied +end + +% OPTIONS ----{ +doptions.minimizer_indicator=1; +doptions.TolX=1e-6; %accuracy of argument +doptions.TolFun=1e-6; %accuracy of function (see Solvopt p.29) +doptions.MaxIter=15000; +doptions.verbosity=1; +doptions.TolXConstraint=1.e-8; +doptions.SpaceDilation=2.5; +doptions.LBGradientStep=1.e-11; + +if nargin<4 + optim=doptions; +elseif isempty(optim) + optim=doptions; +end +% Check the values: +optim.TolX=max(optim.TolX,1.e-12); +optim.TolFun=max(optim.TolFun,1.e-12); +optim.TolX=max(optim.LBGradientStep*1.e2,optim.TolX); +optim.TolX=min(optim.TolX,1); +optim.TolFun=min(optim.TolFun,1); +optim.TolXConstraint=max(optim.TolXConstraint,1e-12); +optim.SpaceDilation=max([optim.SpaceDilation,1.5]); +optim.LBGradientStep=max(optim.LBGradientStep,1e-11); +% ----} + +if isempty(func) + constr=0; +else + constr=1; % Constrained problem + if isempty(gradc), + appconstr=1; + else + appconstr=0; % Exact gradients of constraints are supplied + end +end +% ----} + +% STARTING POINT ----{ +if max(size(x))<=1 + disp(errmes); + disp(error2); + exitflag=-2; + return +elseif size(x,2)==1 + n=size(x,1); + x=x'; + trx=1; +elseif size(x,1)==1 + n=size(x,2); + trx=0; +else + disp(errmes); + disp(error2); + exitflag=-2; + return +end +% ----} + +% WORKING CONSTANTS AND COUNTERS ----{ + +n_f_evals=0; n_grad_evals=0; % function and gradient calculations +if constr + n_constraint_evals=0; + n_constraint_gradient_evals=0; % same for constraints +end +epsnorm=1.e-15; +epsnorm2=1.e-30; % epsilon & epsilon^2 + +if constr, h1=-1; % NLP: restricted to minimization + cnteps=optim.TolXConstraint; % Max. admissible residual +else + h1=sign(optim.minimizer_indicator); % Minimize resp. maximize a function +end + +k=0; % Iteration counter + +wdef=1/optim.SpaceDilation-1; % Default space transf. coeff. + +%Gamma control ---{ +ajb=1+.1/n^2; % Base I +ajp=20; +ajpp=ajp; % Start value for the power +ajs=1.15; % Base II +knorms=0; gnorms=zeros(1,10); % Gradient norms stored +%---} + +%Display control ---{ +if optim.verbosity<=0, dispdata=0; + if optim.verbosity==-1 + dispwarn=0; + else + dispwarn=1; + end +else + dispdata=round(optim.verbosity); + dispwarn=1; +end +ld=dispdata; +%---} + +%Stepsize control ---{ +dq=5.1; % Step divider (at f_{i+1}>gamma*f_{i}) +du20=2;du10=1.5;du03=1.05; % Step multipliers (at certain steps made) +kstore=3;nsteps=zeros(1,kstore); % Steps made at the last 'kstore' iterations +if app + des=6.3; % Desired number of steps per 1-D search +else + des=3.3; +end +mxtc=3; % Number of trial cycles (steep wall detect) +%---} +termx=0; limxterm=50; % Counter and limit for x-criterion + +ddx =max(1e-11,optim.LBGradientStep); % stepsize for gradient approximation + +low_bound=-1+1e-4; % Lower bound cosine used to detect a ravine + +ZeroGrad=n*1.e-16; % Lower bound for a gradient norm + +nzero=0; % Zero-gradient events counter +% Lower bound for values of variables taking into account +lowxbound=max([optim.TolX,1e-3]); +% Lower bound for function values to be considered as making difference +lowfbound=optim.TolFun^2; +krerun=0; % Re-run events counter +detfr=optim.TolFun*100; % relative error for f/f_{record} +detxr=optim.TolX*10; % relative error for norm(x)/norm(x_{record}) + +warnno=0; % the number of warn.mess. to end with + +kflat=0; % counter for points of flatness +stepvanish=0; % counter for vanished steps +stopf=0; +% ----} End of setting constants +% ----} End of the preamble + +% COMPUTE THE FUNCTION ( FIRST TIME ) ----{ +if trx + f=feval(fun,x',varargin{:}); +else + f=feval(fun,x,varargin{:}); +end +n_f_evals=n_f_evals+1; +if isempty(f), if dispwarn,disp(errmes);disp(error30);end + exitflag=-3; if trx, x=x';end, return +elseif isnan(f), if dispwarn,disp(errmes);disp(error31);disp(error6);end + exitflag=-3; if trx, x=x';end, return +elseif abs(f)==Inf, if dispwarn,disp(errmes);disp(error32);disp(error6);end + exitflag=-3; if trx, x=x';end, return +end +xrec=x; frec=f; % record point and function value +% Constrained problem +if constr, fp=f; kless=0; + if trx, + fc=feval(func,x'); + else + fc=feval(func,x); + end + if isempty(fc), + if dispwarn,disp(errmes);disp(error50);end + exitflag=-5; if trx, x=x';end, return + elseif isnan(fc), + if dispwarn,disp(errmes);disp(error51);disp(error6);end + exitflag=-5; if trx, x=x';end, return + elseif abs(fc)==Inf, + if dispwarn,disp(errmes);disp(error52);disp(error6);end + exitflag=-5; if trx, x=x';end, return + end + n_constraint_evals=n_constraint_evals+1; + PenCoef=1; % first rough approximation + if fc<=cnteps + FP=1; fc=0; % feasible point + else + FP=0; % infeasible point + end + f=f+PenCoef*fc; +end +% ----} +% COMPUTE THE GRADIENT ( FIRST TIME ) ----{ +if app + deltax=h1*ddx*ones(size(x)); + if constr + if trx + g=apprgrdn(x',fp,fun,deltax',1,varargin{:}); + else + g=apprgrdn(x ,fp,fun,deltax,1,varargin{:}); + end + else + if trx + g=apprgrdn(x',f,fun,deltax',1,varargin{:}); + else + g=apprgrdn(x ,f,fun,deltax,1,varargin{:}); + end + end + n_f_evals=n_f_evals+n; +else + if trx + g=feval(grad,x',varargin{:}); + else + g=feval(grad,x,varargin{:}); + end + n_grad_evals=n_grad_evals+1; +end +if size(g,2)==1, g=g'; end, ng=norm(g); +if size(g,2)~=n, if dispwarn,disp(errmes);disp(error40);end + exitflag=-4; if trx, x=x';end, return +elseif isnan(ng), if dispwarn,disp(errmes);disp(error41);disp(error6);end + exitflag=-4; if trx, x=x';end, return +elseif ng==Inf, if dispwarn,disp(errmes);disp(error42);disp(error6);end + exitflag=-4; if trx, x=x';end, return +elseif ng2*kd, kd=kd+1; warnno=1; + if any(abs(x-xx)epsnorm*norm(gt)) + z=z/nrmz; + g1=gt+w*(z*gt')*z; B=B+w*(B*z')*z; + else + z=zeros(1,n); + nrmz=0; + g1=gt; + end + d1=norm(g1); g0=(g1/d1)*B'; + % ----} + % RESETTING ----{ + if kcheck>1 + idx=find(abs(g)>ZeroGrad); numelem=size(idx,2); + if numelem>0, grbnd=epsnorm*numelem^2; + if all(abs(g1(idx))<=abs(g(idx))*grbnd) | nrmz==0 + if dispwarn, disp(wrnmes); disp(warn20); end + if abs(fst-f)1.2*PenCoef, + PenCoef=PenCoefNew; Reset=1; kless=0; f=f+PenCoef*fc; break + end + end + end + end + f=f+PenCoef*fc; + end + if abs(f)==Inf || isnan(f) + if dispwarn, disp(wrnmes); + if isnan(f) + disp(error31); + else + disp(error32); + end + end + if ksm || kc>=mxtc + exitflag=-3; + if trx + x=x'; + end + return + else + k2=k2+1; + k1=0; + hp=hp/dq; + x=x1; + f=f1; + knan=1; + if constr + FP=FP1; + fp=fp1; + end + end + % STEP SIZE IS ZERO TO THE EXTENT OF EPSNORM + elseif all(abs(x-x1)=5, + exitflag=-14; + if dispwarn, disp(termwarn1); + disp(endwarn(4,:)); end + if trx,x=x';end, return + else + x=x1; + f=f1; + hp=hp*10; + ksm=1; + if constr + FP=FP1; + fp=fp1; + end + end + % USE SMALLER STEP + elseif h1*f=mxtc, break, end + % 1-D OPTIMIZER IS LEFT BEHIND + else if h1*f<=h1*f1, break, end + % USE LARGER STEP + k1=k1+1; if k2>0, kc=kc+1; end, k2=0; + if k1>=20, hp=du20*hp; + elseif k1>=10, hp=du10*hp; + elseif k1>=3, hp=du03*hp; + end + end + end + % ----} End of 1-D search + % ADJUST THE TRIAL STEP SIZE ----{ + dx=norm(xopt-x); + if kg=2, nsteps(2:kg)=nsteps(1:kg-1); end + nsteps(1)=dx/(abs(h)*norm(g0)); + kk=sum(nsteps(1:kg).*[kg:-1:1])/sum([kg:-1:1]); + if kk>des + if kg==1 + h=h*(kk-des+1); + else + h=h*sqrt(kk-des+1); + end + elseif kk=20, PenCoef=PenCoef/10; Reset=1; kless=0; end + else + kless=0; + end + if appconstr, + deltax=sign(x); idx=find(deltax==0); + deltax(idx)=ones(size(idx)); deltax=ddx*deltax; + if trx + gc=apprgrdn(x',fc,func,deltax',0); + else + gc=apprgrdn(x ,fc,func,deltax ,0); + end + n_constraint_evals=n_constraint_evals+n; + else + if trx + gc=feval(gradc,x'); + else + gc=feval(gradc,x ); + end + n_constraint_gradient_evals=n_constraint_gradient_evals+1; + end + if size(gc,2)==1, gc=gc'; end, ngc=norm(gc); + if isnan(ngc), + if dispwarn,disp(errmes);disp(error61);end + exitflag=-6; if trx, x=x';end, return + elseif ngc==Inf, + if dispwarn,disp(errmes);disp(error62);end + exitflag=-6; if trx, x=x';end, return + elseif ngch1*frec, frec=f; xrec=x; grec=g; end + % ----} + if ng>ZeroGrad, + if knorms<10, knorms=knorms+1; end + if knorms>=2, gnorms(2:knorms)=gnorms(1:knorms-1); end + gnorms(1)=ng; + nng=(prod(gnorms(1:knorms)))^(1/knorms); + end + + % DISPLAY THE CURRENT VALUES ----{ + if k==ld + disp('Iter.# ..... Function ... Step Value ... Gradient Norm '); + disp(sprintf('%5i %13.5e %13.5e %13.5e',k,f,dx,ng)); + ld=k+dispdata; + end + %----} + % CHECK THE STOPPING CRITERIA ----{ + termflag=1; + if constr, if ~FP, termflag=0; end, end + if kcheck<=5, termflag=0; end + if knan, termflag=0; end + if kc>=mxtc, termflag=0; end + % ARGUMENT + if termflag + idx=find(abs(x)>=lowxbound); + if isempty(idx) || all(abs(xopt(idx)-x(idx))<=optim.TolX*abs(x(idx))) + termx=termx+1; + % FUNCTION + if abs(f-frec)> detfr * abs(f) && ... + abs(f-fopt)<=optim.TolFun*abs(f) && ... + krerun<=3 && ... + ~constr + if any(abs(xrec(idx)-x(idx))> detxr * abs(x(idx))) + if dispwarn + disp(wrnmes); + disp(warn09); + end + x=xrec; + f=frec; + g=grec; + ng=norm(g); + krerun=krerun+1; + h=h1*max([dx,detxr*norm(x)])/krerun; + warnno=2; + break + else + h=h*10; + end + elseif abs(f-frec)> optim.TolFun*abs(f) && ... + norm(x-xrec)=limxterm ) + if stopf + if dx<=laststep + if warnno==1 && ng=limxterm + exitflag=-14; + if dispwarn, disp(termwarn1); disp(endwarn(4,:)); + if app, disp(appwarn); end + end + x=xrec; f=frec; + if trx,x=x';end, return + else + stopf=0; + end + end + end + % ITERATIONS LIMIT + if(k==optim.MaxIter) + exitflag=-9; + if trx + x=x'; + end, + if dispwarn, disp(wrnmes); disp(warn4); end + return + end + % ----} + % ZERO GRADIENT ----{ + if constr + if ng<=ZeroGrad, + if dispwarn, disp(termwarn1); disp(warn1); end + exitflag=-8; + if trx + x=x'; + end + return + end + else + if ng<=ZeroGrad, nzero=nzero+1; + if dispwarn, disp(wrnmes); disp(warn1); end + if nzero>=3 + exitflag=-8; + if trx + x=x'; + end + return + end + g0=-h*g0/2; + for i=1:10, + x=x+g0; + if trx + f=feval(fun,x',varargin{:}); + else + f=feval(fun,x,varargin{:}); + end + n_f_evals=n_f_evals+1; + if abs(f)==Inf + if dispwarn + disp(errmes); + disp(error32); + end + exitflag=-3; + if trx + x=x'; + end + return + elseif isnan(f), + if dispwarn + disp(errmes); + disp(error32); + end + exitflag=-3; + if trx + x=x'; + end + return + end + if app, + deltax=sign(g0); + idx=find(deltax==0); + deltax(idx)=ones(size(idx)); + deltax=h1*ddx*deltax; + if trx + g=apprgrdn(x',f,fun,deltax',1,varargin{:}); + else + g=apprgrdn(x,f,fun,deltax,1,varargin{:}); + end + n_f_evals=n_f_evals+n; + else + if trx + g=feval(grad,x',varargin{:}); + else + g=feval(grad,x,varargin{:}); + end + n_grad_evals=n_grad_evals+1; + end + if size(g,2)==1 + g=g'; + end + ng=norm(g); + if ng==Inf + if dispwarn + disp(errmes); + disp(error42); + end + exitflag=-4; + if trx + x=x'; + end + return + elseif isnan(ng) + if dispwarn + disp(errmes); + disp(error41); + end + exitflag=-4; + if trx + x=x'; + end + return + end + if ng>ZeroGrad + break + end + end + if ng<=ZeroGrad, + if dispwarn + disp(termwarn1); + disp(warn1); + end + exitflag=-8; + if trx + x=x'; + end + return + end + h=h1*dx; + break + end + end + % ----} + % FUNCTION IS FLAT AT THE POINT ----{ + if ~constr && abs(f-fopt)5 && ng<1 + idx=find(abs(g)<=epsnorm2); + ni=size(idx,2); + if ni>=1 && ni<=n/2 && kflat<=3, kflat=kflat+1; + if dispwarn, disp(wrnmes); disp(warn31); end, warnno=1; + x1=x; fm=f; + for j=idx, y=x(j); f2=fm; + if y==0, x1(j)=1; elseif abs(y)<1, x1(j)=sign(y); else, x1(j)=y; end + for i=1:20, x1(j)=x1(j)/1.15; + if trx + f1=feval(fun,x1',varargin{:}); + else + f1=feval(fun,x1,varargin{:}); + end + n_f_evals=n_f_evals+1; + if abs(f1)~=Inf && ~isnan(f1), + if h1*f1>h1*fm + y=x1(j); + fm=f1; + elseif h1*f2>h1*f1 + break + elseif f2==f1 + x1(j)=x1(j)/1.5; + end + f2=f1; + end + end + x1(j)=y; + end + if h1*fm>h1*f + if app, + deltax=h1*ddx*ones(size(deltax)); + if trx + gt=apprgrdn(x1',fm,fun,deltax',1,varargin{:}); + else + gt=apprgrdn(x1 ,fm,fun,deltax ,1,varargin{:}); + end + n_f_evals=n_f_evals+n; + else + if trx + gt=feval(grad,x1',varargin{:}); + else + gt=feval(grad,x1,varargin{:}); + end + n_grad_evals=n_grad_evals+1; + end + if size(gt,2)==1 + gt=gt'; + end + ngt=norm(gt); + if ~isnan(ngt) && ngt>epsnorm2, + if dispwarn + disp(warn32); + end + optim.TolFun=optim.TolFun/5; + x=x1; + g=gt; + ng=ngt; + f=fm; + h=h1*dx/3; + break + end + end + end + end + % ----} + end % iterations +end % restart +% end of the function +% +end \ No newline at end of file From a81c9da9a24e6576eeab684c6aa855a095c49d5a Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 6 Apr 2015 11:08:20 +0200 Subject: [PATCH 093/210] Add simulated_annealing.m to optimizers Restores compatibility of mode_compute=102 --- matlab/global_initialization.m | 14 + .../optimization/dynare_minimize_objective.m | 79 +-- matlab/optimization/simulated_annealing.m | 459 ++++++++++++++++++ 3 files changed, 522 insertions(+), 30 deletions(-) create mode 100644 matlab/optimization/simulated_annealing.m diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index bd6f7140b..0273fab97 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -536,6 +536,20 @@ solveopt.SpaceDilation=2.5; solveopt.LBGradientStep=1.e-11; options_.solveopt=solveopt; +%simulated annealing +options_.saopt.neps=10; +options_.saopt.maximizer_indicator=0; +options_.saopt.rt=0.10; +options_.saopt.MaxIter=100000; +options_.saopt.MaxIter=100000; +options_.saopt.verbosity=1; +options_.saopt.TolFun=1.0e-8; +options_.saopt.initial_temperature=15; +options_.saopt.ns=10; +options_.saopt.nt=10; +options_.saopt.step_length_c=0.1; +options_.saopt.initial_step_length=1; + % prior analysis options_.prior_mc = 20000; options_.prior_analysis_endo_var_list = []; diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 773b6a9d0..77b1449dc 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -303,38 +303,57 @@ switch minimizer_algorithm [opt_par_values,fval]=solvopt(start_par_value,objective_function,[],[],[],solveoptoptions,varargin{:}); case 102 %simulating annealing - LB = start_par_value - 1; - UB = start_par_value + 1; - neps=10; - % Set input parameters. - maxy=0; - epsilon=1.0e-9; - rt_=.10; - t=15.0; - ns=10; - nt=10; - maxevl=100000000; - idisp =1; + sa_options = options_.saopt; + if ~isempty(options_.optim_opt) + options_list = read_key_value_string(options_.optim_opt); + for i=1:rows(options_list) + switch options_list{i,1} + case 'neps' + sa_options.neps = options_list{i,2}; + case 'rt' + sa_options.rt = options_list{i,2}; + case 'MaxIter' + sa_options.MaxIter = options_list{i,2}; + case 'TolFun' + sa_options.TolFun = options_list{i,2}; + case 'verbosity' + sa_options.verbosity = options_list{i,2}; + case 'initial_temperature' + sa_options.initial_temperature = options_list{i,2}; + case 'ns' + sa_options.ns = options_list{i,2}; + case 'nt' + sa_options.nt = options_list{i,2}; + case 'step_length_c' + sa_options.step_length_c = options_list{i,2}; + case 'initial_step_length' + sa_options.initial_step_length = options_list{i,2}; + otherwise + warning(['solveopt: Unknown option (' options_list{i,1} ')!']) + end + end + end + npar=length(start_par_value); + LB=bounds(:,1); + LB(isinf(LB))=-1e6; + UB=bounds(:,2); + UB(isinf(UB))=1e6; - disp(['size of param',num2str(length(start_par_value))]) - c=.1*ones(npar,1); - %* Set input values of the input/output parameters.* - - vm=1*ones(npar,1); - disp(['number of parameters= ' num2str(npar) 'max= ' num2str(maxy) 't= ' num2str(t)]); - disp(['rt_= ' num2str(rt_) 'eps= ' num2str(epsilon) 'ns= ' num2str(ns)]); - disp(['nt= ' num2str(nt) 'neps= ' num2str(neps) 'maxevl= ' num2str(maxevl)]); - disp ' '; - disp ' '; - disp(['starting values(x) ' num2str(start_par_value')]); - disp(['initial step length(vm) ' num2str(vm')]); - disp(['lower bound(lb)', 'initial conditions', 'upper bound(ub)' ]); - disp([LB start_par_value UB]); - disp(['c vector ' num2str(c')]); - - [opt_par_values, fval, nacc, nfcnev, nobds, ier, t, vm] = sa(objective_function,xparstart_par_valueam1,maxy,rt_,epsilon,ns,nt ... - ,neps,maxevl,LB,UB,c,idisp ,t,vm,varargin{:}); + fprintf('\nNumber of parameters= %d, initial temperatur= %4.3f \n', npar,sa_options.initial_temperature); + fprintf('rt= %4.3f; TolFun= %4.3f; ns= %4.3f;\n',sa_options.rt,sa_options.TolFun,sa_options.ns); + fprintf('nt= %4.3f; neps= %4.3f; MaxIter= %d\n',sa_options.nt,sa_options.neps,sa_options.MaxIter); + fprintf('Initial step length(vm): %4.3f; step_length_c: %4.3f\n', sa_options.initial_step_length,sa_options.step_length_c); + fprintf('%-20s %-6s %-6s %-6s\n','Name:', 'LB;','Start;','UB;'); + for pariter=1:npar + fprintf('%-20s %6.4f; %6.4f; %6.4f;\n',parameter_names{pariter}, LB(pariter),start_par_value(pariter),UB(pariter)); + end + + sa_options.initial_step_length= sa_options.initial_step_length*ones(npar,1); %bring step length to correct vector size + sa_options.step_length_c= sa_options.step_length_c*ones(npar,1); %bring step_length_c to correct vector size + + [opt_par_values, fval,exitflag, n_accepted_draws, n_total_draws, n_out_of_bounds_draws, t, vm] =... + simulated_annealing(objective_function,start_par_value,sa_options,LB,UB,varargin{:}); otherwise if ischar(minimizer_algorithm) if exist(options_.mode_compute) diff --git a/matlab/optimization/simulated_annealing.m b/matlab/optimization/simulated_annealing.m new file mode 100644 index 000000000..5b505b71d --- /dev/null +++ b/matlab/optimization/simulated_annealing.m @@ -0,0 +1,459 @@ +function [xopt, fopt,exitflag, n_accepted_draws, n_total_draws, n_out_of_bounds_draws, t, vm] = ... + simulated_annealing(fcn,x,optim,lb,ub,varargin) +% function [xopt, fopt,exitflag, n_accepted_draws, n_total_draws, n_out_of_bounds_draws, t, vm] = ... +% simulated_annealing(fcn,x,optim,lb,ub,varargin) +% +% Implements the continuous simulated annealing global optimization +% algorithm described in Corana et al. (1987) +% +% A very quick (perhaps too quick) overview of SA: +% SA tries to find the global optimum of an N dimensional function. +% It moves both up and downhill and as the optimization process +% proceeds, it focuses on the most promising area. +% To start, it randomly chooses a trial point within the step length +% VM (a vector of length N) of the user selected starting point. The +% function is evaluated at this trial point and its value is compared +% to its value at the initial point. +% In a maximization problem, all uphill moves are accepted and the +% algorithm continues from that trial point. Downhill moves may be +% accepted the decision is made by the Metropolis criteria. It uses T +% (temperature) and the size of the downhill move in a probabilistic +% manner. The smaller T and the size of the downhill move are, the more +% likely that move will be accepted. If the trial is accepted, the +% algorithm moves on from that point. If it is rejected, another point +% is chosen instead for a trial evaluation. +% Each element of VM periodically adjusted so that half of all +% function evaluations in that direction are accepted. +% A fall in T is imposed upon the system with the RT option by +% T(i+1) = RT*T(i) where i is the ith iteration. Thus, as T declines, +% downhill moves are less likely to be accepted and the percentage of +% rejections rise. Given the scheme for the selection for VM, VM falls. +% Thus, as T declines, VM falls and SA focuses upon the most promising +% area for optimization. +% +% The importance of the parameter T (initial_temperature): +% The parameter T is crucial in using SA successfully. It influences +% VM, the step length over which the algorithm searches for optima. For +% a small intial T, the step length may be too small thus not enough +% of the function might be evaluated to find the global optima. The user +% should carefully examine VM in the intermediate output (set verbosity = +% 1) to make sure that VM is appropriate. The relationship between the +% initial temperature and the resulting step length is function +% dependent. +% To determine the starting temperature that is consistent with +% optimizing a function, it is worthwhile to run a trial run first. Set +% RT = 1.5 and T = 1.0. With RT > 1.0, the temperature increases and VM +% rises as well. Then select the T that produces a large enough VM. +% +% Input Parameters: +% Note: The suggested values generally come from Corana et al. To +% drastically reduce runtime, see Goffe et al., pp. 90-1 for +% suggestions on choosing the appropriate RT and NT. +% +% fcn - function to be optimized. +% x - The starting values for the variables of the function to be +% optimized. (N) +% optim: Options structure with fields +% +% optim.maximizer_indicator - Denotes whether the function should be maximized or +% minimized. A value =1 denotes maximization while a +% value =0 denotes minimization. Intermediate output (see verbosity) +% takes this into account. +% optim.RT - The temperature reduction factor +% optim.TolFun - Error tolerance for termination. If the final function +% values from the last neps temperatures differ from the +% corresponding value at the current temperature by less than +% optim.TolFun and the final function value at the current temperature +% differs from the current optimal function value by less than +% optim.TolFun, execution terminates and exitflag = 0 is returned. +% optim.ns - Number of cycles. After NS*N function evaluations, each +% element of VM is adjusted so that approximately half of +% all function evaluations are accepted. The suggested value +% is 20. +% optim.nt - Number of iterations before temperature reduction. After +% NT*NS*N function evaluations, temperature (T) is changed +% by the factor optim.RT. Value suggested by Corana et al. is +% max(100, 5*n). See Goffe et al. for further advice. +% optim.neps - Number of final function values used to decide upon termi- +% nation. See optim.TolFun. Suggested value is 4. +% optim.MaxIter - Maximum number of function evaluations. If it is +% exceeded, exitflag = 1. +% optim.step_length_c - Vector that controls the step length adjustment. The suggested +% value for all elements is 2.0. +% optim.verbosity - controls printing inside SA. +% Values: 0 - Nothing printed. +% 1 - Function value for the starting value and summary results before each temperature +% reduction. This includes the optimal function value found so far, the total +% number of moves (broken up into uphill, downhill, accepted and rejected), the +% number of out of bounds trials, the number of new optima found at this +% temperature, the current optimal X and the step length VM. Note that there are +% N*NS*NT function evalutations before each temperature reduction. Finally, notice is +% is also given upon achieveing the termination criteria. +% 2 - Each new step length (VM), the current optimal X (XOPT) and the current trial X (X). This +% gives the user some idea about how far X strays from XOPT as well as how VM is adapting +% to the function. +% 3 - Each function evaluation, its acceptance or rejection and new optima. For many problems, +% this option will likely require a small tree if hard copy is used. This option is best +% used to learn about the algorithm. A small value for optim.MaxIter is thus recommended when +% using optim.verbosity = 3. +% optim.initial_temperature initial temperature. See Goffe et al. for advice. +% optim.initial_step_length (VM) step length vector. On input it should encompass the +% region of interest given the starting value X. For point +% X(I), the next trial point is selected is from X(I) - VM(I) +% to X(I) + VM(I). Since VM is adjusted so that about half +% of all points are accepted, the input value is not very +% important (i.e. is the value is off, SA adjusts VM to the +% correct value) +% +% lb - The lower bound for the allowable solution variables. +% ub - The upper bound for the allowable solution variables. +% If the algorithm chooses X(I) < LB(I) or X(I) > UB(I), +% I = 1, N, a point is from inside is randomly selected. +% This focuses the algorithm on the region inside UB and LB. +% Unless the user wishes to concentrate the search to a par- +% ticular region, UB and LB should be set to very large positive +% and negative values, respectively. Note that the starting +% vector X should be inside this region. Also note that LB and +% UB are fixed in position, while VM is centered on the last +% accepted trial set of variables that optimizes the function. +% +% +% Input/Output Parameters: +% +% Output Parameters: +% xopt - The variables that optimize the function. (N) +% fopt - The optimal value of the function. +% exitflag - The error return number. +% Values: 0 - Normal return termination criteria achieved. +% 1 - Number of function evaluations (NFCNEV) is +% greater than the maximum number (optim.MaxIter). +% 2 - The starting value (X) is not inside the +% bounds (LB and UB). +% 3 - The initial temperature is not positive. +% 99 - Should not be seen only used internally. +% n_accepted_draws - The number of accepted function evaluations. +% n_total_draws - The total number of function evaluations. In a minor +% point, note that the first evaluation is not used in the +% core of the algorithm it simply initializes the +% algorithm. +% n_out_of_bounds_draws - The total number of trial function evaluations that +% would have been out of bounds of LB and UB. Note that +% a trial point is randomly selected between LB and UB. +% t: On output, the final temperature. +% vm: Final step length vector +% +% Algorithm: +% This routine implements the continuous simulated annealing global +% optimization algorithm described in Corana et al.'s article +% "Minimizing Multimodal Functions of Continuous Variables with the +% "Simulated Annealing" Algorithm" in the September 1987 (vol. 13, +% no. 3, pp. 262-280) issue of the ACM Transactions on Mathematical +% Software. +% +% For modifications to the algorithm and many details on its use, +% (particularly for econometric applications) see Goffe, Ferrier +% and Rogers, "Global Optimization of Statistical Functions with +% Simulated Annealing," Journal of Econometrics, vol. 60, no. 1/2, +% Jan./Feb. 1994, pp. 65-100. +% +% Based on the Matlab code written by Thomas Werner (Bundesbank December +% 2002), which in turn is based on the GAUSS version of Bill Goffe's simulated annealing +% program for global optimization, written by E.G.Tsionas (9/4/95). +% +% Copyright (C) 1995 E.G.Tsionas +% Copyright (C) 1995-2002 Thomas Werner +% Copyright (C) 2002-2015 Giovanni Lombardo +% 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 . + +c=optim.step_length_c; +t=optim.initial_temperature; +vm=optim.initial_step_length; +n=size(x,1); +xp=zeros(n,1); +%* Set initial values.* +n_accepted_draws=0; +n_out_of_bounds_draws=0; +n_total_draws=0; +exitflag=99; +xopt=x; +nacp=zeros(n,1); +fstar=1e20*ones(optim.neps,1); +%* If the initial temperature is not positive, notify the user and abort. * +if(t<=0.0); + fprintf('\nThe initial temperature is not positive. Reset the variable t\n'); + exitflag=3; + return; +end; +%* If the initial value is out of bounds, notify the user and abort. * +if(sum(x>ub)+sum(x0); + fprintf('\nInitial condition out of bounds\n'); + exitflag=2; + return; +end; +%* Evaluate the function with input x and return value as f. * +f=feval(fcn,x,varargin{:}); +%* +% If the function is to be minimized, switch the sign of the function. +% Note that all intermediate and final output switches the sign back +% to eliminate any possible confusion for the user. +%* +if(optim.maximizer_indicator==0); + f=-f; +end; +n_total_draws=n_total_draws+1; +fopt=f; +fstar(1)=f; +if(optim.verbosity >1); + disp ' '; + disp(['initial x ' num2str(x(:)')]); + if(optim.maximizer_indicator); + disp(['initial f ' num2str(f)]); + else + disp(['initial f ' num2str(-f)]); + end; +end; +% Start the main loop. Note that it terminates if (i) the algorithm +% succesfully optimizes the function or (ii) there are too many +% function evaluations (more than optim.MaxIter). + +while (1>0); + nup=0; + nrej=0; + nnew=0; + ndown=0; + lnobds=0; + m=1; + while m<=optim.nt; + j=1; + while j<=optim.ns; + h=1; + while h<=n; + %* Generate xp, the trial value of x. Note use of vm to choose xp. * + i=1; + while i<=n; + if(i==h); + xp(i)=x(i)+(rand(1,1)*2.0-1.0)*vm(i); + else + xp(i)=x(i); + end; + %* If xp is out of bounds, select a point in bounds for the trial. * + if((xp(i)ub(i))); + xp(i)=lb(i)+(ub(i)-lb(i))*rand(1,1); + lnobds=lnobds+1; + n_out_of_bounds_draws=n_out_of_bounds_draws+1; + if(optim.verbosity >=3); + if exist('fp','var') + print_current_invalid_try(optim.maximizer_indicator,xp,x,fp,f); + end + end; + end; + i=i+1; + end; + %* Evaluate the function with the trial point xp and return as fp. * + % fp=feval(fcn,xp,listarg); + fp=feval(fcn,xp,varargin{:}); + if(optim.maximizer_indicator==0); + fp=-fp; + end; + n_total_draws=n_total_draws+1; + if(optim.verbosity >=3); + print_current_valid_try(optim.maximizer_indicator,xp,x,fp,f); + end; + %* If too many function evaluations occur, terminate the algorithm. * + if(n_total_draws>=optim.MaxIter); + fprintf('Too many function evaluations; consider\n'); + fprintf('increasing optim.MaxIter or optim.TolFun or decreasing\n'); + fprintf('optim.nt or optim.rt. These results are likely to be poor\n'); + if(optim.maximizer_indicator==0); + fopt=-fopt; + end; + exitflag=1; + return; + end; + %* Accept the new point if the function value increases. * + if(fp>=f); + if(optim.verbosity >=3); + fprintf('point accepted\n'); + end; + x=xp; + f=fp; + n_accepted_draws=n_accepted_draws+1; + nacp(h)=nacp(h)+1; + nup=nup+1; + %* If greater than any other point, record as new optimum. * + if(fp>fopt); + if(optim.verbosity >=3); + fprintf('new optimum\n'); + end; + xopt=xp; + fopt=fp; + nnew=nnew+1; + end; + %* + % If the point is lower, use the Metropolis criteria to decide on + % acceptance or rejection. + %* + else + p=exp((fp-f)/t); + pp=rand(1,1); + if(pp=3); + if(optim.maximizer_indicator); + fprintf('though lower, point accepted\n'); + else + fprintf('though higher, point accepted\n'); + end; + end; + x=xp; + f=fp; + n_accepted_draws=n_accepted_draws+1; + nacp(h)=nacp(h)+1; + ndown=ndown+1; + else + nrej=nrej+1; + if(optim.verbosity >=3); + if(optim.maximizer_indicator); + fprintf('lower point rejected\n'); + else + fprintf('higher point rejected\n'); + end; + end; + end; + end; + h=h+1; + end; + j=j+1; + end; + %* Adjust vm so that approximately half of all evaluations are accepted. * + i=1; + while i<=n; + ratio=nacp(i)/optim.ns; + if(ratio>.6); + vm(i)=vm(i)*(1.+c(i)*(ratio-.6)/.4); + elseif(ratio<.4); + vm(i)=vm(i)/(1.+c(i)*((.4-ratio)/.4)); + end; + if(vm(i)>(ub(i)-lb(i))); + vm(i)=ub(i)-lb(i); + end; + i=i+1; + end; + if(optim.verbosity >=2); + fprintf('intermediate results after step length adjustment\n'); + fprintf('new step length(vm) %4.3f', vm(:)'); + fprintf('current optimal x %4.3f', xopt(:)'); + fprintf('current x %4.3f', x(:)'); + end; + nacp=zeros(n,1); + m=m+1; + end; + if(optim.verbosity >=1); + print_intermediate_statistics(optim.maximizer_indicator,t,xopt,vm,fopt,nup,ndown,nrej,lnobds,nnew); + end; + %* Check termination criteria. * + quit=0; + fstar(1)=f; + if((fopt-fstar(1))<=optim.TolFun); + quit=1; + end; + if(sum(abs(f-fstar)>optim.TolFun)>0); + quit=0; + end; + %* Terminate SA if appropriate. * + if(quit); + exitflag=0; + if(optim.maximizer_indicator==0); + fopt=-fopt; + end; + if(optim.verbosity >=1); + fprintf('SA achieved termination criteria.exitflag=0\n'); + end; + return; + end; + %* If termination criteria are not met, prepare for another loop. * + t=optim.rt*t; + i=optim.neps; + while i>=2; + fstar(i)=fstar(i-1); + i=i-1; + end; + f=fopt; + x=xopt; + %* Loop again. * +end; + +end + +function print_current_invalid_try(max,xp,x,fp,f) +fprintf('\n'); + disp(['Current x ' num2str(x(:)')]); +if(max); + disp(['Current f ' num2str(f)]); +else + disp(['Current f ' num2str(-f)]); +end; +disp(['Trial x ' num2str(xp(:)')]); +disp 'Point rejected since out of bounds'; +end + +function print_current_valid_try(max,xp,x,fp,f) + +disp(['Current x ' num2str(x(:)')]); +if(max); + disp(['Current f ' num2str(f)]); + disp(['Trial x ' num2str(xp(:)')]); + disp(['Resulting f ' num2str(fp)]); +else + disp(['Current f ' num2str(-f)]); + disp(['Trial x ' num2str(xp(:)')]); + disp(['Resulting f ' num2str(-fp)]); +end; +end + + +function print_intermediate_statistics(max,t,xopt,vm,fopt,nup,ndown,nrej,lnobds,nnew) + +totmov=nup+ndown+nrej; +fprintf('\nIntermediate results before next temperature reduction\n'); +disp(['current temperature ' num2str(t)]); + +if(max) + disp(['Max function value so far ' num2str(fopt)]); + disp(['Total moves ' num2str(totmov)]); + disp(['Uphill ' num2str(nup)]); + disp(['Accepted downhill ' num2str(ndown)]); + disp(['Rejected downhill ' num2str(nrej)]); + disp(['Out of bounds trials ' num2str(lnobds)]); + disp(['New maxima this temperature ' num2str(nnew)]); +else + disp(['Min function value so far ' num2str(-fopt)]); + disp(['Total moves ' num2str(totmov)]); + disp(['Downhill ' num2str(nup)]); + disp(['Accepted uphill ' num2str(ndown)]); + disp(['Rejected uphill ' num2str(nrej)]); + disp(['Trials out of bounds ' num2str(lnobds)]); + disp(['New minima this temperature ' num2str(nnew)]); +end +xopt1=xopt(1:round(length(xopt)/2)); +xopt2=xopt(round(length(xopt)/2)+1:end); + +disp(['Current optimal x1 ' num2str(xopt1')]); +disp(['Current optimal x2 ' num2str(xopt2')]); +disp(['Strength(vm) ' num2str(vm')]); +fprintf('\n'); +end \ No newline at end of file From 39ed3eb3f0b44f3d9df0337900ccb16866178389 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 6 Apr 2015 11:24:42 +0200 Subject: [PATCH 094/210] Fix bugs related to allowing mode_compute to be a string Crashes otherwise --- matlab/dynare_estimation.m | 2 +- matlab/dynare_estimation_1.m | 10 +++++----- matlab/optimization/dynare_minimize_objective.m | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m index 348bdf8c4..e0f8907c1 100644 --- a/matlab/dynare_estimation.m +++ b/matlab/dynare_estimation.m @@ -91,7 +91,7 @@ else dynare_estimation_1(var_list,dname); end -if options_.mode_compute && options_.analytic_derivation, +if isnumeric(options_.mode_compute) && options_.mode_compute && options_.analytic_derivation, options_.analytic_derivation=analytic_derivation0; end diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 5fdd91895..eba52ea28 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -261,14 +261,14 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation [xparam1, fval, exitflag, hh, options_, Scale] = dynare_minimize_objective(objective_function,xparam1,options_.mode_compute,options_,[bounds.lb bounds.ub],bayestopt_.name,bayestopt_,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_); fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval); - if options_.mode_compute==5 && options_.analytic_derivation==-1 %reset options changed by newrat + if isnumeric(options_.mode_compute) && options_.mode_compute==5 && options_.analytic_derivation==-1 %reset options changed by newrat options_.analytic_derivation = options_analytic_derivation_old; %reset - elseif options_.mode_compute==6 %save scaling factor + elseif isnumeric(options_.mode_compute) && options_.mode_compute==6 %save scaling factor save([M_.fname '_optimal_mh_scale_parameter.mat'],'Scale'); options_.mh_jscale = Scale; bayestopt_.jscale = ones(length(xparam1),1)*Scale; end - if ~isequal(options_.mode_compute,6) %always already computes covariance matrix + if ~isnumeric(options_.mode_compute) || ~isequal(options_.mode_compute,6) %always already computes covariance matrix if options_.cova_compute == 1 %user did not request covariance not to be computed if options_.analytic_derivation && strcmp(func2str(objective_function),'dsge_likelihood'), ana_deriv_old = options_.analytic_derivation; @@ -276,12 +276,12 @@ 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~=1), + elseif ~isnumeric(options_.mode_compute) || ~(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) + elseif isnumeric(options_.mode_compute) && isequal(options_.mode_compute,5) % other numerical hessian options available with optimizer 5 % % if newratflag == 0 diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 77b1449dc..27456dbac 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -46,14 +46,14 @@ function [opt_par_values,fval,exitflag,hessian_mat,options_,Scale]=dynare_minimi %% set bounds and parameter names if not already set n_params=size(start_par_value,1); if isempty(bounds) - if minimizer_algorithm==10 + if isnumeric(minimizer_algorithm) && minimizer_algorithm==10 error('Algorithm 10 (simpsa) requires upper and lower bounds') else bounds=[-Inf(n_params,1) Inf(n_params,1)]; end end -if minimizer_algorithm==10 && any(any(isinf(bounds))) +if isnumeric(minimizer_algorithm) && minimizer_algorithm==10 && any(any(isinf(bounds))) error('Algorithm 10 (simpsa) requires finite upper and lower bounds') end From d1a80acb44243ebeb1d020abda3b6297bacd2ab9 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 6 Apr 2015 11:28:32 +0200 Subject: [PATCH 095/210] Replace non-available simulated annealing by Matlab's routine Closes #814 --- matlab/optimization/dynare_minimize_objective.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 27456dbac..7d3812a22 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -87,7 +87,18 @@ switch minimizer_algorithm [opt_par_values,fval,exitflag,output,lamdba,grad,hessian_mat] = ... fmincon(objective_function,start_par_value,[],[],[],[],bounds(:,1),bounds(:,2),[],optim_options,varargin{:}); case 2 - error('Optimization algorithm 1 option (Lester Ingber''s Adaptive Simulated Annealing) is no longer available') + if isoctave + error('Optimization algorithm 2 is not available under Octave') + elseif ~user_has_matlab_license('GADS_Toolbox') + error('Optimization algorithm 2 requires the Optimization Toolbox') + end + % Set default optimization options for fmincon. + optim_options = saoptimset('display','iter','TolFun',1e-8); + if ~isempty(options_.optim_opt) + eval(['optim_options = saoptimset(optim_options,' options_.optim_opt ');']); + end + func = @(x)objective_function(x,varargin{:}); + [opt_par_values,fval,exitflag,output] = simulannealbnd(func,start_par_value,bounds(:,1),bounds(:,2),optim_options); case 3 if isoctave && ~user_has_octave_forge_package('optim') error('Optimization algorithm 3 requires the optim package') From 49d4643481b8328c06aeff939773d3b314fa34a8 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 6 Apr 2015 12:04:11 +0200 Subject: [PATCH 096/210] Fix copy and paste typo in gmhmaxlik.m --- matlab/optimization/gmhmaxlik.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/optimization/gmhmaxlik.m b/matlab/optimization/gmhmaxlik.m index 4501f845c..6ac4f79c9 100644 --- a/matlab/optimization/gmhmaxlik.m +++ b/matlab/optimization/gmhmaxlik.m @@ -20,7 +20,7 @@ function [PostMode, HessianMatrix, Scale, ModeValue] = gmhmaxlik(fun, xinit, Hin % Set default options if ~isempty(Hinit); - gmhmaxlikOptionsptions.varinit = 'previous'; + gmhmaxlikOptions.varinit = 'previous'; else gmhmaxlikOptions.varinit = 'prior'; end From aea49e2fa0d1a5f7191d134345c5eac0928c9626 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 6 Apr 2015 12:13:14 +0200 Subject: [PATCH 097/210] Add unit test for mode_computations --- tests/Makefile.am | 4 +- tests/optimizers/fs2000.mod | 154 ++++++++++++++++++ tests/optimizers/optimizer_function_wrapper.m | 16 ++ 3 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tests/optimizers/fs2000.mod create mode 100644 tests/optimizers/optimizer_function_wrapper.m diff --git a/tests/Makefile.am b/tests/Makefile.am index 14e46b716..3ec5ba46f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -205,6 +205,7 @@ MODFILES = \ smoother2histval/fs2000_simul.mod \ smoother2histval/fs2000_smooth.mod \ smoother2histval/fs2000_smooth_stoch_simul.mod \ + optimizers/fs2000.mod \ reporting/example1.mod XFAIL_MODFILES = ramst_xfail.mod \ @@ -394,7 +395,8 @@ EXTRA_DIST = \ loglinear/results_exp.mat \ smoother2histval/fsdat_simul.m \ optimal_policy/Ramsey/find_c.m \ - optimal_policy/Ramsey/oo_ramsey_policy_initval.mat + optimal_policy/Ramsey/oo_ramsey_policy_initval.mat \ + optimizers/optimizer_function_wrapper.m TARGETS = diff --git a/tests/optimizers/fs2000.mod b/tests/optimizers/fs2000.mod new file mode 100644 index 000000000..184b2427f --- /dev/null +++ b/tests/optimizers/fs2000.mod @@ -0,0 +1,154 @@ +/* + * This file replicates the estimation of the cash in advance model described + * Frank Schorfheide (2000): "Loss function-based evaluation of DSGE models", + * Journal of Applied Econometrics, 15(6), 645-670. + * + * The data are in file "fs2000/fsdat_simul.m", and have been artificially generated. + * They are therefore different from the original dataset used by Schorfheide. + * + * The equations are taken from J. Nason and T. Cogley (1994): "Testing the + * implications of long-run neutrality for monetary business cycle models", + * Journal of Applied Econometrics, 9, S37-S70. + * Note that there is an initial minus sign missing in equation (A1), p. S63. + * + * This implementation was written by Michel Juillard. Please note that the + * following copyright notice only applies to this Dynare implementation of the + * model. + */ + +/* + * Copyright (C) 2004-2010 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 . + */ + +var m P c e W R k d n l gy_obs gp_obs y dA; +varexo e_a e_m; + +parameters alp bet gam mst rho psi del; + +alp = 0.33; +bet = 0.99; +gam = 0.003; +mst = 1.011; +rho = 0.7; +psi = 0.787; +del = 0.02; + +model; +dA = exp(gam+e_a); +log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; +-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; +W = l/n; +-(psi/(1-psi))*(c*P/(1-n))+l/n = 0; +R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; +1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; +c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); +P*c = m; +m-1+d = l; +e = exp(e_a); +y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); +gy_obs = dA*y/y(-1); +gp_obs = (P/P(-1))*m(-1)/dA; +end; + +initval; +k = 6; +m = mst; +P = 2.25; +c = 0.45; +e = 1; +W = 4; +R = 1.02; +d = 0.85; +n = 0.19; +l = 0.86; +y = 0.6; +gy_obs = exp(gam); +gp_obs = exp(-gam); +dA = exp(gam); +end; + +shocks; +var e_a; stderr 0.014; +var e_m; stderr 0.005; +end; + +steady_state_model; + dA = exp(gam); + gst = 1/dA; + m = mst; + khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1)); + xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1); + nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp ); + n = xist/(nust+xist); + P = xist + nust; + k = khst*n; + + l = psi*mst*n/( (1-psi)*(1-n) ); + c = mst/P; + d = l - mst + 1; + y = k^alp*n^(1-alp)*gst^alp; + R = mst/bet; + W = l/n; + ist = y-c; + q = 1 - d; + + e = 1; + + gp_obs = m/dA; + gy_obs = dA; +end; + +steady; + +check; + +estimated_params; +alp, beta_pdf, 0.356, 0.02; +bet, beta_pdf, 0.993, 0.002; +gam, normal_pdf, 0.0085, 0.003; +mst, normal_pdf, 1.0002, 0.007; +rho, beta_pdf, 0.129, 0.223; +psi, beta_pdf, 0.65, 0.05; +del, beta_pdf, 0.01, 0.005; +stderr e_a, inv_gamma_pdf, 0.035449, inf; +stderr e_m, inv_gamma_pdf, 0.008862, inf; +end; + +varobs gp_obs gy_obs; +options_.plot_priors=0; +estimation(mode_compute=3,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=4,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=5,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=7,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=8,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=9,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=10,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=101,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=102,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=optimizer_function_wrapper,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +estimation(mode_compute=6,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); + + +/* + * The following lines were used to generate the data file. If you want to + * generate another random data file, comment the "estimation" line and uncomment + * the following lines. + */ + +//stoch_simul(periods=200, order=1); +//datatomfile('fs2000/fsdat_simul', char('gy_obs', 'gp_obs')); diff --git a/tests/optimizers/optimizer_function_wrapper.m b/tests/optimizers/optimizer_function_wrapper.m new file mode 100644 index 000000000..a7992bab3 --- /dev/null +++ b/tests/optimizers/optimizer_function_wrapper.m @@ -0,0 +1,16 @@ +function [opt_par_values,fval,exitflag]=optimizer_function_wrapper(objective_function_handle,start_par_value,varargin) +% function [opt_par_values,fval,exitflag]=optimizer_function_wrapper(objective_function_handle,start_par_value,varargin) +% Demonstrates how to invoke external optimizer for mode_computation + +%set options of optimizer +H0 = 1e-4*eye(length(start_par_value),length(start_par_value)); +nit=1000; +crit = 1e-7; +numgrad = 2; +epsilon = 1e-6; +analytic_grad=[]; + +%call optimizer +[fval,opt_par_values,grad,hessian_mat,itct,fcount,exitflag] = ... + csminwel1(objective_function_handle, start_par_value, H0, analytic_grad, crit, nit, numgrad, epsilon, varargin{:}); +end \ No newline at end of file From 104e4767a473d7298c76741720668c85150cb1ce Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 7 Apr 2015 12:01:23 +0200 Subject: [PATCH 098/210] update license file, #874 --- license.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/license.txt b/license.txt index a354f2a03..52fce2880 100644 --- a/license.txt +++ b/license.txt @@ -39,16 +39,16 @@ License: public-domain Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3, pages 472-489 -Files: matlab/bfgsi1.m matlab/csolve.m matlab/csminit1.m matlab/numgrad2.m - matlab/numgrad3.m matlab/numgrad3_.m matlab/numgrad5.m - matlab/numgrad5_.m matlab/csminwel1.m matlab/bvar_density.m +Files: matlab/bfgsi1.m matlab/csolve.m matlab/optimization/csminit1.m matlab/optimization/numgrad2.m + matlab/optimization/numgrad3.m matlab/optimization/numgrad3_.m matlab/optimization/numgrad5.m + matlab/optimization/numgrad5_.m matlab/optimization/csminwel1.m matlab/bvar_density.m matlab/bvar_toolbox.m matlab/partial_information/PI_gensys.m matlab/qzswitch.m matlab/qzdiv.m Copyright: 1993-2009 Christopher Sims 2006-2013 Dynare Team License: GPL-3+ -Files: matlab/cmaes.m +Files: matlab/optimization/cmaes.m Copyright: 2001-2012 Nikolaus Hansen 2012 Dynare Team License: GPL-3+ @@ -63,7 +63,7 @@ Copyright: 2008-2012 VZLU Prague, a.s. 2014 Dynare Team License: GPL-3+ -Files: matlab/simpsa.m matlab/simpsaget.m matlab/simpsaset.m +Files: matlab/optimization/simpsa.m matlab/optimization/simpsaget.m matlab/optimization/simpsaset.m Copyright: 2005 Henning Schmidt, FCC, henning@fcc.chalmers.se 2006 Brecht Donckels, BIOMATH, brecht.donckels@ugent.be 2013 Dynare Team From fe48de44068224552813e264313d0dc94b2915d4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 8 Apr 2015 15:44:39 +0200 Subject: [PATCH 099/210] Re-set default of new option diffuse_kalman_tol to 1e-6: former hardcoded value was 1e-6 in the univariate smoother (i.e. the one most often used). Updated documentation. --- doc/dynare.texi | 2 +- matlab/global_initialization.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 094089cb4..f107bbf98 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -5222,7 +5222,7 @@ singularity is encountered, Dynare by default automatically switches to the univ @anchor{kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors during the Kalman filter (minimum allowed reciprocal of the matrix condition number). Default value is @code{1e-10} @item diffuse_kalman_tol = @var{DOUBLE} -@anchor{diffuse_kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors (@math{F_{\infty}}) and the rank of the covariance matrix of the state variables (@math{P_{\infty}}) during the Diffuse Kalman filter. Default value is @code{1e-8} +@anchor{diffuse_kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors (@math{F_{\infty}}) and the rank of the covariance matrix of the non-stationary state variables (@math{P_{\infty}}) during the Diffuse Kalman filter. Default value is @code{1e-6} @item filter_covariance @anchor{filter_covariance} Saves the series of one step ahead error of diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index f169bfe6a..93deba482 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -387,7 +387,7 @@ options_.nobs = NaN; options_.kalman_algo = 0; options_.fast_kalman = 0; options_.kalman_tol = 1e-10; -options_.diffuse_kalman_tol = 1e-8; +options_.diffuse_kalman_tol = 1e-6; options_.use_univariate_filters_if_singularity_is_detected = 1; options_.riccati_tol = 1e-6; options_.lik_algo = 1; From ca8f0ea006e4ec9ecb38165a5bc3d2297313ca8c Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 8 Apr 2015 15:49:12 +0200 Subject: [PATCH 100/210] Harmonize filters/likelihood with smoothers by using new option diffuse_kalman_tol --- matlab/dsge_likelihood.m | 7 ++++--- matlab/kalman/likelihood/kalman_filter_d.m | 9 ++++----- .../likelihood/missing_observations_kalman_filter_d.m | 9 ++++----- matlab/kalman/likelihood/univariate_kalman_filter_d.m | 9 ++++----- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m index aae1224e4..41b326c14 100644 --- a/matlab/dsge_likelihood.m +++ b/matlab/dsge_likelihood.m @@ -328,6 +328,7 @@ mm = length(T); pp = DynareDataset.vobs; rr = length(Q); kalman_tol = DynareOptions.kalman_tol; +diffuse_kalman_tol = DynareOptions.kalman_tol; riccati_tol = DynareOptions.riccati_tol; Y = transpose(DynareDataset.data)-trend; @@ -405,13 +406,13 @@ switch DynareOptions.lik_init if no_missing_data_flag [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, 1, size(Y,2), ... zeros(mm,1), Pinf, Pstar, ... - kalman_tol, riccati_tol, DynareOptions.presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... T,R,Q,H,Z,mm,pp,rr); else [dLIK,dlik,a,Pstar] = missing_observations_kalman_filter_d(DatasetInfo.missing.aindex,DatasetInfo.missing.number_of_observations,DatasetInfo.missing.no_more_missing_observations, ... Y, 1, size(Y,2), ... zeros(mm,1), Pinf, Pstar, ... - kalman_tol, riccati_tol, DynareOptions.presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... T,R,Q,H,Z,mm,pp,rr); end diffuse_periods = length(dlik); @@ -448,7 +449,7 @@ switch DynareOptions.lik_init DatasetInfo.missing.no_more_missing_observations, ... Y, 1, size(Y,2), ... zeros(mmm,1), Pinf, Pstar, ... - kalman_tol, riccati_tol, DynareOptions.presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, DynareOptions.presample, ... T,R,Q,H1,Z,mmm,pp,rr); diffuse_periods = size(dlik,1); end diff --git a/matlab/kalman/likelihood/kalman_filter_d.m b/matlab/kalman/likelihood/kalman_filter_d.m index bbec1fe7c..3b1161b75 100644 --- a/matlab/kalman/likelihood/kalman_filter_d.m +++ b/matlab/kalman/likelihood/kalman_filter_d.m @@ -1,4 +1,4 @@ -function [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, start, last, a, Pinf, Pstar, kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) +function [dLIK,dlik,a,Pstar] = kalman_filter_d(Y, start, last, a, Pinf, Pstar, kalman_tol, diffuse_kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) % Computes the diffuse likelihood of a state space model. % % INPUTS @@ -59,14 +59,13 @@ dlik = zeros(smpl,1); % Initialization of the vector gathering the densitie dLIK = Inf; % Default value of the log likelihood. oldK = Inf; s = 0; -crit1=1.e-6; -while rank(Pinf,crit1) && (t<=last) +while rank(Pinf,diffuse_kalman_tol) && (t<=last) s = t-start+1; v = Y(:,t)-Z*a; Finf = Z*Pinf*Z'; - if rcond(Finf) < kalman_tol - if ~all(abs(Finf(:)) < kalman_tol) + if rcond(Finf) < diffuse_kalman_tol + if ~all(abs(Finf(:)) < diffuse_kalman_tol) % The univariate diffuse kalman filter should be used instead. return else diff --git a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m index c09194820..008e1aa89 100644 --- a/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m +++ b/matlab/kalman/likelihood/missing_observations_kalman_filter_d.m @@ -1,7 +1,7 @@ function [dLIK,dlik,a,Pstar] = missing_observations_kalman_filter_d(data_index,number_of_observations,no_more_missing_observations, ... Y, start, last, ... a, Pinf, Pstar, ... - kalman_tol, riccati_tol, presample, ... + kalman_tol, diffuse_kalman_tol, riccati_tol, presample, ... T, R, Q, H, Z, mm, pp, rr) % Computes the diffuse likelihood of a state space model when some observations are missing. % @@ -66,14 +66,13 @@ t = start; % Initialization of the time index. dlik = zeros(smpl,1); % Initialization of the vector gathering the densities. dLIK = Inf; % Default value of the log likelihood. oldK = Inf; -crit1=1.e-6; if isequal(H,0) H = zeros(pp,pp); end s = 0; -while rank(Pinf,crit1) && (t<=last) +while rank(Pinf,diffuse_kalman_tol) && (t<=last) s = t-start+1; d_index = data_index{t}; if isempty(d_index) @@ -84,8 +83,8 @@ while rank(Pinf,crit1) && (t<=last) ZZ = Z(d_index,:); v = Y(d_index,t)-ZZ*a; Finf = ZZ*Pinf*ZZ'; - if rcond(Finf) < kalman_tol - if ~all(abs(Finf(:)) < kalman_tol) + if rcond(Finf) < diffuse_kalman_tol + if ~all(abs(Finf(:)) < diffuse_kalman_tol) % The univariate diffuse kalman filter should be used. return else diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_d.m b/matlab/kalman/likelihood/univariate_kalman_filter_d.m index e3368a6c1..0782f9507 100644 --- a/matlab/kalman/likelihood/univariate_kalman_filter_d.m +++ b/matlab/kalman/likelihood/univariate_kalman_filter_d.m @@ -1,4 +1,4 @@ -function [dLIK, dlikk, a, Pstar, llik] = univariate_kalman_filter_d(data_index, number_of_observations, no_more_missing_observations, Y, start, last, a, Pinf, Pstar, kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) +function [dLIK, dlikk, a, Pstar, llik] = univariate_kalman_filter_d(data_index, number_of_observations, no_more_missing_observations, Y, start, last, a, Pinf, Pstar, kalman_tol, diffuse_kalman_tol, riccati_tol, presample, T, R, Q, H, Z, mm, pp, rr) % Computes the likelihood of a state space model (initialization with diffuse steps, univariate approach). %@info: @@ -110,8 +110,7 @@ dLIK = Inf; % Default value of the log likelihood. oldK = Inf; llik = zeros(smpl,pp); -crit1 = 1.e-6; -newRank = rank(Pinf,crit1); +newRank = rank(Pinf,diffuse_kalman_tol); l2pi = log(2*pi); while newRank && (t<=last) @@ -139,7 +138,7 @@ while newRank && (t<=last) end end if newRank - oldRank = rank(Pinf,crit1); + oldRank = rank(Pinf,diffuse_kalman_tol); else oldRank = 0; end @@ -147,7 +146,7 @@ while newRank && (t<=last) Pstar = T*Pstar*T'+QQ; Pinf = T*Pinf*T'; if newRank - newRank = rank(Pinf,crit1); + newRank = rank(Pinf,diffuse_kalman_tol); end if oldRank ~= newRank disp('univariate_diffuse_kalman_filter:: T does influence the rank of Pinf!') From d8b132e39a701a2d8dcda305e0c02497bf6c7f75 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 12:36:07 +0200 Subject: [PATCH 101/210] preprocessor: remove commented code --- preprocessor/ComputingTasks.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 31545e5e3..a342d041b 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -1940,8 +1940,6 @@ void EstimationDataStatement::writeOutput(ostream &output, const string &basename) const { options_list.writeOutput(output, "options_.dataset"); - //if (options_list.date_options.find("first_obs") == options_list.date_options.end()) - // output << "options_.dataset.first_obs = options_.initial_period;" << endl; } SubsamplesStatement::SubsamplesStatement(const string &name1_arg, From 44bb0672d27241752137bf298a40c7c6d3261fca Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 11:33:02 +0200 Subject: [PATCH 102/210] preprocessor: method out of order --- preprocessor/ComputingTasks.cc | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index a342d041b..889694726 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2501,27 +2501,6 @@ CorrPriorStatement::writeOutput(ostream &output, const string &basename) const writePriorOutput(output, lhs_field, name1); } -PriorEqualStatement::PriorEqualStatement(const string &to_declaration_type_arg, - const string &to_name1_arg, - const string &to_name2_arg, - const string &to_subsample_name_arg, - const string &from_declaration_type_arg, - const string &from_name1_arg, - const string &from_name2_arg, - const string &from_subsample_name_arg, - const SymbolTable &symbol_table_arg) : - to_declaration_type(to_declaration_type_arg), - to_name1(to_name1_arg), - to_name2(to_name2_arg), - to_subsample_name(to_subsample_name_arg), - from_declaration_type(from_declaration_type_arg), - from_name1(from_name1_arg), - from_name2(from_name2_arg), - from_subsample_name(from_subsample_name_arg), - symbol_table(symbol_table_arg) -{ -} - void CorrPriorStatement::writeCOutput(ostream &output, const string &basename) { @@ -2554,6 +2533,27 @@ CorrPriorStatement::writeCOutput(ostream &output, const string &basename) output << endl <<" index, index1, shape, mean, mode, stdev, variance, domain));" << endl; } +PriorEqualStatement::PriorEqualStatement(const string &to_declaration_type_arg, + const string &to_name1_arg, + const string &to_name2_arg, + const string &to_subsample_name_arg, + const string &from_declaration_type_arg, + const string &from_name1_arg, + const string &from_name2_arg, + const string &from_subsample_name_arg, + const SymbolTable &symbol_table_arg) : + to_declaration_type(to_declaration_type_arg), + to_name1(to_name1_arg), + to_name2(to_name2_arg), + to_subsample_name(to_subsample_name_arg), + from_declaration_type(from_declaration_type_arg), + from_name1(from_name1_arg), + from_name2(from_name2_arg), + from_subsample_name(from_subsample_name_arg), + symbol_table(symbol_table_arg) +{ +} + void PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { From b49388891f4bf0cbbbc5a2b960b9fd7542b6a0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 14 Apr 2015 11:56:11 +0200 Subject: [PATCH 103/210] Moved README file for extended preprocessor in subfolder. --- .../README.extended-preprocessor.org | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.extended-preprocessor.org => README/README.extended-preprocessor.org (100%) diff --git a/README.extended-preprocessor.org b/README/README.extended-preprocessor.org similarity index 100% rename from README.extended-preprocessor.org rename to README/README.extended-preprocessor.org From e32cbf626f9f0b9e322b2ac44d93461afcb320a0 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 14 Apr 2015 12:05:32 +0200 Subject: [PATCH 104/210] Fixed bug when neighborhood_width is used : MC option must be forced. --- matlab/dynare_sensitivity.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/matlab/dynare_sensitivity.m b/matlab/dynare_sensitivity.m index 9d4a5085d..0a4aa0035 100644 --- a/matlab/dynare_sensitivity.m +++ b/matlab/dynare_sensitivity.m @@ -163,6 +163,11 @@ options_gsa = set_default_option(options_gsa,'istart_rmse',options_.presample+1) options_gsa = set_default_option(options_gsa,'alpha_rmse',0.001); options_gsa = set_default_option(options_gsa,'alpha2_rmse',1.e-5); +if options_gsa.neighborhood_width, + options_gsa.pprior=0; + options_gsa.ppost=0; +end + if options_gsa.redform && options_gsa.neighborhood_width==0 && isempty(options_gsa.threshold_redform), options_gsa.pprior=1; options_gsa.ppost=0; From a44b3fbfe7c0214c19f6eecabe368c2e72c9346f Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 14 Apr 2015 12:10:46 +0200 Subject: [PATCH 105/210] Bug fixed for incomplete stock matrices of log-posterior kernel and steady state [used in gsa/filt_mc_.m] --- matlab/prior_posterior_statistics_core.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/matlab/prior_posterior_statistics_core.m b/matlab/prior_posterior_statistics_core.m index ef8328c35..26b793c08 100644 --- a/matlab/prior_posterior_statistics_core.m +++ b/matlab/prior_posterior_statistics_core.m @@ -273,6 +273,8 @@ for b=fpar:B if irun(5) > MAX_nruns || b == B stock = stock_param(1:irun(5)-1,:); + stock_logpo = stock_logpo(1:irun(5)-1); + stock_ys = stock_ys(1:irun(5)-1,:); ifil(5) = ifil(5) + 1; save([DirectoryName '/' M_.fname '_param' int2str(ifil(5)) '.mat'],'stock','stock_logpo','stock_ys'); if RemoteFlag==1, From ffc4b7480cc8668c48ef09b6a60ed9d9b9562dc3 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 14 Apr 2015 12:16:50 +0200 Subject: [PATCH 106/210] - improved plots with MATLAB annotations [trapped in octave] and different colors - use uimenu to get the name of the observable associated to each CDF from MATLAB plots [trapped in octave] - also checks multiple significant parameters by individual observable --- matlab/gsa/filt_mc_.m | 306 +++++++++++++++++++++++++++++------------- 1 file changed, 213 insertions(+), 93 deletions(-) diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m index 329c6919d..fbc25214f 100644 --- a/matlab/gsa/filt_mc_.m +++ b/matlab/gsa/filt_mc_.m @@ -43,7 +43,7 @@ alpha = options_gsa_.alpha_rmse; % alpha2 = options_gsa_.alpha2_rmse; alpha2 = 0; pvalue = options_gsa_.alpha2_rmse; -istart = options_gsa_.istart_rmse; +istart = max(2,options_gsa_.istart_rmse); alphaPC = 0.5; fname_ = M_.fname; @@ -255,28 +255,32 @@ if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir); stab_map_2(x(ilik(1:nfilt),:),alpha2,pvalue,anam, OutDir); else - for i=1:size(vvarvecm,1), - [dum, ixx(:,i)]=sort(rmse_MC(:,i)); - if options_.opt_gsa.ppost, + if options_.opt_gsa.ppost, + rmse_txt=rmse_pmean; + r2_txt=r2_pmean; + else + if options_.opt_gsa.pprior || ~exist('rmse_pmean'), + if exist('rmse_mode'), + rmse_txt=rmse_mode; + r2_txt=r2_mode; + else + rmse_txt=NaN(1,size(rmse_MC,2)); + r2_txt=NaN(1,size(r2_MC,2)); + end + else %nfilt0(i)=length(find(rmse_MC(:,i)alphaPC); - % if ~isempty(i2), - % j2=j2+1; - % if mod(j2,12)==1, - % ifig=ifig+1; - % figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]), - % end - % subplot(3,4,j2-(ifig-1)*12) - % bar(pc(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - % title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%']) - % end - % if (mod(j2,12)==0 | j==(npar+nshock)) & j2, - % saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)]) - % end - % end - % close all - end +% skipline() +% disp('Starting bivariate analysis:') +% +% for i=1:size(vvarvecm,1) +% if options_.opt_gsa.ppost +% fnam = ['rmse_post_',deblank(vvarvecm(i,:))]; +% else +% if options_.opt_gsa.pprior +% fnam = ['rmse_prior_',deblank(vvarvecm(i,:))]; +% else +% fnam = ['rmse_mc_',deblank(vvarvecm(i,:))]; +% end +% end +% stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,pvalue,fnam, OutDir,[],[temp_name ' observed variable ' deblank(vvarvecm(i,:))]); +% +% % [pc,latent,explained] = pcacov(c0); +% % %figure, bar([explained cumsum(explained)]) +% % ifig=0; +% % j2=0; +% % for j=1:npar+nshock, +% % i2=find(abs(pc(:,j))>alphaPC); +% % if ~isempty(i2), +% % j2=j2+1; +% % if mod(j2,12)==1, +% % ifig=ifig+1; +% % figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]), +% % end +% % subplot(3,4,j2-(ifig-1)*12) +% % bar(pc(i2,j)), +% % set(gca,'xticklabel',bayestopt_.name(i2)), +% % set(gca,'xtick',[1:length(i2)]) +% % title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%']) +% % end +% % if (mod(j2,12)==0 | j==(npar+nshock)) & j2, +% % saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)]) +% % end +% % end +% % close all +% end end \ No newline at end of file From 0bd8fef2029f27e47f7668247b3ab146d1e7ed81 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 14 Apr 2015 12:24:49 +0200 Subject: [PATCH 107/210] - Various bug fixes on moment calibration - Bug fixes on plots showing restrictions - Improved and increased graphical info --- matlab/gsa/map_calibration.m | 276 ++++++++++++++++++++++++----------- matlab/gsa/stab_map_.m | 6 +- 2 files changed, 199 insertions(+), 83 deletions(-) diff --git a/matlab/gsa/map_calibration.m b/matlab/gsa/map_calibration.m index da933023d..d391cee79 100644 --- a/matlab/gsa/map_calibration.m +++ b/matlab/gsa/map_calibration.m @@ -55,7 +55,7 @@ else load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox') lpmat = [lpmat0 lpmat]; type = 'mc'; - end + end end [Nsam, np] = size(lpmat); npar = size(pnames,1); @@ -65,58 +65,91 @@ nbr_irf_restrictions = size(DynareOptions.endogenous_prior_restrictions.irf,1); nbr_moment_restrictions = size(DynareOptions.endogenous_prior_restrictions.moment,1); if init -mat_irf=cell(nbr_irf_restrictions,1); -for ij=1:nbr_irf_restrictions, - mat_irf{ij}=NaN(Nsam,length(DynareOptions.endogenous_prior_restrictions.irf{ij,3})); -end - -mat_moment=cell(nbr_moment_restrictions,1); -for ij=1:nbr_moment_restrictions, - mat_moment{ij}=NaN(Nsam,length(DynareOptions.endogenous_prior_restrictions.moment{ij,3})); -end - -irestrictions = [1:Nsam]; -h = dyn_waitbar(0,'Please wait...'); -for j=1:Nsam, - Model = set_all_parameters(lpmat(j,:)',EstimatedParameters,Model); - [Tt,Rr,SteadyState,info] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict'); - if info(1)==0, - [info, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,Model,DynareOptions,DynareResults); - if ~isempty(info_irf) - for ij=1:nbr_irf_restrictions, - mat_irf{ij}(j,:)=data_irf{ij}(:,2)'; - end - indx_irf(j,:)=info_irf(:,1); - end - if ~isempty(info_moment) - for ij=1:nbr_moment_restrictions, - mat_moment{ij}(j,:)=data_moment{ij}(:,2)'; - end - indx_moment(j,:)=info_moment(:,1); - end - else - irestrictions(j)=0; + mat_irf=cell(nbr_irf_restrictions,1); + for ij=1:nbr_irf_restrictions, + mat_irf{ij}=NaN(Nsam,length(DynareOptions.endogenous_prior_restrictions.irf{ij,3})); end - dyn_waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)]) -end -dyn_waitbar_close(h); - -irestrictions=irestrictions(find(irestrictions)); -xmat=lpmat(irestrictions,:); -skipline() -endo_prior_restrictions=DynareOptions.endogenous_prior_restrictions; -save([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment','endo_prior_restrictions'); -else -load([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment','endo_prior_restrictions'); -end -if ~isempty(indx_irf), - % For single legend search which has maximum nbr of restrictions + mat_moment=cell(nbr_moment_restrictions,1); + for ij=1:nbr_moment_restrictions, + mat_moment{ij}=NaN(Nsam,length(DynareOptions.endogenous_prior_restrictions.moment{ij,3})); + end + + irestrictions = [1:Nsam]; + h = dyn_waitbar(0,'Please wait...'); + for j=1:Nsam, + Model = set_all_parameters(lpmat(j,:)',EstimatedParameters,Model); + if nbr_moment_restrictions, + [Tt,Rr,SteadyState,info,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults); + else + [Tt,Rr,SteadyState,info,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict'); + end + if info(1)==0, + [info, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,Model,DynareOptions,DynareResults); + if ~isempty(info_irf) + for ij=1:nbr_irf_restrictions, + mat_irf{ij}(j,:)=data_irf{ij}(:,2)'; + end + indx_irf(j,:)=info_irf(:,1); + end + if ~isempty(info_moment) + for ij=1:nbr_moment_restrictions, + mat_moment{ij}(j,:)=data_moment{ij}(:,2)'; + end + indx_moment(j,:)=info_moment(:,1); + end + else + irestrictions(j)=0; + end + dyn_waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)]) + end + dyn_waitbar_close(h); + + irestrictions=irestrictions(find(irestrictions)); + xmat=lpmat(irestrictions,:); + skipline() + endo_prior_restrictions=DynareOptions.endogenous_prior_restrictions; + save([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment','endo_prior_restrictions'); +else + load([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment','endo_prior_restrictions'); +end +if ~isempty(indx_irf), + skipline() + disp('Deleting old IRF calibration plots ...') + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_irf_calib*.eps']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_irf_calib*.fig']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_irf_calib*.pdf']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions.eps']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions.fig']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions.pdf']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + disp('done !') + skipline() + + % For single legend search which has maximum nbr of restrictions all_irf_couples = cellstr([char(endo_prior_restrictions.irf(:,1)) char(endo_prior_restrictions.irf(:,2))]); irf_couples = unique(all_irf_couples); nbr_irf_couples = size(irf_couples,1); plot_indx = NaN(nbr_irf_couples,1); time_matrix=cell(nbr_irf_couples,1); + indx_irf_matrix=zeros(length(irestrictions),nbr_irf_couples); irf_matrix=cell(nbr_irf_couples,1); irf_mean=cell(nbr_irf_couples,1); irf_median=cell(nbr_irf_couples,1); @@ -131,6 +164,7 @@ if ~isempty(indx_irf), plot_indx(ij) = find(strcmp(irf_couples,all_irf_couples(ij,:))); time_matrix{plot_indx(ij)} = [time_matrix{plot_indx(ij)} endo_prior_restrictions.irf{ij,3}]; end + iplot_indx = ones(size(plot_indx)); indx_irf = indx_irf(irestrictions,:); h1=dyn_figure(DynareOptions,'name',[type ' evaluation of irf restrictions']); @@ -142,6 +176,7 @@ if ~isempty(indx_irf), for ij=1:nbr_irf_restrictions, mat_irf{ij}=mat_irf{ij}(irestrictions,:); irf_matrix{plot_indx(ij)} = [irf_matrix{plot_indx(ij)} mat_irf{ij}]; + indx_irf_matrix(:,plot_indx(ij)) = indx_irf_matrix(:,plot_indx(ij)) + indx_irf(:,ij); for ik=1:size(mat_irf{ij},2), [Mean,Median,Var,HPD,Distrib] = ... posterior_moments(mat_irf{ij}(:,ik),0,DynareOptions.mh_conf_sig); @@ -156,7 +191,8 @@ if ~isempty(indx_irf), if size(mat_irf{ij},2)>1, leg = [leg,':' ,num2str(endo_prior_restrictions.irf{ij,3}(end))]; aleg = [aleg,'-' ,num2str(endo_prior_restrictions.irf{ij,3}(end))]; - end + iplot_indx(ij)=0; + end if length(time_matrix{plot_indx(ij)})==1, figure(h1), subplot(nrow,ncol, plot_indx(ij)), @@ -185,28 +221,28 @@ if ~isempty(indx_irf), indx1 = find(indx_irf(:,ij)==0); indx2 = find(indx_irf(:,ij)~=0); atitle0=[endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')']; - fprintf(['%4.1f%% of the prior support matches IRF ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.irf{ij,4}) + fprintf(['%4.1f%% of the ',type,' support matches IRF ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.irf{ij,4}) % aname=[type '_irf_calib_',int2str(ij)]; aname=[type '_irf_calib_',endo_prior_restrictions.irf{ij,1},'_vs_',endo_prior_restrictions.irf{ij,2},'_',aleg]; atitle=[type ' IRF Calib: Parameter(s) driving ',endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')']; options_mcf.amcf_name = aname; options_mcf.amcf_title = atitle; - options_mcf.beha_title = 'IRF prior restriction'; - options_mcf.nobeha_title = 'NO IRF prior restriction'; + options_mcf.beha_title = 'IRF restriction'; + options_mcf.nobeha_title = 'NO IRF restriction'; options_mcf.title = atitle0; if ~isempty(indx1) && ~isempty(indx2) mcf_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, DynareOptions); end - -% [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0); -% indplot=find(proba1, + figure(h1); subplot(nrow,ncol, ij) itmp = (find(plot_indx==ij)); plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2) @@ -217,14 +253,14 @@ if ~isempty(indx_irf), tmp=[]; for ir=1:length(itmp), for it=1:length(endo_prior_restrictions.irf{itmp(ir),3}) - temp_index = find(time_matrix{ij}==endo_prior_restrictions.irf{itmp(ir),3}(it)); - tmp(temp_index,:) = endo_prior_restrictions.irf{itmp(ir),4}; + temp_index = find(time_matrix{ij}==endo_prior_restrictions.irf{itmp(ir),3}(it)); + tmp(temp_index,:) = endo_prior_restrictions.irf{itmp(ir),4}; end end -% tmp = cell2mat(endo_prior_restrictions.irf(itmp,4)); + % tmp = cell2mat(endo_prior_restrictions.irf(itmp,4)); tmp(isinf(tmp(:,1)),1)=a(3); tmp(isinf(tmp(:,2)),2)=a(4); - hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],tmp(:),'b'); + hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); set(hp,'FaceAlpha',[0.5]) plot(a(1:2),[0 0],'r') hold off, @@ -233,27 +269,79 @@ if ~isempty(indx_irf), set(gca,'xtick',sort(time_matrix{ij})) itmp = min(itmp); title([endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}],'interpreter','none'), + + if any(iplot_indx.*plot_indx==ij), + % MCF of the couples with logical AND + indx1 = find(indx_irf_matrix(:,ij)==0); + indx2 = find(indx_irf_matrix(:,ij)~=0); + leg = num2str(time_matrix{ij}(1)); + leg = [leg '...' num2str(time_matrix{ij}(end))]; + aleg = 'ALL'; + atitle0=[endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}, '(', leg,')']; + fprintf(['%4.1f%% of the ',type,' support matches IRF restrictions ',atitle0,'\n'],length(indx1)/length(irestrictions)*100) + % aname=[type '_irf_calib_',int2str(ij)]; + aname=[type '_irf_calib_',endo_prior_restrictions.irf{itmp,1},'_vs_',endo_prior_restrictions.irf{itmp,2},'_',aleg]; + atitle=[type ' IRF Calib: Parameter(s) driving ',endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}, '(', leg,')']; + options_mcf.amcf_name = aname; + options_mcf.amcf_title = atitle; + options_mcf.beha_title = 'IRF restriction'; + options_mcf.nobeha_title = 'NO IRF restriction'; + options_mcf.title = atitle0; + if ~isempty(indx1) && ~isempty(indx2) + mcf_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, DynareOptions); + end + end end end dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions'],DynareOptions); - + skipline() end if ~isempty(indx_moment) + skipline() + disp('Deleting old MOMENT calibration plots ...') + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_moment_calib*.eps']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_moment_calib*.fig']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_moment_calib*.pdf']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions.eps']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions.fig']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + a=dir([OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions.pdf']); + for j=1:length(a), + delete([OutputDirectoryName,filesep,a(j).name]); + end + disp('done !') + skipline() + options_mcf.param_names = char(BayesInfo.name); all_moment_couples = cellstr([char(endo_prior_restrictions.moment(:,1)) char(endo_prior_restrictions.moment(:,2))]); moment_couples = unique(all_moment_couples); nbr_moment_couples = size(moment_couples,1); plot_indx = NaN(nbr_moment_couples,1); time_matrix=cell(nbr_moment_couples,1); + indx_moment_matrix=zeros(length(irestrictions),nbr_moment_couples); moment_matrix=cell(nbr_moment_couples,1); moment_mean=cell(nbr_moment_couples,1); moment_median=cell(nbr_moment_couples,1); moment_var=cell(nbr_moment_couples,1); moment_HPD=cell(nbr_moment_couples,1); moment_distrib=cell(nbr_moment_couples,1); - % For single legend search which has maximum nbr of restrictions + % For single legend search which has maximum nbr of restrictions maxijv=0; for ij=1:nbr_moment_restrictions if length(endo_prior_restrictions.moment{ij,3})>maxijv @@ -262,6 +350,7 @@ if ~isempty(indx_moment) plot_indx(ij) = find(strcmp(moment_couples,all_moment_couples(ij,:))); time_matrix{plot_indx(ij)} = [time_matrix{plot_indx(ij)} endo_prior_restrictions.moment{ij,3}]; end + iplot_indx = ones(size(plot_indx)); indx_moment = indx_moment(irestrictions,:); h2=dyn_figure(DynareOptions,'name',[type ' evaluation of moment restrictions']); @@ -274,6 +363,7 @@ if ~isempty(indx_moment) for ij=1:nbr_moment_restrictions, mat_moment{ij}=mat_moment{ij}(irestrictions,:); moment_matrix{plot_indx(ij)} = [moment_matrix{plot_indx(ij)} mat_moment{ij}]; + indx_moment_matrix(:,plot_indx(ij)) = indx_moment_matrix(:,plot_indx(ij)) + indx_moment(:,ij); for ik=1:size(mat_moment{ij},2), [Mean,Median,Var,HPD,Distrib] = ... posterior_moments(mat_moment{ij}(:,ik),0,DynareOptions.mh_conf_sig); @@ -288,6 +378,7 @@ if ~isempty(indx_moment) if size(mat_moment{ij},2)>1, leg = [leg,':' ,num2str(endo_prior_restrictions.moment{ij,3}(end))]; aleg = [aleg,'_' ,num2str(endo_prior_restrictions.moment{ij,3}(end))]; + iplot_indx(ij)=0; end if length(time_matrix{plot_indx(ij)})==1, figure(h2), @@ -303,38 +394,38 @@ if ~isempty(indx_moment) set(hp,'FaceAlpha', 0.5) hold off, title([endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2},'(',leg,')'],'interpreter','none'), -% if ij==maxij -% leg1 = num2str(endo_prior_restrictions.moment{ij,3}(:)); -% [legend_h,object_h,plot_h,text_strings]=legend(leg1); -% Position=get(legend_h,'Position');Position(1:2)=[-0.055 0.95-Position(4)]; -% set(legend_h,'Position',Position); -% end + % if ij==maxij + % leg1 = num2str(endo_prior_restrictions.moment{ij,3}(:)); + % [legend_h,object_h,plot_h,text_strings]=legend(leg1); + % Position=get(legend_h,'Position');Position(1:2)=[-0.055 0.95-Position(4)]; + % set(legend_h,'Position',Position); + % end end indx1 = find(indx_moment(:,ij)==0); indx2 = find(indx_moment(:,ij)~=0); atitle0=[endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2}, '(', leg,')']; - fprintf(['%4.1f%% of the prior support matches MOMENT ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.moment{ij,4}) + fprintf(['%4.1f%% of the ',type,' support matches MOMENT ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.moment{ij,4}) % aname=[type '_moment_calib_',int2str(ij)]; aname=[type '_moment_calib_',endo_prior_restrictions.moment{ij,1},'_vs_',endo_prior_restrictions.moment{ij,2},'_',aleg]; atitle=[type ' MOMENT Calib: Parameter(s) driving ',endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2}, '(', leg,')']; options_mcf.amcf_name = aname; options_mcf.amcf_title = atitle; - options_mcf.beha_title = 'moment prior restriction'; - options_mcf.nobeha_title = 'NO moment prior restriction'; + options_mcf.beha_title = 'moment restriction'; + options_mcf.nobeha_title = 'NO moment restriction'; options_mcf.title = atitle0; if ~isempty(indx1) && ~isempty(indx2) mcf_analysis(xmat, indx1, indx2, options_mcf, DynareOptions); end -% [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0); -% indplot=find(proba1, + figure(h2); subplot(nrow,ncol, ij) itmp = (find(plot_indx==ij)); plot(time_matrix{ij},[max(moment_matrix{ij})' min(moment_matrix{ij})'],'k--','linewidth',2) @@ -345,14 +436,14 @@ if ~isempty(indx_moment) tmp=[]; for ir=1:length(itmp), for it=1:length(endo_prior_restrictions.moment{itmp(ir),3}) - temp_index = find(time_matrix{ij}==endo_prior_restrictions.moment{itmp(ir),3}(it)); - tmp(temp_index,:) = endo_prior_restrictions.moment{itmp(ir),4}; + temp_index = find(time_matrix{ij}==endo_prior_restrictions.moment{itmp(ir),3}(it)); + tmp(temp_index,:) = endo_prior_restrictions.moment{itmp(ir),4}; end end -% tmp = cell2mat(endo_prior_restrictions.moment(itmp,4)); + % tmp = cell2mat(endo_prior_restrictions.moment(itmp,4)); tmp(isinf(tmp(:,1)),1)=a(3); tmp(isinf(tmp(:,2)),2)=a(4); - hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],tmp(:),'b'); + hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); set(hp,'FaceAlpha',[0.5]) plot(a(1:2),[0 0],'r') hold off, @@ -361,6 +452,27 @@ if ~isempty(indx_moment) set(gca,'xtick',sort(time_matrix{ij})) itmp = min(itmp); title([endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}],'interpreter','none'), + if any(iplot_indx.*plot_indx==ij), + % MCF of the couples with logical AND + indx1 = find(indx_moment_matrix(:,ij)==0); + indx2 = find(indx_moment_matrix(:,ij)~=0); + leg = num2str(time_matrix{ij}(1)); + leg = [leg '...' num2str(time_matrix{ij}(end))]; + aleg = 'ALL'; + atitle0=[endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}, '(', leg,')']; + fprintf(['%4.1f%% of the ',type,' support matches MOMENT restrictions ',atitle0,'\n'],length(indx1)/length(irestrictions)*100) + % aname=[type '_moment_calib_',int2str(ij)]; + aname=[type '_moment_calib_',endo_prior_restrictions.moment{itmp,1},'_vs_',endo_prior_restrictions.moment{itmp,2},'_',aleg]; + atitle=[type ' MOMENT Calib: Parameter(s) driving ',endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}, '(', leg,')']; + options_mcf.amcf_name = aname; + options_mcf.amcf_title = atitle; + options_mcf.beha_title = 'moment restriction'; + options_mcf.nobeha_title = 'NO moment restriction'; + options_mcf.title = atitle0; + if ~isempty(indx1) && ~isempty(indx2) + mcf_analysis(xmat, indx1, indx2, options_mcf, DynareOptions); + end + end end end dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions'],DynareOptions); diff --git a/matlab/gsa/stab_map_.m b/matlab/gsa/stab_map_.m index f7db079df..b813aa367 100644 --- a/matlab/gsa/stab_map_.m +++ b/matlab/gsa/stab_map_.m @@ -267,7 +267,11 @@ if fload==0, M_ = set_all_parameters([lpmat0(j,:) lpmat(j,:)]',estim_params_,M_); %try stoch_simul([]); try - [Tt,Rr,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_,'restrict'); + if ~ isempty(options_.endogenous_prior_restrictions.moment) + [Tt,Rr,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_); + else + [Tt,Rr,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_,'restrict'); + end infox(j,1)=info(1); if infox(j,1)==0 && ~exist('T'), dr_=oo_.dr; From 8908cfe0f4c385be5f505d9d10ff9ab0199a2af2 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 14 Apr 2015 12:38:18 +0200 Subject: [PATCH 108/210] Updated testing routine --- tests/gsa/ls2003a.mod | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/gsa/ls2003a.mod b/tests/gsa/ls2003a.mod index fcbd9b75c..c93e48c2c 100644 --- a/tests/gsa/ls2003a.mod +++ b/tests/gsa/ls2003a.mod @@ -54,11 +54,18 @@ rho_q ,beta_pdf,0.4,0.2; rho_A ,beta_pdf,0.5,0.2; rho_ys ,beta_pdf,0.8,0.1; rho_pies,beta_pdf,0.7,0.15; -stderr e_R,inv_gamma_pdf,1.2533,0.6551; -stderr e_q,inv_gamma_pdf,2.5066,1.3103; -stderr e_A,inv_gamma_pdf,1.2533,0.6551; -stderr e_ys,inv_gamma_pdf,1.2533,0.6551; -stderr e_pies,inv_gamma_pdf,1.88,0.9827; +/* +stderr e_R,inv_gamma_pdf,(1.2533),(0.6551); +stderr e_q,inv_gamma_pdf,(2.5066),(1.3103); +stderr e_A,inv_gamma_pdf,(1.2533),(0.6551); +stderr e_ys,inv_gamma_pdf,(1.2533),(0.6551); +stderr e_pies,inv_gamma_pdf,(1.88),(0.9827); +*/ +stderr e_R,inv_gamma_pdf,(1.2533/3),(0.6551/10); +stderr e_q,inv_gamma_pdf,(2.5066/3),(1.3103/10); +stderr e_A,inv_gamma_pdf,(1.2533/3),(0.6551/10); +stderr e_ys,inv_gamma_pdf,(1.2533/3),(0.6551/10); +stderr e_pies,inv_gamma_pdf,(1.88/3),(0.9827/10); end; // endogenous prior restrictions @@ -83,12 +90,16 @@ end; moment_calibration; //y_obs,y_obs, [0.8 1.1]; //[unconditional variance] y_obs,y_obs(-(1:4)), +; //[first year acf] -@#for ilag in 0:1 -y_obs,R_obs(-@{ilag}), -; //[ccf] +//y_obs,pie_obs(-4:4), -; //[ccf] +@#for ilag in -2:2 +y_obs,R_obs(@{ilag}), -; //[ccf] +@#endfor +@#for ilag in -4:4 +y_obs,pie_obs(@{ilag}), -; //[ccf] @#endfor end; -dynare_sensitivity(prior_range=0); +dynare_sensitivity(prior_range=0, nodisplay, graph_format=(fig,eps)); /* estimation(datafile='data_ca1.m',first_obs=8,nobs=79,mh_nblocks=2, mode_file = ls2003a_mode, prefilter=1,mh_jscale=0.5,mh_replic=5000, mode_compute=0, mh_drop=0.6, bayesian_irf); From f5cf7617a6a84f98a212c2830957c1c022b8a5cd Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 14:47:26 +0200 Subject: [PATCH 109/210] preprocessor: method out of order --- preprocessor/ComputingTasks.cc | 54 +++++++++++++++++----------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 889694726..76ed6faad 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -2818,6 +2818,33 @@ CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const writeOptionsOutput(output, lhs_field, name1); } +void +CorrOptionsStatement::writeCOutput(ostream &output, const string &basename) +{ + output << endl + << "index = "; + if (is_structural_innovation(symbol_table.getType(name))) + output << "exo_names"; + else + output << "endo_names"; + output << "[\""<< name << "\"];" << endl; + + output << "index1 = "; + if (is_structural_innovation(symbol_table.getType(name1))) + output << "exo_names"; + else + output << "endo_names"; + output << "[\""<< name1 << "\"];" << endl; + + writeCOutputHelper(output, "init"); + + if (is_structural_innovation(symbol_table.getType(name))) + output << "msdsgeinfo->addStructuralInnovationCorrOption(new ModFileStructuralInnovationCorrOption("; + else + output << "msdsgeinfo->addMeasurementErrorCorrOption(new ModFileMeasurementErrorCorrOption("; + output << "index, index1, init));" << endl; +} + OptionsEqualStatement::OptionsEqualStatement(const string &to_declaration_type_arg, const string &to_name1_arg, const string &to_name2_arg, @@ -2985,33 +3012,6 @@ ModelDiagnosticsStatement::writeOutput(ostream &output, const string &basename) output << "model_diagnostics(M_,options_,oo_);" << endl; } -void -CorrOptionsStatement::writeCOutput(ostream &output, const string &basename) -{ - output << endl - << "index = "; - if (is_structural_innovation(symbol_table.getType(name))) - output << "exo_names"; - else - output << "endo_names"; - output << "[\""<< name << "\"];" << endl; - - output << "index1 = "; - if (is_structural_innovation(symbol_table.getType(name1))) - output << "exo_names"; - else - output << "endo_names"; - output << "[\""<< name1 << "\"];" << endl; - - writeCOutputHelper(output, "init"); - - if (is_structural_innovation(symbol_table.getType(name))) - output << "msdsgeinfo->addStructuralInnovationCorrOption(new ModFileStructuralInnovationCorrOption("; - else - output << "msdsgeinfo->addMeasurementErrorCorrOption(new ModFileMeasurementErrorCorrOption("; - output << "index, index1, init));" << endl; -} - Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_list_arg) : options_list(options_list_arg) { From 1a6afc0fdbad28d9a0cfc6c282ec829a6bfff687 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 11 Apr 2015 08:56:59 +0200 Subject: [PATCH 110/210] Restore compatibility of recursive estimation with new data interface Use dataset_ structure instead of reconstructing data to plot. Eliminates crashes --- matlab/dynare_estimation.m | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m index 348bdf8c4..ba49a1c18 100644 --- a/matlab/dynare_estimation.m +++ b/matlab/dynare_estimation.m @@ -28,7 +28,7 @@ function oo_recursive_=dynare_estimation(var_list,dname) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -global options_ oo_ M_ +global options_ oo_ M_ dataset_ oo_recursive_={}; @@ -97,14 +97,6 @@ end if nnobs > 1 && horizon > 0 mh_replic = options_.mh_replic; - rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range); - gend = options_.nobs; - data_plot_end_point=min(options_.first_obs+gend-1+horizon,size(rawdata,1)); %compute last observation that can be plotted - rawdata = rawdata(options_.first_obs:data_plot_end_point,:); - % Take the log of the variables if needed - if options_.loglinear && ~options_.logdata % and if the data are not in logs, then... - rawdata = log(rawdata); - end endo_names = M_.endo_names; n_varobs = length(options_.varobs); @@ -132,11 +124,12 @@ if nnobs > 1 && horizon > 0 IdObs(j,1) = iobs; end end - + + gend = dataset_.nobs; time_offset=min(3,gend-1); %for observables, plot 3 previous periods unless data is shorter k = time_offset+min(nobs(end)-nobs(1)+horizon, ... - size(rawdata,1)-nobs(1)); - data2 = rawdata(end-k+1:end,:); + size(dataset_.data,1)-nobs(1)); + data2 = dataset_.data(end-k+1:end,:); [nbplt,nr,nc,lr,lc,nstar] = pltorg(nvar); m = 1; plot_index=0; From 62f81da6ddd2f0dd4cdef31c8294071ffad6bd81 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 11 Apr 2015 09:18:51 +0200 Subject: [PATCH 111/210] Add unit test for recursive estimation with Excel data --- tests/Makefile.am | 2 + tests/recursive/data_ca1_xls.xlsx | Bin 0 -> 14804 bytes tests/recursive/ls2003_bayesian_xls.mod | 65 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 tests/recursive/data_ca1_xls.xlsx create mode 100644 tests/recursive/ls2003_bayesian_xls.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 14e46b716..5eead4544 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -136,6 +136,7 @@ MODFILES = \ conditional_forecasts/fs2000_est.mod \ recursive/ls2003.mod \ recursive/ls2003_bayesian.mod \ + recursive/ls2003_bayesian_xls.mod \ ms-sbvar/test_exclusions.mod \ ms-sbvar/test_exclusions_nc.mod \ ms-sbvar/test_lower_cholesky.mod \ @@ -378,6 +379,7 @@ EXTRA_DIST = \ ms-sbvar/archive-files/specification_2v.dat \ ms-sbvar/archive-files/specification_2v2c.dat \ recursive/data_ca1.m \ + recursive/data_ca1_xls.xlsx \ kalman_filter_smoother/fsdat_simul.m \ kalman_filter_smoother/fs2000a_steadystate.m \ identification/kim/kim2_steadystate.m \ diff --git a/tests/recursive/data_ca1_xls.xlsx b/tests/recursive/data_ca1_xls.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..62ce5a51f8688ee68d7894f7475d5714045e7b62 GIT binary patch literal 14804 zcmeHuWpErxwyv0&nVBuNm@Q^zX2upXTFg?5nOU-!!D42M(UvS`$Zij*2SRSQ61=MB5&C|^g8BUH$5q4idl4P%I7fmfI?&v%q5We4}3A532SGq$PcB)7*@x*xJ7yfXaWf)7Yf`pZxQ5kZ^&f) z{{9qFhhISrb@6-IYTe1bCfZU#7i+KC3MDbsov{{XX{Pw*?_T2~J-<{OJ z+0533nd!Ilf1LAwu}A)?>(PnR@&hag!{?HnqWjN3>?L9Hi#uc`J4jWDdMVC`n_~(o zgzoP`z=Nbs)@SdIrUi92&kn6ri3yCE?jM z8=JNUfTCoe@$z$7!{^U;&cz8VN@GTrvq`vRX5W$z_``aL6dCyz z`>bK0y`d`vp7uk&$K4M^&Ed;({rmcS`O>kH6 ztglm|y;(9(SF~`g&OHc~((cS4XX+ibgJ693vA^FeGV>uj}n zN?Mqv;!5pxng{MK0lr|8rIxwu#xg^pAWwDPQcFbjq+*ClagcZUe>XQp6Ei5Tw>0uw*m3e#q*nu-`3esy7gJ(Oj?EWf`Y zLOLSQWQc2~%H8g4penqiD1eYPDrS9-_Ny{DJEOf6#-VNEh@V9Vv`;uVU}d|7XE#F! zfel+U!R2SL9e#$h-l1**4F=A&YeR(CPy6f%Ng9BLXtNQCv#G?4SdMlp)i;Hg2g+7XZ)h>+eIH8&9WL@zLf{W^omi%%cIR9E+k6D>QBOH5FAEtus0KIs1*_KICU`NTtk zfE45ZmYe=Q9j=yUc4o}KpFjNO&Zk-m4*232J>-{!65b9b)b4nn+$vV;@hz1LRv3Rc zbrPM+^LI36;!@utHh-d^5EIsoZ*>w9DpucB7Ldz>iCU=b1!ipA%Dc-Ya)N>0lCEYy zPCmbFc4l<>?FkRgprR&TwfmI~ebV9rNn=OAC?VREwJ zQL`t9nHWK$Njxt1?M|dPaWVz-`v6O-hNp;eI?xf-2(p$;6BphG!IiwFLA$cLRxEv( zD9Q=K^u8`n+1P=;aNR_RPhA=LK^B2sO&OF(;RKKDs9_v}r@!haXxs-uqD1I1Q3M%C zbh}z}zs<3wTg=W3CS&W-wf^?*$KsPY$i43sJG4PcQ%#!=O*KFFZx92@S!t?(tgCU-akaPtS z6p9iB+7GkT?3+?BwHV_V|ETIEov9(&P{{}H^M^~a2%zE+bApxwknnibKQrSGoEFN>1DpA%kEo@wYxhn zK(bKNK948IhJ_8(3cV2RCt%wgWD6~%OB5xjFX+3kgR2Z7m>guhEu-j8HSfK`7!N*h8W0j;an zci#pieIk4b*egEkmWkXuYlQD3#N#Go1QVN{5DUe0Ksy^eH=LqMPp1Rt*eG8>jd`oE zWrK5DcLwORtZ#DK8mo;qdRJ&N5B!3cxk1Vqf`(`)$f|OnzgdU-`Rj=Ora`y+rM;78 zNU_*W)EHqYS-Qx;U?f0G2-h`wN z%8-Yezz^E<5L4r}KeeSXT)hd+-53|z+7@FhOXzsMIj1y7PR9S@&)Ac40K>K++G%aB5yQ`_whmTs(vFrMkZEH92aY-#)fsL$u60iWh zANFXCAof5XO52s(j0vi7>`hy5tMWvW2>Y+6#hyg(=$dy?)#thkr+Ndd}Xv_80<)-AT3^HSs*tpq<$w5-6`x8Y- z-(l7Ml<;zxCrGB_rsm0HovisHdi~G1S%f1Duuj_cZc*kLwmT&x2dwE|f&h6s#itT& zpDT@(UlUbn!!F-sF}rem2?y6Sy?etui~ zV182sz6B9{f8#u2KulV4OjZqN7Yge4D-sd@3Ytub?rVWkS?ZleIjSr|RRFg;HW4N-U5yCYl##!W?Tj@8hybZ^>Mfz1-*n5s10L7sB_ULOeV?{Q?3gq!SqQfFn! z`g}xo__NPgqxod=%J!U*u7DcLPMv%l&QN^?PTOj&rvwK3o3-5#omJ=BL%keyD<{C_BD*rg(Qph?pe8roJL6t@)Db zq!#TKEd%FL;5EOQE#s=^i?6WB(PYN>)acMSySuf~$dbEld3j%BsR~9I)vDAm_plE& zz2Ee1;q&$};e$PkiFBr6P@Ec=C^A2bC&;M7$IN0K|M!gH-vby|E8y7cJ+u|Qx8nSf zPqUaqEE4T;HiJ;4qbQT=6xf%mvN8g)Sx-qEONNg*oN(|{+F{!9m^@3Fu3n@)?Sctl z#~-kvmYO;0gd49>EJMT`Gh5#l)|d#bHeVo*+`gT)y99Teh*@P94}hff0}o8lS$@pb zpG}Xd0?EB$r5ZRP3(yoPa*rSLf5OiXQzt-3Dx2J=Wwr(%a zuIJasv&)BH7dubW1LL<_0-Em%S;~?B3UmqTN zkaG=s>M1iXA1@BhzKkrtalgKN85mf0sD0_7Wc@JP`TTP9df_~saY55j)#Q5?7soK> zZ@|x=r^`1yzd^j??=NrD($OSIH=~h@#9Z6Mw-U9iao^L`Nt7%997au)1~=W+uPUmf!X)|u=&;gCqP)S$6t1H>vd{fYY-=K6YlR`=xvszn27y2qxmr0hpUSyVd@Gm(DNbuaq{hnqHsoKDf~z&%l# zINItnaI{7eNKrdpG^K;UB~?%y6gxScYUZ|S>ZzAz<>JTbdFeC$8ULZ_L9U@Psljd* z$Y<4%TFK||p}RZ$`pGTB%q)rW1y;kSl_;y&vWBVU{@y9hP8~~JJ=v;hYTJpcY9322 zX%Q0HOJ5N}(H1ozFdJm0%WAw+cAY`ME6&zKEeT6JF-2`SxXG?4uM4{L_G;so?`C<$ z94l=i)a<(T&&Q#l73es5cTc3&(RDs6{FIIe(88{7APA>}Gc8g&sdm}sYJfa#;Yhq)ov2`0&!Tbf+o2`}(wdNOWCoyIEf+v;NDd;O2YBK3? zwh*vCEa(gx8d5`5G1xhVrtfE({NU?cO@V|{QMLTQRAg5;aK_Ia!ynjVg;dXY!a12> z-A?u@JZmYMonLOJ6*`c~s03kTda~>Ijse3^y(1{Kw7;`K#(2)xxwgY|MOAxgRt{@? zHz(}rg)HG|tn{$X4W+B6gdI_6yDYXddn~rO#L-<=zWy~Pf@Y1efaO98<9p5E?e=+P zOT^Td>sDJ0jl=PiCaWccvU|gRNd|C#e6{IoI+@53Mgb4;g5dB%eoBq?62y{xOVpr* znsH3BJO$&g?pi}m$z=lsffCast(w`ipWpdv~q7 zAhZ`iue1d_l_k$iv+s`AVJ4FKiujvbGo|;`>S-%w^{Fcp9d)O$nm?}^tbt?$Nj2pT z%*VwTFC~$eTAKpo@&$12RCx=0a3H zoY!%u$9@U^kiE(olxOASY& znF%|L+B{wu2li8lyx7xfF_ESaE2&17S?(f4Q9BF2|LKb^4MJc;Gwc1jHfJ*n)>_BBNMfJ zla&Y_<^)e{S}OE(4fR!_cUMOxOuM+sPA>T(9)zS}=xUL;co^51kpN^$aDC1A!S+YI zA^{33#ZlXQ1fs9FhvG^L6z-3^2mC0(n){07(0O|d$=H&OUIUDP)&s&adHo}TUM=|B zUokd%udg{7MmdhIE&!U$^1gn00J}cvI64{sDXnP^ycEDyl7Cu(pvgMdOQ?lBUs^?W z_IS+sT6pFwV=!a9&!H6Rx9?T_bVz$TX`e+`wam33XUS@ThF-Jy?&aawEP@fb8Pslo zJWa2zJgL6J3(m-a+OYOz96#Ysnq^$Ekf}^G$bP=fIru%@H28itcJc%@Bo3WI1)_9x zrHJ&%Hc0*xfm?2UKPxPvfb~krv=43-JX#cY!b@bzC5)h8a4~lkyAf2Tz+)4kTuoH< zWeQbf=a=bBd-tGW!CgGEQ+x*LE6?RhKDV>=lSjsy*A=gP=Kt2COsCRGpN& zrdHUFsgb;f6){S-=^xP>*q%sT3UllRY%lT`lnaej+k7bF%`0>8JT+rKZQwsS;C8Ion4`KC zE=a0Hd6^`I-2mn8kVY#(=#8rn?!18| zl|-i`RB#R&^0smnlygvXMhsjFMcGr9YXGtAx(`R&>+YnIP$UA`BZ?kyeDkEp{C=8? zbG-b*XZ<(@GMtH0sF8|q>N3WPI8+t(LMUQ;v8t}d8x7Q}AGbs)1AZ?lfSpZ z9ZXqkUr?r_5>s?P_-8^&6+VI=kr1s|sXMddnm^9Nbfd^VrU<~H_x&jB3ZK}EIVcT~ z@*_QV_heI6dLI*A4CxJ$Z$(eZQVq>yQfZ#-ZtZ9ub4%Rq$2;DjH6LMn;$aIJj4rSS zXPIlhb|5w6^sOcafqJ1zQ@iMw7O)U`w9)XL1b4+7a-lH7u?ufkl;|DKn(kxyl><4n zV60Hdk0HCLkbCf$g4S@fSV$pE_A;9VG}lSSQT@6_d66a?Zi zK;oha57nyfvO(b2a+`5EhkW{(K_6Zi3JX!#7mQIQAp>a2`a{3PUa7RYb_s8*_fYB$ zRu<)_P7-JB&_&4=vE3IX0rZw}F%sX%cn>o9odHAg+e5KItQd<7^zJxdy5rK2C=(DG zMz>bUlkPdUehct@7QEJ`ka%J@PxPA^4!hZ)zRK_n^?9A z_!d_NGu<5K;1!-H6fF}-Vd(VkP7`A8+c}92t458QyS{zGXsWv^38alaqg(Sq;Wqy? zFndQO`k9rq8NJXP+j~YgQdjs%?mEtoTWb3XkvC9-7l=#pxwnL@`3y3>CPL(1eDs(p z-Yb!`at2DPT-ZDEm)H`mFlI%K^NJX!i^2m9+=V`hBm&pck$gNQS)Q6GNJ+j!xBU+D zOS_Hp#k~`D2=d@)S$OfOZh|iKDk0x3lTYV?Q{%Gw2V1g?wxf`Uz&r`vx+WLb124|( zUfMpT{aP3<^zX5<9oRRS3@?Y~M6%?jj6<*W_=JpHU!AFV@cQ!$H2OirTRR)~QnFkv7&PPVu%()keezHoGu1}p^W%tPP*DxFAL9C>lD72U?KN~*Uop*K+* z5Fj4MH@U+ho+O^JNCA!f$^V1#$&&EeR^k9vcLw}X;g}`5FncJQ@&4F}TM#otXmJ{> zC?O%hbiFIDKCYO>)EkItS#FUs7`*yG{SiQ+AEYdvVwi^VcI_D{fB}p!7s?GPOCXpE zj!we}nWE7cEavS?N=l{N%t4SH3JixHO5t#Atj?X} zIIo>s8RUSU=9pD7AB~nzf@9de_(A24K_U43aL}S&l#{ z5dP$2xWG^&{ccWZ5_9wdLKh(?);I%J%5jiKKR5$;Ek!q#aJJlF*gMUFaxHx)(48nfmaH%?yUGC8@;mg%c*EYG^*0>xNx$R-mI%6ts;x8I&#GoTBn*tfTJ$I)AwPs`V zAqKLFG-ZLXiWv(WlRbtTN51TBTF->W#R+jG-36CZ$W~T2ntPW_C0S$^Km_?hC=}=% zX`MBhf1>*0|KsV!N0=n(*diXpcu3vXy;Lu(~GTm?MLn$7+zDio$ROn;%pGSOgL zTDDVHs#*gU>4(%HgM*Slv0j@D+q?{XzClMe!D4A+^hO3gGq#jq<9S!@*i?@oG1PvQ zbb(r>JpGx)M3pgLV5V{2D1dFx&TA|w=^`$YQcEhkOy=3Ag)}8dsqXWmTYgB)8RVXh zx`_9H6o7l4i?373&((8L9B{KH+tOojn*OOzg%!Cj$7{3@DppP*S zy=wW14MV3yRV#Q+oa0`8n-g=82E2H}+_rb31y8;n`{t!J$?PH9K~j_(yfSIF_KxyI zikL4Q$K>@ZYhb zqPHEUz$)$!>b_?}fc8dDCwf+$!bBTV*f=KaX5Q6xC`uY|mI$tfBS5|I3_xxw`lGeE zcjBzlBwf|+iWr-W0$ZfzplgY5-N-R{f@5NKUWTJ2o_WgUF8i=7fr~!3R-}OsW%O6) zrC6~eD-_O4kzkNXBbF%3Tt&twHM&SS)yA7eF`3H#Wwndr=A<(SyT{A}BHCPmXwGg$ zgdTuc#$7|Io4_`ltmO)qnoK@YkOX7;LxH;rE~5t(Z|pXKOV*w|9xNRz;$Q~9O%&t48Bd)L^+?v8?o49 zNglD9$>r+80;Y5WYJVYVy#%2vTzd2po0v}h?S$4l=lNFlzJxW9AH;4016l}RBSz?g zt;bu_CsFpQz+-cvY1eu4X%?;6VW^BQ6(UUXproGlh-%Lj4)k+KeP%%DHzxOF!m3Ae z{jnP|1A+k({{XuWXySA*!gq=(!&L2Bv>PD?Mr|n^LF&9mVBz+eTSaBUt{TYm@O9d( za&2+7B73;pAwPEo+sysBE5snewd*;$V+Q6$Rg`RZfhnaSMaKxASrkCiOnf$(d* zex6ChV)*IU`~z}x!D3h5^8U^}RTnt`b*#Fe*4{ckRFTwAKZv*+<|i`x;OU|&3NXUr z0JcCa5qGsN)eiT&H?>eBIh{30eKd#u0=$nLjNcZ%HU-8CE{P?sA` zjDxq-xQ-hfnn#PjN`OYpRTRCFsV)&+i2Wd4Zg9r7EtQa}FlSgHTx?EAoE?-my0ne^ z0KwkJ;i!fN1epD7BSa*`AGfSZBAvUSVW82OUSHII~si3KbVL=P2$l zGrnt6a51jMv2ewtD`5KJDy|_hWu7L6g-70MA3>GWb~mB<_VX&Xky8c$E$GvF zrzX^nDUofmFvhXBmUnRo{e3l6-w0z<;{<(m`U;6-r6I~BY^AEtZKo=pL?HkEB?z%A#n!a6+8kX%`BO~T86|0taR9I)meSvKA={?L;7U$M-;rvhTf%-b6 zo*x7|1E}X_w0mI3?UUA_4lJHrY9qqi7}$*Sh)q0SjU*~jI8nc@&5PiRH7gWXXX;2y zZ^9-jEIUKhovJ=?4l()O=+BH_C4W0SI*(Y&Uuo7K#cY~1!ae^2J5!&@v0nV%gOnt6z%lM57$!EV+JvxN82I(ke`pz);b!_pTH!A9OX& zs9AJq0pt7+s?e{cH?vol3-|hG;k$5K0SS$(wOCAP_z+0fAZCIieIF!0O*^qPGzzBs)F8P^+J0uA+Oou`b5tf3A%%>_yq4h`tcH%zZ2?t zDc!W!4}GXLUC$!C8f{gK4PSwP(d&W~wOO-3b-^Pid0@bk;`x#cjbz#rye`enLWFO$ zuU3SwCGN}5_1cH|d0}-UUILzKLHxwHALewRg+|ya;}TN%rNX$mPb*}$FeuDYiPoD@ zxh*>RLhpQ%xI5^^g%ZRcjfU#~vZ(7s8DSf--HHn4Gf*{c8&4N3SJiO&f%7Th=g$9a*05S*bO8 zu!65}7WNf%2aXERe3S7$4G3zy&OT(;AFaQ!SO z5HlUyf+1Zt6?qX9--R#0#ir4Ki%^+zKkdceHlrd)h>j3la8x!`3hh^%CQOYu8HGsI zK8m$#a-V)l!lc1c=;O+m=?BM^<|4v1R~krN5n-IGX+EqN-uKMZDa!wN#N>%<>@oYz z{TO^XA`y?DIjUG*0IiJfo&pOi&ns$~h%5IL;giK6f9&I+#AmiANC#W;*S!rvgoh5K z<=W$&Fz>%DzRKkLz#G1|h`g8j5dW)#uAa7LzxS+2b<1X*1;vl})E~u5;Q%0&2C*K> z&VkXcBnj=EV)qes5t)2cue1KmmwL5c<*6>FThpU-zVuvR<73-LsX+bodfiHl=~}Yr zbUL@8Mbe?IoU2th@{_WPvYDvjRuil(Q({4iCAXlTanT|gfH;n6TRh4PNtD<6!^MYf@6K?Hwa2$uwlEJ}LG;+t|G{D7~v93{3MajY*%#K(Op zq~b@COTMt7ep05vuXJ}1B=MAau_h7++j)I{Kk!=h`$X?pNY9y9p+!49J3G0B`a`vp zEmef~WWBOPwa7Go29)iD7aC;SZ|hhd2^}z$bMsq@L#7u&<08_Onu?tIy7<-_80A_Q zX=liI7!>2IEqr$5%#ZIoz4RK{Gbp%S!LHMnxN$NVaDNT_bLbrSy?%L$3A(8 zldeobE0;%Uzy4OpHd_#ynfKnJ@vcloc~_>II+!RrJ2<*98#y}u=4bCB?*Hgf-(55- zsn33$1tIJl{0=GXEGDZ6Crn6PsR`d}r4Gc&+rpFwl}aXT5N|Zc!l3~h-;Oz^5t08! z;;Piow}8UU#Zq_4NS5kLp)tA~EjF3JWzwvgUD!MY!WRDLjKv5%aA{`8Cyj&xSepHx$^Oufn^5Ga8zD&CFrO zuDWhF>hpBzIn4YiBdLMSbl`#XcELOvS6OB2EpAI7m)~zSY>XxIOHSwe@>HDZ=t?&8 zJY!R1yGGd6@WGMJ0it@rGG+U1c|<5rMm2rIMQWcakq|@EDW8K!+E7-p(C*Shk4dyI z23vjC(-G=z(8Yc6zgW`RZPez9;iT->DB<>h53;hYy>+(S-fpPp!m-k9-DhC@D7*E8 zL+lCp&N+&oC3=Qj9#+Q{=}4s?dr5G2m&0j4JI5{^SLJo+cIfH+dp+X-KT1xRzm_VH zU##k(TmI?&bpU6xw^Sb97ra&S{BLl-R6OzCB6AF;ugs=u4V6`{UdV48-sk4uBS_em zpr6n?tBu|lS=2wX+Qh-x>_4=AAG7~D-sL^-8)tCB&x5w|_cy8RvZXC~6<37`VC-o& zMXv1WIsGLIHoCj4Iu^(H0J45Pe4bZ{#@%UhH;_w<+9@=0Fi}EIjMmMJvtG>+4odrc zDnT6D!jVYZGo9~xyViVN9YD)kz%55BO?-0Uw`9wsu6!KcZtziEG(5Txd^^f(Bdaef zEU$en0c;{Q^$^n#*9acHE74-EVsHXvlcjcE0oyou@p+vCR*Ad0HPG}MxzJChbIHwu z=@%u1XUU8YD6v1gDo2dhTcm*ZczuFH4&$Y1ujNkF?OIMkYNXr;Sn10xUJJY>7_DFm zoE@N?6OU%;wS=FtfsM$(@Jy$d!;4tcg>`&X}d&qrNF7&S!Oc zXuR=k!6M;b(OmfNMw_pO0Kils1)eb$x!%X`AG8AnV|-6i{(jHeKS%kW*T31prYQ5T z0ROt5=AVYYU5npW=s)eQ`K#f-ZZY_?;rP2w`G4MU@K>C_3eEpOLWKP{+4*0M|0;|A z!#E4>Z$;971^BBh?GFGw)c=0^zlqfT?@ix* m|7!iOtLUGtdD;JD{m(U3Q3mpzX&@j7zkS}x+Q9kSum1y9|I}#! literal 0 HcmV?d00001 diff --git a/tests/recursive/ls2003_bayesian_xls.mod b/tests/recursive/ls2003_bayesian_xls.mod new file mode 100644 index 000000000..57c46c6b6 --- /dev/null +++ b/tests/recursive/ls2003_bayesian_xls.mod @@ -0,0 +1,65 @@ +var y y_s R pie dq pie_s de A y_obs pie_obs R_obs; +varexo e_R e_q e_ys e_pies e_A; + +parameters psi1 psi2 psi3 rho_R tau alpha rr k rho_q rho_A rho_ys rho_pies; + +psi1 = 1.54; +psi2 = 0.25; +psi3 = 0.25; +rho_R = 0.5; +alpha = 0.3; +rr = 2.51; +k = 0.5; +tau = 0.5; +rho_q = 0.4; +rho_A = 0.2; +rho_ys = 0.9; +rho_pies = 0.7; + + +model(linear); +y = y(+1) - (tau +alpha*(2-alpha)*(1-tau))*(R-pie(+1))-alpha*(tau +alpha*(2-alpha)*(1-tau))*dq(+1) + alpha*(2-alpha)*((1-tau)/tau)*(y_s-y_s(+1))-A(+1); +pie = exp(-rr/400)*pie(+1)+alpha*exp(-rr/400)*dq(+1)-alpha*dq+(k/(tau+alpha*(2-alpha)*(1-tau)))*y+alpha*(2-alpha)*(1-tau)/(tau*(tau+alpha*(2-alpha)*(1-tau)))*y_s; +pie = de+(1-alpha)*dq+pie_s; +R = rho_R*R(-1)+(1-rho_R)*(psi1*pie+psi2*(y+alpha*(2-alpha)*((1-tau)/tau)*y_s)+psi3*de)+e_R; +dq = rho_q*dq(-1)+e_q; +y_s = rho_ys*y_s(-1)+e_ys; +pie_s = rho_pies*pie_s(-1)+e_pies; +A = rho_A*A(-1)+e_A; +y_obs = y-y(-1)+A; +pie_obs = 4*pie; +R_obs = 4*R; +end; + +shocks; +var e_R = 1.25^2; +var e_q = 2.5^2; +var e_A = 1.89; +var e_ys = 1.89; +var e_pies = 1.89; +end; + +varobs y_obs R_obs pie_obs dq de; + +estimated_params; +psi1 , gamma_pdf,1.5,0.5; +psi2 , gamma_pdf,0.25,0.125; +psi3 , gamma_pdf,0.25,0.125; +rho_R ,beta_pdf,0.5,0.2; +alpha ,beta_pdf,0.3,0.1; +rr ,gamma_pdf,2.5,1; +k , gamma_pdf,0.5,0.25; +tau ,gamma_pdf,0.5,0.2; +rho_q ,beta_pdf,0.4,0.2; +rho_A ,beta_pdf,0.5,0.2; +rho_ys ,beta_pdf,0.8,0.1; +rho_pies,beta_pdf,0.7,0.15; +stderr e_R,inv_gamma_pdf,1.2533,0.6551; +stderr e_q,inv_gamma_pdf,2.5066,1.3103; +stderr e_A,inv_gamma_pdf,1.2533,0.6551; +stderr e_ys,inv_gamma_pdf,1.2533,0.6551; +stderr e_pies,inv_gamma_pdf,1.88,0.9827; +end; + +estimation(datafile=data_ca1_xls,first_obs=8,nobs=[76 79],mh_nblocks=1,prefilter=1,mh_jscale=0.5,mh_replic=2000,forecast=8) y_obs R_obs pie_obs dq de; + From 8022a181c8f7f170ef203002cdd457b570457535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 14 Apr 2015 15:08:34 +0200 Subject: [PATCH 112/210] Removed excel data file used in ls2003_bayesian_xls.mod. The excel data file available here: http://www.dynare.org/Datasets/data_ca1_xls.xlsx is downloaded by Matlab/Octave when performing the test. The file is deleted after the estimation command. --- tests/Makefile.am | 1 - tests/recursive/data_ca1_xls.xlsx | Bin 14804 -> 0 bytes tests/recursive/ls2003_bayesian_xls.mod | 7 +++++++ 3 files changed, 7 insertions(+), 1 deletion(-) delete mode 100644 tests/recursive/data_ca1_xls.xlsx diff --git a/tests/Makefile.am b/tests/Makefile.am index 5eead4544..8b060a700 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -379,7 +379,6 @@ EXTRA_DIST = \ ms-sbvar/archive-files/specification_2v.dat \ ms-sbvar/archive-files/specification_2v2c.dat \ recursive/data_ca1.m \ - recursive/data_ca1_xls.xlsx \ kalman_filter_smoother/fsdat_simul.m \ kalman_filter_smoother/fs2000a_steadystate.m \ identification/kim/kim2_steadystate.m \ diff --git a/tests/recursive/data_ca1_xls.xlsx b/tests/recursive/data_ca1_xls.xlsx deleted file mode 100644 index 62ce5a51f8688ee68d7894f7475d5714045e7b62..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14804 zcmeHuWpErxwyv0&nVBuNm@Q^zX2upXTFg?5nOU-!!D42M(UvS`$Zij*2SRSQ61=MB5&C|^g8BUH$5q4idl4P%I7fmfI?&v%q5We4}3A532SGq$PcB)7*@x*xJ7yfXaWf)7Yf`pZxQ5kZ^&f) z{{9qFhhISrb@6-IYTe1bCfZU#7i+KC3MDbsov{{XX{Pw*?_T2~J-<{OJ z+0533nd!Ilf1LAwu}A)?>(PnR@&hag!{?HnqWjN3>?L9Hi#uc`J4jWDdMVC`n_~(o zgzoP`z=Nbs)@SdIrUi92&kn6ri3yCE?jM z8=JNUfTCoe@$z$7!{^U;&cz8VN@GTrvq`vRX5W$z_``aL6dCyz z`>bK0y`d`vp7uk&$K4M^&Ed;({rmcS`O>kH6 ztglm|y;(9(SF~`g&OHc~((cS4XX+ibgJ693vA^FeGV>uj}n zN?Mqv;!5pxng{MK0lr|8rIxwu#xg^pAWwDPQcFbjq+*ClagcZUe>XQp6Ei5Tw>0uw*m3e#q*nu-`3esy7gJ(Oj?EWf`Y zLOLSQWQc2~%H8g4penqiD1eYPDrS9-_Ny{DJEOf6#-VNEh@V9Vv`;uVU}d|7XE#F! zfel+U!R2SL9e#$h-l1**4F=A&YeR(CPy6f%Ng9BLXtNQCv#G?4SdMlp)i;Hg2g+7XZ)h>+eIH8&9WL@zLf{W^omi%%cIR9E+k6D>QBOH5FAEtus0KIs1*_KICU`NTtk zfE45ZmYe=Q9j=yUc4o}KpFjNO&Zk-m4*232J>-{!65b9b)b4nn+$vV;@hz1LRv3Rc zbrPM+^LI36;!@utHh-d^5EIsoZ*>w9DpucB7Ldz>iCU=b1!ipA%Dc-Ya)N>0lCEYy zPCmbFc4l<>?FkRgprR&TwfmI~ebV9rNn=OAC?VREwJ zQL`t9nHWK$Njxt1?M|dPaWVz-`v6O-hNp;eI?xf-2(p$;6BphG!IiwFLA$cLRxEv( zD9Q=K^u8`n+1P=;aNR_RPhA=LK^B2sO&OF(;RKKDs9_v}r@!haXxs-uqD1I1Q3M%C zbh}z}zs<3wTg=W3CS&W-wf^?*$KsPY$i43sJG4PcQ%#!=O*KFFZx92@S!t?(tgCU-akaPtS z6p9iB+7GkT?3+?BwHV_V|ETIEov9(&P{{}H^M^~a2%zE+bApxwknnibKQrSGoEFN>1DpA%kEo@wYxhn zK(bKNK948IhJ_8(3cV2RCt%wgWD6~%OB5xjFX+3kgR2Z7m>guhEu-j8HSfK`7!N*h8W0j;an zci#pieIk4b*egEkmWkXuYlQD3#N#Go1QVN{5DUe0Ksy^eH=LqMPp1Rt*eG8>jd`oE zWrK5DcLwORtZ#DK8mo;qdRJ&N5B!3cxk1Vqf`(`)$f|OnzgdU-`Rj=Ora`y+rM;78 zNU_*W)EHqYS-Qx;U?f0G2-h`wN z%8-Yezz^E<5L4r}KeeSXT)hd+-53|z+7@FhOXzsMIj1y7PR9S@&)Ac40K>K++G%aB5yQ`_whmTs(vFrMkZEH92aY-#)fsL$u60iWh zANFXCAof5XO52s(j0vi7>`hy5tMWvW2>Y+6#hyg(=$dy?)#thkr+Ndd}Xv_80<)-AT3^HSs*tpq<$w5-6`x8Y- z-(l7Ml<;zxCrGB_rsm0HovisHdi~G1S%f1Duuj_cZc*kLwmT&x2dwE|f&h6s#itT& zpDT@(UlUbn!!F-sF}rem2?y6Sy?etui~ zV182sz6B9{f8#u2KulV4OjZqN7Yge4D-sd@3Ytub?rVWkS?ZleIjSr|RRFg;HW4N-U5yCYl##!W?Tj@8hybZ^>Mfz1-*n5s10L7sB_ULOeV?{Q?3gq!SqQfFn! z`g}xo__NPgqxod=%J!U*u7DcLPMv%l&QN^?PTOj&rvwK3o3-5#omJ=BL%keyD<{C_BD*rg(Qph?pe8roJL6t@)Db zq!#TKEd%FL;5EOQE#s=^i?6WB(PYN>)acMSySuf~$dbEld3j%BsR~9I)vDAm_plE& zz2Ee1;q&$};e$PkiFBr6P@Ec=C^A2bC&;M7$IN0K|M!gH-vby|E8y7cJ+u|Qx8nSf zPqUaqEE4T;HiJ;4qbQT=6xf%mvN8g)Sx-qEONNg*oN(|{+F{!9m^@3Fu3n@)?Sctl z#~-kvmYO;0gd49>EJMT`Gh5#l)|d#bHeVo*+`gT)y99Teh*@P94}hff0}o8lS$@pb zpG}Xd0?EB$r5ZRP3(yoPa*rSLf5OiXQzt-3Dx2J=Wwr(%a zuIJasv&)BH7dubW1LL<_0-Em%S;~?B3UmqTN zkaG=s>M1iXA1@BhzKkrtalgKN85mf0sD0_7Wc@JP`TTP9df_~saY55j)#Q5?7soK> zZ@|x=r^`1yzd^j??=NrD($OSIH=~h@#9Z6Mw-U9iao^L`Nt7%997au)1~=W+uPUmf!X)|u=&;gCqP)S$6t1H>vd{fYY-=K6YlR`=xvszn27y2qxmr0hpUSyVd@Gm(DNbuaq{hnqHsoKDf~z&%l# zINItnaI{7eNKrdpG^K;UB~?%y6gxScYUZ|S>ZzAz<>JTbdFeC$8ULZ_L9U@Psljd* z$Y<4%TFK||p}RZ$`pGTB%q)rW1y;kSl_;y&vWBVU{@y9hP8~~JJ=v;hYTJpcY9322 zX%Q0HOJ5N}(H1ozFdJm0%WAw+cAY`ME6&zKEeT6JF-2`SxXG?4uM4{L_G;so?`C<$ z94l=i)a<(T&&Q#l73es5cTc3&(RDs6{FIIe(88{7APA>}Gc8g&sdm}sYJfa#;Yhq)ov2`0&!Tbf+o2`}(wdNOWCoyIEf+v;NDd;O2YBK3? zwh*vCEa(gx8d5`5G1xhVrtfE({NU?cO@V|{QMLTQRAg5;aK_Ia!ynjVg;dXY!a12> z-A?u@JZmYMonLOJ6*`c~s03kTda~>Ijse3^y(1{Kw7;`K#(2)xxwgY|MOAxgRt{@? zHz(}rg)HG|tn{$X4W+B6gdI_6yDYXddn~rO#L-<=zWy~Pf@Y1efaO98<9p5E?e=+P zOT^Td>sDJ0jl=PiCaWccvU|gRNd|C#e6{IoI+@53Mgb4;g5dB%eoBq?62y{xOVpr* znsH3BJO$&g?pi}m$z=lsffCast(w`ipWpdv~q7 zAhZ`iue1d_l_k$iv+s`AVJ4FKiujvbGo|;`>S-%w^{Fcp9d)O$nm?}^tbt?$Nj2pT z%*VwTFC~$eTAKpo@&$12RCx=0a3H zoY!%u$9@U^kiE(olxOASY& znF%|L+B{wu2li8lyx7xfF_ESaE2&17S?(f4Q9BF2|LKb^4MJc;Gwc1jHfJ*n)>_BBNMfJ zla&Y_<^)e{S}OE(4fR!_cUMOxOuM+sPA>T(9)zS}=xUL;co^51kpN^$aDC1A!S+YI zA^{33#ZlXQ1fs9FhvG^L6z-3^2mC0(n){07(0O|d$=H&OUIUDP)&s&adHo}TUM=|B zUokd%udg{7MmdhIE&!U$^1gn00J}cvI64{sDXnP^ycEDyl7Cu(pvgMdOQ?lBUs^?W z_IS+sT6pFwV=!a9&!H6Rx9?T_bVz$TX`e+`wam33XUS@ThF-Jy?&aawEP@fb8Pslo zJWa2zJgL6J3(m-a+OYOz96#Ysnq^$Ekf}^G$bP=fIru%@H28itcJc%@Bo3WI1)_9x zrHJ&%Hc0*xfm?2UKPxPvfb~krv=43-JX#cY!b@bzC5)h8a4~lkyAf2Tz+)4kTuoH< zWeQbf=a=bBd-tGW!CgGEQ+x*LE6?RhKDV>=lSjsy*A=gP=Kt2COsCRGpN& zrdHUFsgb;f6){S-=^xP>*q%sT3UllRY%lT`lnaej+k7bF%`0>8JT+rKZQwsS;C8Ion4`KC zE=a0Hd6^`I-2mn8kVY#(=#8rn?!18| zl|-i`RB#R&^0smnlygvXMhsjFMcGr9YXGtAx(`R&>+YnIP$UA`BZ?kyeDkEp{C=8? zbG-b*XZ<(@GMtH0sF8|q>N3WPI8+t(LMUQ;v8t}d8x7Q}AGbs)1AZ?lfSpZ z9ZXqkUr?r_5>s?P_-8^&6+VI=kr1s|sXMddnm^9Nbfd^VrU<~H_x&jB3ZK}EIVcT~ z@*_QV_heI6dLI*A4CxJ$Z$(eZQVq>yQfZ#-ZtZ9ub4%Rq$2;DjH6LMn;$aIJj4rSS zXPIlhb|5w6^sOcafqJ1zQ@iMw7O)U`w9)XL1b4+7a-lH7u?ufkl;|DKn(kxyl><4n zV60Hdk0HCLkbCf$g4S@fSV$pE_A;9VG}lSSQT@6_d66a?Zi zK;oha57nyfvO(b2a+`5EhkW{(K_6Zi3JX!#7mQIQAp>a2`a{3PUa7RYb_s8*_fYB$ zRu<)_P7-JB&_&4=vE3IX0rZw}F%sX%cn>o9odHAg+e5KItQd<7^zJxdy5rK2C=(DG zMz>bUlkPdUehct@7QEJ`ka%J@PxPA^4!hZ)zRK_n^?9A z_!d_NGu<5K;1!-H6fF}-Vd(VkP7`A8+c}92t458QyS{zGXsWv^38alaqg(Sq;Wqy? zFndQO`k9rq8NJXP+j~YgQdjs%?mEtoTWb3XkvC9-7l=#pxwnL@`3y3>CPL(1eDs(p z-Yb!`at2DPT-ZDEm)H`mFlI%K^NJX!i^2m9+=V`hBm&pck$gNQS)Q6GNJ+j!xBU+D zOS_Hp#k~`D2=d@)S$OfOZh|iKDk0x3lTYV?Q{%Gw2V1g?wxf`Uz&r`vx+WLb124|( zUfMpT{aP3<^zX5<9oRRS3@?Y~M6%?jj6<*W_=JpHU!AFV@cQ!$H2OirTRR)~QnFkv7&PPVu%()keezHoGu1}p^W%tPP*DxFAL9C>lD72U?KN~*Uop*K+* z5Fj4MH@U+ho+O^JNCA!f$^V1#$&&EeR^k9vcLw}X;g}`5FncJQ@&4F}TM#otXmJ{> zC?O%hbiFIDKCYO>)EkItS#FUs7`*yG{SiQ+AEYdvVwi^VcI_D{fB}p!7s?GPOCXpE zj!we}nWE7cEavS?N=l{N%t4SH3JixHO5t#Atj?X} zIIo>s8RUSU=9pD7AB~nzf@9de_(A24K_U43aL}S&l#{ z5dP$2xWG^&{ccWZ5_9wdLKh(?);I%J%5jiKKR5$;Ek!q#aJJlF*gMUFaxHx)(48nfmaH%?yUGC8@;mg%c*EYG^*0>xNx$R-mI%6ts;x8I&#GoTBn*tfTJ$I)AwPs`V zAqKLFG-ZLXiWv(WlRbtTN51TBTF->W#R+jG-36CZ$W~T2ntPW_C0S$^Km_?hC=}=% zX`MBhf1>*0|KsV!N0=n(*diXpcu3vXy;Lu(~GTm?MLn$7+zDio$ROn;%pGSOgL zTDDVHs#*gU>4(%HgM*Slv0j@D+q?{XzClMe!D4A+^hO3gGq#jq<9S!@*i?@oG1PvQ zbb(r>JpGx)M3pgLV5V{2D1dFx&TA|w=^`$YQcEhkOy=3Ag)}8dsqXWmTYgB)8RVXh zx`_9H6o7l4i?373&((8L9B{KH+tOojn*OOzg%!Cj$7{3@DppP*S zy=wW14MV3yRV#Q+oa0`8n-g=82E2H}+_rb31y8;n`{t!J$?PH9K~j_(yfSIF_KxyI zikL4Q$K>@ZYhb zqPHEUz$)$!>b_?}fc8dDCwf+$!bBTV*f=KaX5Q6xC`uY|mI$tfBS5|I3_xxw`lGeE zcjBzlBwf|+iWr-W0$ZfzplgY5-N-R{f@5NKUWTJ2o_WgUF8i=7fr~!3R-}OsW%O6) zrC6~eD-_O4kzkNXBbF%3Tt&twHM&SS)yA7eF`3H#Wwndr=A<(SyT{A}BHCPmXwGg$ zgdTuc#$7|Io4_`ltmO)qnoK@YkOX7;LxH;rE~5t(Z|pXKOV*w|9xNRz;$Q~9O%&t48Bd)L^+?v8?o49 zNglD9$>r+80;Y5WYJVYVy#%2vTzd2po0v}h?S$4l=lNFlzJxW9AH;4016l}RBSz?g zt;bu_CsFpQz+-cvY1eu4X%?;6VW^BQ6(UUXproGlh-%Lj4)k+KeP%%DHzxOF!m3Ae z{jnP|1A+k({{XuWXySA*!gq=(!&L2Bv>PD?Mr|n^LF&9mVBz+eTSaBUt{TYm@O9d( za&2+7B73;pAwPEo+sysBE5snewd*;$V+Q6$Rg`RZfhnaSMaKxASrkCiOnf$(d* zex6ChV)*IU`~z}x!D3h5^8U^}RTnt`b*#Fe*4{ckRFTwAKZv*+<|i`x;OU|&3NXUr z0JcCa5qGsN)eiT&H?>eBIh{30eKd#u0=$nLjNcZ%HU-8CE{P?sA` zjDxq-xQ-hfnn#PjN`OYpRTRCFsV)&+i2Wd4Zg9r7EtQa}FlSgHTx?EAoE?-my0ne^ z0KwkJ;i!fN1epD7BSa*`AGfSZBAvUSVW82OUSHII~si3KbVL=P2$l zGrnt6a51jMv2ewtD`5KJDy|_hWu7L6g-70MA3>GWb~mB<_VX&Xky8c$E$GvF zrzX^nDUofmFvhXBmUnRo{e3l6-w0z<;{<(m`U;6-r6I~BY^AEtZKo=pL?HkEB?z%A#n!a6+8kX%`BO~T86|0taR9I)meSvKA={?L;7U$M-;rvhTf%-b6 zo*x7|1E}X_w0mI3?UUA_4lJHrY9qqi7}$*Sh)q0SjU*~jI8nc@&5PiRH7gWXXX;2y zZ^9-jEIUKhovJ=?4l()O=+BH_C4W0SI*(Y&Uuo7K#cY~1!ae^2J5!&@v0nV%gOnt6z%lM57$!EV+JvxN82I(ke`pz);b!_pTH!A9OX& zs9AJq0pt7+s?e{cH?vol3-|hG;k$5K0SS$(wOCAP_z+0fAZCIieIF!0O*^qPGzzBs)F8P^+J0uA+Oou`b5tf3A%%>_yq4h`tcH%zZ2?t zDc!W!4}GXLUC$!C8f{gK4PSwP(d&W~wOO-3b-^Pid0@bk;`x#cjbz#rye`enLWFO$ zuU3SwCGN}5_1cH|d0}-UUILzKLHxwHALewRg+|ya;}TN%rNX$mPb*}$FeuDYiPoD@ zxh*>RLhpQ%xI5^^g%ZRcjfU#~vZ(7s8DSf--HHn4Gf*{c8&4N3SJiO&f%7Th=g$9a*05S*bO8 zu!65}7WNf%2aXERe3S7$4G3zy&OT(;AFaQ!SO z5HlUyf+1Zt6?qX9--R#0#ir4Ki%^+zKkdceHlrd)h>j3la8x!`3hh^%CQOYu8HGsI zK8m$#a-V)l!lc1c=;O+m=?BM^<|4v1R~krN5n-IGX+EqN-uKMZDa!wN#N>%<>@oYz z{TO^XA`y?DIjUG*0IiJfo&pOi&ns$~h%5IL;giK6f9&I+#AmiANC#W;*S!rvgoh5K z<=W$&Fz>%DzRKkLz#G1|h`g8j5dW)#uAa7LzxS+2b<1X*1;vl})E~u5;Q%0&2C*K> z&VkXcBnj=EV)qes5t)2cue1KmmwL5c<*6>FThpU-zVuvR<73-LsX+bodfiHl=~}Yr zbUL@8Mbe?IoU2th@{_WPvYDvjRuil(Q({4iCAXlTanT|gfH;n6TRh4PNtD<6!^MYf@6K?Hwa2$uwlEJ}LG;+t|G{D7~v93{3MajY*%#K(Op zq~b@COTMt7ep05vuXJ}1B=MAau_h7++j)I{Kk!=h`$X?pNY9y9p+!49J3G0B`a`vp zEmef~WWBOPwa7Go29)iD7aC;SZ|hhd2^}z$bMsq@L#7u&<08_Onu?tIy7<-_80A_Q zX=liI7!>2IEqr$5%#ZIoz4RK{Gbp%S!LHMnxN$NVaDNT_bLbrSy?%L$3A(8 zldeobE0;%Uzy4OpHd_#ynfKnJ@vcloc~_>II+!RrJ2<*98#y}u=4bCB?*Hgf-(55- zsn33$1tIJl{0=GXEGDZ6Crn6PsR`d}r4Gc&+rpFwl}aXT5N|Zc!l3~h-;Oz^5t08! z;;Piow}8UU#Zq_4NS5kLp)tA~EjF3JWzwvgUD!MY!WRDLjKv5%aA{`8Cyj&xSepHx$^Oufn^5Ga8zD&CFrO zuDWhF>hpBzIn4YiBdLMSbl`#XcELOvS6OB2EpAI7m)~zSY>XxIOHSwe@>HDZ=t?&8 zJY!R1yGGd6@WGMJ0it@rGG+U1c|<5rMm2rIMQWcakq|@EDW8K!+E7-p(C*Shk4dyI z23vjC(-G=z(8Yc6zgW`RZPez9;iT->DB<>h53;hYy>+(S-fpPp!m-k9-DhC@D7*E8 zL+lCp&N+&oC3=Qj9#+Q{=}4s?dr5G2m&0j4JI5{^SLJo+cIfH+dp+X-KT1xRzm_VH zU##k(TmI?&bpU6xw^Sb97ra&S{BLl-R6OzCB6AF;ugs=u4V6`{UdV48-sk4uBS_em zpr6n?tBu|lS=2wX+Qh-x>_4=AAG7~D-sL^-8)tCB&x5w|_cy8RvZXC~6<37`VC-o& zMXv1WIsGLIHoCj4Iu^(H0J45Pe4bZ{#@%UhH;_w<+9@=0Fi}EIjMmMJvtG>+4odrc zDnT6D!jVYZGo9~xyViVN9YD)kz%55BO?-0Uw`9wsu6!KcZtziEG(5Txd^^f(Bdaef zEU$en0c;{Q^$^n#*9acHE74-EVsHXvlcjcE0oyou@p+vCR*Ad0HPG}MxzJChbIHwu z=@%u1XUU8YD6v1gDo2dhTcm*ZczuFH4&$Y1ujNkF?OIMkYNXr;Sn10xUJJY>7_DFm zoE@N?6OU%;wS=FtfsM$(@Jy$d!;4tcg>`&X}d&qrNF7&S!Oc zXuR=k!6M;b(OmfNMw_pO0Kils1)eb$x!%X`AG8AnV|-6i{(jHeKS%kW*T31prYQ5T z0ROt5=AVYYU5npW=s)eQ`K#f-ZZY_?;rP2w`G4MU@K>C_3eEpOLWKP{+4*0M|0;|A z!#E4>Z$;971^BBh?GFGw)c=0^zlqfT?@ix* m|7!iOtLUGtdD;JD{m(U3Q3mpzX&@j7zkS}x+Q9kSum1y9|I}#! diff --git a/tests/recursive/ls2003_bayesian_xls.mod b/tests/recursive/ls2003_bayesian_xls.mod index 57c46c6b6..c0b048a60 100644 --- a/tests/recursive/ls2003_bayesian_xls.mod +++ b/tests/recursive/ls2003_bayesian_xls.mod @@ -1,3 +1,9 @@ +if ~isoctave() && ~matlab_ver_less_than('8.4') + websave('data_ca1_xls.xlsx','http://www.dynare.org/Datasets/data_ca1_xls.xlsx') +else + urlwrite('http://www.dynare.org/Datasets/data_ca1_xls.xlsx','data_ca1_xls.xlsx') +end + var y y_s R pie dq pie_s de A y_obs pie_obs R_obs; varexo e_R e_q e_ys e_pies e_A; @@ -63,3 +69,4 @@ end; estimation(datafile=data_ca1_xls,first_obs=8,nobs=[76 79],mh_nblocks=1,prefilter=1,mh_jscale=0.5,mh_replic=2000,forecast=8) y_obs R_obs pie_obs dq de; +delete('data_ca1_xls.xlsx') From 58641d0efc01c56dd4b77b28510f467fe5ce0c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 14 Apr 2015 15:51:50 +0200 Subject: [PATCH 113/210] Added gsa/ls2003a.mod in testuite. --- tests/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 14e46b716..801229acd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,6 +7,7 @@ MODFILES = \ estimation/fs2000_initialize_from_calib.mod \ estimation/fs2000_calibrated_covariance.mod \ gsa/ls2003.mod \ + gsa/ls2003a.mod \ ramst.mod \ ramst_a.mod \ ramst_static_tag.mod \ From a7f0366980540d668a4b54bb8517798e1ae4deac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 15 Apr 2015 12:31:09 +0200 Subject: [PATCH 114/210] Removed gsa/ls2003a.mod from the test suite (which causes a segmentation fault and breaks the test suite). --- tests/Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 8120d7784..8b060a700 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,7 +7,6 @@ MODFILES = \ estimation/fs2000_initialize_from_calib.mod \ estimation/fs2000_calibrated_covariance.mod \ gsa/ls2003.mod \ - gsa/ls2003a.mod \ ramst.mod \ ramst_a.mod \ ramst_static_tag.mod \ From f0770186ca11c18181df63640fe50f2211b7858d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 15 Apr 2015 12:42:08 +0200 Subject: [PATCH 115/210] Exhanged mode_compute=2 and mode_compute=102. These options are for the simulated annealing algorithm, the Mathworks' global optimization toolbox is mandatory for mode_compute=102. The first option relies on a free implementation (works also with Octave). --- .../optimization/dynare_minimize_objective.m | 116 +++++++++--------- 1 file changed, 56 insertions(+), 60 deletions(-) diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 7d3812a22..c0259880b 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -87,18 +87,54 @@ switch minimizer_algorithm [opt_par_values,fval,exitflag,output,lamdba,grad,hessian_mat] = ... fmincon(objective_function,start_par_value,[],[],[],[],bounds(:,1),bounds(:,2),[],optim_options,varargin{:}); case 2 - if isoctave - error('Optimization algorithm 2 is not available under Octave') - elseif ~user_has_matlab_license('GADS_Toolbox') - error('Optimization algorithm 2 requires the Optimization Toolbox') - end - % Set default optimization options for fmincon. - optim_options = saoptimset('display','iter','TolFun',1e-8); + %simulating annealing + sa_options = options_.saopt; if ~isempty(options_.optim_opt) - eval(['optim_options = saoptimset(optim_options,' options_.optim_opt ');']); + options_list = read_key_value_string(options_.optim_opt); + for i=1:rows(options_list) + switch options_list{i,1} + case 'neps' + sa_options.neps = options_list{i,2}; + case 'rt' + sa_options.rt = options_list{i,2}; + case 'MaxIter' + sa_options.MaxIter = options_list{i,2}; + case 'TolFun' + sa_options.TolFun = options_list{i,2}; + case 'verbosity' + sa_options.verbosity = options_list{i,2}; + case 'initial_temperature' + sa_options.initial_temperature = options_list{i,2}; + case 'ns' + sa_options.ns = options_list{i,2}; + case 'nt' + sa_options.nt = options_list{i,2}; + case 'step_length_c' + sa_options.step_length_c = options_list{i,2}; + case 'initial_step_length' + sa_options.initial_step_length = options_list{i,2}; + otherwise + warning(['solveopt: Unknown option (' options_list{i,1} ')!']) + end + end end - func = @(x)objective_function(x,varargin{:}); - [opt_par_values,fval,exitflag,output] = simulannealbnd(func,start_par_value,bounds(:,1),bounds(:,2),optim_options); + npar=length(start_par_value); + LB=bounds(:,1); + LB(isinf(LB))=-1e6; + UB=bounds(:,2); + UB(isinf(UB))=1e6; + fprintf('\nNumber of parameters= %d, initial temperatur= %4.3f \n', npar,sa_options.initial_temperature); + fprintf('rt= %4.3f; TolFun= %4.3f; ns= %4.3f;\n',sa_options.rt,sa_options.TolFun,sa_options.ns); + fprintf('nt= %4.3f; neps= %4.3f; MaxIter= %d\n',sa_options.nt,sa_options.neps,sa_options.MaxIter); + fprintf('Initial step length(vm): %4.3f; step_length_c: %4.3f\n', sa_options.initial_step_length,sa_options.step_length_c); + fprintf('%-20s %-6s %-6s %-6s\n','Name:', 'LB;','Start;','UB;'); + for pariter=1:npar + fprintf('%-20s %6.4f; %6.4f; %6.4f;\n',parameter_names{pariter}, LB(pariter),start_par_value(pariter),UB(pariter)); + end + sa_options.initial_step_length= sa_options.initial_step_length*ones(npar,1); %bring step length to correct vector size + sa_options.step_length_c= sa_options.step_length_c*ones(npar,1); %bring step_length_c to correct vector size + [opt_par_values, fval,exitflag, n_accepted_draws, n_total_draws, n_out_of_bounds_draws, t, vm] =... + simulated_annealing(objective_function,start_par_value,sa_options,LB,UB,varargin{:}); case 3 if isoctave && ~user_has_octave_forge_package('optim') error('Optimization algorithm 3 requires the optim package') @@ -313,58 +349,18 @@ switch minimizer_algorithm end [opt_par_values,fval]=solvopt(start_par_value,objective_function,[],[],[],solveoptoptions,varargin{:}); case 102 - %simulating annealing - sa_options = options_.saopt; + if isoctave + error('Optimization algorithm 2 is not available under Octave') + elseif ~user_has_matlab_license('GADS_Toolbox') + error('Optimization algorithm 2 requires the Global Optimization Toolbox') + end + % Set default optimization options for fmincon. + optim_options = saoptimset('display','iter','TolFun',1e-8); if ~isempty(options_.optim_opt) - options_list = read_key_value_string(options_.optim_opt); - for i=1:rows(options_list) - switch options_list{i,1} - case 'neps' - sa_options.neps = options_list{i,2}; - case 'rt' - sa_options.rt = options_list{i,2}; - case 'MaxIter' - sa_options.MaxIter = options_list{i,2}; - case 'TolFun' - sa_options.TolFun = options_list{i,2}; - case 'verbosity' - sa_options.verbosity = options_list{i,2}; - case 'initial_temperature' - sa_options.initial_temperature = options_list{i,2}; - case 'ns' - sa_options.ns = options_list{i,2}; - case 'nt' - sa_options.nt = options_list{i,2}; - case 'step_length_c' - sa_options.step_length_c = options_list{i,2}; - case 'initial_step_length' - sa_options.initial_step_length = options_list{i,2}; - otherwise - warning(['solveopt: Unknown option (' options_list{i,1} ')!']) - end - end + eval(['optim_options = saoptimset(optim_options,' options_.optim_opt ');']); end - - npar=length(start_par_value); - LB=bounds(:,1); - LB(isinf(LB))=-1e6; - UB=bounds(:,2); - UB(isinf(UB))=1e6; - - fprintf('\nNumber of parameters= %d, initial temperatur= %4.3f \n', npar,sa_options.initial_temperature); - fprintf('rt= %4.3f; TolFun= %4.3f; ns= %4.3f;\n',sa_options.rt,sa_options.TolFun,sa_options.ns); - fprintf('nt= %4.3f; neps= %4.3f; MaxIter= %d\n',sa_options.nt,sa_options.neps,sa_options.MaxIter); - fprintf('Initial step length(vm): %4.3f; step_length_c: %4.3f\n', sa_options.initial_step_length,sa_options.step_length_c); - fprintf('%-20s %-6s %-6s %-6s\n','Name:', 'LB;','Start;','UB;'); - for pariter=1:npar - fprintf('%-20s %6.4f; %6.4f; %6.4f;\n',parameter_names{pariter}, LB(pariter),start_par_value(pariter),UB(pariter)); - end - - sa_options.initial_step_length= sa_options.initial_step_length*ones(npar,1); %bring step length to correct vector size - sa_options.step_length_c= sa_options.step_length_c*ones(npar,1); %bring step_length_c to correct vector size - - [opt_par_values, fval,exitflag, n_accepted_draws, n_total_draws, n_out_of_bounds_draws, t, vm] =... - simulated_annealing(objective_function,start_par_value,sa_options,LB,UB,varargin{:}); + func = @(x)objective_function(x,varargin{:}); + [opt_par_values,fval,exitflag,output] = simulannealbnd(func,start_par_value,bounds(:,1),bounds(:,2),optim_options); otherwise if ischar(minimizer_algorithm) if exist(options_.mode_compute) From 79d0310c10b8514faf25b35b4bab4018a2a78b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 15 Apr 2015 12:48:03 +0200 Subject: [PATCH 116/210] Added traps if some optimization algorithm are not availabe (testsuite). --- tests/optimizers/fs2000.mod | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/optimizers/fs2000.mod b/tests/optimizers/fs2000.mod index 184b2427f..6da79bd48 100644 --- a/tests/optimizers/fs2000.mod +++ b/tests/optimizers/fs2000.mod @@ -131,19 +131,32 @@ end; varobs gp_obs gy_obs; options_.plot_priors=0; -estimation(mode_compute=3,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); + +estimation(mode_compute=2,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); + +if exist('fminunc','file') + estimation(mode_compute=3,datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +end + estimation(mode_compute=4,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); estimation(mode_compute=5,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -estimation(mode_compute=7,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); + +if exist('fminsearch','file') + estimation(mode_compute=7,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +end + estimation(mode_compute=8,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); estimation(mode_compute=9,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); estimation(mode_compute=10,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); estimation(mode_compute=101,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -estimation(mode_compute=102,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); + +if ~isoctave() && exist('simulannealbnd','file') + estimation(mode_compute=102,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +end + estimation(mode_compute=optimizer_function_wrapper,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); estimation(mode_compute=6,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); - /* * The following lines were used to generate the data file. If you want to * generate another random data file, comment the "estimation" line and uncomment From 41cebf7e4e0f76f50d4ded96b63d449ea7084991 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 15 Apr 2015 22:54:36 +0200 Subject: [PATCH 117/210] - fix nograph option in GSA graphical output - fix graphical output issues on unix --- matlab/gsa/map_calibration.m | 144 +++++++++++++++++++---------------- matlab/gsa/mcf_analysis.m | 2 +- 2 files changed, 80 insertions(+), 66 deletions(-) diff --git a/matlab/gsa/map_calibration.m b/matlab/gsa/map_calibration.m index d391cee79..65d7857b4 100644 --- a/matlab/gsa/map_calibration.m +++ b/matlab/gsa/map_calibration.m @@ -167,11 +167,13 @@ if ~isempty(indx_irf), iplot_indx = ones(size(plot_indx)); indx_irf = indx_irf(irestrictions,:); - h1=dyn_figure(DynareOptions,'name',[type ' evaluation of irf restrictions']); - nrow=ceil(sqrt(nbr_irf_couples)); - ncol=nrow; - if nrow*(nrow-1)>nbr_irf_couples, - ncol=nrow-1; + if ~DynareOptions.nograph, + h1=dyn_figure(DynareOptions,'name',[type ' evaluation of irf restrictions']); + nrow=ceil(sqrt(nbr_irf_couples)); + ncol=nrow; + if nrow*(nrow-1)>nbr_irf_couples, + ncol=nrow-1; + end end for ij=1:nbr_irf_restrictions, mat_irf{ij}=mat_irf{ij}(irestrictions,:); @@ -193,8 +195,8 @@ if ~isempty(indx_irf), aleg = [aleg,'-' ,num2str(endo_prior_restrictions.irf{ij,3}(end))]; iplot_indx(ij)=0; end - if length(time_matrix{plot_indx(ij)})==1, - figure(h1), + if ~DynareOptions.nograph && length(time_matrix{plot_indx(ij)})==1, + set(0,'currentfigure',h1), subplot(nrow,ncol, plot_indx(ij)), hc = cumplot(mat_irf{ij}(:,ik)); set(hc,'color','k','linewidth',2) @@ -242,36 +244,38 @@ if ~isempty(indx_irf), end for ij=1:nbr_irf_couples, if length(time_matrix{ij})>1, - figure(h1); - subplot(nrow,ncol, ij) - itmp = (find(plot_indx==ij)); - plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2) - hold on, - plot(time_matrix{ij},irf_median{ij},'k','linewidth',2) - plot(time_matrix{ij},[irf_distrib{ij}],'k-') - a=axis; - tmp=[]; - for ir=1:length(itmp), - for it=1:length(endo_prior_restrictions.irf{itmp(ir),3}) - temp_index = find(time_matrix{ij}==endo_prior_restrictions.irf{itmp(ir),3}(it)); - tmp(temp_index,:) = endo_prior_restrictions.irf{itmp(ir),4}; + if ~DynareOptions.nograph, + figure(h1); + subplot(nrow,ncol, ij) + itmp = (find(plot_indx==ij)); + plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2) + hold on, + plot(time_matrix{ij},irf_median{ij},'k','linewidth',2) + plot(time_matrix{ij},[irf_distrib{ij}],'k-') + a=axis; + tmp=[]; + for ir=1:length(itmp), + for it=1:length(endo_prior_restrictions.irf{itmp(ir),3}) + temp_index = find(time_matrix{ij}==endo_prior_restrictions.irf{itmp(ir),3}(it)); + tmp(temp_index,:) = endo_prior_restrictions.irf{itmp(ir),4}; + end end + % tmp = cell2mat(endo_prior_restrictions.irf(itmp,4)); + tmp(isinf(tmp(:,1)),1)=a(3); + tmp(isinf(tmp(:,2)),2)=a(4); + hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); + set(hp,'FaceAlpha',[0.5]) + plot(a(1:2),[0 0],'r') + hold off, + axis([max(1,a(1)) a(2:4)]) + box on, + set(gca,'xtick',sort(time_matrix{ij})) + itmp = min(itmp); + title([endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}],'interpreter','none'), end - % tmp = cell2mat(endo_prior_restrictions.irf(itmp,4)); - tmp(isinf(tmp(:,1)),1)=a(3); - tmp(isinf(tmp(:,2)),2)=a(4); - hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); - set(hp,'FaceAlpha',[0.5]) - plot(a(1:2),[0 0],'r') - hold off, - axis([max(1,a(1)) a(2:4)]) - box on, - set(gca,'xtick',sort(time_matrix{ij})) - itmp = min(itmp); - title([endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}],'interpreter','none'), - if any(iplot_indx.*plot_indx==ij), % MCF of the couples with logical AND + itmp = min(find(plot_indx==ij)); indx1 = find(indx_irf_matrix(:,ij)==0); indx2 = find(indx_irf_matrix(:,ij)~=0); leg = num2str(time_matrix{ij}(1)); @@ -293,7 +297,9 @@ if ~isempty(indx_irf), end end end - dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions'],DynareOptions); + if ~DynareOptions.nograph, + dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions'],DynareOptions); + end skipline() end @@ -353,11 +359,13 @@ if ~isempty(indx_moment) iplot_indx = ones(size(plot_indx)); indx_moment = indx_moment(irestrictions,:); - h2=dyn_figure(DynareOptions,'name',[type ' evaluation of moment restrictions']); - nrow=ceil(sqrt(nbr_moment_couples)); - ncol=nrow; - if nrow*(nrow-1)>nbr_moment_couples, - ncol=nrow-1; + if ~DynareOptions.nograph, + h2=dyn_figure(DynareOptions,'name',[type ' evaluation of moment restrictions']); + nrow=ceil(sqrt(nbr_moment_couples)); + ncol=nrow; + if nrow*(nrow-1)>nbr_moment_couples, + ncol=nrow-1; + end end for ij=1:nbr_moment_restrictions, @@ -425,35 +433,38 @@ if ~isempty(indx_moment) end for ij=1:nbr_moment_couples, if length(time_matrix{ij})>1, - figure(h2); - subplot(nrow,ncol, ij) - itmp = (find(plot_indx==ij)); - plot(time_matrix{ij},[max(moment_matrix{ij})' min(moment_matrix{ij})'],'k--','linewidth',2) - hold on, - plot(time_matrix{ij},moment_median{ij},'k','linewidth',2) - plot(time_matrix{ij},[moment_distrib{ij}],'k-') - a=axis; - tmp=[]; - for ir=1:length(itmp), - for it=1:length(endo_prior_restrictions.moment{itmp(ir),3}) - temp_index = find(time_matrix{ij}==endo_prior_restrictions.moment{itmp(ir),3}(it)); - tmp(temp_index,:) = endo_prior_restrictions.moment{itmp(ir),4}; + if ~DynareOptions.nograph + itmp = (find(plot_indx==ij)); + set(0,'currentfigure',h2); + subplot(nrow,ncol, ij) + plot(time_matrix{ij},[max(moment_matrix{ij})' min(moment_matrix{ij})'],'k--','linewidth',2) + hold on, + plot(time_matrix{ij},moment_median{ij},'k','linewidth',2) + plot(time_matrix{ij},[moment_distrib{ij}],'k-') + a=axis; + tmp=[]; + for ir=1:length(itmp), + for it=1:length(endo_prior_restrictions.moment{itmp(ir),3}) + temp_index = find(time_matrix{ij}==endo_prior_restrictions.moment{itmp(ir),3}(it)); + tmp(temp_index,:) = endo_prior_restrictions.moment{itmp(ir),4}; + end end + % tmp = cell2mat(endo_prior_restrictions.moment(itmp,4)); + tmp(isinf(tmp(:,1)),1)=a(3); + tmp(isinf(tmp(:,2)),2)=a(4); + hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); + set(hp,'FaceAlpha',[0.5]) + plot(a(1:2),[0 0],'r') + hold off, + axis(a) + box on, + set(gca,'xtick',sort(time_matrix{ij})) + itmp = min(itmp); + title([endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}],'interpreter','none'), end - % tmp = cell2mat(endo_prior_restrictions.moment(itmp,4)); - tmp(isinf(tmp(:,1)),1)=a(3); - tmp(isinf(tmp(:,2)),2)=a(4); - hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); - set(hp,'FaceAlpha',[0.5]) - plot(a(1:2),[0 0],'r') - hold off, - axis(a) - box on, - set(gca,'xtick',sort(time_matrix{ij})) - itmp = min(itmp); - title([endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}],'interpreter','none'), if any(iplot_indx.*plot_indx==ij), % MCF of the couples with logical AND + itmp = min(find(plot_indx==ij)); indx1 = find(indx_moment_matrix(:,ij)==0); indx2 = find(indx_moment_matrix(:,ij)~=0); leg = num2str(time_matrix{ij}(1)); @@ -475,7 +486,10 @@ if ~isempty(indx_moment) end end end - dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions'],DynareOptions); + if ~DynareOptions.nograph, + dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions'],DynareOptions); + end + skipline() end return diff --git a/matlab/gsa/mcf_analysis.m b/matlab/gsa/mcf_analysis.m index fb46c51bc..82d7bfb7f 100644 --- a/matlab/gsa/mcf_analysis.m +++ b/matlab/gsa/mcf_analysis.m @@ -53,7 +53,7 @@ if length(ibeha)>10 && length(inobeha)>10, indcorr = indcorr(~ismember(indcorr(:),indmcf)); indmcf = [indmcf(:); indcorr(:)]; end -if ~isempty(indmcf) +if ~isempty(indmcf) && ~DynareOptions.nograph, skipline() scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names(indmcf,:), ... '.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,[], DynareOptions, ... From 31dc8630777454be2917ed32a9278049ea5b1275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 16 Apr 2015 00:30:52 +0200 Subject: [PATCH 118/210] Fixed graphic issue in tests/gsa/ls2003a.mod. We still need to find out why eps format does not work under matlab... --- tests/Makefile.am | 1 + tests/gsa/ls2003a.mod | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 8b060a700..8120d7784 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,6 +7,7 @@ MODFILES = \ estimation/fs2000_initialize_from_calib.mod \ estimation/fs2000_calibrated_covariance.mod \ gsa/ls2003.mod \ + gsa/ls2003a.mod \ ramst.mod \ ramst_a.mod \ ramst_static_tag.mod \ diff --git a/tests/gsa/ls2003a.mod b/tests/gsa/ls2003a.mod index c93e48c2c..19d5f88ba 100644 --- a/tests/gsa/ls2003a.mod +++ b/tests/gsa/ls2003a.mod @@ -99,7 +99,12 @@ y_obs,pie_obs(@{ilag}), -; //[ccf] @#endfor end; -dynare_sensitivity(prior_range=0, nodisplay, graph_format=(fig,eps)); +if isoctave() + dynare_sensitivity(prior_range=0, nodisplay, graph_format=(eps)); +else + dynare_sensitivity(prior_range=0, nodisplay, graph_format=(fig)); +end + /* estimation(datafile='data_ca1.m',first_obs=8,nobs=79,mh_nblocks=2, mode_file = ls2003a_mode, prefilter=1,mh_jscale=0.5,mh_replic=5000, mode_compute=0, mh_drop=0.6, bayesian_irf); From 8d679bff6f61896bd708629cfd2fa1f7fe0b0f2a Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Apr 2015 08:52:42 +0200 Subject: [PATCH 119/210] missing bits in fixes to graphical issues #881. --- matlab/gsa/map_calibration.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/gsa/map_calibration.m b/matlab/gsa/map_calibration.m index 65d7857b4..c9258f585 100644 --- a/matlab/gsa/map_calibration.m +++ b/matlab/gsa/map_calibration.m @@ -245,7 +245,7 @@ if ~isempty(indx_irf), for ij=1:nbr_irf_couples, if length(time_matrix{ij})>1, if ~DynareOptions.nograph, - figure(h1); + set(0,'currentfigure',h1); subplot(nrow,ncol, ij) itmp = (find(plot_indx==ij)); plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2) @@ -388,8 +388,8 @@ if ~isempty(indx_moment) aleg = [aleg,'_' ,num2str(endo_prior_restrictions.moment{ij,3}(end))]; iplot_indx(ij)=0; end - if length(time_matrix{plot_indx(ij)})==1, - figure(h2), + if ~DynareOptions.nograph && length(time_matrix{plot_indx(ij)})==1, + set(0,'currentfigure',h2); subplot(nrow,ncol,plot_indx(ij)), hc = cumplot(mat_moment{ij}(:,ik)); set(hc,'color','k','linewidth',2) From 4e1e7732fddf35352c1459c2a95e62f11e47f5d4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Apr 2015 12:30:27 +0200 Subject: [PATCH 120/210] fix graphic issues with eps --- matlab/gsa/map_calibration.m | 43 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/matlab/gsa/map_calibration.m b/matlab/gsa/map_calibration.m index c9258f585..6dae9fe51 100644 --- a/matlab/gsa/map_calibration.m +++ b/matlab/gsa/map_calibration.m @@ -199,13 +199,15 @@ if ~isempty(indx_irf), set(0,'currentfigure',h1), subplot(nrow,ncol, plot_indx(ij)), hc = cumplot(mat_irf{ij}(:,ik)); - set(hc,'color','k','linewidth',2) - hold all, a=axis; + delete(hc); x1val=max(endo_prior_restrictions.irf{ij,4}(1),a(1)); x2val=min(endo_prior_restrictions.irf{ij,4}(2),a(2)); hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b'); - set(hp,'FaceAlpha', 0.5) + hold all, + set(hp,'FaceColor', [0.7 0.8 1]) + hc = cumplot(mat_irf{ij}(:,ik)); + set(hc,'color','k','linewidth',2) hold off, % hold off, title([endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')'],'interpreter','none'), @@ -248,11 +250,9 @@ if ~isempty(indx_irf), set(0,'currentfigure',h1); subplot(nrow,ncol, ij) itmp = (find(plot_indx==ij)); - plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2) - hold on, - plot(time_matrix{ij},irf_median{ij},'k','linewidth',2) - plot(time_matrix{ij},[irf_distrib{ij}],'k-') + htmp = plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2); a=axis; + delete(htmp); tmp=[]; for ir=1:length(itmp), for it=1:length(endo_prior_restrictions.irf{itmp(ir),3}) @@ -263,8 +263,12 @@ if ~isempty(indx_irf), % tmp = cell2mat(endo_prior_restrictions.irf(itmp,4)); tmp(isinf(tmp(:,1)),1)=a(3); tmp(isinf(tmp(:,2)),2)=a(4); - hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); - set(hp,'FaceAlpha',[0.5]) + hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'c'); + set(hp,'FaceColor',[0.7 0.8 1]) + hold on, + plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2) + plot(time_matrix{ij},irf_median{ij},'k','linewidth',2) + plot(time_matrix{ij},[irf_distrib{ij}],'k-') plot(a(1:2),[0 0],'r') hold off, axis([max(1,a(1)) a(2:4)]) @@ -392,14 +396,15 @@ if ~isempty(indx_moment) set(0,'currentfigure',h2); subplot(nrow,ncol,plot_indx(ij)), hc = cumplot(mat_moment{ij}(:,ik)); - set(hc,'color','k','linewidth',2) - hold all, + a=axis; delete(hc), % hist(mat_moment{ij}), - a=axis; x1val=max(endo_prior_restrictions.moment{ij,4}(1),a(1)); x2val=min(endo_prior_restrictions.moment{ij,4}(2),a(2)); hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b'); - set(hp,'FaceAlpha', 0.5) + set(hp,'FaceColor', [0.7 0.8 1]) + hold all, + hc = cumplot(mat_moment{ij}(:,ik)); + set(hc,'color','k','linewidth',2) hold off, title([endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2},'(',leg,')'],'interpreter','none'), % if ij==maxij @@ -437,11 +442,9 @@ if ~isempty(indx_moment) itmp = (find(plot_indx==ij)); set(0,'currentfigure',h2); subplot(nrow,ncol, ij) - plot(time_matrix{ij},[max(moment_matrix{ij})' min(moment_matrix{ij})'],'k--','linewidth',2) - hold on, - plot(time_matrix{ij},moment_median{ij},'k','linewidth',2) - plot(time_matrix{ij},[moment_distrib{ij}],'k-') + htmp = plot(time_matrix{ij},[max(moment_matrix{ij})' min(moment_matrix{ij})'],'k--','linewidth',2); a=axis; + delete(htmp); tmp=[]; for ir=1:length(itmp), for it=1:length(endo_prior_restrictions.moment{itmp(ir),3}) @@ -453,7 +456,11 @@ if ~isempty(indx_moment) tmp(isinf(tmp(:,1)),1)=a(3); tmp(isinf(tmp(:,2)),2)=a(4); hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],[tmp(:,1); tmp(end:-1:1,2)],'b'); - set(hp,'FaceAlpha',[0.5]) + set(hp,'FaceColor',[0.7 0.8 1]) + hold on, + plot(time_matrix{ij},[max(moment_matrix{ij})' min(moment_matrix{ij})'],'k--','linewidth',2) + plot(time_matrix{ij},moment_median{ij},'k','linewidth',2) + plot(time_matrix{ij},[moment_distrib{ij}],'k-') plot(a(1:2),[0 0],'r') hold off, axis(a) From ae6302c348e618a1b54316034a26752c7be792a4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Apr 2015 16:09:39 +0200 Subject: [PATCH 121/210] Added output argument to mcf_analysis.m --- matlab/gsa/filt_mc_.m | 2 +- matlab/gsa/mcf_analysis.m | 2 +- matlab/gsa/stab_map_.m | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m index fbc25214f..6d562206d 100644 --- a/matlab/gsa/filt_mc_.m +++ b/matlab/gsa/filt_mc_.m @@ -588,7 +588,7 @@ else options_mcf.beha_title = ['better fit of ' deblank(vvarvecm(iy,:))]; options_mcf.nobeha_title = ['worse fit of ' deblank(vvarvecm(iy,:))]; options_mcf.title = ['the fit of ' deblank(vvarvecm(iy,:))]; - mcf_analysis(x, ixx(1:nfilt0(iy),iy), ixx(nfilt0(iy)+1:end,iy), options_mcf, options_) + mcf_analysis(x, ixx(1:nfilt0(iy),iy), ixx(nfilt0(iy)+1:end,iy), options_mcf, options_); end for iy=1:size(vvarvecm,1), ipar = find(any(squeeze(PPV(iy,:,:))0 || length(iwrong)>0, options_mcf.beha_title = 'unique Stable Saddle-Path'; options_mcf.nobeha_title = 'NO unique Stable Saddle-Path'; options_mcf.title = 'unique solution'; - mcf_analysis(lpmat, istable, itmp, options_mcf, options_) + mcf_analysis(lpmat, istable, itmp, options_mcf, options_); if ~isempty(iindeterm), itmp = itot(find(~ismember(itot,iindeterm))); @@ -570,7 +570,7 @@ if length(iunstable)>0 || length(iwrong)>0, options_mcf.beha_title = 'NO indeterminacy'; options_mcf.nobeha_title = 'indeterminacy'; options_mcf.title = 'indeterminacy'; - mcf_analysis(lpmat, itmp, iindeterm, options_mcf, options_) + mcf_analysis(lpmat, itmp, iindeterm, options_mcf, options_); end if ~isempty(ixun), @@ -580,7 +580,7 @@ if length(iunstable)>0 || length(iwrong)>0, options_mcf.beha_title = 'NO explosive solution'; options_mcf.nobeha_title = 'explosive solution'; options_mcf.title = 'instability'; - mcf_analysis(lpmat, itmp, ixun, options_mcf, options_) + mcf_analysis(lpmat, itmp, ixun, options_mcf, options_); end inorestriction = istable(find(~ismember(istable,irestriction))); % what went wrong beyong prior restrictions @@ -592,7 +592,7 @@ if length(iunstable)>0 || length(iwrong)>0, options_mcf.beha_title = 'NO inability to find a solution'; options_mcf.nobeha_title = 'inability to find a solution'; options_mcf.title = 'inability to find a solution'; - mcf_analysis(lpmat, itmp, iwrong, options_mcf, options_) + mcf_analysis(lpmat, itmp, iwrong, options_mcf, options_); end if ~isempty(irestriction), @@ -602,7 +602,7 @@ if length(iunstable)>0 || length(iwrong)>0, options_mcf.beha_title = 'prior IRF/moment calibration'; options_mcf.nobeha_title = 'NO prior IRF/moment calibration'; options_mcf.title = 'prior restrictions'; - mcf_analysis([lpmat0 lpmat], irestriction, inorestriction, options_mcf, options_) + mcf_analysis([lpmat0 lpmat], irestriction, inorestriction, options_mcf, options_); iok = irestriction(1); x0 = [lpmat0(iok,:)'; lpmat(iok,:)']; else From 0faf6e1981c45e95f05063047a5dbbcaa3bfcd7c Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Apr 2015 16:13:00 +0200 Subject: [PATCH 122/210] Allow inverse transform and set minimum threshold for lam --- matlab/gsa/log_trans_.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matlab/gsa/log_trans_.m b/matlab/gsa/log_trans_.m index d8c726c5f..2f48c7156 100644 --- a/matlab/gsa/log_trans_.m +++ b/matlab/gsa/log_trans_.m @@ -1,4 +1,4 @@ -function [yy, xdir, isig, lam]=log_trans_(y0,xdir0) +function [yy, xdir, isig, lam]=log_trans_(y0,xdir0,isig,lam) % Copyright (C) 2012 Dynare Team % @@ -17,6 +17,12 @@ function [yy, xdir, isig, lam]=log_trans_(y0,xdir0) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . +if nargin==4, + % inverse transformation + yy = (exp(y0)-lam)*isig; + return +end + if nargin==1, xdir0=''; end @@ -67,5 +73,6 @@ else lam = -min(y0)+abs(median(y0)); %abs(100*(1+min(y0))); end end + lam = max(lam,0); yy = log(y0+lam); end From 57e9b9fa8bdaf6bbe24992c319d79752fb9339b5 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Apr 2015 16:13:16 +0200 Subject: [PATCH 123/210] Revived reduced form mapping routine: 1) use new mcf_analysis.m; 2) use generic filtering when threshold does not work; 3) make log-tranformed mapping meaningful and comparable to baseline; 3) harmonize names of files saved and reduced number of directories created; --- matlab/gsa/redform_map.m | 492 ++++++++++++++++++++++++++++++++------- 1 file changed, 403 insertions(+), 89 deletions(-) diff --git a/matlab/gsa/redform_map.m b/matlab/gsa/redform_map.m index 7421e1c92..448b1a634 100644 --- a/matlab/gsa/redform_map.m +++ b/matlab/gsa/redform_map.m @@ -53,21 +53,31 @@ alpha2 = options_gsa_.alpha2_redform; alpha2=0; pvalue_ks = options_gsa_.ksstat_redform; pvalue_corr = options_gsa_.alpha2_redform; +pnames = M_.param_names(estim_params_.param_vals(:,1),:); +fname_ = M_.fname; bounds = prior_bounds(bayestopt_,options_); -pnames = M_.param_names(estim_params_.param_vals(:,1),:); if nargin==0, dirname=''; end if pprior load([dirname,filesep,M_.fname,'_prior'],'lpmat', 'lpmat0', 'istable','T'); - adir=[dirname filesep 'redform_stab']; + adir=[dirname filesep 'redform_prior']; + type = 'prior'; else load([dirname,filesep,M_.fname,'_mc'],'lpmat', 'lpmat0', 'istable','T'); adir=[dirname filesep 'redform_mc']; + type = 'mc'; end +options_mcf.pvalue_ks = options_gsa_.ksstat_redform; +options_mcf.pvalue_corr = options_gsa_.alpha2_redform; +options_mcf.alpha2 = options_gsa_.alpha2_redform; +options_mcf.param_names = pnames; +options_mcf.fname_ = M_.fname; +options_mcf.OutputDirectoryName = adir; + if ~exist('T') stab_map_(dirname,options_gsa_); if pprior @@ -106,6 +116,15 @@ else pd = [bayestopt_.p6(offset+1:end) bayestopt_.p7(offset+1:end) bayestopt_.p3(offset+1:end) bayestopt_.p4(offset+1:end)]; end +options_map.param_names = pnames; +options_map.fname_ = M_.fname; +options_map.OutputDirectoryName = adir; +options_map.iload = iload; +options_map.log_trans = ilog; +options_map.prior_range = options_gsa_.prior_range; +options_map.pshape = pshape; +options_map.pd = pd; + nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:))); lpmat=[]; lpmat0=[]; @@ -119,7 +138,7 @@ for j=1:size(anamendo,1) namexo=deblank(anamexo(jx,:)); iexo=strmatch(namexo,M_.exo_names,'exact'); skipline() - disp(['[', namendo,' vs. ',namexo,']']) + disp(['[', namendo,' vs ',namexo,']']) if ~isempty(iexo), @@ -128,7 +147,7 @@ for j=1:size(anamendo,1) if (max(y0)-min(y0))>1.e-10, if mod(iplo,9)==0 && isempty(threshold) && ~options_.nograph, ifig=ifig+1; - hfig = dyn_figure(options_,'name',['Reduced Form Mapping: ', namendo,' vs. shocks ',int2str(ifig)]); + hfig = dyn_figure(options_,'name',['Reduced Form Mapping: ', namendo,' vs shocks ',int2str(ifig)]); iplo=0; end iplo=iplo+1; @@ -139,7 +158,15 @@ for j=1:size(anamendo,1) if isempty(dir(xdir0)) mkdir(xdir0) end - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namexo, xdir0, options_gsa_); + atitle0=['Reduced Form Mapping (ANOVA) for ',namendo,' vs ', namexo]; + aname=[type '_' namendo '_vs_' namexo]; + atitle=[type ' Reduced Form Mapping (ANOVA): Parameter(s) driving ',namendo,' vs ',namexo]; + options_map.amap_name = aname; + options_map.amap_title = atitle; + options_map.figtitle = atitle0; + options_map.title = [namendo,' vs ', namexo]; + options_map.OutputDirectoryName = xdir0; + si(:,js) = redform_private(x0, y0, options_map, options_); else iy=find( (y0>threshold(1)) & (y0=threshold(2))); @@ -148,41 +175,65 @@ for j=1:size(anamendo,1) mkdir(xdir) end if ~options_.nograph, - hf=dyn_figure(options_,'name',['Reduced Form Mapping: ',namendo,' vs. ', namexo]); hist(y0,30), title([namendo,' vs. ', namexo],'interpreter','none') - dyn_saveas(hf,[xdir,filesep, namendo,'_vs_', namexo],options_); + hf=dyn_figure(options_,'name',['Reduced Form Mapping (Monte Carlo Filtering): ',namendo,' vs ', namexo]); + hc = cumplot(y0); + a=axis; delete(hc); + % hist(mat_moment{ij}), + x1val=max(threshold(1),a(1)); + x2val=min(threshold(2),a(2)); + hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b'); + set(hp,'FaceColor', [0.7 0.8 1]) + hold all, + hc = cumplot(y0); + set(hc,'color','k','linewidth',2) + hold off, + title([namendo,' vs ', namexo ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','none') + dyn_saveas(hf,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namexo],options_); end - % if ~isempty(iy), - % si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir, options_gsa_); - % else si(:,js) = NaN(np,1); - % end - if length(iy)>size(x0,2) && length(iyc)>size(x0,2) - delete([xdir, '/*threshold*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'threshold',0); - % indsmirnov = find(dproba>ksstat); - indsmirnov = find(proba1.e-10, if mod(iplo,9)==0 && isempty(threshold) && ~options_.nograph, ifig=ifig+1; - hfig = dyn_figure(options_,'name',['Reduced Form Mapping: ' namendo,' vs. lags ',int2str(ifig)]); + hfig = dyn_figure(options_,'name',['Reduced Form Mapping: ' namendo,' vs lags ',int2str(ifig)]); iplo=0; end iplo=iplo+1; @@ -240,7 +291,15 @@ for j=1:size(anamendo,1) if isempty(dir(xdir0)) mkdir(xdir0) end - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namlagendo, xdir0, options_gsa_); + atitle0=['Reduced Form Mapping (ANOVA) for ',namendo,' vs ', namlagendo]; + aname=[type '_' namendo '_vs_' namlagendo]; + atitle=[type ' Reduced Form Mapping (ANOVA): Parameter(s) driving ',namendo,' vs ',namlagendo]; + options_map.amap_name = aname; + options_map.amap_title = atitle; + options_map.figtitle = atitle0; + options_map.title = [namendo,' vs ', namlagendo]; + options_map.OutputDirectoryName = xdir0; + si(:,js) = redform_private(x0, y0, options_map, options_); else iy=find( (y0>threshold(1)) & (y0=threshold(2))); @@ -248,41 +307,67 @@ for j=1:size(anamendo,1) if isempty(dir(xdir)) mkdir(xdir) end - % if ~isempty(iy) - % si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namlagendo, xdir, options_gsa_); - % end if ~options_.nograph, - hf=dyn_figure(options_,'name',['Reduced Form Mapping: ',namendo,' vs. lagged ', namlagendo]); hist(y0,30), title([namendo,' vs. lagged ', namlagendo],'interpreter','none') - dyn_saveas(hf,[xdir,filesep, namendo,'_vs_', namlagendo],options_); + hf=dyn_figure(options_,'name',['Reduced Form Mapping (Monte Carlo Filtering): ',namendo,' vs lagged ', namlagendo]); + hc = cumplot(y0); + a=axis; delete(hc); + % hist(mat_moment{ij}), + x1val=max(threshold(1),a(1)); + x2val=min(threshold(2),a(2)); + hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b'); + set(hp,'FaceColor', [0.7 0.8 1]) + hold all, + hc = cumplot(y0); + set(hc,'color','k','linewidth',2) + hold off, + title([namendo,' vs lagged ', namlagendo ' - threshold [' num2str(threshold(1)) ' ' num2str(threshold(2)) ']'],'interpreter','none') + dyn_saveas(hf,[xdir,filesep, fname_ '_' type '_' namendo,'_vs_', namlagendo],options_); end - if length(iy)>size(x0,2) && length(iyc)>size(x0,2), - delete([xdir, '/*threshold*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'threshold',0); - % indsmirnov = find(dproba>ksstat); - indsmirnov = find(probanest, - gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames); +% gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[-1 -1 -1 -1 -1 0],[],0,[fname,'_est'], pnames); + [ys,is] = sort(y0); + istep = ceil(nrun/nest); + iest = is(floor(istep/2):istep:end); + nest = length(iest); + irest = is(setdiff([1:nrun],[floor(istep/2):istep:nrun])); + istep = ceil(length(irest)/(nfit-nest)); + ifit = union(iest, irest(1:istep:end)); + if ~ismember(irest(end),ifit), + ifit = union(ifit, irest(end)); + end + nfit=length(ifit); +% ifit = union(iest, irest(randperm(nrun-nest,nfit-nest))); +% ifit = iest; +% nfit=nest; + ipred = setdiff([1:nrun],ifit); + + if ilog, + [y1, tmp, isig, lam] = log_trans_(y0(iest)); + y1 = log(y0*isig+lam); end - save([fname,'.mat'],'gsa_') - [sidum, iii]=sort(-gsa_.si); - gsa_.x0=x00(1:nfit,:); if ~options_.nograph, - hfig=gsa_sdp_plot(gsa_,fname,pnames,iii(1:min(12,np))); - if options_.nodisplay - close(hfig); + hfig=dyn_figure(options_,'name',options_map.figtitle); + subplot(221) + if ilog, + hist(y1,30), + else + hist(y0,30), end + title(options_map.title,'interpreter','none') + subplot(222) + if ilog, + hc = cumplot(y1); + else + hc = cumplot(y0); + end + set(hc,'color','k','linewidth',2) + title([options_map.title ' CDF'],'interpreter','none') end - gsa_.x0=x0(1:nfit,:); + + gsa0 = ss_anova(y0(iest), x0(iest,:), 1); + if ilog, + [gsa22, gsa1, gsax] = ss_anova_log(y1(iest), x0(iest,:), isig, lam, gsa0); + end +% if (gsa1.out.bic-gsa0.out.bic) < 10, +% y00=y0; +% gsa00=gsa0; +% gsa0=gsa1; +% y0=y1; +% ilog=1; +% end +if nfit>nest, + % gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames); + nvr = gsa0.nvr*nest^3/nfit^3; + nvr(gsa0.stat<2) = gsa0.nvr(gsa0.stat<2)*nest^5/nfit^5; + gsa_ = ss_anova(y0(ifit), x0(ifit,:), 1, 0, 2, nvr); + if ilog + gsa0 = gsa_; + nvr1 = gsa1.nvr*nest^3/nfit^3; + nvr1(gsa1.stat<2) = gsa1.nvr(gsa1.stat<2)*nest^5/nfit^5; + nvrx = gsax.nvr*nest^3/nfit^3; + nvrx(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5; + [gsa22, gsa1, gsax] = ss_anova_log(y1(ifit), x0(ifit,:), isig, lam, gsa0, [nvr1' nvrx']); +% gsa1 = ss_anova(y1(ifit), x0(ifit,:), 1, 0, 2, nvr); +% gsa2=gsa1; +% gsa2.y = gsa0.y; +% gsa2.fit = (exp(gsa1.fit)-lam)*isig; +% gsa2.f0 = mean(gsa2.fit); +% gsa2.out.SSE = sum((gsa2.fit-gsa2.y).^2); +% gsa2.out.bic = gsa2.out.bic-nest*log(gsa1.out.SSE)+nest*log(gsa2.out.SSE); +% gsa2.r2 = 1-cov(gsa2.fit-gsa2.y)/cov(gsa2.y); +% for j=1:np, +% gsa2.fs(:,j) = exp(gsa1.fs(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0; +% gsa2.f(:,j) = exp(gsa1.f(:,j)).*mean(exp(gsa1.fit-gsa1.f(:,j)))*isig-lam*isig-gsa2.f0; +% gsa2.si(j) = var(gsa2.f(:,j))/var(gsa2.y); +% end +% nvr = gsax.nvr*nest^3/nfit^3; +% nvr(gsax.stat<2) = gsax.nvr(gsax.stat<2)*nest^5/nfit^5; +% gsax = ss_anova([gsa2.y-gsa2.fit], x0(ifit,:), 1, 0, 2, nvr); +% gsa22=gsa2; +% gsa22.fit = gsa2.fit+gsax.fit; +% gsa22.f0 = mean(gsa22.fit); +% gsa22.out.SSE = sum((gsa22.fit-gsa22.y).^2); +% gsa22.out.bic = nest*log(gsa22.out.SSE/nest) + (gsax.out.df+gsa2.out.df-1)*log(nest); +% gsa22.r2 = 1-sum((gsa22.fit-gsa22.y).^2)/sum((gsa22.y-mean(gsa22.y)).^2); +% for j=1:np, +% gsa22.fs(:,j) = gsa2.fs(:,j)+gsax.fs(:,j); +% gsa22.f(:,j) = gsa2.f(:,j)+gsax.f(:,j); +% gsa22.si(j) = var(gsa22.f(:,j))/var(gsa22.y); +% end + gsa_ = gsa22; + end +else + if ilog + gsa_ = gsa22; + else + gsa_ = gsa0; + end +end + save([fname,'_map.mat'],'gsa_') + [sidum, iii]=sort(-gsa_.si); + gsa_.x0=x00(ifit,:); + if ~options_.nograph, + hmap=gsa_sdp_plot(gsa_,[fname '_map'],pnames,iii(1:min(12,np))); + set(hmap,'name',options_map.amap_title); + end + gsa_.x0=x0(ifit,:); % copyfile([fname,'_est.mat'],[fname,'.mat']) if ~options_.nograph, - hfig=dyn_figure(options_,'name',['Reduced Form Mapping: ' namy,'_vs_', namx,'_fit']); - plot(y0(1:nfit),[gsa_.fit y0(1:nfit)],'.'), - title([namy,' vs. ', namx,' fit'],'interpreter','none') - dyn_saveas(hfig,[xdir,filesep, namy,'_vs_', namx,'_fit'],options_); + figure(hfig); + subplot(223), + plot(y0(ifit),[gsa_.fit y0(ifit)],'.'), + r2 = gsa_.r2; +% if ilog, +% plot(y00(ifit),[log_trans_(gsa_.fit,'',isig,lam) y00(ifit)],'.'), +% r2 = 1 - cov(log_trans_(gsa_.fit,'',isig,lam)-y00(ifit))/cov(y00(ifit)); +% else +% plot(y0(ifit),[gsa_.fit y0(ifit)],'.'), +% r2 = gsa_.r2; +% end + title(['Learning sample fit - R2=' num2str(r2,2)],'interpreter','none') if nfit=5 && ~isempty(gsa0), + for j=1:np, + nvr2(j) = var(diff(gsa2.fs(:,j),2)); + nvr0(j) = var(diff(gsa0.fs(:,j),2)); + end + inda = find((gsa0.stat<2)&(gsa1.stat>2)); + inda = inda(log10(nvr0(inda)./nvr2(inda))/2<0); + gsa1.nvr(inda)=gsa1.nvr(inda).*10.^(log10(nvr0(inda)./nvr2(inda))); + gsa1 = ss_anova(y, x, 1, 0, 2, gsa1.nvr); + gsa2 = log2level_map(gsa1, isig, lam); +end +if nargin==6, + gsax = ss_anova(gsa2.y-gsa2.fit, x, 1, 0, 2, nvrs(:,2)); +else + gsax = ss_anova(gsa2.y-gsa2.fit, x, 1); +end +gsa22=gsa2; +gsa22.fit = gsa2.fit+gsax.fit; +gsa22.f0 = mean(gsa22.fit); +gsa22.out.SSE = sum((gsa22.fit-gsa22.y).^2); +gsa22.out.bic = nest*log(gsa22.out.SSE/nest) + (gsax.out.df+gsa2.out.df-1)*log(nest); +gsa22.r2 = 1-sum((gsa22.fit-gsa22.y).^2)/sum((gsa22.y-mean(gsa22.y)).^2); +for j=1:np, + gsa22.fs(:,j) = gsa2.fs(:,j)+gsax.fs(:,j); + gsa22.fses(:,j) = gsax.fses(:,j); + gsa22.f(:,j) = gsa2.f(:,j)+gsax.f(:,j); + gsa22.si(j) = var(gsa22.f(:,j))/var(gsa22.y); +end + +return + +function indmcf = redform_mcf(y0, x0, options_mcf, options_) + +hfig=dyn_figure(options_,'name',options_mcf.amcf_title); + +[post_mean, post_median, post_var, hpd_interval, post_deciles, ... + density] = posterior_moments(y0,1,0.9); +post_deciles = [-inf; post_deciles; inf]; + +for jt=1:10, + indy{jt}=find( (y0>post_deciles(jt)) & (y0<=post_deciles(jt+1))); + leg{jt}=[int2str(jt) '-dec']; +end +[proba, dproba] = stab_map_1(x0, indy{1}, indy{end}, [],0); +indmcf=find(probanbr_par, + ncol=nrow-1; +end + +cmap = colormap(jet(10)); +for jx=1:nbr_par, + subplot(nrow,ncol,jx) + hold off + for jt=1:10, + h=cumplot(x0(indy{jt},indmcf(jx))); + set(h,'color', cmap(jt,:), 'linewidth', 2) + hold all, + end + title(options_mcf.param_names(indmcf(jx),:),'interpreter','none') +end +hleg = legend(leg); +aa=get(hleg,'Position'); +aa(1)=1-aa(3)-0.02; +aa(2)=0.02; +set(hleg,'Position',aa); +if ~isoctave + annotation('textbox', [0.25,0.01,0.5,0.05], ... + 'String', options_mcf.title, ... + 'Color','black',... + 'FontWeight','bold',... + 'interpreter','none',... + 'horizontalalignment','center'); +end + +dyn_saveas(hfig,[options_mcf.OutputDirectoryName filesep options_mcf.fname_,'_',options_mcf.amcf_name],options_); + +return From b0f4f2af78334a986a4e2f6be1954dcba74348ca Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Thu, 16 Apr 2015 18:03:07 +0200 Subject: [PATCH 124/210] Harmonize use of front-end mcf_analysis.m in GSA and identification routines. --- matlab/gsa/filt_mc_.m | 31 ++++++++++++++++++++++++++----- matlab/plot_identification.m | 23 ++++++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/matlab/gsa/filt_mc_.m b/matlab/gsa/filt_mc_.m index 6d562206d..472480135 100644 --- a/matlab/gsa/filt_mc_.m +++ b/matlab/gsa/filt_mc_.m @@ -242,18 +242,39 @@ end if ~options_.opt_gsa.ppost && options_.opt_gsa.lik_only if options_.opt_gsa.pprior anam='rmse_prior_post'; + atitle='RMSE prior: Log Posterior Kernel'; else anam='rmse_mc_post'; + atitle='RMSE MC: Log Posterior Kernel'; end - stab_map_1(x, ipost(1:nfilt), ipost(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ipost(1:nfilt),:),alpha2,pvalue,anam, OutDir); + + options_mcf.pvalue_ks = alpha; + options_mcf.pvalue_corr = pvalue; + options_mcf.alpha2 = alpha2; + options_mcf.param_names = char(bayestopt_.name); + options_mcf.fname_ = fname_; + options_mcf.OutputDirectoryName = OutDir; + options_mcf.amcf_name = anam; + options_mcf.amcf_title = atitle; + options_mcf.title = atitle; + options_mcf.beha_title = 'better posterior kernel'; + options_mcf.nobeha_title = 'worse posterior kernel'; + mcf_analysis(x, ipost(1:nfilt), ipost(nfilt+1:end), options_mcf, options_); + if options_.opt_gsa.pprior - anam='rmse_prior_lik'; + anam = 'rmse_prior_lik'; + atitle = 'RMSE prior: Log Likelihood Kernel'; else anam='rmse_mc_lik'; + atitle = 'RMSE MC: Log Likelihood Kernel'; end - stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ilik(1:nfilt),:),alpha2,pvalue,anam, OutDir); + options_mcf.amcf_name = anam; + options_mcf.amcf_title = atitle; + options_mcf.title = atitle; + options_mcf.beha_title = 'better likelihood'; + options_mcf.nobeha_title = 'worse likelihood'; + mcf_analysis(x, ilik(1:nfilt), ilik(nfilt+1:end), options_mcf, options_); + else if options_.opt_gsa.ppost, rmse_txt=rmse_pmean; diff --git a/matlab/plot_identification.m b/matlab/plot_identification.m index 4f9fcf98a..549224ef0 100644 --- a/matlab/plot_identification.m +++ b/matlab/plot_identification.m @@ -247,13 +247,30 @@ else hist(log10(idelre.cond)) title('log10 of Condition number in the LRE model') dyn_saveas(hh,[IdentifDirectoryName '/' M_.fname '_ident_COND' ],options_); + options_mcf.pvalue_ks = 0.1; + options_mcf.pvalue_corr = 0.001; + options_mcf.alpha2 = 0; + options_mcf.param_names = name; + options_mcf.fname_ = M_.fname; + options_mcf.OutputDirectoryName = IdentifDirectoryName; + options_mcf.beha_title = 'LOW condition nbr'; + options_mcf.nobeha_title = 'HIGH condition nbr'; + options_mcf.amcf_name = 'MC_HighestCondNumberLRE'; + options_mcf.amcf_title = 'MC Highest Condition Number LRE Model'; + options_mcf.title = 'MC Highest Condition Number LRE Model'; ncut=floor(SampleSize/10*9); [dum,is]=sort(idelre.cond); - [proba, dproba] = stab_map_1(params, is(1:ncut), is(ncut+1:end), 'MC_HighestCondNumberLRE', 1, [], IdentifDirectoryName, 0.1,'MC Highest Condition Number LRE Model'); + mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_); + options_mcf.amcf_name = 'MC_HighestCondNumberModel'; + options_mcf.amcf_title = 'MC Highest Condition Number Model Solution'; + options_mcf.title = 'MC Highest Condition Number Model Solution'; [dum,is]=sort(idemodel.cond); - [proba, dproba] = stab_map_1(params, is(1:ncut), is(ncut+1:end), 'MC_HighestCondNumberModel', 1, [], IdentifDirectoryName, 0.1,'MC Highest Condition Number Model Solution'); + mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_); + options_mcf.amcf_name = 'MC_HighestCondNumberMoments'; + options_mcf.amcf_title = 'MC Highest Condition Number Model Moments'; + options_mcf.title = 'MC Highest Condition Number Model Moments'; [dum,is]=sort(idemoments.cond); - [proba, dproba] = stab_map_1(params, is(1:ncut), is(ncut+1:end), 'MC_HighestCondNumberMoments', 1, [], IdentifDirectoryName, 0.1,'MC Highest Condition Number Model Moments'); + mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_); % [proba, dproba] = stab_map_1(idemoments.Mco', is(1:ncut), is(ncut+1:end), 'HighestCondNumberMoments_vs_Mco', 1, [], IdentifDirectoryName); % for j=1:nparam, % % ibeh=find(idemoments.Mco(j,:)<0.9); From fff07396d208d4f7d6d314eb158a8b3a5ebda0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 16 Apr 2015 22:26:24 +0200 Subject: [PATCH 125/210] Divided tests/optimizers/fs2000.mod into 12 mod files... Otherwise the execution of the testsuite is not parallelized. Also, added a test for mode_compute=1 (if fmincon from Mathworks' Optimization toolbox is available). --- tests/Makefile.am | 16 +++++++-- .../{fs2000.mod => fs2000.common.inc} | 34 ------------------- tests/optimizers/fs2000_1.mod | 5 +++ tests/optimizers/fs2000_10.mod | 3 ++ tests/optimizers/fs2000_101.mod | 3 ++ tests/optimizers/fs2000_102.mod | 5 +++ tests/optimizers/fs2000_2.mod | 3 ++ tests/optimizers/fs2000_3.mod | 5 +++ tests/optimizers/fs2000_4.mod | 3 ++ tests/optimizers/fs2000_5.mod | 3 ++ tests/optimizers/fs2000_6.mod | 3 ++ tests/optimizers/fs2000_7.mod | 5 +++ tests/optimizers/fs2000_8.mod | 3 ++ tests/optimizers/fs2000_9.mod | 3 ++ tests/optimizers/fs2000_w.mod | 3 ++ 15 files changed, 61 insertions(+), 36 deletions(-) rename tests/optimizers/{fs2000.mod => fs2000.common.inc} (62%) create mode 100644 tests/optimizers/fs2000_1.mod create mode 100644 tests/optimizers/fs2000_10.mod create mode 100644 tests/optimizers/fs2000_101.mod create mode 100644 tests/optimizers/fs2000_102.mod create mode 100644 tests/optimizers/fs2000_2.mod create mode 100644 tests/optimizers/fs2000_3.mod create mode 100644 tests/optimizers/fs2000_4.mod create mode 100644 tests/optimizers/fs2000_5.mod create mode 100644 tests/optimizers/fs2000_6.mod create mode 100644 tests/optimizers/fs2000_7.mod create mode 100644 tests/optimizers/fs2000_8.mod create mode 100644 tests/optimizers/fs2000_9.mod create mode 100644 tests/optimizers/fs2000_w.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 3ec5ba46f..107d778bb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -205,7 +205,18 @@ MODFILES = \ smoother2histval/fs2000_simul.mod \ smoother2histval/fs2000_smooth.mod \ smoother2histval/fs2000_smooth_stoch_simul.mod \ - optimizers/fs2000.mod \ + optimizers/fs2000_2.mod \ + optimizers/fs2000_3.mod \ + optimizers/fs2000_4.mod \ + optimizers/fs2000_5.mod \ + optimizers/fs2000_6.mod \ + optimizers/fs2000_7.mod \ + optimizers/fs2000_8.mod \ + optimizers/fs2000_9.mod \ + optimizers/fs2000_10.mod \ + optimizers/fs2000_101.mod \ + optimizers/fs2000_102.mod \ + optimizers/fs2000_w.mod \ reporting/example1.mod XFAIL_MODFILES = ramst_xfail.mod \ @@ -396,7 +407,8 @@ EXTRA_DIST = \ smoother2histval/fsdat_simul.m \ optimal_policy/Ramsey/find_c.m \ optimal_policy/Ramsey/oo_ramsey_policy_initval.mat \ - optimizers/optimizer_function_wrapper.m + optimizers/optimizer_function_wrapper.m \ + optimizers/fs2000.common.inc TARGETS = diff --git a/tests/optimizers/fs2000.mod b/tests/optimizers/fs2000.common.inc similarity index 62% rename from tests/optimizers/fs2000.mod rename to tests/optimizers/fs2000.common.inc index 6da79bd48..b0762753f 100644 --- a/tests/optimizers/fs2000.mod +++ b/tests/optimizers/fs2000.common.inc @@ -131,37 +131,3 @@ end; varobs gp_obs gy_obs; options_.plot_priors=0; - -estimation(mode_compute=2,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); - -if exist('fminunc','file') - estimation(mode_compute=3,datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -end - -estimation(mode_compute=4,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -estimation(mode_compute=5,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); - -if exist('fminsearch','file') - estimation(mode_compute=7,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -end - -estimation(mode_compute=8,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -estimation(mode_compute=9,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -estimation(mode_compute=10,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -estimation(mode_compute=101,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); - -if ~isoctave() && exist('simulannealbnd','file') - estimation(mode_compute=102,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -end - -estimation(mode_compute=optimizer_function_wrapper,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); -estimation(mode_compute=6,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); - -/* - * The following lines were used to generate the data file. If you want to - * generate another random data file, comment the "estimation" line and uncomment - * the following lines. - */ - -//stoch_simul(periods=200, order=1); -//datatomfile('fs2000/fsdat_simul', char('gy_obs', 'gp_obs')); diff --git a/tests/optimizers/fs2000_1.mod b/tests/optimizers/fs2000_1.mod new file mode 100644 index 000000000..fe3704835 --- /dev/null +++ b/tests/optimizers/fs2000_1.mod @@ -0,0 +1,5 @@ +@#include "fs2000.common.inc" + +if ~isoctave() && exist('fmincon','file') + estimation(mode_compute=1,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); +end diff --git a/tests/optimizers/fs2000_10.mod b/tests/optimizers/fs2000_10.mod new file mode 100644 index 000000000..d46ef9d85 --- /dev/null +++ b/tests/optimizers/fs2000_10.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=10,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_101.mod b/tests/optimizers/fs2000_101.mod new file mode 100644 index 000000000..d301ecd18 --- /dev/null +++ b/tests/optimizers/fs2000_101.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=101,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_102.mod b/tests/optimizers/fs2000_102.mod new file mode 100644 index 000000000..e43dcb254 --- /dev/null +++ b/tests/optimizers/fs2000_102.mod @@ -0,0 +1,5 @@ +@#include "fs2000.common.inc" + +if ~isoctave() && exist('simulannealbnd','file') + estimation(mode_compute=102,mode_file=fs2000_mode,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0, mh_nblocks=2, mh_jscale=0.8); +end diff --git a/tests/optimizers/fs2000_2.mod b/tests/optimizers/fs2000_2.mod new file mode 100644 index 000000000..bfd38c7c4 --- /dev/null +++ b/tests/optimizers/fs2000_2.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=2,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_3.mod b/tests/optimizers/fs2000_3.mod new file mode 100644 index 000000000..5efc98d2a --- /dev/null +++ b/tests/optimizers/fs2000_3.mod @@ -0,0 +1,5 @@ +@#include "fs2000.common.inc" + +if exist('fminunc','file') + estimation(mode_compute=3,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); +end diff --git a/tests/optimizers/fs2000_4.mod b/tests/optimizers/fs2000_4.mod new file mode 100644 index 000000000..c500afa7f --- /dev/null +++ b/tests/optimizers/fs2000_4.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=4,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_5.mod b/tests/optimizers/fs2000_5.mod new file mode 100644 index 000000000..16fdd957e --- /dev/null +++ b/tests/optimizers/fs2000_5.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=5,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_6.mod b/tests/optimizers/fs2000_6.mod new file mode 100644 index 000000000..7bd0673a7 --- /dev/null +++ b/tests/optimizers/fs2000_6.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=6,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_7.mod b/tests/optimizers/fs2000_7.mod new file mode 100644 index 000000000..3a58b5fa2 --- /dev/null +++ b/tests/optimizers/fs2000_7.mod @@ -0,0 +1,5 @@ +@#include "fs2000.common.inc" + +if exist('fminsearch','file') + estimation(mode_compute=7,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); +end diff --git a/tests/optimizers/fs2000_8.mod b/tests/optimizers/fs2000_8.mod new file mode 100644 index 000000000..f7415df12 --- /dev/null +++ b/tests/optimizers/fs2000_8.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=8,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_9.mod b/tests/optimizers/fs2000_9.mod new file mode 100644 index 000000000..96d75bf96 --- /dev/null +++ b/tests/optimizers/fs2000_9.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=9,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); diff --git a/tests/optimizers/fs2000_w.mod b/tests/optimizers/fs2000_w.mod new file mode 100644 index 000000000..73f6bdc62 --- /dev/null +++ b/tests/optimizers/fs2000_w.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=optimizer_function_wrapper,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0); From 84f0060cbdebf462c9e5238f8d4ce726fed2fad0 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 16 Apr 2015 17:48:30 +0200 Subject: [PATCH 126/210] Fix bug where inverse Hessian from csminwel1.m was taken as Hessian --- matlab/optimization/dynare_minimize_objective.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index c0259880b..9e8761bd2 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -190,8 +190,9 @@ switch minimizer_algorithm analytic_grad=[]; end % Call csminwell. - [fval,opt_par_values,grad,hessian_mat,itct,fcount,exitflag] = ... + [fval,opt_par_values,grad,inverse_hessian_mat,itct,fcount,exitflag] = ... csminwel1(objective_function, start_par_value, H0, analytic_grad, crit, nit, numgrad, epsilon, varargin{:}); + hessian_mat=inv(inverse_hessian_mat); case 5 if options_.analytic_derivation==-1 %set outside as code for use of analytic derivation analytic_grad=1; From b629d3ca19cf5bcf039f9d2b0ed8371cb60c96be Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 16 Apr 2015 17:50:02 +0200 Subject: [PATCH 127/210] Cosmetic changes to csminwel routines Mostly adds documentation --- matlab/bfgsi1.m | 15 +++++++++++---- matlab/optimization/csminit1.m | 32 +++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/matlab/bfgsi1.m b/matlab/bfgsi1.m index 48d58562d..c3b87ca49 100644 --- a/matlab/bfgsi1.m +++ b/matlab/bfgsi1.m @@ -1,13 +1,20 @@ function H = bfgsi1(H0,dg,dx) % H = bfgsi1(H0,dg,dx) -% dg is previous change in gradient; dx is previous change in x; +% Update Inverse Hessian matrix +% +% Inputs: +% H0 [npar by npar] initial inverse Hessian matrix +% dg [npar by 1] previous change in gradient +% dx [npar by 1] previous change in x; +% % 6/8/93 version that updates inverse hessian instead of hessian % itself. - +% % Original file downloaded from: % http://sims.princeton.edu/yftp/optimize/mfiles/bfgsi.m - +% % Copyright (C) 1993-2009 Christopher Sims +% Copyright (C) 2009-2015 Dynare Team % % This file is part of Dynare. % @@ -41,4 +48,4 @@ else disp(['|H*dg| = ' num2str(Hdg'*Hdg)]) H=H0; end -save H.dat H +save('H.dat','H') diff --git a/matlab/optimization/csminit1.m b/matlab/optimization/csminit1.m index b6eb95da0..b6574b005 100644 --- a/matlab/optimization/csminit1.m +++ b/matlab/optimization/csminit1.m @@ -1,10 +1,24 @@ function [fhat,xhat,fcount,retcode] = csminit1(fcn,x0,f0,g0,badg,H0,varargin) -% [fhat,xhat,fcount,retcode] = csminit1(fcn,x0,f0,g0,badg,H0,... -% P1,P2,P3,P4,P5,P6,P7,P8) -% retcodes: 0, normal step. 5, largest step still improves too fast. -% 4,2 back and forth adjustment of stepsize didn't finish. 3, smallest -% stepsize still improves too slow. 6, no improvement found. 1, zero -% gradient. +% [fhat,xhat,fcount,retcode] = csminit1(fcn,x0,f0,g0,badg,H0,varargin) +% +% Inputs: +% fcn: [string] string naming the objective function to be minimized +% x0: [npar by 1] initial value of the parameter vector +% g0: [npar by 1] initial value of the gradient vector +% H0: [npar by npar] initial value for the inverse Hessian. Must be positive definite. +% varargin: Optional additional inputs that get handed off to fcn each +% time it is called. + +% Outputs: +% fhat: [scalar] function value at minimum +% xhat: [npar by 1] parameter vector at minimum +% fcount [scalar] function iteration count upon termination +% retcode [scalar] 0: normal step +% 1: zero gradient. +% 5: largest step still improves too fast. +% 2,4: back and forth adjustment of stepsize didn't finish. +% 3: smallest stepsize still improves too slow +% 6: no improvement found %--------------------- % Modified 7/22/96 to omit variable-length P list, for efficiency and compilation. % Places where the number of P's need to be altered or the code could be returned to @@ -15,12 +29,12 @@ function [fhat,xhat,fcount,retcode] = csminit1(fcn,x0,f0,g0,badg,H0,varargin) % % Fixed 7/19/93 to flip eigenvalues of H to get better performance when % it's not psd. - +% % Original file downloaded from: % http://sims.princeton.edu/yftp/optimize/mfiles/csminit.m - +% % Copyright (C) 1993-2007 Christopher Sims -% Copyright (C) 2008-2011 Dynare Team +% Copyright (C) 2008-2015 Dynare Team % % This file is part of Dynare. % From bc6cf0345fe9a593445b9b9ea7a64ebe2052eceb Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 16 Apr 2015 17:51:05 +0200 Subject: [PATCH 128/210] Clean up csminwel1.m Adds documentation and puts calling of numerical gradient to nested function as previously suggested in comment at the bottom of file --- matlab/optimization/csminwel1.m | 241 +++++++++++++------------------- 1 file changed, 100 insertions(+), 141 deletions(-) diff --git a/matlab/optimization/csminwel1.m b/matlab/optimization/csminwel1.m index b6e38fedc..dcc579f50 100644 --- a/matlab/optimization/csminwel1.m +++ b/matlab/optimization/csminwel1.m @@ -1,29 +1,48 @@ function [fh,xh,gh,H,itct,fcount,retcodeh] = csminwel1(fcn,x0,H0,grad,crit,nit,method,epsilon,varargin) -%[fhat,xhat,ghat,Hhat,itct,fcount,retcodehat] = csminwel1(fcn,x0,H0,grad,crit,nit,method,epsilon,varargin) -% fcn: string naming the objective function to be minimized -% x0: initial value of the parameter vector -% H0: initial value for the inverse Hessian. Must be positive definite. -% grad: Either a string naming a function that calculates the gradient, or the null matrix. -% If it's null, the program calculates a numerical gradient. In this case fcn must -% be written so that it can take a matrix argument and produce a row vector of values. -% crit: Convergence criterion. Iteration will cease when it proves impossible to improve the -% function value by more than crit. -% nit: Maximum number of iterations. -% method: integer scalar, 2, 3 or 5 points formula. -% epsilon: scalar double, numerical differentiation increment -% varargin: A list of optional length of additional parameters that get handed off to fcn each -% time it is called. +%[fhat,xhat,ghat,Hhat,itct,fcount,retcodeh] = csminwel1(fcn,x0,H0,grad,crit,nit,method,epsilon,varargin) +% Inputs: +% fcn: [string] string naming the objective function to be minimized +% x0: [npar by 1] initial value of the parameter vector +% H0: [npar by npar] initial value for the inverse Hessian. Must be positive definite. +% grad: [string or empty matrix] Either a string naming a function that calculates the gradient, or the null matrix. +% If it's null, the program calculates a numerical gradient. In this case fcn must +% be written so that it can take a matrix argument and produce a row vector of values. +% crit: [scalar] Convergence criterion. Iteration will cease when it proves impossible to improve the +% function value by more than crit. +% nit: [scalar] Maximum number of iterations. +% method: [scalar] integer scalar for selecting gradient method: 2, 3 or 5 points formula. +% epsilon: [scalar] scalar double, numerical differentiation increment +% varargin: Optional additional inputs that get handed off to fcn each +% time it is called. +% % Note that if the program ends abnormally, it is possible to retrieve the current x, % f, and H from the files g1.mat and H.mat that are written at each iteration and at each % hessian update, respectively. (When the routine hits certain kinds of difficulty, it -% write g2.mat and g3.mat as well. If all were written at about the same time, any of them -% may be a decent starting point. One can also start from the one with best function value.) - +% writes g2.mat and g3.mat as well. If all were written at about the same time, any of them +% may be a decent starting point. One can also start from the one with best function value.) +% +% Outputs: +% fh: [scalar] function value at minimum +% xh: [npar by 1] parameter vector at minimum +% gh [npar by 1] gradient vector +% H [npar by npar] inverse of the Hessian matrix +% itct [scalar] iteration count upon termination +% fcount [scalar] function iteration count upon termination +% retcodeh [scalar] return code: +% 0: normal step +% 1: zero gradient +% 2: back and forth on step length never finished +% 3: smallest step still improving too slow +% 4: back and forth on step length never finished +% 5: largest step still improving too fast +% 6: smallest step still improving too slow, reversed gradient +% 7: warning: possible inaccuracy in H matrix +% % Original file downloaded from: % http://sims.princeton.edu/yftp/optimize/mfiles/csminwel.m - +% % Copyright (C) 1993-2007 Christopher Sims -% Copyright (C) 2006-2012 Dynare Team +% Copyright (C) 2006-2015 Dynare Team % % This file is part of Dynare. % @@ -51,7 +70,6 @@ NumGrad= isempty(grad); done=0; itct=0; fcount=0; -snit=100; gh = []; H = []; retcodeh = []; @@ -74,20 +92,7 @@ if ~cost_flag end if NumGrad - switch method - case 2 - [g,badg] = numgrad2(fcn, f0, x0, epsilon, varargin{:}); - case 3 - [g,badg] = numgrad3(fcn, f0, x0, epsilon, varargin{:}); - case 5 - [g,badg] = numgrad5(fcn, f0, x0, epsilon, varargin{:}); - case 13 - [g,badg] = numgrad3_(fcn, f0, x0, epsilon, varargin{:}); - case 15 - [g,badg] = numgrad5_(fcn, f0, x0, epsilon, varargin{:}); - otherwise - error('csminwel1: Unknown method for gradient evaluation!') - end + [g, badg]=get_num_grad(method,fcn,f0,x0,epsilon,varargin{:}); elseif ischar(grad) [g,badg] = feval(grad,x0,varargin{:}); else @@ -105,19 +110,15 @@ while ~done g1=[]; g2=[]; g3=[]; %addition fj. 7/6/94 for control - disp('-----------------') - disp('-----------------') - %disp('f and x at the beginning of new iteration') - disp(sprintf('f at the beginning of new iteration, %20.10f',f)) + if Verbose + disp('-----------------') + disp(sprintf('f at the beginning of new iteration, %20.10f',f)) + end %-----------Comment out this line if the x vector is long---------------- % disp([sprintf('x = ') sprintf('%15.8g %15.8g %15.8g %15.8g\n',x)]); %------------------------- itct=itct+1; - [f1 x1 fc retcode1] = csminit1(fcn,x,f,g,badg,H,varargin{:}); - %ARGLIST - %[f1 x1 fc retcode1] = csminit(fcn,x,f,g,badg,H,P1,P2,P3,P4,P5,P6,P7,... - % P8,P9,P10,P11,P12,P13); - % itct=itct+1; + [f1, x1, fc, retcode1] = csminit1(fcn,x,f,g,badg,H,varargin{:}); fcount = fcount+fc; % erased on 8/4/94 % if (retcode == 1) || (abs(f1-f) < crit) @@ -132,22 +133,9 @@ while ~done wall1=1; badg1=1; else if NumGrad - switch method - case 2 - [g1 badg1] = numgrad2(fcn, f1, x1, epsilon, varargin{:}); - case 3 - [g1 badg1] = numgrad3(fcn, f1, x1, epsilon, varargin{:}); - case 5 - [g1,badg1] = numgrad5(fcn, f1, x1, epsilon, varargin{:}); - case 13 - [g1,badg1] = numgrad3_(fcn, f1, x1, epsilon, varargin{:}); - case 15 - [g1,badg1] = numgrad5_(fcn, f1, x1, epsilon, varargin{:}); - otherwise - error('csminwel1: Unknown method for gradient evaluation!') - end + [g1, badg1]=get_num_grad(method,fcn,f1,x1,epsilon,varargin{:}); elseif ischar(grad), - [g1 badg1] = feval(grad,x1,varargin{:}); + [g1, badg1] = feval(grad,x1,varargin{:}); else [junk1,g1,junk2, cost_flag] = feval(fcn,x1,varargin{:}); badg1 = ~cost_flag; @@ -155,8 +143,6 @@ while ~done wall1=badg1; % g1 save g1.mat g1 x1 f1 varargin; - %ARGLIST - %save g1 g1 x1 f1 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; end if wall1 % && (~done) by Jinill % Bad gradient or back and forth on step length. Possibly at @@ -164,33 +150,19 @@ while ~done % %fcliff=fh;xcliff=xh; Hcliff=H+diag(diag(H).*rand(nx,1)); - disp('Cliff. Perturbing search direction.') - [f2 x2 fc retcode2] = csminit1(fcn,x,f,g,badg,Hcliff,varargin{:}); - %ARGLIST - %[f2 x2 fc retcode2] = csminit(fcn,x,f,g,badg,Hcliff,P1,P2,P3,P4,... - % P5,P6,P7,P8,P9,P10,P11,P12,P13); + if Verbose + disp('Cliff. Perturbing search direction.') + end + [f2, x2, fc, retcode2] = csminit1(fcn,x,f,g,badg,Hcliff,varargin{:}); fcount = fcount+fc; % put by Jinill if f2 < f if retcode2==2 || retcode2==4 wall2=1; badg2=1; else if NumGrad - switch method - case 2 - [g2 badg2] = numgrad2(fcn, f2, x2, epsilon, varargin{:}); - case 3 - [g2 badg2] = numgrad3(fcn, f2, x2, epsilon, varargin{:}); - case 5 - [g2,badg2] = numgrad5(fcn, f2, x2, epsilon, varargin{:}); - case 13 - [g2,badg2] = numgrad3_(fcn, f2, x2, epsilon, varargin{:}); - case 15 - [g2,badg2] = numgrad5_(fcn, f2, x2, epsilon, varargin{:}); - otherwise - error('csminwel1: Unknown method for gradient evaluation!') - end + [g2, badg2]=get_num_grad(method,fcn,f2,x2,epsilon,varargin{:}); elseif ischar(grad), - [g2 badg2] = feval(grad,x2,varargin{:}); + [g2, badg2] = feval(grad,x2,varargin{:}); else [junk1,g2,junk2, cost_flag] = feval(fcn,x1,varargin{:}); badg2 = ~cost_flag; @@ -199,8 +171,6 @@ while ~done % g2 badg2 save g2.mat g2 x2 f2 varargin - %ARGLIST - %save g2 g2 x2 f2 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; end if wall2 disp('Cliff again. Try traversing') @@ -208,33 +178,19 @@ while ~done f3=f; x3=x; badg3=1;retcode3=101; else gcliff=((f2-f1)/((norm(x2-x1))^2))*(x2-x1); - if(size(x0,2)>1), gcliff=gcliff', end - [f3 x3 fc retcode3] = csminit1(fcn,x,f,gcliff,0,eye(nx),varargin{:}); - %ARGLIST - %[f3 x3 fc retcode3] = csminit(fcn,x,f,gcliff,0,eye(nx),P1,P2,P3,... - % P4,P5,P6,P7,P8,... - % P9,P10,P11,P12,P13); + if(size(x0,2)>1) + gcliff=gcliff'; + end + [f3, x3, fc, retcode3] = csminit1(fcn,x,f,gcliff,0,eye(nx),varargin{:}); fcount = fcount+fc; % put by Jinill if retcode3==2 || retcode3==4 - wall3=1; badg3=1; + wall3=1; + badg3=1; else if NumGrad - switch method - case 2 - [g3 badg3] = numgrad2(fcn, f3, x3, epsilon, varargin{:}); - case 3 - [g3 badg3] = numgrad3(fcn, f3, x3, epsilon, varargin{:}); - case 5 - [g3,badg3] = numgrad5(fcn, f3, x3, epsilon, varargin{:}); - case 13 - [g3,badg3] = numgrad3_(fcn, f3, x3, epsilon, varargin{:}); - case 15 - [g3,badg3] = numgrad5_(fcn, f3, x3, epsilon, varargin{:}); - otherwise - error('csminwel1: Unknown method for gradient evaluation!') - end + [g3, badg3]=get_num_grad(method,fcn,f3,x3,epsilon,varargin{:}); elseif ischar(grad), - [g3 badg3] = feval(grad,x3,varargin{:}); + [g3, badg3] = feval(grad,x3,varargin{:}); else [junk1,g3,junk2, cost_flag] = feval(fcn,x1,varargin{:}); badg3 = ~cost_flag; @@ -242,8 +198,6 @@ while ~done wall3=badg3; % g3 save g3.mat g3 x3 f3 varargin; - %ARGLIST - %save g3 g3 x3 f3 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13; end end else @@ -292,22 +246,9 @@ while ~done end if nogh if NumGrad - switch method - case 2 - [gh,badgh] = numgrad2(fcn, fh, xh, epsilon, varargin{:}); - case 3 - [gh,badgh] = numgrad3(fcn, fh, xh, epsilon, varargin{:}); - case 5 - [gh,badgh] = numgrad5(fcn, fh, xh, epsilon, varargin{:}); - case 13 - [gh,badgh] = numgrad3_(fcn, fh, xh, epsilon, varargin{:}); - case 15 - [gh,badgh] = numgrad5_(fcn, fh, xh, epsilon, varargin{:}); - otherwise - error('csminwel1: Unknown method for gradient evaluation!') - end + [gh, badgh]=get_num_grad(method,fcn,fh,xh,epsilon,varargin{:}); elseif ischar(grad), - [gh badgh] = feval(grad, xh,varargin{:}); + [gh, badgh] = feval(grad, xh,varargin{:}); else [junk1,gh,junk2, cost_flag] = feval(fcn,x1,varargin{:}); badgh = ~cost_flag; @@ -316,11 +257,6 @@ while ~done badgh=1; end %end of picking - %ih - %fh - %xh - %gh - %badgh stuck = (abs(fh-f) < crit); if (~badg) && (~badgh) && (~stuck) H = bfgsi1(H,gh-g,xh-x); @@ -338,24 +274,47 @@ while ~done done = 1; end rc=retcodeh; - if rc == 1 - disp('zero gradient') - elseif rc == 6 - disp('smallest step still improving too slow, reversed gradient') - elseif rc == 5 - disp('largest step still improving too fast') - elseif (rc == 4) || (rc==2) - disp('back and forth on step length never finished') - elseif rc == 3 - disp('smallest step still improving too slow') - elseif rc == 7 - disp('warning: possible inaccuracy in H matrix') + if Verbose || done + if rc ==0 + %do nothing, just a normal step + elseif rc == 1 + disp('zero gradient') + elseif rc == 6 + disp('smallest step still improving too slow, reversed gradient') + elseif rc == 5 + disp('largest step still improving too fast') + elseif (rc == 4) || (rc==2) + disp('back and forth on step length never finished') + elseif rc == 3 + disp('smallest step still improving too slow') + elseif rc == 7 + disp('warning: possible inaccuracy in H matrix') + else + error('Unaccounted Case, please contact the developers') + end end - % end + f=fh; x=xh; g=gh; badg=badgh; end -% what about making an m-file of 10 lines including numgrad.m -% since it appears three times in csminwel.m \ No newline at end of file + +end + +function [g, badg]=get_num_grad(method,fcn,f0,x0,epsilon,varargin) + switch method + case 2 + [g,badg] = numgrad2(fcn, f0, x0, epsilon, varargin{:}); + case 3 + [g,badg] = numgrad3(fcn, f0, x0, epsilon, varargin{:}); + case 5 + [g,badg] = numgrad5(fcn, f0, x0, epsilon, varargin{:}); + case 13 + [g,badg] = numgrad3_(fcn, f0, x0, epsilon, varargin{:}); + case 15 + [g,badg] = numgrad5_(fcn, f0, x0, epsilon, varargin{:}); + otherwise + error('csminwel1: Unknown method for gradient evaluation!') + end +end \ No newline at end of file From 8ab8d462813c4633417751e9caa758b6c6b3cab1 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Fri, 17 Apr 2015 09:16:54 +0200 Subject: [PATCH 129/210] small fix in matlab annotation --- matlab/gsa/scatter_mcf.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matlab/gsa/scatter_mcf.m b/matlab/gsa/scatter_mcf.m index 90d363cb3..226549890 100644 --- a/matlab/gsa/scatter_mcf.m +++ b/matlab/gsa/scatter_mcf.m @@ -158,8 +158,8 @@ for i = 1:p end end if ~isoctave - annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center'); - annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center'); + annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center','interpreter','none'); + annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center','interpreter','none'); end if ~nograph, From 31cd80e9a91296a8eb74dbac6f7cdcc3abfc5705 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 19 Apr 2015 10:50:45 +0200 Subject: [PATCH 130/210] Fix crash in error message display of perfect_foresight_setup.m when more than one variable is not present in current period Concatenation otherwise crashes due to non-conformable matrices --- .../perfect_foresight_setup.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index da03d46a6..081eaf887 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -34,8 +34,16 @@ global M_ options_ oo_ test_for_deep_parameters_calibration(M_); if size(M_.lead_lag_incidence,2)-nnz(M_.lead_lag_incidence(M_.maximum_endo_lag+1,:)) > 0 - mess = ['PERFECT_FORESIGHT_SETUP: error in model specification : variable ' M_.endo_names(find(M_.lead_lag_incidence(M_.maximum_lag+1,:)==0),:)]; - mess = [mess ' doesn''t appear as current variable.']; + mess = ['PERFECT_FORESIGHT_SETUP: error in model specification : the variable(s) ']; + var_list=M_.endo_names(find(M_.lead_lag_incidence(M_.maximum_lag+1,:)==0),:); + for i=1:size(var_list,1) + if i Date: Mon, 20 Apr 2015 11:06:21 +0200 Subject: [PATCH 131/210] updated documentation for IRF/moment restrictions and refreshed sensitivity analyses and plots --- doc/dynare.texi | 786 +++++++++++++++++++++++++++++------------------- 1 file changed, 480 insertions(+), 306 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index fcb976aec..05c58ce42 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -241,13 +241,19 @@ Stochastic solution and simulation Sensitivity and identification analysis +* Performing sensitivity analysis:: +* Performing identification analysis:: +* IRF/moment calibration:: +* Types of analysis and output files:: + +Types of analysis and output files * Sampling:: * Stability Mapping:: +* IRF/moment restrictions:: * Reduced Form Mapping:: * RMSE:: * Screening Analysis:: * Identification Analysis:: -* Performing Sensitivity and Identification Analysis:: Macro-processing language @@ -6869,311 +6875,8 @@ With respect to the previous version of the toolbox, in order to work properly, the GSA toolbox no longer requires that the Dynare estimation environment is set up. -Sensitivity analysis results are saved locally in @code{/GSA}, -where @code{.mod} is the name of the DYNARE model file. - -@menu -* Sampling:: -* Stability Mapping:: -* Reduced Form Mapping:: -* RMSE:: -* Screening Analysis:: -* Identification Analysis:: -* Performing Sensitivity and Identification Analysis:: -@end menu - -@node Sampling -@subsection Sampling - -The following binary files are produced: -@itemize -@item -@code{_prior.mat}: this file stores information about the analyses -performed sampling from the prior ranges, @i{i.e.} @code{pprior=1} and @code{ppost=0}; - -@item -@code{_mc.mat}: this file stores information about the analyses performed -sampling from multivariate normal, @i{i.e.} @code{pprior=0} and @code{ppost=0}; - -@item -@code{_post.mat}: this file stores information about analyses performed -using the Metropolis posterior sample, @i{i.e.} @code{ppost=1}. -@end itemize - -@node Stability Mapping -@subsection Stability Mapping - -Figure files produced are of the form @code{_prior_*.fig} and store results -for stability mapping from prior Monte-Carlo samples: -@itemize -@item -@code{_prior_stab_SA_*.fig}: plots of the Smirnov test analyses -confronting the cdf of the sample fulfilling Blanchard-Kahn conditions -with the cdf of the rest of the sample; - -@item -@code{_prior_stab_indet_SA_*.fig}: plots of the Smirnov test -analyses confronting the cdf of the sample producing indeterminacy -with the cdf of the original prior sample; - -@item -@code{_prior_stab_unst_SA_*.fig}: plots of the Smirnov test -analyses confronting the cdf of the sample producing unstable (explosive -roots) behavior with the cdf of the original prior sample; - -@item -@code{_prior_stable_corr_*.fig}: plots of bivariate projections -of the sample fulfilling Blanchard-Kahn conditions; - -@item -@code{_prior_indeterm_corr_*.fig}: plots of bivariate projections -of the sample producing indeterminacy; - -@item -@code{_prior_unstable_corr_*.fig}: plots of bivariate projections -of the sample producing instability; - -@item -@code{_prior_unacceptable_corr_*.fig}: plots of bivariate projections -of the sample producing unacceptable solutions, @i{i.e.} either -instability or indeterminacy or the solution could not be found (@i{e.g.} -the steady state solution could not be found by the solver). -@end itemize - -Similar conventions apply for @code{_mc_*.fig} files, obtained when -samples from multivariate normal are used. - -@node Reduced Form Mapping -@subsection Reduced Form Mapping - -The mapping of the reduced form solution forces the use of samples from -prior ranges or prior distributions, @i{i.e.}: @code{pprior=1} and @code{ppost=0}. It -uses 250 samples to optimize smoothing parameters and 1000 samples to compute the -fit. The rest of the sample is used for out-of-sample validation. One can also -load a previously estimated mapping with a new Monte-Carlo sample, to look at the -forecast for the new Monte-Carlo sample. - -The following synthetic figures are produced: -@itemize -@item -@code{_redform__vs_lags_*.fig}: shows bar charts -of the sensitivity indices for the ten most important parameters driving -the reduced form coefficients of the selected endogenous variables -(@code{namendo}) versus lagged endogenous variables (@code{namlagendo}); suffix -@code{log} indicates the results for log-transformed entries; - -@item -@code{_redform__vs_shocks_*.fig}: shows bar charts -of the sensitivity indices for the ten most important parameters driving -the reduced form coefficients of the selected endogenous variables -(@code{namendo}) versus exogenous variables (@code{namexo}); suffix @code{log} -indicates the results for log-transformed entries; - -@item -@code{_redform_GSA(_log).fig}: shows bar chart of all sensitivity -indices for each parameter: this allows one to notice parameters that -have a minor effect for any of the reduced form coefficients. -@end itemize - -Detailed results of the analyses are shown in the subfolder @code{/GSA/redform_stab}, -where the detailed results of the estimation of the single functional relationships -between parameters @math{\theta} and reduced form coefficient are stored in separate directories -named as: - -@itemize -@item -@code{_vs_}: for the entries of the transition matrix; - -@item -@code{_vs_}: for entries of the matrix of the shocks. -@end itemize -Moreover, analyses for log-transformed entries are denoted with the following -suffixes (@math{y} denotes the generic reduced form coefficient): -@itemize -@item -@code{log}: @math{y^* = \log(y)}; -@item -@code{minuslog}: @math{y^* = \log(-y)}; -@item -@code{logsquared}: @math{y^* = \log(y^2)} for symmetric fat tails; -@item -@code{logskew}: @math{y^* = \log(|y + \lambda|)} for asymmetric fat tails. -@end itemize -The optimal type of transformation is automatically selected without the -need of user intervention. - -@node RMSE -@subsection RMSE - -The RMSE analysis can be performed with different types of sampling options: -@enumerate -@item -When @code{pprior=1} and @code{ppost=0}, the toolbox analyzes the RMSEs for -the Monte-Carlo sample obtained by sampling parameters from their prior distributions -(or prior ranges): this analysis provides some hints about -what parameter drives the fit of which observed series, prior to the full -estimation; - -@item -When @code{pprior=0} and @code{ppost=0}, the toolbox analyzes the RMSEs for -a multivariate normal Monte-Carlo sample, with covariance matrix based on -the inverse Hessian at the optimum: this analysis is useful when maximum likelihood -estimation is done (@i{i.e.} no Bayesian estimation); - -@item -When @code{ppost=1} the toolbox analyzes the RMSEs for the posterior sample -obtained by Dynare's Metropolis procedure. -@end enumerate - -The use of cases 2 and 3 requires an estimation step beforehand. To -facilitate the sensitivity analysis after estimation, the @code{dynare_sensitivity} -command also allows you to indicate some options of the @code{estimation} -command. These are: -@itemize @bullet -@item @code{datafile} -@item @code{nobs} -@item @code{first_obs} -@item @code{prefilter} -@item @code{presample} -@item @code{nograph} -@item @code{nodisplay} -@item @code{graph_format} -@item @code{conf_sig} -@item @code{loglinear} -@item @code{mode_file} -@end itemize - -Binary files produced my RMSE analysis are: -@itemize -@item -@code{_prior_*.mat}: these files store the filtered and smoothed - variables for the prior Monte-Carlo sample, generated when doing RMSE analysis - (@code{pprior=1} and @code{ppost=0}); -@item -@code{_mc_*.mat}: these files store the filtered and smoothed variables - for the multivariate normal Monte-Carlo sample, generated when doing - RMSE analysis (@code{pprior=0} and @code{ppost=0}). -@end itemize - -Figure files @code{_rmse_*.fig} store results for the RMSE analysis. - -@itemize -@item -@code{_rmse_prior*.fig}: save results for the analysis using prior -Monte-Carlo samples; - -@item -@code{_rmse_mc*.fig}: save results for the analysis using multivariate -normal Monte-Carlo samples; - -@item -@code{_rmse_post*.fig}: save results for the analysis using Metropolis -posterior samples. -@end itemize - -The following types of figures are saved (we show prior sample to fix ideas, -but the same conventions are used for multivariate normal and posterior): - -@itemize -@item -@code{_rmse_prior_*.fig}: for each parameter, plots the cdfs -corresponding to the best 10% RMSEs of each observed series; - -@item -@code{_rmse_prior_dens_*.fig}: for each parameter, plots the -pdfs corresponding to the best 10% RMESs of each observed series; - -@item -@code{_rmse_prior__corr_*.fig}: for -each observed series plots the bi-dimensional projections of samples -with the best 10% RMSEs, when the correlation is significant; - -@item -@code{_rmse_prior_lnlik*.fig}: for each observed series, plots -in red the cdf of the log-likelihood corresponding to the best 10% -RMSEs, in green the cdf of the rest of the sample and in blue the -cdf of the full sample; this allows one to see the presence of some -idiosyncratic behavior; - -@item -@code{_rmse_prior_lnpost*.fig}: for each observed series, plots -in red the cdf of the log-posterior corresponding to the best 10% RMSEs, -in green the cdf of the rest of the sample and in blue the cdf of the full -sample; this allows one to see idiosyncratic behavior; - -@item -@code{_rmse_prior_lnprior*.fig}: for each observed series, plots -in red the cdf of the log-prior corresponding to the best 10% RMSEs, -in green the cdf of the rest of the sample and in blue the cdf of the full -sample; this allows one to see idiosyncratic behavior; - -@item -@code{_rmse_prior_lik_SA_*.fig}: when @code{lik_only=1}, this shows -the Smirnov tests for the filtering of the best 10% log-likelihood values; - -@item -@code{_rmse_prior_post_SA_*.fig}: when @code{lik_only=1}, this shows -the Smirnov test for the filtering of the best 10% log-posterior values. -@end itemize - -@node Screening Analysis -@subsection Screening Analysis - -Screening analysis does not require any additional options with respect to -those listed in @ref{Sampling Options}. The toolbox performs all the -analyses required and displays results. - -The results of the screening analysis with Morris sampling design are stored -in the subfolder @code{/GSA/SCREEN}. The data file @code{_prior} stores -all the information of the analysis (Morris sample, reduced form coefficients, -etc.). - -Screening analysis merely concerns reduced form coefficients. Similar -synthetic bar charts as for the reduced form analysis with Monte-Carlo samples are -saved: -@itemize -@item -@code{_redform__vs_lags_*.fig}: shows bar charts -of the elementary effect tests for the ten most important parameters -driving the reduced form coefficients of the selected endogenous variables -(@code{namendo}) versus lagged endogenous variables (@code{namlagendo}); - -@item -@code{_redform__vs_shocks_*.fig}: shows bar charts -of the elementary effect tests for the ten most important parameters -driving the reduced form coefficients of the selected endogenous variables -(@code{namendo}) versus exogenous variables (@code{namexo}); - -@item -@code{_redform_screen.fig}: shows bar chart of all elementary -effect tests for each parameter: this allows one to identify parameters that -have a minor effect for any of the reduced form coefficients. -@end itemize - -@node Identification Analysis -@subsection Identification Analysis - -Setting the option @code{identification=1}, an identification analysis based on -theoretical moments is performed. Sensitivity plots are provided that allow -to infer which parameters are most likely to be less identifiable. - -Prerequisite for properly running all the identification routines, is the keyword -@code{identification}; in the Dynare model file. This keyword triggers -the computation of analytic derivatives of the model with respect to estimated -parameters and shocks. This is required for option @code{morris=2}, -which implements @cite{Iskrev (2010)} identification analysis. - -For example, the placing @code{identification; dynare_sensitivity(identification=1, morris=2);} -in the Dynare model file trigger identification analysis using analytic derivatives -@cite{Iskrev (2010)}, jointly with the mapping of the acceptable region. - -The identification analysis with derivatives can also be triggered by the -commands @code{identification;} This does not do the mapping of -acceptable regions for the model and uses the standard random sampler of Dynare. -It completely offsets any use of the sensitivity analysis toolbox. - -@node Performing Sensitivity and Identification Analysis -@subsection Performing Sensitivity and Identification Analysis +@node Performing sensitivity analysis +@subsection Performing sensitivity analysis @deffn Command dynare_sensitivity ; @deffnx Command dynare_sensitivity (@var{OPTIONS}@dots{}); @@ -7406,6 +7109,80 @@ Maximum number of lags for moments in identification analysis. Default: @code{1} @end deffn +@node IRF/Moment calibration +@subsection IRF/Moment calibration + +IRF and moment calibration can be defined in @code{irf_calibration} and @code{moment_calibration} blocks: + +@deffn Block irf_calibration; +@deffnx Block irf_calibration(@var{OPTIONS}@dots{}); + +@descriptionhead + +This block allows defining IRF calibration criteria and is terminated by @code{end;}. +To set IRF sign restrictions, the following syntax is used +@example +@var{VARIABLE_NAME}(@var{INTEGER}),@var{EXOGENOUS_NAME}, -; +@var{VARIABLE_NAME}(@var{INTEGER}:@var{INTEGER}),@var{EXOGENOUS_NAME}, +; +@end example +To set IRF restrictions with specific intervals, the following syntax is used +@example +@var{VARIABLE_NAME}(@var{INTEGER}),@var{EXOGENOUS_NAME}, [@var{DOUBLE} @var{DOUBLE}]; +@var{VARIABLE_NAME}(@var{INTEGER}:@var{INTEGER}),@var{EXOGENOUS_NAME}, [@var{DOUBLE} @var{DOUBLE}]; +@end example + +When @code{(@var{INTEGER}:@var{INTEGER})} is used, the restriction is considered to be fulfilled by a logical OR. +A list of restrictions must always be fulfilled with logical AND. + +@examplehead + +@example +irf_calibration; +y(1:4), e_ys, [ -50 50]; //[first year response with logical OR] +@@#for ilag in 21:40 +R_obs(@@@{ilag@}), e_ys, [0 6]; //[response from 5th to 10th years with logical AND] +@@#endfor +end; +@end example + +@end deffn + +@deffn Block moment_calibration; +@deffnx Block moment_calibration(@var{OPTIONS}@dots{}); + +@descriptionhead + +This block allows defining moment calibration criteria. This block is terminated by @code{end;}, and contains lines of the +form: +@example +@var{VARIABLE_NAME1},@var{VARIABLE_NAME2}(+/-@var{INTEGER}), [@var{DOUBLE} @var{DOUBLE}]; +@var{VARIABLE_NAME1},@var{VARIABLE_NAME2}(+/-@var{INTEGER}), +/-; +@var{VARIABLE_NAME1},@var{VARIABLE_NAME2}(+/-(@var{INTEGER}:@var{INTEGER})), [@var{DOUBLE} @var{DOUBLE}]; +@var{VARIABLE_NAME1},@var{VARIABLE_NAME2}((-@var{INTEGER}:+@var{INTEGER})), [@var{DOUBLE} @var{DOUBLE}]; +@end example + +When @code{(@var{INTEGER}:@var{INTEGER})} is used, the restriction is considered to be fulfilled by a logical OR. +A list of restrictions must always be fulfilled with logical AND. + +@examplehead + +@example +moment_calibration; +y_obs,y_obs, [0.5 1.5]; //[unconditional variance] +y_obs,y_obs(-(1:4)), +; //[sign restriction for first year acf with logical OR] +@@#for ilag in -2:2 +y_obs,R_obs(@@@{ilag@}), -; //[-2:2 ccf with logical AND] +@@#endfor +@@#for ilag in -4:4 +y_obs,pie_obs(@@@{ilag@}), -; //[-4_4 ccf with logical AND] +@@#endfor +end; +@end example + +@end deffn +@node Performing identification analysis +@subsection Performing identification analysis + @deffn Command identification ; @deffnx Command identification (@var{OPTIONS}@dots{}); @@ -7486,6 +7263,403 @@ Specify the parameter set to use. Default: @code{prior_mean} @end deffn +@node Types of analysis and output files +@subsection Types of analysis and output files + +The sensitivity analysis toolbox includes several types of analyses. +Sensitivity analysis results are saved locally in @code{/GSA}, +where @code{.mod} is the name of the DYNARE model file. + +@menu +* Sampling:: +* Stability Mapping:: +* IRF/moment restrictions:: +* Reduced Form Mapping:: +* RMSE:: +* Screening Analysis:: +* Identification Analysis:: +@end menu + +@node Sampling +@subsubsection Sampling + +The following binary files are produced: +@itemize +@item +@code{_prior.mat}: this file stores information about the analyses +performed sampling from the prior, @i{i.e.} @code{pprior=1} and @code{ppost=0}; + +@item +@code{_mc.mat}: this file stores information about the analyses performed +sampling from multivariate normal, @i{i.e.} @code{pprior=0} and @code{ppost=0}; + +@item +@code{_post.mat}: this file stores information about analyses performed +using the Metropolis posterior sample, @i{i.e.} @code{ppost=1}. +@end itemize + +@node Stability Mapping +@subsubsection Stability Mapping + +Figure files produced are of the form @code{_prior_*.fig} and store results +for stability mapping from prior Monte-Carlo samples: +@itemize +@item +@code{_prior_stable.fig}: plots of the Smirnov test and the correlation analyses +confronting the cdf of the sample fulfilling Blanchard-Kahn conditions (blue color) +with the cdf of the rest of the sample (red color), @i{i.e.} either +instability or indeterminacy or the solution could not be found (@i{e.g.} +the steady state solution could not be found by the solver); + +@item +@code{_prior_indeterm.fig}: plots of the Smirnov test and the correlation +analyses confronting the cdf of the sample producing indeterminacy (red color) +with the cdf of the rest of the sample (blue color); + +@item +@code{_prior_unstable.fig}: plots of the Smirnov test and the correlation +analyses confronting the cdf of the sample producing explosive roots (red color) +with the cdf of the rest of the sample (blue color); + +@item +@code{_prior_wrong.fig}: plots of the Smirnov test and the correlation +analyses confronting the cdf of the sample where the solution could not be found (@i{e.g.} +the steady state solution could not be found by the solver - red color) +with the cdf of the rest of the sample (blue color); + +@item +@code{_prior_calib.fig}: plots of the Smirnov test and the correlation +analyses splitting the sample fulfilling Blanchard-Kahn conditions, +by confronting the cdf of the sample where IRF/moment restrictions are matched (blue color) +with the cdf where IRF/moment restrictions are NOT matched (red color); + +@end itemize + +Similar conventions apply for @code{_mc_*.fig} files, obtained when +samples from multivariate normal are used. + +@node IRF/Moment restrictions +@subsubsection IRF/Moment restrictions + +The following binary files are produced: +@itemize +@item +@code{_prior_restrictions.mat}: this file stores information about the IRF/moment restriction analysis +performed sampling from the prior ranges, @i{i.e.} @code{pprior=1} and @code{ppost=0}; + +@item +@code{_mc_restrictions.mat}: this file stores information about the IRF/moment restriction analysis performed +sampling from multivariate normal, @i{i.e.} @code{pprior=0} and @code{ppost=0}; + +@item +@code{_post_restrictions.mat}: this file stores information about IRF/moment restriction analysis performed +using the Metropolis posterior sample, @i{i.e.} @code{ppost=1}. +@end itemize + +Figure files produced are of the form @code{_prior_irf_calib_*.fig} and @code{_prior_moment_calib_*.fig} and store results +for mapping restrictions from prior Monte-Carlo samples: +@itemize +@item +@code{_prior_irf_calib__vs__.fig}: plots of the Smirnov test and the correlation +analyses splitting the sample fulfilling Blanchard-Kahn conditions, +by confronting the cdf of the sample where the individual IRF restriction +@code{} vs. @code{} at period(s) @code{} is matched (blue color) +with the cdf where the IRF restriction is NOT matched (red color) + +@item +@code{_prior_irf_calib__vs__ALL.fig}: plots of the Smirnov test and the correlation +analyses splitting the sample fulfilling Blanchard-Kahn conditions, +by confronting the cdf of the sample where ALL the individual IRF restrictions for the same couple +@code{} vs. @code{} are matched (blue color) +with the cdf where the IRF restriction is NOT matched (red color) + +@item +@code{_prior_irf_restrictions.fig}: plots visual information on the IRF restrictions +compared to the actual Monte Carlo realization from prior sample. + +@item +@code{_prior_moment_calib__vs__.fig}: plots of the Smirnov test and the correlation +analyses splitting the sample fulfilling Blanchard-Kahn conditions, +by confronting the cdf of the sample where the individual acf/ccf moment restriction +@code{} vs. @code{} at lag(s) @code{} is matched (blue color) +with the cdf where the IRF restriction is NOT matched (red color) + +@item +@code{_prior_moment_calib__vs__ALL.fig}: plots of the Smirnov test and the correlation +analyses splitting the sample fulfilling Blanchard-Kahn conditions, +by confronting the cdf of the sample where ALL the individual acf/ccf moment restrictions for the same couple +@code{} vs. @code{} are matched (blue color) +with the cdf where the IRF restriction is NOT matched (red color) + +@item +@code{_prior_moment_restrictions.fig}: plots visual information on the moment restrictions +compared to the actual Monte Carlo realization from prior sample. + +@end itemize + +Similar conventions apply for @code{_mc_*.fig} and @code{_post_*.fig} files, obtained when +samples from multivariate normal or from posterior are used. + +@node Reduced Form Mapping +@subsubsection Reduced Form Mapping + +When the option @code{threshold_redform} is not set, or it is empty (the default), this analysis estimates a multivariate +smoothing spline ANOVA model (the 'mapping') for the selected entries in the transition matrix of the shock matrix of the reduce form first order solution of the model. +The mapping of the reduced form solution forces the use of samples from +prior ranges or prior distributions, @i{i.e.}: @code{pprior=1} and @code{ppost=0}. It +uses 250 samples to optimize smoothing parameters and 1000 samples to compute the +fit. The rest of the sample is used for out-of-sample validation. One can also +load a previously estimated mapping with a new Monte-Carlo sample, to look at the +forecast for the new Monte-Carlo sample. + +The following synthetic figures are produced: +@itemize +@item +@code{_redform__vs_lags_*.fig}: shows bar charts +of the sensitivity indices for the ten most important parameters driving +the reduced form coefficients of the selected endogenous variables +(@code{namendo}) versus lagged endogenous variables (@code{namlagendo}); suffix +@code{log} indicates the results for log-transformed entries; + +@item +@code{_redform__vs_shocks_*.fig}: shows bar charts +of the sensitivity indices for the ten most important parameters driving +the reduced form coefficients of the selected endogenous variables +(@code{namendo}) versus exogenous variables (@code{namexo}); suffix @code{log} +indicates the results for log-transformed entries; + +@item +@code{_redform_GSA(_log).fig}: shows bar chart of all sensitivity +indices for each parameter: this allows one to notice parameters that +have a minor effect for any of the reduced form coefficients. +@end itemize + +Detailed results of the analyses are shown in the subfolder @code{/GSA/redform_prior}, +where the detailed results of the estimation of the single functional relationships +between parameters @math{\theta} and reduced form coefficient (denoted as @math{y} hereafter) are stored in separate directories +named as: + +@itemize +@item +@code{_vs_}: for the entries of the transition matrix; + +@item +@code{_vs_}: for entries of the matrix of the shocks. +@end itemize + +The following files are stored in each directory: +@itemize +@item +@code{__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry +of the shock matrix, in sample and out of sample fit of the ANOVA model; + +@item +@code{__vs__map_SE.fig}: for entries of the shock matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter \math{\theta_i}; + +@item +@code{__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry +of the transition matrix, in sample and out of sample fit of the ANOVA model; + +@item +@code{__vs__map_SE.fig}: for entries of the transition matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter @math{\theta_i}; + +@item +@code{__vs__map.mat}, @code{__vs__map.mat}: these files store info in the estimation; + +@end itemize + +When option @code{logtrans_redform} is set, the ANOVA estimation is performed using a log-transformation of each @code{y}. +The ANOVA mapping is then transformed back onto the original scale, to allow comparability with the baseline estimation. +Graphs for this log-transformed case, are stored in the same folder in files denoted with the @code{_log} suffix. + +When the option @code{threshold_redform} is set, the analysis is performed via Monte Carlo filtering, by displaying parameters that drive the individual entry @code{y} inside the range specified in @code{threshold_redform}. If no entry is found (or all entries are in the range), the MCF algorithm ignores the range specified in @code{threshold_redform} and performs the analysis splitting the MC sample of @code{y} into deciles. Setting @code{threshold_redform=[-inf inf]} triggers this approach for all @code{y}'s. + +Results are stored in subdirectories of @code{/GSA/redform_prior} named +@itemize +@item +@code{_vs__threshold}: for the entries of the transition matrix; + +@item +@code{_vs__threshold}: for entries of the matrix of the shocks. +@end itemize + +The files saved are named +@itemize +@item +@code{__vs__threshold.fig},@code{__vs__threshold.fig}: graphical outputs; +@item +@code{__vs__threshold.mat},@code{__vs__threshold.mat}: info on the analysis; + +@end itemize + +@node RMSE +@subsubsection RMSE + +The RMSE analysis can be performed with different types of sampling options: +@enumerate +@item +When @code{pprior=1} and @code{ppost=0}, the toolbox analyzes the RMSEs for +the Monte-Carlo sample obtained by sampling parameters from their prior distributions +(or prior ranges): this analysis provides some hints about +what parameter drives the fit of which observed series, prior to the full +estimation; + +@item +When @code{pprior=0} and @code{ppost=0}, the toolbox analyzes the RMSEs for +a multivariate normal Monte-Carlo sample, with covariance matrix based on +the inverse Hessian at the optimum: this analysis is useful when maximum likelihood +estimation is done (@i{i.e.} no Bayesian estimation); + +@item +When @code{ppost=1} the toolbox analyzes the RMSEs for the posterior sample +obtained by Dynare's Metropolis procedure. +@end enumerate + +The use of cases 2 and 3 requires an estimation step beforehand. To +facilitate the sensitivity analysis after estimation, the @code{dynare_sensitivity} +command also allows you to indicate some options of the @code{estimation} +command. These are: +@itemize @bullet +@item @code{datafile} +@item @code{nobs} +@item @code{first_obs} +@item @code{prefilter} +@item @code{presample} +@item @code{nograph} +@item @code{nodisplay} +@item @code{graph_format} +@item @code{conf_sig} +@item @code{loglinear} +@item @code{mode_file} +@end itemize + +Binary files produced my RMSE analysis are: +@itemize +@item +@code{_prior_*.mat}: these files store the filtered and smoothed + variables for the prior Monte-Carlo sample, generated when doing RMSE analysis + (@code{pprior=1} and @code{ppost=0}); +@item +@code{_mc_*.mat}: these files store the filtered and smoothed variables + for the multivariate normal Monte-Carlo sample, generated when doing + RMSE analysis (@code{pprior=0} and @code{ppost=0}). +@end itemize + +Figure files @code{_rmse_*.fig} store results for the RMSE analysis. + +@itemize +@item +@code{_rmse_prior*.fig}: save results for the analysis using prior +Monte-Carlo samples; + +@item +@code{_rmse_mc*.fig}: save results for the analysis using multivariate +normal Monte-Carlo samples; + +@item +@code{_rmse_post*.fig}: save results for the analysis using Metropolis +posterior samples. +@end itemize + +The following types of figures are saved (we show prior sample to fix ideas, +but the same conventions are used for multivariate normal and posterior): + +@itemize +@item +@code{_rmse_prior_params_*.fig}: for each parameter, plots the cdfs +corresponding to the best 10% RMSEs of each observed series (only those cdfs below the significance threshold @code{alpha_rmse}); + +@item +@code{_rmse_prior__*.fig}: if a parameter significantly affects the fit of @code{var_obs}, all possible trade-off's with other observables for same parameter are plotted; + +@item +@code{_rmse_prior__map.fig}: plots the MCF analysis of parameters significantly driving the fit the observed series @code{var_obs}; + +@item +@code{_rmse_prior_lnlik*.fig}: for each observed series, plots +in BLUE the cdf of the log-likelihood corresponding to the best 10% +RMSEs, in RED the cdf of the rest of the sample and in BLACK the +cdf of the full sample; this allows one to see the presence of some +idiosyncratic behavior; + +@item +@code{_rmse_prior_lnpost*.fig}: for each observed series, plots +in BLUE the cdf of the log-posterior corresponding to the best 10% RMSEs, +in RED the cdf of the rest of the sample and in BLACK the cdf of the full +sample; this allows one to see idiosyncratic behavior; + +@item +@code{_rmse_prior_lnprior*.fig}: for each observed series, plots +in BLUE the cdf of the log-prior corresponding to the best 10% RMSEs, +in RED the cdf of the rest of the sample and in BLACK the cdf of the full +sample; this allows one to see idiosyncratic behavior; + +@item +@code{_rmse_prior_lik.fig}: when @code{lik_only=1}, this shows +the MCF tests for the filtering of the best 10% log-likelihood values; + +@item +@code{_rmse_prior_post.fig}: when @code{lik_only=1}, this shows +the MCF tests for the filtering of the best 10% log-posterior values. +@end itemize + +@node Screening Analysis +@subsubsection Screening Analysis + +Screening analysis does not require any additional options with respect to +those listed in @ref{Sampling Options}. The toolbox performs all the +analyses required and displays results. + +The results of the screening analysis with Morris sampling design are stored +in the subfolder @code{/GSA/SCREEN}. The data file @code{_prior} stores +all the information of the analysis (Morris sample, reduced form coefficients, +etc.). + +Screening analysis merely concerns reduced form coefficients. Similar +synthetic bar charts as for the reduced form analysis with Monte-Carlo samples are +saved: +@itemize +@item +@code{_redform__vs_lags_*.fig}: shows bar charts +of the elementary effect tests for the ten most important parameters +driving the reduced form coefficients of the selected endogenous variables +(@code{namendo}) versus lagged endogenous variables (@code{namlagendo}); + +@item +@code{_redform__vs_shocks_*.fig}: shows bar charts +of the elementary effect tests for the ten most important parameters +driving the reduced form coefficients of the selected endogenous variables +(@code{namendo}) versus exogenous variables (@code{namexo}); + +@item +@code{_redform_screen.fig}: shows bar chart of all elementary +effect tests for each parameter: this allows one to identify parameters that +have a minor effect for any of the reduced form coefficients. +@end itemize + +@node Identification Analysis +@subsubsection Identification Analysis + +Setting the option @code{identification=1}, an identification analysis based on +theoretical moments is performed. Sensitivity plots are provided that allow +to infer which parameters are most likely to be less identifiable. + +Prerequisite for properly running all the identification routines, is the keyword +@code{identification}; in the Dynare model file. This keyword triggers +the computation of analytic derivatives of the model with respect to estimated +parameters and shocks. This is required for option @code{morris=2}, +which implements @cite{Iskrev (2010)} identification analysis. + +For example, the placing @code{identification; dynare_sensitivity(identification=1, morris=2);} +in the Dynare model file trigger identification analysis using analytic derivatives +@cite{Iskrev (2010)}, jointly with the mapping of the acceptable region. + +The identification analysis with derivatives can also be triggered by the +commands @code{identification;} This does not do the mapping of +acceptable regions for the model and uses the standard random sampler of Dynare. +It completely offsets any use of the sensitivity analysis toolbox. + + @node Markov-switching SBVAR @section Markov-switching SBVAR From c5f7091ad0a89c70ca7bda8138e129572af712c7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 20 Apr 2015 11:21:54 +0200 Subject: [PATCH 132/210] doc: fix typo introduced in c46b6cdfea04fc2c1618facfd4430081838f42c1 --- doc/dynare.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index fcb976aec..ad6518fae 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -6765,7 +6765,7 @@ available, leading to a second-order accurate welfare ranking This command generates all the output variables of @code{stoch_simul}. For specifying the initial values for the endogenous state variables (except for the Lagrange -multipliers}, @xref{histval} +multipliers), @xref{histval}. @vindex oo_.planner_objective_value @anchor{planner_objective_value} From e3ed925400e50851fdbdb4f255e7a0e76bcb73b4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Mon, 20 Apr 2015 11:28:54 +0200 Subject: [PATCH 133/210] Document reduced form mapping for MC samples with neighborhood_width --- doc/dynare.texi | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 05c58ce42..232c1a06c 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7405,7 +7405,8 @@ samples from multivariate normal or from posterior are used. When the option @code{threshold_redform} is not set, or it is empty (the default), this analysis estimates a multivariate smoothing spline ANOVA model (the 'mapping') for the selected entries in the transition matrix of the shock matrix of the reduce form first order solution of the model. -The mapping of the reduced form solution forces the use of samples from +This mapping is done either with prior samples or with MC samples with @code{neighborhood_width}. +The unless @code{neighborhood_width} is set with MC samples, the mapping of the reduced form solution forces the use of samples from prior ranges or prior distributions, @i{i.e.}: @code{pprior=1} and @code{ppost=0}. It uses 250 samples to optimize smoothing parameters and 1000 samples to compute the fit. The rest of the sample is used for out-of-sample validation. One can also @@ -7434,7 +7435,7 @@ indices for each parameter: this allows one to notice parameters that have a minor effect for any of the reduced form coefficients. @end itemize -Detailed results of the analyses are shown in the subfolder @code{/GSA/redform_prior}, +Detailed results of the analyses are shown in the subfolder @code{/GSA/redform_prior} for prior samples and in @code{/GSA/redform_mc}, where the detailed results of the estimation of the single functional relationships between parameters @math{\theta} and reduced form coefficient (denoted as @math{y} hereafter) are stored in separate directories named as: @@ -7447,24 +7448,24 @@ named as: @code{_vs_}: for entries of the matrix of the shocks. @end itemize -The following files are stored in each directory: +The following files are stored in each directory (we stick with prior sample but similar convetins are used for MC samples): @itemize @item -@code{__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry +@code{_prior__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry of the shock matrix, in sample and out of sample fit of the ANOVA model; @item -@code{__vs__map_SE.fig}: for entries of the shock matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter \math{\theta_i}; +@code{_prior__vs__map_SE.fig}: for entries of the shock matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter \math{\theta_i}; @item -@code{__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry +@code{_prior__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry of the transition matrix, in sample and out of sample fit of the ANOVA model; @item -@code{__vs__map_SE.fig}: for entries of the transition matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter @math{\theta_i}; +@code{_prior__vs__map_SE.fig}: for entries of the transition matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter @math{\theta_i}; @item -@code{__vs__map.mat}, @code{__vs__map.mat}: these files store info in the estimation; +@code{_prior__vs__map.mat}, @code{__vs__map.mat}: these files store info in the estimation; @end itemize @@ -7477,18 +7478,18 @@ When the option @code{threshold_redform} is set, the analysis is performed via M Results are stored in subdirectories of @code{/GSA/redform_prior} named @itemize @item -@code{_vs__threshold}: for the entries of the transition matrix; +@code{_prior__vs__threshold}: for the entries of the transition matrix; @item -@code{_vs__threshold}: for entries of the matrix of the shocks. +@code{_prior__vs__threshold}: for entries of the matrix of the shocks. @end itemize The files saved are named @itemize @item -@code{__vs__threshold.fig},@code{__vs__threshold.fig}: graphical outputs; +@code{_prior__vs__threshold.fig},@code{__vs__threshold.fig}: graphical outputs; @item -@code{__vs__threshold.mat},@code{__vs__threshold.mat}: info on the analysis; +@code{_prior__vs__threshold.mat},@code{__vs__threshold.mat}: info on the analysis; @end itemize From 9bd47caab86b68811fb30f13959dee6dd134267b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 20 Apr 2015 11:36:22 +0200 Subject: [PATCH 134/210] doc: change xref to pxref where appropriate --- doc/dynare.texi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 57119d2fb..b1a5b2683 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -2379,7 +2379,8 @@ Moreover, as only states enter the recursive policy functions, all values specif For @ref{Ramsey} policy, it also specifies the values of the endogenous states at which the objective function of the planner is computed. Note that the initial values -of the Lagrange multipliers associated with the planner's problem cannot be set, @xref{planner_objective_value}. +of the Lagrange multipliers associated with the planner's problem cannot be set +(@pxref{planner_objective_value}). @examplehead @@ -6771,7 +6772,7 @@ available, leading to a second-order accurate welfare ranking This command generates all the output variables of @code{stoch_simul}. For specifying the initial values for the endogenous state variables (except for the Lagrange -multipliers), @xref{histval}. +multipliers), @pxref{histval}. @vindex oo_.planner_objective_value @anchor{planner_objective_value} @@ -6783,7 +6784,7 @@ taken to be at their steady state values. The result is a 1 by 2 vector, where the first entry stores the value of the planner objective under the timeless perspective to Ramsey policy, i.e. where the initial Lagrange multipliers associated with the planner's problem are set to their steady state -values (@xref{ramsey_policy}). +values (@pxref{ramsey_policy}). In contrast, the second entry stores the value of the planner objective with initial Lagrange multipliers of the planner's problem set to 0, i.e. it is assumed that the planner succumbs to the temptation to exploit the preset private expecatations From e56550839881055a0bcf8177e367a35935744711 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 20 Apr 2015 16:22:20 +0200 Subject: [PATCH 135/210] Fix manual structure after changes in 591cd064d1291d5777e339d47da5fc6129d36ce9 --- doc/dynare.texi | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index b1a5b2683..d7eb848aa 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -243,13 +243,13 @@ Sensitivity and identification analysis * Performing sensitivity analysis:: * Performing identification analysis:: -* IRF/moment calibration:: +* IRF/Moment calibration:: * Types of analysis and output files:: Types of analysis and output files * Sampling:: * Stability Mapping:: -* IRF/moment restrictions:: +* IRF/Moment restrictions:: * Reduced Form Mapping:: * RMSE:: * Screening Analysis:: @@ -6791,7 +6791,7 @@ that the planner succumbs to the temptation to exploit the preset private expeca in the first period (but not in later periods due to commitment). @customhead{Steady state} -@xref{Ramsey steady state} +@xref{Ramsey steady state}. @end deffn @@ -6876,6 +6876,15 @@ With respect to the previous version of the toolbox, in order to work properly, the GSA toolbox no longer requires that the Dynare estimation environment is set up. + +@menu +* Performing sensitivity analysis:: +* Performing identification analysis:: +* IRF/Moment calibration:: +* Types of analysis and output files:: +@end menu + + @node Performing sensitivity analysis @subsection Performing sensitivity analysis @@ -7274,7 +7283,7 @@ where @code{.mod} is the name of the DYNARE model file. @menu * Sampling:: * Stability Mapping:: -* IRF/moment restrictions:: +* IRF/Moment restrictions:: * Reduced Form Mapping:: * RMSE:: * Screening Analysis:: From 3dee87c243c29262d68dc5845bb27b55a61b1cf2 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 20 Apr 2015 16:45:51 +0200 Subject: [PATCH 136/210] Fix crash in unit test fs2000_smoother_only For calibrated models, the param_vals field does not exist --- matlab/initial_estimation_checks.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 7b1bf2380..669e84f20 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -49,7 +49,7 @@ old_steady_params=Model.params; %save initial parameters for check if steady sta % % check if steady state solves static model (except if diffuse_filter == 1) [DynareResults.steady_state, new_steady_params] = evaluate_steady_state(DynareResults.steady_state,Model,DynareOptions,DynareResults,DynareOptions.diffuse_filter==0); -if ~isempty(EstimatedParameters.param_vals) +if isfield(EstimatedParameters,'param_vals') && ~isempty(EstimatedParameters.param_vals) %check whether steady state file changes estimated parameters Model_par_varied=Model; %store Model structure Model_par_varied.params(EstimatedParameters.param_vals(:,1))=Model_par_varied.params(EstimatedParameters.param_vals(:,1))*1.01; %vary parameters From 6760938c6e202e08c97a4b6e15a1433eb8e2b83c Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Mon, 20 Apr 2015 16:50:02 +0200 Subject: [PATCH 137/210] fixed typo --- doc/dynare.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index d7eb848aa..c3aa898a2 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7465,7 +7465,7 @@ The following files are stored in each directory (we stick with prior sample but of the shock matrix, in sample and out of sample fit of the ANOVA model; @item -@code{_prior__vs__map_SE.fig}: for entries of the shock matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter \math{\theta_i}; +@code{_prior__vs__map_SE.fig}: for entries of the shock matrix it shows graphs of the estimated first order ANOVA terms @math{y = f(\theta_i)} for each deep parameter @math{\theta_i}; @item @code{_prior__vs_.fig}: histogram and CDF plot of the MC sample of the individual entry From 9596154f03309585acc1839a2ccd0cb7f0e419bf Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Tue, 21 Apr 2015 09:24:30 +0200 Subject: [PATCH 138/210] Small typos and formatting fixes. --- doc/dynare.texi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index c3aa898a2..8d5a09c2a 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -7277,7 +7277,7 @@ Specify the parameter set to use. Default: @code{prior_mean} @subsection Types of analysis and output files The sensitivity analysis toolbox includes several types of analyses. -Sensitivity analysis results are saved locally in @code{/GSA}, +Sensitivity analysis results are saved locally in @code{/gsa}, where @code{.mod} is the name of the DYNARE model file. @menu @@ -7416,7 +7416,7 @@ samples from multivariate normal or from posterior are used. When the option @code{threshold_redform} is not set, or it is empty (the default), this analysis estimates a multivariate smoothing spline ANOVA model (the 'mapping') for the selected entries in the transition matrix of the shock matrix of the reduce form first order solution of the model. This mapping is done either with prior samples or with MC samples with @code{neighborhood_width}. -The unless @code{neighborhood_width} is set with MC samples, the mapping of the reduced form solution forces the use of samples from +Unless @code{neighborhood_width} is set with MC samples, the mapping of the reduced form solution forces the use of samples from prior ranges or prior distributions, @i{i.e.}: @code{pprior=1} and @code{ppost=0}. It uses 250 samples to optimize smoothing parameters and 1000 samples to compute the fit. The rest of the sample is used for out-of-sample validation. One can also @@ -7440,12 +7440,12 @@ the reduced form coefficients of the selected endogenous variables indicates the results for log-transformed entries; @item -@code{_redform_GSA(_log).fig}: shows bar chart of all sensitivity +@code{_redform_gsa(_log).fig}: shows bar chart of all sensitivity indices for each parameter: this allows one to notice parameters that have a minor effect for any of the reduced form coefficients. @end itemize -Detailed results of the analyses are shown in the subfolder @code{/GSA/redform_prior} for prior samples and in @code{/GSA/redform_mc}, +Detailed results of the analyses are shown in the subfolder @code{/gsa/redform_prior} for prior samples and in @code{/gsa/redform_mc} for MC samples with option @code{neighborhood_width}, where the detailed results of the estimation of the single functional relationships between parameters @math{\theta} and reduced form coefficient (denoted as @math{y} hereafter) are stored in separate directories named as: @@ -7485,7 +7485,7 @@ Graphs for this log-transformed case, are stored in the same folder in files den When the option @code{threshold_redform} is set, the analysis is performed via Monte Carlo filtering, by displaying parameters that drive the individual entry @code{y} inside the range specified in @code{threshold_redform}. If no entry is found (or all entries are in the range), the MCF algorithm ignores the range specified in @code{threshold_redform} and performs the analysis splitting the MC sample of @code{y} into deciles. Setting @code{threshold_redform=[-inf inf]} triggers this approach for all @code{y}'s. -Results are stored in subdirectories of @code{/GSA/redform_prior} named +Results are stored in subdirectories of @code{/gsa/redform_prior} named @itemize @item @code{_prior__vs__threshold}: for the entries of the transition matrix; @@ -7622,7 +7622,7 @@ those listed in @ref{Sampling Options}. The toolbox performs all the analyses required and displays results. The results of the screening analysis with Morris sampling design are stored -in the subfolder @code{/GSA/SCREEN}. The data file @code{_prior} stores +in the subfolder @code{/gsa/screen}. The data file @code{_prior} stores all the information of the analysis (Morris sample, reduced form coefficients, etc.). From c6c5cd8ce81864802107f76cd3b5e3b7f973016f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 21 Apr 2015 16:26:46 +0200 Subject: [PATCH 139/210] Allow Inf bounds in simpsa by replacing them with big finite number Closes #585 --- .../optimization/dynare_minimize_objective.m | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 9e8761bd2..8e8286985 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -53,10 +53,6 @@ if isempty(bounds) end end -if isnumeric(minimizer_algorithm) && minimizer_algorithm==10 && any(any(isinf(bounds))) - error('Algorithm 10 (simpsa) requires finite upper and lower bounds') -end - if isempty(parameter_names) parameter_names=[repmat('parameter ',n_params,1),num2str((1:n_params)')]; end @@ -119,10 +115,7 @@ switch minimizer_algorithm end end npar=length(start_par_value); - LB=bounds(:,1); - LB(isinf(LB))=-1e6; - UB=bounds(:,2); - UB(isinf(UB))=1e6; + [LB, UB]=set_bounds_to_finite_values(bounds); fprintf('\nNumber of parameters= %d, initial temperatur= %4.3f \n', npar,sa_options.initial_temperature); fprintf('rt= %4.3f; TolFun= %4.3f; ns= %4.3f;\n',sa_options.rt,sa_options.TolFun,sa_options.ns); fprintf('nt= %4.3f; neps= %4.3f; MaxIter= %d\n',sa_options.nt,sa_options.neps,sa_options.MaxIter); @@ -321,7 +314,8 @@ switch minimizer_algorithm end simpsaOptionsList = options2cell(simpsaOptions); simpsaOptions = simpsaset(simpsaOptionsList{:}); - [opt_par_values, fval, exitflag] = simpsa(func2str(objective_function),start_par_value,bounds(:,1),bounds(:,2),simpsaOptions,varargin{:}); + [LB, UB]=set_bounds_to_finite_values(bounds) + [opt_par_values, fval, exitflag] = simpsa(func2str(objective_function),start_par_value,LB,UB,simpsaOptions,varargin{:}); case 11 options_.cova_compute = 0 ; [opt_par_values,stdh,lb_95,ub_95,med_param] = online_auxiliary_filter(start_par_value,varargin{:}) ; @@ -373,3 +367,12 @@ switch minimizer_algorithm error(['Optimization algorithm ' int2str(minimizer_algorithm) ' is unknown!']) end end + +end + +function [LB, UB]=set_bounds_to_finite_values(bounds) + LB=bounds(:,1); + LB(isinf(LB))=-1e6; + UB=bounds(:,2); + UB(isinf(UB))=1e6; +end From 6702d5b8caa98bebe057118082f0d2be621442dc Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 21 Apr 2015 16:49:37 +0200 Subject: [PATCH 140/210] preprocessor: remove commented code --- preprocessor/DynamicModel.cc | 92 ------------------------------------ 1 file changed, 92 deletions(-) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 1de6bc8ca..f4957557e 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -261,8 +261,6 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const { int lag = it->first.first; unsigned int var = it->first.second.first; - //int eqr = getBlockInitialEquationID(block, eq); - //int varr = getBlockInitialVariableID(block, var); if (var != prev_var || lag != prev_lag) { prev_var = var; @@ -280,8 +278,6 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const { int lag = it->first.first; unsigned int var = it->first.second.first; - //int eqr = getBlockInitialEquationID(block, eq); - //int varr = getBlockInitialVariableID(block, var); if (var != prev_var || lag != prev_lag) { prev_var = var; @@ -299,8 +295,6 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const { int lag = it->first.first; unsigned int var = it->first.second.first; - //int eqr = getBlockInitialEquationID(block, eq); - //int varr = getBlockInitialVariableID(block, var); if (var != prev_var || lag != prev_lag) { prev_var = var; @@ -318,8 +312,6 @@ DynamicModel::writeModelEquationsOrdered_M(const string &dynamic_basename) const { int lag = it->first.first; unsigned int var = it->first.second.first; - //int eqr = getBlockInitialEquationID(block, eq); - //int varr = getBlockInitialVariableID(block, var); if (var != prev_var || lag != prev_lag) { prev_var = var; @@ -2801,89 +2793,6 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de typedef pair > index_KF; vector v_index_KF; - - /* DO 170, J = 1, N - TEMP1 = ALPHA*A( J, J ) - DO 110, I = 1, M - C( I, J ) = TEMP1*B( I, J ) - 11 110 CONTINUE - DO 140, K = 1, J - 1 - TEMP1 = ALPHA*A( K, J ) - DO 130, I = 1, M - C( I, J ) = C( I, J ) + TEMP1*B( I, K ) - 13 130 CONTINUE - 14 140 CONTINUE - DO 160, K = J + 1, N - TEMP1 = ALPHA*A( J, K ) - DO 150, I = 1, M - C( I, J ) = C( I, J ) + TEMP1*B( I, K ) - 15 150 CONTINUE - 16 160 CONTINUE - 17 170 CONTINUE - for(int j = 0; j < n; j++) - { - double temp1 = P_t_t1[j + j * n]; - for (int i = 0; i < n; i++) - tmp[i + j * n] = tmp1 * T[i + j * n]; - for (int k = 0; k < j - 1; k++) - { - temp1 = P_t_t1[k + j * n]; - for (int i = 0; i < n; i++) - tmp[i + j * n] += temp1 * T[i + k * n]; - } - for (int k = j + 1; k < n; k++) - { - temp1 = P_t_t1[j + k * n]; - for (int i = 0; i < n; i++) - tmp[i + j * n] += temp1 * T[i + k * n]; - } - } - - for(int j = n_obs; j < n; j++) - { - int j1 = j - n_obs; - double temp1 = P_t_t1[j1 + j1 * n_state]; - for (int i = 0; i < n; i++) - tmp[i + j1 * n] = tmp1 * T[i + j * n]; - for (int k = n_obs; k < j - 1; k++) - { - int k1 = k - n_obs; - temp1 = P_t_t1[k1 + j1 * n_state]; - for (int i = 0; i < n; i++) - tmp[i + j1 * n] += temp1 * T[i + k * n]; - } - for (int k = max(j + 1, n_obs); k < n; k++) - { - int k1 = k - n_obs; - temp1 = P_t_t1[j1 + k1 * n_state]; - for (int i = 0; i < n; i++) - tmp[i + j1 * n] += temp1 * T[i + k * n]; - } - } - - for(int j = n_obs; j < n; j++) - { - int j1 = j - n_obs; - double temp1 = P_t_t1[j1 + j1 * n_state]; - for (int i = 0; i < n; i++) - tmp[i + j1 * n] = tmp1 * T[i + j * n]; - for (int k = n_obs; k < j - 1; k++) - { - int k1 = k - n_obs; - temp1 = P_t_t1[k1 + j1 * n_state]; - for (int i = 0; i < n; i++) - if ((i < n_obs) || (i >= nb_diag + n_obs) || (j1 >= nb_diag)) - tmp[i + j1 * n] += temp1 * T[i + k * n]; - } - for (int k = max(j + 1, n_obs); k < n; k++) - { - int k1 = k - n_obs; - temp1 = P_t_t1[j1 + k1 * n_state]; - for (int i = 0; i < n; i++) - if ((i < n_obs) || (i >= nb_diag + n_obs) || (j1 >= nb_diag)) - tmp[i + j1 * n] += temp1 * T[i + k * n]; - } - }*/ for (int i = 0; i < n; i++) //int i = 0; for (int j = n_obs; j < n; j++) @@ -2902,7 +2811,6 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de for (vector::iterator it = v_index_KF.begin(); it != v_index_KF.end(); it++) KF_index_file.write(reinterpret_cast(&(*it)), sizeof(index_KF)); - //typedef pair, pair > index_KF_2; vector v_index_KF_2; int n_n_obs = n * n_obs; for (int i = 0; i < n; i++) From 39c7b793f2b8812cf58bacc851ae2bb9c9bc2c96 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Apr 2015 09:07:40 +0200 Subject: [PATCH 141/210] Add check for valid filename Uses the same restrictions as variable names. --- matlab/dynare.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/matlab/dynare.m b/matlab/dynare.m index 026670af9..ac6f01ab0 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -94,6 +94,10 @@ if ~ischar(fname) error('DYNARE: argument of dynare must be a text string') end +if ~isvarname(fname) + error('DYNARE: argument of dynare must conform to Matlab''s convention for naming functions, i.e. start with a letter and not contain special characters. Please rename your MOD-file.') +end + % Testing if file have extension % If no extension default .mod is added if isempty(strfind(fname,'.')) From 8eaa645800ae2779d7d1b7a4592d684fddfa2ab6 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Apr 2015 11:08:32 +0200 Subject: [PATCH 142/210] Fix compatibility of mode_compute=7 Uses wrapper as for mode_compute=3 to restore to conform to Octave syntax --- matlab/optimization/dynare_minimize_objective.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/matlab/optimization/dynare_minimize_objective.m b/matlab/optimization/dynare_minimize_objective.m index 9e8761bd2..65e38e050 100644 --- a/matlab/optimization/dynare_minimize_objective.m +++ b/matlab/optimization/dynare_minimize_objective.m @@ -240,7 +240,13 @@ switch minimizer_algorithm if ~isempty(options_.optim_opt) eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']); end - [opt_par_values,fval,exitflag] = fminsearch(objective_function,start_par_value,optim_options,varargin{:}); + if ~isoctave + [opt_par_values,fval,exitflag] = fminsearch(objective_function,start_par_value,optim_options,varargin{:}); + else + % Under Octave, use a wrapper, since fminsearch() does not have a 4th arg + func = @(x) objective_function(x,varargin{:}); + [opt_par_values,fval,exitflag] = fminsearch(func,start_par_value,optim_options); + end case 8 % Dynare implementation of the simplex algorithm. simplexOptions = options_.simplex; From df697febcb946340901275739f19f7e7a6081c69 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 22 Apr 2015 11:38:22 +0200 Subject: [PATCH 143/210] dseries: submodule update --- matlab/modules/dseries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index c976d1444..4aa6f4d33 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit c976d14444eeea21bc2cb36770344c0456e94e79 +Subproject commit 4aa6f4d335a4cfa688328b7d6748ecaee38f4ede From 8ab1239d7901c8de0e3444d6a182e581c33b249c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 22 Apr 2015 12:23:20 +0200 Subject: [PATCH 144/210] Fix handling of warnings in perfect foresight solver with homotopy. --- matlab/perfect-foresight-models/perfect_foresight_solver.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver.m b/matlab/perfect-foresight-models/perfect_foresight_solver.m index 76f2b69dc..5d1969313 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver.m @@ -68,6 +68,7 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy skipline() % Disable warnings if homotopy + warning_old_state = warning; warning off all % Do not print anything oldverbositylevel = options_.verbosity; @@ -147,7 +148,7 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy fprintf('++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n') skipline() options_.verbosity = oldverbositylevel; - warning on all + warning(warning_old_state); end if oo_.deterministic_simulation.status == 1 From 9f7d3524e95ebac8f293035d1dd55620cccd6b96 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Apr 2015 09:07:40 +0200 Subject: [PATCH 145/210] Add check for valid filename Uses the same restrictions as variable names. --- matlab/dynare.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 026670af9..3ab08aef4 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -96,6 +96,10 @@ end % Testing if file have extension % If no extension default .mod is added +dot_location=(strfind(fname,'.')); +if length(dot_location)>1 + error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions') +end if isempty(strfind(fname,'.')) fnamelength = length(fname); fname1 = [fname '.dyn']; @@ -106,9 +110,10 @@ if isempty(strfind(fname,'.')) fname = fname1; % Checking file extension else - if ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ... + if dot_location~=length(fname)-3 ... %if the file name has fewer than 4 characters and there is a period + || ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ... && ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN') - error('DYNARE: argument must be a filename with .mod or .dyn extension') + error('DYNARE: argument must be a filename with .mod or .dyn extension and must not include any other periods') end; fnamelength = length(fname) - 4; end; @@ -155,6 +160,10 @@ if ~exist(fname,'file') || isequal(fname,'dir') error(['dynare:: can''t open ' fname]) end +if ~isvarname(fname(1:end-4)) + error('DYNARE: argument of dynare must conform to Matlab''s convention for naming functions, i.e. start with a letter and not contain special characters. Please rename your MOD-file.') +end + % pre-dynare-preprocessor-hook if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') && exist([fname(1:end-4) filesep 'hooks/priorprocessing.m'],'file') run([fname(1:end-4) filesep 'hooks/priorprocessing']) From ac15eda6de782302a6092d6c586db727e2d30980 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 22 Apr 2015 13:55:35 +0200 Subject: [PATCH 146/210] Revert "Add check for valid filename" This reverts commit 39c7b793f2b8812cf58bacc851ae2bb9c9bc2c96. (would not be necessary if 9f7d3524e95ebac8f293035d1dd55620cccd6b96 had been rebased) --- matlab/dynare.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index ef07d0916..3ab08aef4 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -94,10 +94,6 @@ if ~ischar(fname) error('DYNARE: argument of dynare must be a text string') end -if ~isvarname(fname) - error('DYNARE: argument of dynare must conform to Matlab''s convention for naming functions, i.e. start with a letter and not contain special characters. Please rename your MOD-file.') -end - % Testing if file have extension % If no extension default .mod is added dot_location=(strfind(fname,'.')); From f86b91d3d67635f327b6880f7c42fa5548984d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 22 Apr 2015 14:44:39 +0200 Subject: [PATCH 147/210] Perfect foresight solver: inform the user when we switch to a homotopy method. --- matlab/perfect-foresight-models/perfect_foresight_solver.m | 1 + 1 file changed, 1 insertion(+) diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver.m b/matlab/perfect-foresight-models/perfect_foresight_solver.m index 5d1969313..4c1ee15a0 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver.m @@ -65,6 +65,7 @@ oo_ = simulation_core(options_, M_, oo_); if ~oo_.deterministic_simulation.status && ~options_.no_homotopy skipline() disp('Simulation of the perfect foresight model failed!') + disp('Switching to a homotopy method...') skipline() % Disable warnings if homotopy From 0dac179944016dbeb7d22be6f8aed4ee26d49cdf Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Apr 2015 15:26:03 +0200 Subject: [PATCH 148/210] Improve display of tables Closes #892 by allowing for optional inputs for cell lengths. Replaces centering of headers by right-flush to improve readability. --- matlab/dyntable.m | 67 ++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/matlab/dyntable.m b/matlab/dyntable.m index 181d7e3ab..2330dc3ba 100644 --- a/matlab/dyntable.m +++ b/matlab/dyntable.m @@ -1,7 +1,16 @@ -function dyntable(title,headers,labels,values,label_width,val_width, ... - val_precis) - -% Copyright (C) 2002-2013 Dynare Team +function dyntable(title,headers,labels,values,label_width,val_width,val_precis) +% function dyntable(title,headers,labels,values,label_width,val_width,val_precis) +% Inputs: +% title [string] Table title +% headers [n by nchar] character array of labels for header row +% labels [n by nchar] character array of labels for label column +% values [matrix] matrix of values to display +% label_width [scalar] Width of the label +% val_width [scalar] Width of value column +% val_precis [integer] precision of displayed values +% +% +% Copyright (C) 2002-2015 Dynare Team % % This file is part of Dynare. % @@ -24,48 +33,46 @@ if options_.noprint return end -%label_width = max(size(deblank(char(headers(1,:),labels)),2)+2, ... -% label_width); -label_width = max(size(deblank(char(headers(1,:),labels)),2))+2; - -label_fmt = sprintf('%%-%ds',label_width); +%% get width of label column +if ~isempty(label_width) + label_width = max(size(deblank(char(headers(1,:),labels)),2)+2, ... + label_width); +else %use default length + label_width = max(size(deblank(char(headers(1,:),labels)),2))+2; +end +label_format_leftbound = sprintf('%%-%ds',label_width); +%% get width of label column if all(~isfinite(values)) values_length = 4; else values_length = max(ceil(max(max(log10(abs(values(isfinite(values))))))),1)+val_precis+1; end -if any(values) < 0 +if any(values) < 0 %add one character for minus sign values_length = values_length+1; end -headers_length = max(size(deblank(headers(2:end,:)),2)); -%val_width = max(values_length,val_width); -val_width = max(headers_length,values_length)+2; -%header_fmt = sprintf('%%-%ds',val_width); -val_fmt = sprintf('%%%d.%df',val_width,val_precis); -headers_offset = 0; -values_offset = 0; -if headers_length > values_length - % values_offset = ceil((val_width-values_length)/2); +%% get width of header strings +headers_length = max(size(deblank(headers(2:end,:)),2)); +if ~isempty(val_width) + val_width = max(max(headers_length,values_length)+2,val_width); +else + val_width = max(headers_length,values_length)+2; end +value_format = sprintf('%%%d.%df',val_width,val_precis); +header_string_format = sprintf('%%%ds',val_width); if length(title) > 0 - disp(sprintf('\n\n%s\n',title)); + fprintf('\n\n%s\n',title); end +%Create and print header string if length(headers) > 0 - hh = sprintf(label_fmt,headers(1,:)); + hh = sprintf(label_format_leftbound ,deblank(headers(1,:))); for i=2:size(headers,1) - hla = size(deblank(headers(i,:)),2); - hlb = ceil((val_width - hla)/2); - hla = val_width - hla - hlb; - hh = [hh char(32*ones(1,hlb)) deblank(headers(i,:)) ... - char(32*ones(1,hla))]; + hh = [hh sprintf(header_string_format,deblank(headers(i,:)))]; end disp(hh); end for i=1:size(values,1) - disp([sprintf(label_fmt,deblank(labels(i,:))) char(32*ones(1,values_offset)) sprintf(val_fmt,values(i,:))]); -end - -% 10/30/02 MJ \ No newline at end of file + disp([sprintf(label_format_leftbound ,deblank(labels(i,:))) sprintf(value_format ,values(i,:))]); +end \ No newline at end of file From 20a4f551ed22b32dad5466215f69d09d898ee4b8 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Apr 2015 15:29:04 +0200 Subject: [PATCH 149/210] Improve display of decision rules by accounting for variable lengths Also cleans up file by factoring code --- matlab/disp_dr.m | 117 +++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/matlab/disp_dr.m b/matlab/disp_dr.m index 34fd620c3..56fd42230 100644 --- a/matlab/disp_dr.m +++ b/matlab/disp_dr.m @@ -1,5 +1,5 @@ - function disp_dr(dr,order,var_list) +% function disp_dr(dr,order,var_list) % Display the decision rules % % INPUTS @@ -7,8 +7,8 @@ function disp_dr(dr,order,var_list) % order [int]: order of approximation % var_list [char array]: list of endogenous variables for which the % decision rules should be printed - -% Copyright (C) 2001-2012 Dynare Team +% +% Copyright (C) 2001-2015 Dynare Team % % This file is part of Dynare. % @@ -55,44 +55,67 @@ for i=1:nvar end end +% get length of display strings +header_label_length=16; %default +for ii=1:length(ivar) + header_label_length=max(header_label_length,length(deblank(M_.endo_names(k1(ivar(ii)),:)))+2); +end +header_label_format = sprintf('%%%ds',header_label_length); +value_format_float = sprintf('%%%d.6f',header_label_length); +value_format_zero = sprintf('%%%dd',header_label_length); + +% account for additional characters introduced by auxiliary variables +if ~isempty(M_.aux_vars) + aux_vars_type = [M_.aux_vars.type]; + if any(aux_vars_type==4) + aux_var_additional_characters=14; + else + aux_var_additional_characters=3; + end +else + aux_var_additional_characters=0; +end + +var_name_width=max([max(size(deblank(M_.endo_names(k1(ivar),:)),2)),max(size(deblank(M_.exo_names),2))]); + +%deal with covariances +if order > 1 + var_name_width=max(2*(var_name_width+aux_var_additional_characters)+2,20); %account for covariances, separated by comma +else + var_name_width=max(var_name_width+aux_var_additional_characters,20); +end +label_format = sprintf('%%-%ds',var_name_width); + + +%% start displayimg disp('POLICY AND TRANSITION FUNCTIONS') % variable names -str = ' '; +str = char(32*ones(1,var_name_width)); for i=1:nvar - str = [str sprintf('%16s',M_.endo_names(k1(ivar(i)),:))]; + str = [str sprintf(header_label_format,M_.endo_names(k1(ivar(i)),:))]; end disp(str); % % constant % -str = 'Constant '; +str=sprintf(label_format,'Constant'); flag = 0; for i=1:nvar x = dr.ys(k1(ivar(i))); if order > 1 x = x + dr.ghs2(ivar(i))/2; end - if abs(x) > 1e-6 - flag = 1; - str = [str sprintf('%16.6f',x)]; - else - str = [str ' 0']; - end + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); end if flag disp(str) end if order > 1 - str = '(correction) '; + str = sprintf(label_format,'(correction)'); flag = 0; for i=1:nvar x = dr.ghs2(ivar(i))/2; - if abs(x) > 1e-6 - flag = 1; - str = [str sprintf('%16.6f',x)]; - else - str = [str ' 0']; - end + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); end if flag disp(str) @@ -108,15 +131,10 @@ for k=1:nx else str1 = subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2); end - str = sprintf('%-20s',str1); + str = sprintf(label_format,str1); for i=1:nvar x = dr.ghx(ivar(i),k); - if abs(x) > 1e-6 - flag = 1; - str = [str sprintf('%16.6f',x)]; - else - str = [str ' 0']; - end + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); end if flag disp(str) @@ -127,15 +145,10 @@ end % for k=1:nu flag = 0; - str = sprintf('%-20s',M_.exo_names(k,:)); + str = sprintf(label_format,M_.exo_names(k,:)); for i=1:nvar x = dr.ghu(ivar(i),k); - if abs(x) > 1e-6 - flag = 1; - str = [str sprintf('%16.6f',x)]; - else - str = [str ' 0']; - end + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); end if flag disp(str) @@ -149,19 +162,14 @@ if order > 1 flag = 0; str1 = sprintf('%s,%s',subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2), ... subst_auxvar(k1(klag(j,1)),klag(j,2)-M_.maximum_lag-2)); - str = sprintf('%-20s',str1); + str = sprintf(label_format,str1); for i=1:nvar if k == j x = dr.ghxx(ivar(i),(k-1)*nx+j)/2; else x = dr.ghxx(ivar(i),(k-1)*nx+j); end - if abs(x) > 1e-6 - flag = 1; - str = [str sprintf('%16.6f',x)]; - else - str = [str ' 0']; - end + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); end if flag disp(str) @@ -174,19 +182,14 @@ if order > 1 for k = 1:nu for j = 1:k flag = 0; - str = sprintf('%-20s',[M_.exo_names(k,:) ',' M_.exo_names(j,:)] ); + str = sprintf(label_format,[deblank(M_.exo_names(k,:)) ',' deblank(M_.exo_names(j,:))] ); for i=1:nvar if k == j x = dr.ghuu(ivar(i),(k-1)*nu+j)/2; else x = dr.ghuu(ivar(i),(k-1)*nu+j); end - if abs(x) > 1e-6 - flag = 1; - str = [str sprintf('%16.6f',x)]; - else - str = [str ' 0']; - end + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); end if flag disp(str) @@ -200,16 +203,11 @@ if order > 1 for j = 1:nu flag = 0; str1 = sprintf('%s,%s',subst_auxvar(k1(klag(k,1)),klag(k,2)-M_.maximum_lag-2), ... - M_.exo_names(j,:)); - str = sprintf('%-20s',str1); + deblank(M_.exo_names(j,:))); + str = sprintf(label_format,str1); for i=1:nvar x = dr.ghxu(ivar(i),(k-1)*nu+j); - if abs(x) > 1e-6 - flag = 1; - str = [str sprintf('%16.6f',x)]; - else - str = [str ' 0']; - end + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); end if flag disp(str) @@ -253,3 +251,12 @@ for i = 1:length(M_.aux_vars) end error(sprintf('Could not find aux var: %s', M_.endo_names(aux_index, :))) end + +function [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag) + if abs(x) > 1e-6 + flag = 1; + str = [str sprintf(value_format_float,x)]; + else + str = [str sprintf(value_format_zero,0)]; + end +end \ No newline at end of file From 8285121f9b2620101a33ae125968acfe4de9732b Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 22 Apr 2015 15:37:35 +0200 Subject: [PATCH 150/210] Allow selection of tolerance for display of decision rules --- matlab/disp_dr.m | 18 +++++++++--------- matlab/global_initialization.m | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/matlab/disp_dr.m b/matlab/disp_dr.m index 56fd42230..243a8f5b9 100644 --- a/matlab/disp_dr.m +++ b/matlab/disp_dr.m @@ -105,7 +105,7 @@ for i=1:nvar if order > 1 x = x + dr.ghs2(ivar(i))/2; end - [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_); end if flag disp(str) @@ -115,7 +115,7 @@ if order > 1 flag = 0; for i=1:nvar x = dr.ghs2(ivar(i))/2; - [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_); end if flag disp(str) @@ -134,7 +134,7 @@ for k=1:nx str = sprintf(label_format,str1); for i=1:nvar x = dr.ghx(ivar(i),k); - [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_); end if flag disp(str) @@ -148,7 +148,7 @@ for k=1:nu str = sprintf(label_format,M_.exo_names(k,:)); for i=1:nvar x = dr.ghu(ivar(i),k); - [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_); end if flag disp(str) @@ -169,7 +169,7 @@ if order > 1 else x = dr.ghxx(ivar(i),(k-1)*nx+j); end - [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_); end if flag disp(str) @@ -189,7 +189,7 @@ if order > 1 else x = dr.ghuu(ivar(i),(k-1)*nu+j); end - [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_); end if flag disp(str) @@ -207,7 +207,7 @@ if order > 1 str = sprintf(label_format,str1); for i=1:nvar x = dr.ghxu(ivar(i),(k-1)*nu+j); - [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag); + [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_); end if flag disp(str) @@ -252,8 +252,8 @@ end error(sprintf('Could not find aux var: %s', M_.endo_names(aux_index, :))) end -function [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag) - if abs(x) > 1e-6 +function [str,flag]=get_print_string(str,x,value_format_zero,value_format_float,flag,options_) + if abs(x) > options_.dr_display_tol flag = 1; str = [str sprintf(value_format_float,x)]; else diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 4ec37b459..f19dd0349 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -55,6 +55,7 @@ options_.qz_zero_threshold = 1e-6; options_.lyapunov_complex_threshold = 1e-15; options_.solve_tolf = eps^(1/3); options_.solve_tolx = eps^(2/3); +options_.dr_display_tol=1e-6; options_.dp.maxit = 3000; options_.steady.maxit = 50; From db272f114b66322a07084444301f1fae346e4d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 22 Apr 2015 16:45:15 +0200 Subject: [PATCH 151/210] Compatibility fixes for MATLAB <= 7.7. The tilde syntax was introduced in MATLAB 7.8. --- matlab/lmmcp/lmmcp.m | 2 +- matlab/perfect-foresight-models/private/simulation_core.m | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/matlab/lmmcp/lmmcp.m b/matlab/lmmcp/lmmcp.m index 2d6189fd0..aa170222c 100644 --- a/matlab/lmmcp/lmmcp.m +++ b/matlab/lmmcp/lmmcp.m @@ -392,7 +392,7 @@ while (k < kmax) && (Psix > eps2) Fx = Fxnew; Phix = Phixnew; Psix = Psixnew; - [~,DFx] = feval(FUN,x,varargin{:}); + [junk,DFx] = feval(FUN,x,varargin{:}); DPhix = DPhi(x,Fx,DFx,lb,ub,lambda1,lambda2,n,Indexset); DPsix = DPhix'*Phix; normDPsix = norm(DPsix); diff --git a/matlab/perfect-foresight-models/private/simulation_core.m b/matlab/perfect-foresight-models/private/simulation_core.m index 6e86671df..ecf5c8964 100644 --- a/matlab/perfect-foresight-models/private/simulation_core.m +++ b/matlab/perfect-foresight-models/private/simulation_core.m @@ -75,9 +75,9 @@ else yT = y(:,periods+2); z = y(:,2:periods+1); illi = M_.lead_lag_incidence'; - [i_cols,~,i_cols_j] = find(illi(:)); + [i_cols,junk,i_cols_j] = find(illi(:)); illi = illi(:,2:3); - [i_cols_J1,~,i_cols_1] = find(illi(:)); + [i_cols_J1,junk,i_cols_1] = find(illi(:)); i_cols_T = nonzeros(M_.lead_lag_incidence(1:2,:)'); [y,info] = dynare_solve(@perfect_foresight_problem,z(:),1, ... str2func([M_.fname '_dynamic']),y0,yT, ... @@ -109,9 +109,9 @@ if nargout>1 yy = oo_.endo_simul(:,2:options_.periods+1); if ~exist('illi') illi = M_.lead_lag_incidence'; - [i_cols,~,i_cols_j] = find(illi(:)); + [i_cols,junk,i_cols_j] = find(illi(:)); illi = illi(:,2:3); - [i_cols_J1,~,i_cols_1] = find(illi(:)); + [i_cols_J1,junk,i_cols_1] = find(illi(:)); i_cols_T = nonzeros(M_.lead_lag_incidence(1:2,:)'); end if options_.block && ~options_.bytecode From 4ffebeee2e37d8dd1d9226955cadc10896da2016 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 23 Apr 2015 14:15:47 +0200 Subject: [PATCH 152/210] dseries: submodule update --- matlab/modules/dseries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/dseries b/matlab/modules/dseries index 4aa6f4d33..55686d7f0 160000 --- a/matlab/modules/dseries +++ b/matlab/modules/dseries @@ -1 +1 @@ -Subproject commit 4aa6f4d335a4cfa688328b7d6748ecaee38f4ede +Subproject commit 55686d7f06673bde2ab52e75833a1bbdba16b2a1 From f6c29d9eb4455da45388389d322e2e2f3a99976f Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 24 Apr 2015 09:42:23 +0200 Subject: [PATCH 153/210] Deletes redundant mode_compute tests and moves others to optimizers directory Closes #888 --- tests/Makefile.am | 6 +- tests/fs2000/fs2000_cmaes.mod | 75 ---------------------- tests/fs2000/fs2000_mode_compute_8.mod | 82 ------------------------ tests/fs2000/fs2000d.mod | 75 ---------------------- tests/fs2000/fs2000e.mod | 75 ---------------------- tests/optimizers/fs2000_4_with_optim.mod | 3 + tests/optimizers/fs2000_8_with_optim.mod | 11 ++++ 7 files changed, 16 insertions(+), 311 deletions(-) delete mode 100644 tests/fs2000/fs2000_cmaes.mod delete mode 100644 tests/fs2000/fs2000_mode_compute_8.mod delete mode 100644 tests/fs2000/fs2000d.mod delete mode 100644 tests/fs2000/fs2000e.mod create mode 100644 tests/optimizers/fs2000_4_with_optim.mod create mode 100644 tests/optimizers/fs2000_8_with_optim.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index af4d71ab3..c4c4cc41c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -90,15 +90,11 @@ MODFILES = \ fs2000/fs2000.mod \ fs2000/fs2000a.mod \ fs2000/fs2000c.mod \ - fs2000/fs2000d.mod \ - fs2000/fs2000e.mod \ - fs2000/fs2000_cmaes.mod \ fs2000/fs2000_calib.mod \ fs2000/fs2000_calib_dseries.mod \ fs2000/fs2000_analytic_derivation.mod \ fs2000/fs2000_missing_data.mod \ fs2000/fs2000_sd.mod \ - fs2000/fs2000_mode_compute_8.mod \ fs2000/fs2000_dseries_a.mod \ fs2000/fs2000_dseries_b.mod \ homotopy/homotopy1_test.mod \ @@ -210,10 +206,12 @@ MODFILES = \ optimizers/fs2000_2.mod \ optimizers/fs2000_3.mod \ optimizers/fs2000_4.mod \ + optimizers/fs2000_4_with_optim.mod \ optimizers/fs2000_5.mod \ optimizers/fs2000_6.mod \ optimizers/fs2000_7.mod \ optimizers/fs2000_8.mod \ + optimizers/fs2000_8_with_optim.mod \ optimizers/fs2000_9.mod \ optimizers/fs2000_10.mod \ optimizers/fs2000_101.mod \ diff --git a/tests/fs2000/fs2000_cmaes.mod b/tests/fs2000/fs2000_cmaes.mod deleted file mode 100644 index 5ef75a76b..000000000 --- a/tests/fs2000/fs2000_cmaes.mod +++ /dev/null @@ -1,75 +0,0 @@ -// See fs2000.mod in the examples/ directory for details on the model - -var m P c e W R k d n l gy_obs gp_obs y dA; -varexo e_a e_m; - -parameters alp bet gam mst rho psi del; - -alp = 0.33; -bet = 0.99; -gam = 0.003; -mst = 1.011; -rho = 0.7; -psi = 0.787; -del = 0.02; - -model; -dA = exp(gam+e_a); -log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; --P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; -W = l/n; --(psi/(1-psi))*(c*P/(1-n))+l/n = 0; -R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; -1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; -c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); -P*c = m; -m-1+d = l; -e = exp(e_a); -y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); -gy_obs = dA*y/y(-1); -gp_obs = (P/P(-1))*m(-1)/dA; -end; - -initval; -k = 6; -m = mst; -P = 2.25; -c = 0.45; -e = 1; -W = 4; -R = 1.02; -d = 0.85; -n = 0.19; -l = 0.86; -y = 0.6; -gy_obs = exp(gam); -gp_obs = exp(-gam); -dA = exp(gam); -end; - -shocks; -var e_a; stderr 0.014; -var e_m; stderr 0.005; -end; - -steady; - -check; - -estimated_params; -alp, beta_pdf, 0.356, 0.02; -bet, beta_pdf, 0.993, 0.002; -gam, normal_pdf, 0.0085, 0.003; -mst, normal_pdf, 1.0002, 0.007; -rho, beta_pdf, 0.129, 0.223; -psi, beta_pdf, 0.65, 0.05; -del, beta_pdf, 0.01, 0.005; -stderr e_a, inv_gamma_pdf, 0.035449, inf; -stderr e_m, inv_gamma_pdf, 0.008862, inf; -end; - -varobs gp_obs gy_obs; - -options_.solve_tolf = 1e-12; - -estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mode_compute=9,mh_replic=0); diff --git a/tests/fs2000/fs2000_mode_compute_8.mod b/tests/fs2000/fs2000_mode_compute_8.mod deleted file mode 100644 index 4f39e10bf..000000000 --- a/tests/fs2000/fs2000_mode_compute_8.mod +++ /dev/null @@ -1,82 +0,0 @@ -// See fs2000.mod in the examples/ directory for details on the model - -var m P c e W R k d n l gy_obs gp_obs y dA; -varexo e_a e_m; - -parameters alp bet gam mst rho psi del; - -alp = 0.33; -bet = 0.99; -gam = 0.003; -mst = 1.011; -rho = 0.7; -psi = 0.787; -del = 0.02; - -model; -dA = exp(gam+e_a); -log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; --P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; -W = l/n; --(psi/(1-psi))*(c*P/(1-n))+l/n = 0; -R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; -1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; -c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); -P*c = m; -m-1+d = l; -e = exp(e_a); -y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); -gy_obs = dA*y/y(-1); -gp_obs = (P/P(-1))*m(-1)/dA; -end; - -initval; -k = 6; -m = mst; -P = 2.25; -c = 0.45; -e = 1; -W = 4; -R = 1.02; -d = 0.85; -n = 0.19; -l = 0.86; -y = 0.6; -gy_obs = exp(gam); -gp_obs = exp(-gam); -dA = exp(gam); -end; - -shocks; -var e_a; stderr 0.014; -var e_m; stderr 0.005; -end; - -steady; - -check; - -estimated_params; -alp, beta_pdf, 0.356, 0.02; -bet, beta_pdf, 0.993, 0.002; -gam, normal_pdf, 0.0085, 0.003; -mst, normal_pdf, 1.0002, 0.007; -rho, beta_pdf, 0.129, 0.223; -psi, beta_pdf, 0.65, 0.05; -del, beta_pdf, 0.01, 0.005; -stderr e_a, inv_gamma_pdf, 0.035449, inf; -stderr e_m, inv_gamma_pdf, 0.008862, inf; -end; - -varobs gp_obs gy_obs; - -options_.solve_tolf = 1e-12; - -estimation(order=1,datafile=fsdat_simul,nobs=192,mode_compute=8,loglinear,mh_replic=0,optim=( -'MaxIter',5000, -'TolFun',1e-4, -'TolX',1e-4, -'MaxFunEvals',5000, -'MaxFunEvalFactor',500, -'InitialSimplexSize',0.05 -)); diff --git a/tests/fs2000/fs2000d.mod b/tests/fs2000/fs2000d.mod deleted file mode 100644 index 04f122805..000000000 --- a/tests/fs2000/fs2000d.mod +++ /dev/null @@ -1,75 +0,0 @@ -// See fs2000.mod in the examples/ directory for details on the model - -var m P c e W R k d n l gy_obs gp_obs y dA; -varexo e_a e_m; - -parameters alp bet gam mst rho psi del; - -alp = 0.33; -bet = 0.99; -gam = 0.003; -mst = 1.011; -rho = 0.7; -psi = 0.787; -del = 0.02; - -model; -dA = exp(gam+e_a); -log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; --P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; -W = l/n; --(psi/(1-psi))*(c*P/(1-n))+l/n = 0; -R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; -1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; -c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); -P*c = m; -m-1+d = l; -e = exp(e_a); -y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); -gy_obs = dA*y/y(-1); -gp_obs = (P/P(-1))*m(-1)/dA; -end; - -initval; -k = 6; -m = mst; -P = 2.25; -c = 0.45; -e = 1; -W = 4; -R = 1.02; -d = 0.85; -n = 0.19; -l = 0.86; -y = 0.6; -gy_obs = exp(gam); -gp_obs = exp(-gam); -dA = exp(gam); -end; - -shocks; -var e_a; stderr 0.014; -var e_m; stderr 0.005; -end; - -steady; - -check; - -estimated_params; -alp, beta_pdf, 0.356, 0.02; -bet, beta_pdf, 0.993, 0.002; -gam, normal_pdf, 0.0085, 0.003; -mst, normal_pdf, 1.0002, 0.007; -rho, beta_pdf, 0.129, 0.223; -psi, beta_pdf, 0.65, 0.05; -del, beta_pdf, 0.01, 0.005; -stderr e_a, inv_gamma_pdf, 0.035449, inf; -stderr e_m, inv_gamma_pdf, 0.008862, inf; -end; - -varobs gp_obs gy_obs; - -options_.solve_tolf = 1e-12; - -estimation(order=1,datafile=fsdat_simul,nobs=192,mode_compute=5,loglinear,mh_replic=0); diff --git a/tests/fs2000/fs2000e.mod b/tests/fs2000/fs2000e.mod deleted file mode 100644 index 83416a791..000000000 --- a/tests/fs2000/fs2000e.mod +++ /dev/null @@ -1,75 +0,0 @@ -// See fs2000.mod in the examples/ directory for details on the model - -var m P c e W R k d n l gy_obs gp_obs y dA; -varexo e_a e_m; - -parameters alp bet gam mst rho psi del; - -alp = 0.33; -bet = 0.99; -gam = 0.003; -mst = 1.011; -rho = 0.7; -psi = 0.787; -del = 0.02; - -model; -dA = exp(gam+e_a); -log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; --P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; -W = l/n; --(psi/(1-psi))*(c*P/(1-n))+l/n = 0; -R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; -1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; -c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); -P*c = m; -m-1+d = l; -e = exp(e_a); -y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); -gy_obs = dA*y/y(-1); -gp_obs = (P/P(-1))*m(-1)/dA; -end; - -initval; -k = 6; -m = mst; -P = 2.25; -c = 0.45; -e = 1; -W = 4; -R = 1.02; -d = 0.85; -n = 0.19; -l = 0.86; -y = 0.6; -gy_obs = exp(gam); -gp_obs = exp(-gam); -dA = exp(gam); -end; - -shocks; -var e_a; stderr 0.014; -var e_m; stderr 0.005; -end; - -steady; - -check; - -estimated_params; -alp, beta_pdf, 0.356, 0.02; -bet, beta_pdf, 0.993, 0.002; -gam, normal_pdf, 0.0085, 0.003; -mst, normal_pdf, 1.0002, 0.007; -rho, beta_pdf, 0.129, 0.223; -psi, beta_pdf, 0.65, 0.05; -del, beta_pdf, 0.01, 0.005; -stderr e_a, inv_gamma_pdf, 0.035449, inf; -stderr e_m, inv_gamma_pdf, 0.008862, inf; -end; - -varobs gp_obs gy_obs; - -options_.solve_tolf = 1e-12; - -estimation(order=1,datafile=fsdat_simul,nobs=192,optim=('NumgradEpsilon',1e-6,'NumgradAlgorithm',3,'MaxIter',100,'InitialInverseHessian','eye(9)*.0001'),loglinear,mh_replic=0); diff --git a/tests/optimizers/fs2000_4_with_optim.mod b/tests/optimizers/fs2000_4_with_optim.mod new file mode 100644 index 000000000..ecb4254ed --- /dev/null +++ b/tests/optimizers/fs2000_4_with_optim.mod @@ -0,0 +1,3 @@ +@#include "fs2000.common.inc" + +estimation(mode_compute=4,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0,optim=('NumgradEpsilon',1e-6,'NumgradAlgorithm',3,'MaxIter',100,'InitialInverseHessian','eye(9)*.0001')); \ No newline at end of file diff --git a/tests/optimizers/fs2000_8_with_optim.mod b/tests/optimizers/fs2000_8_with_optim.mod new file mode 100644 index 000000000..c166d7047 --- /dev/null +++ b/tests/optimizers/fs2000_8_with_optim.mod @@ -0,0 +1,11 @@ +@#include "fs2000.common.inc" + +options_.solve_tolf = 1e-12; +estimation(mode_compute=8,order=1, datafile='../fs2000/fsdat_simul', nobs=192, mh_replic=0,optim=( +'MaxIter',5000, +'TolFun',1e-4, +'TolX',1e-4, +'MaxFunEvals',5000, +'MaxFunEvalFactor',500, +'InitialSimplexSize',0.05 +)); From eed98a2c44d829fe0a6c43cdef09e47f864287a3 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 24 Apr 2015 12:30:51 +0200 Subject: [PATCH 154/210] Adds documentation and license info for new optimizers Also introduced alphabetic ordering for documented options Closes #887 --- doc/dynare.texi | 144 +++++++++++++++++++++++++++++++++++++++--------- license.txt | 13 +++++ 2 files changed, 131 insertions(+), 26 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 8d5a09c2a..78f25b4d7 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -4859,10 +4859,11 @@ compute the smoothed value of the variables of a model with calibrated parameter @item 1 Uses @code{fmincon} optimization routine (available under MATLAB if -the optimization toolbox is installed; not available under Octave) +the Optimization Toolbox is installed; not available under Octave) @item 2 -Value no longer used +Uses the continuous simulated annealing global optimization algorithm +described in @cite{Corana et al. (1987)} and @cite{Goffe et al. (1994)}. @item 3 Uses @code{fminunc} optimization routine (available under MATLAB if @@ -4896,12 +4897,21 @@ routine (generally more efficient than the MATLAB or Octave implementation available with @code{mode_compute=7}) @item 9 -Uses the CMA-ES (Covariance Matrix Adaptation Evolution Strategy) algorithm, an evolutionary algorithm for difficult non-linear non-convex optimization +Uses the CMA-ES (Covariance Matrix Adaptation Evolution Strategy) algorithm of +@cite{Hansen and Kern (2004)}, an evolutionary algorithm for difficult non-linear non-convex optimization @item 10 Uses the simpsa algorithm, based on the combination of the non-linear simplex and simulated annealing algorithms and proposed by @cite{Cardoso, Salcedo and Feyo de Azevedo (1996)}. +@item 101 +Uses the SolveOpt algorithm for local nonlinear optimization problems proposed by +@cite{Kuntsevich and Kappel (1997)}. + +@item 102 +Uses @code{simulannealbnd} optimization routine (available under MATLAB if +the Global Optimization Toolbox is installed; not available under Octave) + @item @var{FUNCTION_NAME} It is also possible to give a @var{FUNCTION_NAME} to this option, instead of an @var{INTEGER}. In that case, Dynare takes the return @@ -4972,13 +4982,54 @@ A list of @var{NAME} and @var{VALUE} pairs. Can be used to set options for the o @table @code @item 1, 3, 7 -Available options are given in the documentation of the MATLAB optimization toolbox or in Octave's documentation. +Available options are given in the documentation of the MATLAB Optimization Toolbox or in Octave's documentation. + +@item 2 +Available options are: + +@table @code + +@item 'initial_step_length' +Initial step length. Default: @code{1} + +@item 'initial_temperature' +Initial temperature. Default: @code{15} + +@item 'MaxIter' +Maximum number of function evaluations. Default: @code{100000} + +@item 'neps' +Number of final function values used to decide upon termination. Default: @code{10} + +@item 'ns' +Number of cycles. Default: @code{10} + +@item 'nt' +Number of iterations before temperature reduction. Default: @code{10} + +@item 'step_length_c' +Step length adjustment. Default: @code{0.1} + +@item 'TolFun' +Stopping criteria. Default: @code{1e-8} + +@item 'rt' +Temperature reduction factor. Default: @code{0.1} + +@item 'verbosity' +Controls verbosity of display during optimization, ranging from 0 (silent) to 3 +(each function evaluation). Default: @code{1} + +@end table @item 4 Available options are: @table @code +@item 'InitialInverseHessian' +Initial approximation for the inverse of the Hessian matrix of the posterior kernel (or likelihood). Obviously this approximation has to be a square, positive definite and symmetric matrix. Default: @code{'1e-4*eye(nx)'}, where @code{nx} is the number of parameters to be estimated. + @item 'MaxIter' Maximum number of iterations. Default: @code{1000} @@ -4991,9 +5042,6 @@ Size of the perturbation used to compute numerically the gradient of the objecti @item 'TolFun' Stopping criteria. Default: @code{1e-7} -@item 'InitialInverseHessian' -Initial approximation for the inverse of the Hessian matrix of the posterior kernel (or likelihood). Obviously this approximation has to be a square, positive definite and symmetric matrix. Default: @code{'1e-4*eye(nx)'}, where @code{nx} is the number of parameters to be estimated. - @end table @item 5 @@ -5001,15 +5049,15 @@ 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 'MaxIter' +Maximum number of iterations. Default: @code{1000} + @item 'TolFun' Stopping criteria. Default: @code{1e-5} for numerical derivatives @code{1e-7} for analytic derivatives. @@ -5020,8 +5068,14 @@ Available options are: @table @code -@item 'NumberOfMh' -Number of MCMC run sequentially. Default: @code{3} +@item 'AcceptanceRateTarget' +A real number between zero and one. The scale parameter of the jumping distribution is adjusted so that the effective acceptance rate matches the value of option @code{'AcceptanceRateTarget'}. Default: @code{1.0/3.0} + +@item 'InitialCovarianceMatrix' +Initial covariance matrix of the jumping distribution. Default is @code{'previous'} if option @code{mode_file} is used, @code{'prior'} otherwise. + +@item 'nclimb' +Number of iterations in the last MCMC (climbing mode). @item 'ncov-mh' Number of iterations used for updating the covariance matrix of the jumping distribution. Default: @code{20000} @@ -5029,14 +5083,8 @@ Number of iterations used for updating the covariance matrix of the jumping dist @item 'nscale-mh' Maximum number of iterations used for adjusting the scale parameter of the jumping distribution. @code{200000} -@item 'nclimb' -Number of iterations in the last MCMC (climbing mode). - -@item 'InitialCovarianceMatrix' -Initial covariance matrix of the jumping distribution. Default is @code{'previous'} if option @code{mode_file} is used, @code{'prior'} otherwise. - -@item 'AcceptanceRateTarget' -A real number between zero and one. The scale parameter of the jumping distribution is adjusted so that the effective acceptance rate matches the value of option @code{'AcceptanceRateTarget'}. Default: @code{1.0/3.0} +@item 'NumberOfMh' +Number of MCMC run sequentially. Default: @code{3} @end table @@ -5045,6 +5093,9 @@ Available options are: @table @code +@item 'InitialSimplexSize' +Initial size of the simplex, expressed as percentage deviation from the provided initial guess in each direction. Default: @code{.05} + @item 'MaxIter' Maximum number of iterations. Default: @code{5000} @@ -5060,10 +5111,6 @@ Tolerance parameter (w.r.t the objective function). Default: @code{1e-4} @item 'TolX' Tolerance parameter (w.r.t the instruments). Default: @code{1e-4} -@item 'InitialSimplexSize' - -Initial size of the simplex, expressed as percentage deviation from the provided initial guess in each direction. Default: @code{.05} - @end table @item 9 @@ -5090,6 +5137,9 @@ Available options are: @table @code +@item 'EndTemperature' +Terminal condition w.r.t the temperature. When the temperature reaches @code{EndTemperature}, the temperature is set to zero and the algorithm falls back into a standard simplex algorithm. Default: @code{.1} + @item 'MaxIter' Maximum number of iterations. Default: @code{5000} @@ -5102,11 +5152,33 @@ Tolerance parameter (w.r.t the objective function). Default: @code{1e-4} @item 'TolX' Tolerance parameter (w.r.t the instruments). Default: @code{1e-4} -@item 'EndTemperature' -Terminal condition w.r.t the temperature. When the temperature reaches @code{EndTemperature}, the temperature is set to zero and the algorithm falls back into a standard simplex algorithm. Default: @code{.1} +@end table + +@item 101 +Available options are: + +@table @code + +@item 'LBGradientStep' +Lower bound for the stepsize used for the difference approximation of gradients. Default: @code{1e-11} + +@item 'MaxIter' +Maximum number of iterations. Default: @code{15000} + +@item 'SpaceDilation' +Coefficient of space dilation. Default: @code{2.5} + +@item 'TolFun' +Tolerance parameter (w.r.t the objective function). Default: @code{1e-6} + +@item 'TolX' +Tolerance parameter (w.r.t the instruments). Default: @code{1e-6} @end table +@item 102 +Available options are given in the documentation of the MATLAB Global Optimization Toolbox. + @end table @customhead{Example 1} @@ -12428,6 +12500,11 @@ Expansion Approach to Simulation of Stochastic Forward-Looking Models with an Application to a Non-Linear Phillips Curve,'' @i{Computational Economics}, 17, 125--139 +@item +Corona, Angelo, M. Marchesi, Claudio Martini, and Sandro Ridella (1987): +``Minimizing multimodal functions of continuous variables with the ``simulated annealing'' algorithm'', +@i{ACM Transactions on Mathematical Software}, 13(3), 262--280 + @item Christiano, Lawrence J., Mathias Trabandt and Karl Walentin (2011): ``Introducing financial frictions and unemployment into a small open @@ -12476,6 +12553,16 @@ International Meeting on Bayesian Statistics, pp. 169--194, Oxford University Pr Geweke, John (1999): ``Using simulation methods for Bayesian econometric models: Inference, development and communication,'' @i{Econometric Reviews}, 18(1), 1--73 +@item +Goffe, William L., Gary D. Ferrier, and John Rogers (1994): ``Global Optimization +of Statistical Functions with Simulated Annealing,'' @i{Journal of Econometrics}, 60(1/2), +65--100 + +@item +Hansen, Nikolaus and Stefan Kern (2004): ``Evaluating the CMA Evolution Strategy +on Multimodal Test Functions''. In: @i{Eighth International Conference on Parallel +Problem Solving from Nature PPSN VIII, Proceedings}, Berlin: Springer, 282--291 + @item Ireland, Peter (2004): ``A Method for Taking Models to the Data,'' @i{Journal of Economic Dynamics and Control}, 28, 1205--26 @@ -12514,6 +12601,11 @@ Koopman, S. J. and J. Durbin (2003): ``Filtering and Smoothing of State Vector for Diffuse State Space Models,'' @i{Journal of Time Series Analysis}, 24(1), 85--98 +@item +Kuntsevich, Alexei V. and Franz Kappel (1997): ``SolvOpt - The solver +for local nonlinear optimization problems (version 1.1, Matlab, C, FORTRAN)'', +University of Graz, Graz, Austria + @item Laffargue, Jean-Pierre (1990): ``Résolution d'un modèle macroéconomique avec anticipations rationnelles'', @i{Annales diff --git a/license.txt b/license.txt index 52fce2880..0f9bcbaf4 100644 --- a/license.txt +++ b/license.txt @@ -53,6 +53,19 @@ Copyright: 2001-2012 Nikolaus Hansen 2012 Dynare Team License: GPL-3+ +Files: matlab/optimization/solvopt.m +Copyright: 1997-2008 Alexei Kuntsevich and Franz Kappel + 2008-2015 Giovanni Lombardo + 2015 Dynare Team +License: GPL-3+ + +Files: matlab/optimization/simulated_annealing.m +Copyright: 1995 E.G.Tsionas + 1995-2002 Thomas Werner + 2002-2015 Giovanni Lombardo + 2015 Dynare Team +License: GPL-3+ + Files: matlab/endogenous_prior.m Copyright: 2011 Lawrence J. Christiano, Mathias Trabandt and Karl Walentin 2013 Dynare Team From 9408319e48df731eb14bbc185ae7f1a3c79e20cd Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 24 Apr 2015 12:31:27 +0200 Subject: [PATCH 155/210] Cosmetic changes related to solvopt.m --- matlab/global_initialization.m | 1 - matlab/optimization/solvopt.m | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 4ec37b459..3fa5421e4 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -541,7 +541,6 @@ options_.saopt.neps=10; options_.saopt.maximizer_indicator=0; options_.saopt.rt=0.10; options_.saopt.MaxIter=100000; -options_.saopt.MaxIter=100000; options_.saopt.verbosity=1; options_.saopt.TolFun=1.0e-8; options_.saopt.initial_temperature=15; diff --git a/matlab/optimization/solvopt.m b/matlab/optimization/solvopt.m index 9e5aa6139..6d5693e86 100644 --- a/matlab/optimization/solvopt.m +++ b/matlab/optimization/solvopt.m @@ -53,7 +53,7 @@ function [x,f,exitflag,n_f_evals,n_grad_evals,n_constraint_evals,n_constraint_gr % n_constraint_gradient_evals number of constraint gradient evaluations. % % -% Algorithm: Kuntsevich, A.V., Kappel, F., The solver for local nonlinear optimization problems +% Algorithm: Kuntsevich, A.V., Kappel, F., SolvOpt - The solver for local nonlinear optimization problems % (version 1.1, Matlab, C, FORTRAN). University of Graz, Graz, 1997. % % From b4941c02d323fe1321cc56f90d80d52c50df5220 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 24 Apr 2015 18:12:46 +0200 Subject: [PATCH 156/210] Cosmetic Fixes to Metropolis-Hastings routines - Adds comments and headers and fixes typos in previous ones - Make naming in random_walk_metropolis_hastings_core.m more intuitive --- matlab/metropolis_hastings_initialization.m | 41 +++-- matlab/prior_posterior_statistics.m | 8 +- matlab/random_walk_metropolis_hastings.m | 45 ++--- matlab/random_walk_metropolis_hastings_core.m | 165 ++++++++---------- 4 files changed, 130 insertions(+), 129 deletions(-) diff --git a/matlab/metropolis_hastings_initialization.m b/matlab/metropolis_hastings_initialization.m index e8f4d0ef1..4650830e5 100644 --- a/matlab/metropolis_hastings_initialization.m +++ b/matlab/metropolis_hastings_initialization.m @@ -1,7 +1,7 @@ function [ ix2, ilogpo2, ModelName, MetropolisFolder, fblck, fline, npar, nblck, nruns, NewFile, MAX_nruns, d ] = ... metropolis_hastings_initialization(TargetFun, xparam1, vv, mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_) -%function [ ix2, ilogpo2, ModelName, MhDirectoryName, fblck, fline, npar, nblck, nruns, NewFile, MAX_nruns, d ] = -% metropolis_hastings_initialization(TargetFun, xparam1, vv, mh_bounds, dataset_,dataset_info,,options_,M_,estim_params_,bayestopt_,oo_) +%function [ ix2, ilogpo2, ModelName, MetropolisFolder, fblck, fline, npar, nblck, nruns, NewFile, MAX_nruns, d ] = ... +% metropolis_hastings_initialization(TargetFun, xparam1, vv, mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_) % Metropolis-Hastings initialization. % % INPUTS @@ -11,6 +11,7 @@ function [ ix2, ilogpo2, ModelName, MetropolisFolder, fblck, fline, npar, nblck, % o vv [double] (p*p) matrix, posterior covariance matrix (at the mode). % o mh_bounds [double] (p*2) matrix defining lower and upper bounds for the parameters. % o dataset_ data structure +% o dataset_info dataset info structure % o options_ options structure % o M_ model structure % o estim_params_ estimated parameters structure @@ -18,12 +19,25 @@ function [ ix2, ilogpo2, ModelName, MetropolisFolder, fblck, fline, npar, nblck, % o oo_ outputs structure % % OUTPUTS -% None +% o ix2 [double] (nblck*npar) vector of starting points for different chains +% o ilogpo2 [double] (nblck*1) vector of initial posterior values for different chains +% o ModelName [string] name of the mod-file +% o MetropolisFolder [string] path to the Metropolis subfolder +% o fblck [scalar] number of the first MH chain to be run (not equal to 1 in case of recovery) +% o fline [double] (nblck*1) vector of first draw in each chain (not equal to 1 in case of recovery) +% o npar [scalar] number of parameters estimated +% o nblck [scalar] Number of MCM chains requested +% o nruns [double] (nblck*1) number of draws in each chain +% o NewFile [scalar] (nblck*1) vector storing the number +% of the first MH-file to created for each chain when saving additional +% draws +% o MAX_nruns [scalar] maximum number of draws in each MH-file on the harddisk +% o d [double] (p*p) matrix, Cholesky decomposition of the posterior covariance matrix (at the mode). % % SPECIAL REQUIREMENTS % None. -% Copyright (C) 2006-2013 Dynare Team +% Copyright (C) 2006-2015 Dynare Team % % This file is part of Dynare. % @@ -40,6 +54,7 @@ function [ ix2, ilogpo2, ModelName, MetropolisFolder, fblck, fline, npar, nblck, % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . +%Initialize outputs ix2 = []; ilogpo2 = []; ModelName = []; @@ -68,7 +83,7 @@ MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8); d = chol(vv); if ~options_.load_mh_file && ~options_.mh_recover - % Here we start a new metropolis-hastings, previous draws are discarded. + % Here we start a new Metropolis-Hastings, previous draws are discarded. if nblck > 1 disp('Estimation::mcmc: Multiple chains mode.') else @@ -80,7 +95,7 @@ if ~options_.load_mh_file && ~options_.mh_recover delete([BaseName '_mh*_blck*.mat']); disp('Estimation::mcmc: Old mh-files successfully erased!') end - % Delete old metropolis log file. + % Delete old Metropolis log file. file = dir([ MetropolisFolder '/metropolis.log']); if length(file) delete([ MetropolisFolder '/metropolis.log']); @@ -128,11 +143,11 @@ if ~options_.load_mh_file && ~options_.mh_recover if init_iter > 100 && validate == 0 disp(['Estimation::mcmc: I couldn''t get a valid initial value in 100 trials.']) if options_.nointeractive - disp(['Estimation::mcmc: I reduce mh_init_scale by ten percent:']) + disp(['Estimation::mcmc: I reduce mh_init_scale by 10 percent:']) options_.mh_init_scale = .9*options_.mh_init_scale; disp(sprintf('Estimation::mcmc: Parameter mh_init_scale is now equal to %f.',options_.mh_init_scale)) else - disp(['Estimation::mcmc: You should Reduce mh_init_scale...']) + disp(['Estimation::mcmc: You should reduce mh_init_scale...']) disp(sprintf('Estimation::mcmc: Parameter mh_init_scale is equal to %f.',options_.mh_init_scale)) options_.mh_init_scale = input('Estimation::mcmc: Enter a new value... '); end @@ -217,7 +232,7 @@ if ~options_.load_mh_file && ~options_.mh_recover fclose(fidlog); elseif options_.load_mh_file && ~options_.mh_recover % Here we consider previous mh files (previous mh did not crash). - disp('Estimation::mcmc: I am loading past metropolis-hastings simulations...') + disp('Estimation::mcmc: I am loading past Metropolis-Hastings simulations...') load_last_mh_history_file(MetropolisFolder, ModelName); mh_files = dir([ MetropolisFolder filesep ModelName '_mh*.mat']); if ~length(mh_files) @@ -238,7 +253,7 @@ elseif options_.load_mh_file && ~options_.mh_recover nblck = past_number_of_blocks; options_.mh_nblck = nblck; end - % I read the last line of the last mh-file for initialization of the new metropolis-hastings simulations: + % I read the last line of the last mh-file for initialization of the new Metropolis-Hastings simulations: LastFileNumber = record.LastFileNumber; LastLineNumber = record.LastLineNumber; if LastLineNumber < MAX_nruns @@ -252,7 +267,7 @@ elseif options_.load_mh_file && ~options_.mh_recover ix2 = record.LastParameters; fblck = 1; NumberOfPreviousSimulations = sum(record.MhDraws(:,1),1); - fprintf('Estimation::mcmc: I am writting a new mh-history file... '); + fprintf('Estimation::mcmc: I am writing a new mh-history file... '); record.MhDraws = [record.MhDraws;zeros(1,3)]; NumberOfDrawsWrittenInThePastLastFile = MAX_nruns - LastLineNumber; NumberOfDrawsToBeSaved = nruns(1) - NumberOfDrawsWrittenInThePastLastFile; @@ -318,7 +333,7 @@ elseif options_.mh_recover disp('Estimation::mcmc: It appears that you don''t need to use the mh_recover option!') disp(' You have to edit the mod file and remove the mh_recover option') disp(' in the estimation command') - error() + error('Estimation::mcmc: mh_recover option not required!') end % I count the number of saved mh files per block. NumberOfMhFilesPerBlock = zeros(nblck,1); @@ -339,7 +354,7 @@ elseif options_.mh_recover end % How many mh-files are saved in this block? NumberOfSavedMhFilesInTheCrashedBlck = NumberOfMhFilesPerBlock(fblck); - % Correct the number of saved mh files if the crashed metropolis was not the first session (so + % Correct the number of saved mh files if the crashed Metropolis was not the first session (so % that NumberOfSavedMhFilesInTheCrashedBlck is the number of saved mh files in the crashed chain % of the current session). if OldMh diff --git a/matlab/prior_posterior_statistics.m b/matlab/prior_posterior_statistics.m index 4908d6b64..a2f43343e 100644 --- a/matlab/prior_posterior_statistics.m +++ b/matlab/prior_posterior_statistics.m @@ -14,11 +14,11 @@ function prior_posterior_statistics(type,dataset,dataset_info) % % SPECIAL REQUIREMENTS % none - +% % PARALLEL CONTEXT -% See the comments random_walk_metropolis_hastings.m funtion. - - +% See the comments in the random_walk_metropolis_hastings.m funtion. +% +% % Copyright (C) 2005-2013 Dynare Team % % This file is part of Dynare. diff --git a/matlab/random_walk_metropolis_hastings.m b/matlab/random_walk_metropolis_hastings.m index c2a49e7a2..2092922ac 100644 --- a/matlab/random_walk_metropolis_hastings.m +++ b/matlab/random_walk_metropolis_hastings.m @@ -1,14 +1,17 @@ function random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv,mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_) -%function record=random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv,mh_bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_) -% Random walk Metropolis-Hastings algorithm. +% function random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv,mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_) +% Random Walk Metropolis-Hastings algorithm. % % INPUTS % o TargetFun [char] string specifying the name of the objective % function (posterior kernel). +% o ProposalFun [char] string specifying the name of the proposal +% density % o xparam1 [double] (p*1) vector of parameters to be estimated (initial values). % o vv [double] (p*p) matrix, posterior covariance matrix (at the mode). % o mh_bounds [double] (p*2) matrix defining lower and upper bounds for the parameters. % o dataset_ data structure +% o dataset_info dataset info structure % o options_ options structure % o M_ model structure % o estim_params_ estimated parameters structure @@ -16,27 +19,27 @@ function random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv,mh_bou % o oo_ outputs structure % % ALGORITHM -% Metropolis-Hastings. +% Random-Walk Metropolis-Hastings. % % SPECIAL REQUIREMENTS % None. % % PARALLEL CONTEXT % The most computationally intensive part of this function may be executed -% in parallel. The code sutable to be executed in -% parallel on multi core or cluster machine (in general a 'for' cycle), -% is removed from this function and placed in random_walk_metropolis_hastings_core.m funtion. -% Then the DYNARE parallel package contain a set of pairs matlab functions that can be executed in -% parallel and called name_function.m and name_function_core.m. -% In addition in parallel package we have second set of functions used -% to manage the parallel computation. +% in parallel. The code suitable to be executed in +% parallel on multi core or cluster machine (in general a 'for' cycle) +% has been removed from this function and been placed in the random_walk_metropolis_hastings_core.m funtion. +% +% The DYNARE parallel packages comprise a i) set of pairs of Matlab functions that can be executed in +% parallel and called name_function.m and name_function_core.m and ii) a second set of functions used +% to manage the parallel computations. % -% This function was the first function to be parallelized, later other +% This function was the first function to be parallelized. Later, other % functions have been parallelized using the same methodology. % Then the comments write here can be used for all the other pairs of -% parallel functions and also for management funtions. +% parallel functions and also for management functions. -% Copyright (C) 2006-2013 Dynare Team +% Copyright (C) 2006-2015 Dynare Team % % This file is part of Dynare. % @@ -54,7 +57,7 @@ function random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv,mh_bou % along with Dynare. If not, see . -% In Metropolis, we set penalty to Inf to as to reject all parameter sets triggering error in target density computation +% In Metropolis, we set penalty to Inf so as to reject all parameter sets triggering an error during target density computation global objective_function_penalty_base objective_function_penalty_base = Inf; @@ -73,16 +76,16 @@ load_last_mh_history_file(MetropolisFolder, ModelName); % First run in serial mode, and then comment the follow line. % save('recordSerial.mat','-struct', 'record'); -% For parllel runs after serial runs with the abobe line active. +% For parallel runs after serial runs with the abobe line active. % TempRecord=load('recordSerial.mat'); % record.Seeds=TempRecord.Seeds; % Snapshot of the current state of computing. It necessary for the parallel -% execution (i.e. to execute in a corretct way portion of code remotely or -% on many core). The mandatory variables for local/remote parallel -% computing are stored in localVars struct. +% execution (i.e. to execute in a corretct way a portion of code remotely or +% on many cores). The mandatory variables for local/remote parallel +% computing are stored in the localVars struct. localVars = struct('TargetFun', TargetFun, ... 'ProposalFun', ProposalFun, ... @@ -110,9 +113,8 @@ localVars = struct('TargetFun', TargetFun, ... 'varargin',[]); -% The user don't want to use parallel computing, or want to compute a -% single chain. In this cases Random walk Metropolis-Hastings algorithm is -% computed sequentially. +% User doesn't want to use parallel computing, or wants to compute a +% single chain compute Random walk Metropolis-Hastings algorithm sequentially. if isnumeric(options_.parallel) || (nblck-fblck)==0, fout = random_walk_metropolis_hastings_core(localVars, fblck, nblck, 0); @@ -152,6 +154,7 @@ NewFile = fout(1).NewFile; update_last_mh_history_file(MetropolisFolder, ModelName, record); +% Provide diagnostic output skipline() disp(['Estimation::mcmc: Number of mh files: ' int2str(NewFile(1)) ' per block.']) disp(['Estimation::mcmc: Total number of generated files: ' int2str(NewFile(1)*nblck) '.']) diff --git a/matlab/random_walk_metropolis_hastings_core.m b/matlab/random_walk_metropolis_hastings_core.m index 90c89e871..2c26de0e5 100644 --- a/matlab/random_walk_metropolis_hastings_core.m +++ b/matlab/random_walk_metropolis_hastings_core.m @@ -1,25 +1,25 @@ function myoutput = random_walk_metropolis_hastings_core(myinputs,fblck,nblck,whoiam, ThisMatlab) -% PARALLEL CONTEXT -% This function contain the most computationally intensive portion of code in -% random_walk_metropolis_hastings (the 'for xxx = fblck:nblck' loop). The branches in 'for' -% cycle and are completely independent than suitable to be executed in parallel way. +% function myoutput = random_walk_metropolis_hastings_core(myinputs,fblck,nblck,whoiam, ThisMatlab) +% Contains the most computationally intensive portion of code in +% random_walk_metropolis_hastings (the 'for xxx = fblck:nblck' loop). The branches in that 'for' +% cycle are completely independent to be suitable for parallel execution. % % INPUTS % o myimput [struc] The mandatory variables for local/remote % parallel computing obtained from random_walk_metropolis_hastings.m % function. % o fblck and nblck [integer] The Metropolis-Hastings chains. -% o whoiam [integer] In concurrent programming a modality to refer to the differents thread running in parallel is needed. +% o whoiam [integer] In concurrent programming a modality to refer to the different threads running in parallel is needed. % The integer whoaim is the integer that % allows us to distinguish between them. Then it is the index number of this CPU among all CPUs in the % cluster. % o ThisMatlab [integer] Allows us to distinguish between the -% 'main' matlab, the slave matlab worker, local matlab, remote matlab, +% 'main' Matlab, the slave Matlab worker, local Matlab, remote Matlab, % ... Then it is the index number of this slave machine in the cluster. % OUTPUTS % o myoutput [struc] -% If executed without parallel is the original output of 'for b = -% fblck:nblck' otherwise a portion of it computed on a specific core or +% If executed without parallel, this is the original output of 'for b = +% fblck:nblck'. Otherwise, it's a portion of it computed on a specific core or % remote machine. In this case: % record; % irun; @@ -31,23 +31,12 @@ function myoutput = random_walk_metropolis_hastings_core(myinputs,fblck,nblck,wh % % SPECIAL REQUIREMENTS. % None. - +% % PARALLEL CONTEXT -% The most computationally intensive part of this function may be executed -% in parallel. The code sutable to be executed in parallel on multi core or cluster machine, -% is removed from this function and placed in random_walk_metropolis_hastings_core.m funtion. -% Then the DYNARE parallel package contain a set of pairs matlab functios that can be executed in -% parallel and called name_function.m and name_function_core.m. -% In addition in the parallel package we have second set of functions used -% to manage the parallel computation. -% -% This function was the first function to be parallelized, later other -% functions have been parallelized using the same methodology. -% Then the comments write here can be used for all the other pairs of -% parallel functions and also for management funtions. +% See the comments in the random_walk_metropolis_hastings.m funtion. -% Copyright (C) 2006-2013 Dynare Team +% Copyright (C) 2006-2015 Dynare Team % % This file is part of Dynare. % @@ -74,11 +63,9 @@ end TargetFun=myinputs.TargetFun; ProposalFun=myinputs.ProposalFun; xparam1=myinputs.xparam1; -vv=myinputs.vv; mh_bounds=myinputs.mh_bounds; -ix2=myinputs.ix2; -ilogpo2=myinputs.ilogpo2; -ModelName=myinputs.ModelName; +last_draw=myinputs.ix2; +last_posterior=myinputs.ilogpo2; fline=myinputs.fline; npar=myinputs.npar; nruns=myinputs.nruns; @@ -94,11 +81,9 @@ estim_params_ = myinputs.estim_params_; options_ = myinputs.options_; M_ = myinputs.M_; oo_ = myinputs.oo_; -varargin=myinputs.varargin; % Necessary only for remote computing! if whoiam - Parallel=myinputs.Parallel; % initialize persistent variables in priordens() priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, bayestopt_.p3,bayestopt_.p4,1); end @@ -116,53 +101,51 @@ elseif strcmpi(ProposalFun,'rand_multivariate_student') end % -% NOW i run the (nblck-fblck+1) metropolis-hastings chains +% Now I run the (nblck-fblck+1) Metropolis-Hastings chains % proposal_covariance_Cholesky_decomposition = d*diag(bayestopt_.jscale); -jloop=0; +block_iter=0; -JSUM = 0; -for b = fblck:nblck, - jloop=jloop+1; +for curr_block = fblck:nblck, + block_iter=block_iter+1; try - % This will not work if the master uses a random generator not + % This will not work if the master uses a random number generator not % available in the slave (different Matlab version or - % Matlab/Octave cluster). Therefor the trap. + % Matlab/Octave cluster). Therefore the trap. % - % This set the random generator type (the seed is useless but - % needed by the function) + % Set the random number generator type (the seed is useless but needed by the function) set_dynare_seed(options_.DynareRandomStreams.algo, options_.DynareRandomStreams.seed); - % This set the state - set_dynare_random_generator_state(record.InitialSeeds(b).Unifor, record.InitialSeeds(b).Normal); + % Set the state of the RNG + set_dynare_random_generator_state(record.InitialSeeds(curr_block).Unifor, record.InitialSeeds(curr_block).Normal); catch - % If the state set by master is incompatible with the slave, we - % only reseed - set_dynare_seed(options_.DynareRandomStreams.seed+b); + % If the state set by master is incompatible with the slave, we only reseed + set_dynare_seed(options_.DynareRandomStreams.seed+curr_block); end - if (options_.load_mh_file~=0) && (fline(b)>1) && OpenOldFile(b) - load([BaseName '_mh' int2str(NewFile(b)) '_blck' int2str(b) '.mat']) - x2 = [x2;zeros(InitSizeArray(b)-fline(b)+1,npar)]; - logpo2 = [logpo2;zeros(InitSizeArray(b)-fline(b)+1,1)]; - OpenOldFile(b) = 0; + if (options_.load_mh_file~=0) && (fline(curr_block)>1) && OpenOldFile(curr_block) %load previous draws and likelihood + load([BaseName '_mh' int2str(NewFile(curr_block)) '_blck' int2str(curr_block) '.mat']) + x2 = [x2;zeros(InitSizeArray(curr_block)-fline(curr_block)+1,npar)]; + logpo2 = [logpo2;zeros(InitSizeArray(curr_block)-fline(curr_block)+1,1)]; + OpenOldFile(curr_block) = 0; else - x2 = zeros(InitSizeArray(b),npar); - logpo2 = zeros(InitSizeArray(b),1); + x2 = zeros(InitSizeArray(curr_block),npar); + logpo2 = zeros(InitSizeArray(curr_block),1); end + %Prepare waiting bars if whoiam - prc0=(b-fblck)/(nblck-fblck+1)*(isoctave || options_.console_mode); - hh = dyn_waitbar({prc0,whoiam,options_.parallel(ThisMatlab)},['MH (' int2str(b) '/' int2str(options_.mh_nblck) ')...']); + prc0=(curr_block-fblck)/(nblck-fblck+1)*(isoctave || options_.console_mode); + hh = dyn_waitbar({prc0,whoiam,options_.parallel(ThisMatlab)},['MH (' int2str(curr_block) '/' int2str(options_.mh_nblck) ')...']); else - hh = dyn_waitbar(0,['Metropolis-Hastings (' int2str(b) '/' int2str(options_.mh_nblck) ')...']); + hh = dyn_waitbar(0,['Metropolis-Hastings (' int2str(curr_block) '/' int2str(options_.mh_nblck) ')...']); set(hh,'Name','Metropolis-Hastings'); end - isux = 0; - jsux = 0; - irun = fline(b); - j = 1; - while j <= nruns(b) - par = feval(ProposalFun, ix2(b,:), proposal_covariance_Cholesky_decomposition, n); + accepted_draws_this_chain = 0; + accepted_draws_this_file = 0; + draw_index_current_file = fline(curr_block); %get location of first draw in current block + draw_iter = 1; + while draw_iter <= nruns(curr_block) + par = feval(ProposalFun, last_draw(curr_block,:), proposal_covariance_Cholesky_decomposition, n); if all( par(:) > mh_bounds.lb ) && all( par(:) < mh_bounds.ub ) try logpost = - feval(TargetFun, par(:),dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_); @@ -172,29 +155,29 @@ for b = fblck:nblck, else logpost = -inf; end - if (logpost > -inf) && (log(rand) < logpost-ilogpo2(b)) - x2(irun,:) = par; - ix2(b,:) = par; - logpo2(irun) = logpost; - ilogpo2(b) = logpost; - isux = isux + 1; - jsux = jsux + 1; + if (logpost > -inf) && (log(rand) < logpost-last_posterior(curr_block)) + x2(draw_index_current_file,:) = par; + last_draw(curr_block,:) = par; + logpo2(draw_index_current_file) = logpost; + last_posterior(curr_block) = logpost; + accepted_draws_this_chain = accepted_draws_this_chain + 1; + accepted_draws_this_file = accepted_draws_this_file + 1; else - x2(irun,:) = ix2(b,:); - logpo2(irun) = ilogpo2(b); + x2(draw_index_current_file,:) = last_draw(curr_block,:); + logpo2(draw_index_current_file) = last_posterior(curr_block); end - prtfrc = j/nruns(b); - if (mod(j, 3)==0 && ~whoiam) || (mod(j,50)==0 && whoiam) - dyn_waitbar(prtfrc,hh,[ 'MH (' int2str(b) '/' int2str(options_.mh_nblck) ') ' sprintf('Current acceptance ratio %4.3f', isux/j)]); + prtfrc = draw_iter/nruns(curr_block); + if (mod(draw_iter, 3)==0 && ~whoiam) || (mod(draw_iter,50)==0 && whoiam) + dyn_waitbar(prtfrc,hh,[ 'MH (' int2str(curr_block) '/' int2str(options_.mh_nblck) ') ' sprintf('Current acceptance ratio %4.3f', accepted_draws_this_chain/draw_iter)]); end - if (irun == InitSizeArray(b)) || (j == nruns(b)) % Now I save the simulations - save([BaseName '_mh' int2str(NewFile(b)) '_blck' int2str(b) '.mat'],'x2','logpo2'); + if (draw_index_current_file == InitSizeArray(curr_block)) || (draw_iter == nruns(curr_block)) % Now I save the simulations, either because the current file is full or the chain is done + save([BaseName '_mh' int2str(NewFile(curr_block)) '_blck' int2str(curr_block) '.mat'],'x2','logpo2'); fidlog = fopen([MetropolisFolder '/metropolis.log'],'a'); fprintf(fidlog,['\n']); - fprintf(fidlog,['%% Mh' int2str(NewFile(b)) 'Blck' int2str(b) ' (' datestr(now,0) ')\n']); + fprintf(fidlog,['%% Mh' int2str(NewFile(curr_block)) 'Blck' int2str(curr_block) ' (' datestr(now,0) ')\n']); fprintf(fidlog,' \n'); fprintf(fidlog,[' Number of simulations.: ' int2str(length(logpo2)) '\n']); - fprintf(fidlog,[' Acceptance ratio......: ' num2str(jsux/length(logpo2)) '\n']); + fprintf(fidlog,[' Acceptance ratio......: ' num2str(accepted_draws_this_file/length(logpo2)) '\n']); fprintf(fidlog,[' Posterior mean........:\n']); for i=1:length(x2(1,:)) fprintf(fidlog,[' params:' int2str(i) ': ' num2str(mean(x2(:,i))) '\n']); @@ -212,32 +195,32 @@ for b = fblck:nblck, fprintf(fidlog,[' log2po:' num2str(max(logpo2)) '\n']); fprintf(fidlog,' \n'); fclose(fidlog); - jsux = 0; - if j == nruns(b) % I record the last draw... - record.LastParameters(b,:) = x2(end,:); - record.LastLogPost(b) = logpo2(end); + accepted_draws_this_file = 0; + if draw_iter == nruns(curr_block) % I record the last draw... + record.LastParameters(curr_block,:) = x2(end,:); + record.LastLogPost(curr_block) = logpo2(end); end - % size of next file in chain b - InitSizeArray(b) = min(nruns(b)-j,MAX_nruns); + % size of next file in chain curr_block + InitSizeArray(curr_block) = min(nruns(curr_block)-draw_iter,MAX_nruns); % initialization of next file if necessary - if InitSizeArray(b) - x2 = zeros(InitSizeArray(b),npar); - logpo2 = zeros(InitSizeArray(b),1); - NewFile(b) = NewFile(b) + 1; - irun = 0; + if InitSizeArray(curr_block) + x2 = zeros(InitSizeArray(curr_block),npar); + logpo2 = zeros(InitSizeArray(curr_block),1); + NewFile(curr_block) = NewFile(curr_block) + 1; + draw_index_current_file = 0; end end - j=j+1; - irun = irun + 1; + draw_iter=draw_iter+1; + draw_index_current_file = draw_index_current_file + 1; end% End of the simulations for one mh-block. - record.AcceptanceRatio(b) = isux/j; + record.AcceptanceRatio(curr_block) = accepted_draws_this_chain/draw_iter; dyn_waitbar_close(hh); - [record.LastSeeds(b).Unifor, record.LastSeeds(b).Normal] = get_dynare_random_generator_state(); - OutputFileName(jloop,:) = {[MetropolisFolder,filesep], [ModelName '_mh*_blck' int2str(b) '.mat']}; + [record.LastSeeds(curr_block).Unifor, record.LastSeeds(curr_block).Normal] = get_dynare_random_generator_state(); + OutputFileName(block_iter,:) = {[MetropolisFolder,filesep], [ModelName '_mh*_blck' int2str(curr_block) '.mat']}; end% End of the loop over the mh-blocks. myoutput.record = record; -myoutput.irun = irun; +myoutput.irun = draw_index_current_file; myoutput.NewFile = NewFile; myoutput.OutputFileName = OutputFileName; \ No newline at end of file From d7293b110affa719dc9be3368ed5636541276465 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 25 Apr 2015 19:28:58 +0200 Subject: [PATCH 157/210] Add unit test for mh_recover option --- tests/Makefile.am | 1 + .../estimation/MH_recover/fs2000_recover.mod | 139 ++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 tests/estimation/MH_recover/fs2000_recover.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index af4d71ab3..7a7a6f349 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,7 @@ MODFILES = \ estimation/fs2000_MCMC_jumping_covariance.mod \ estimation/fs2000_initialize_from_calib.mod \ estimation/fs2000_calibrated_covariance.mod \ + estimation/MH_recover/fs2000_recover.mod \ gsa/ls2003.mod \ gsa/ls2003a.mod \ ramst.mod \ diff --git a/tests/estimation/MH_recover/fs2000_recover.mod b/tests/estimation/MH_recover/fs2000_recover.mod new file mode 100644 index 000000000..bfb7b68d0 --- /dev/null +++ b/tests/estimation/MH_recover/fs2000_recover.mod @@ -0,0 +1,139 @@ +/* + * This file replicates the estimation of the cash in advance model described + * Frank Schorfheide (2000): "Loss function-based evaluation of DSGE models", + * Journal of Applied Econometrics, 15(6), 645-670. + * + * The data are in file "fsdat_simul.m", and have been artificially generated. + * They are therefore different from the original dataset used by Schorfheide. + * + * The equations are taken from J. Nason and T. Cogley (1994): "Testing the + * implications of long-run neutrality for monetary business cycle models", + * Journal of Applied Econometrics, 9, S37-S70. + * Note that there is an initial minus sign missing in equation (A1), p. S63. + * + * This implementation was written by Michel Juillard. Please note that the + * following copyright notice only applies to this Dynare implementation of the + * model. + */ + +/* + * Copyright (C) 2004-2010 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 . + */ + +var m P c e W R k d n l gy_obs gp_obs y dA; +varexo e_a e_m; + +parameters alp bet gam mst rho psi del; + +alp = 0.33; +bet = 0.99; +gam = 0.003; +mst = 1.011; +rho = 0.7; +psi = 0.787; +del = 0.02; + +model; +dA = exp(gam+e_a); +log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; +-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; +W = l/n; +-(psi/(1-psi))*(c*P/(1-n))+l/n = 0; +R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; +1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; +c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); +P*c = m; +m-1+d = l; +e = exp(e_a); +y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); +gy_obs = dA*y/y(-1); +gp_obs = (P/P(-1))*m(-1)/dA; +end; + +shocks; +var e_a; stderr 0.014; +var e_m; stderr 0.005; +end; + +steady_state_model; + dA = exp(gam); + gst = 1/dA; + m = mst; + khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1)); + xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1); + nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp ); + n = xist/(nust+xist); + P = xist + nust; + k = khst*n; + + l = psi*mst*n/( (1-psi)*(1-n) ); + c = mst/P; + d = l - mst + 1; + y = k^alp*n^(1-alp)*gst^alp; + R = mst/bet; + W = l/n; + ist = y-c; + q = 1 - d; + + e = 1; + + gp_obs = m/dA; + gy_obs = dA; +end; + +steady; + +check; + +estimated_params; +alp, beta_pdf, 0.356, 0.02; +bet, beta_pdf, 0.993, 0.002; +gam, normal_pdf, 0.0085, 0.003; +mst, normal_pdf, 1.0002, 0.007; +rho, beta_pdf, 0.129, 0.223; +psi, beta_pdf, 0.65, 0.05; +del, beta_pdf, 0.01, 0.005; +stderr e_a, inv_gamma_pdf, 0.035449, inf; +stderr e_m, inv_gamma_pdf, 0.008862, inf; +end; + +varobs gp_obs gy_obs; + +options_.MaxNumberOfBytes=2000*11*8/4; +estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8); +copyfile([M_.dname filesep 'metropolis' filesep 'fs2000_recover_mh1_blck1.mat'],'fs2000_mh1_blck1.mat') +copyfile([M_.dname filesep 'metropolis' filesep 'fs2000_recover_mh3_blck2.mat'],'fs2000_mh3_blck2.mat') +delete([M_.dname filesep 'metropolis' filesep 'fs2000_recover_mh4_blck2.mat']) + +estimation(order=1, datafile='../fsdat_simul',mode_compute=0,mode_file=fs2000_recover_mode, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8,mh_recover); + +%check first unaffected chain +temp1=load('fs2000_mh1_blck1.mat'); +temp2=load([M_.dname filesep 'Metropolis' filesep 'fs2000_recover_mh1_blck1.mat']); + +if max(max(temp1.x2-temp2.x2))>1e-10 + error('Draws of unaffected chain are not the same') +end + +%check second, affected chain with last unaffected file +temp1=load('fs2000_mh3_blck2.mat'); +temp2=load([M_.dname filesep 'Metropolis' filesep 'fs2000_recover_mh3_blck2.mat']); + +if max(max(temp1.x2-temp2.x2))>1e-10 + error('Draws of affected chain''s unaffected files are not the same') +end From 17e03a82e33a73d62149b06d6155022c55d6d463 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 27 Apr 2015 11:07:52 +0200 Subject: [PATCH 158/210] fix comment --- matlab/dynare_estimation.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m index a70a760bd..80e91c041 100644 --- a/matlab/dynare_estimation.m +++ b/matlab/dynare_estimation.m @@ -1,9 +1,10 @@ function oo_recursive_=dynare_estimation(var_list,dname) -% function dynare_estimation(var_list) +% function dynare_estimation(var_list, dname) % runs the estimation of the model % % INPUTS % var_list: selected endogenous variables vector +% dname: alternative directory name % % OUTPUTS % oo_recursive_: cell array containing the results structures from recursive estimation @@ -11,7 +12,7 @@ function oo_recursive_=dynare_estimation(var_list,dname) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2003-2014 Dynare Team +% Copyright (C) 2003-2015 Dynare Team % % This file is part of Dynare. % From 18e952145078b8b7743d4032b314beeaa18981c6 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 27 Apr 2015 11:50:25 +0200 Subject: [PATCH 159/210] preprocessor: add dirname option to estimation. closes #910 --- doc/dynare.texi | 5 +++++ matlab/dynare_estimation.m | 2 +- matlab/global_initialization.m | 1 + preprocessor/DynareBison.yy | 4 +++- preprocessor/DynareFlex.ll | 1 + tests/pi2004/ireland.mod | 2 +- 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 8d5a09c2a..39178a0ef 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -4671,6 +4671,11 @@ a @uref{http://www.java.com/download,Java Runtime Environment}). Note that the base name (ie without extension) of the datafile has to be different from the base name of the model file. +@item dirname = @var{FILENAME} +Directory in which to store @code{estimation} output. To pass a +subdirectory of a directory, you must quote the argument. Default: +@code{} + @item xls_sheet = @var{NAME} @anchor{xls_sheet} The name of the sheet with the data in an Excel file diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m index 80e91c041..7bb49f380 100644 --- a/matlab/dynare_estimation.m +++ b/matlab/dynare_estimation.m @@ -56,7 +56,7 @@ nnobs = length(nobs); horizon = options_.forecast; if nargin<2 || ~exist(dname) || isempty(dname) - dname = M_.fname; + dname = options_.dirname; end M_.dname = dname; diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 4ec37b459..230661dc1 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -33,6 +33,7 @@ global oo_ M_ options_ estim_params_ bayestopt_ estimation_info ex0_ ys0_ estim_params_ = []; bayestopt_ = []; options_.datafile = ''; +options_.dirname = M_.fname; options_.dataset = []; options_.verbosity = 1; options_.terminal_condition = 0; diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 6c76d4161..b7288da93 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -92,7 +92,7 @@ class ParsingDriver; %token CONSIDER_ALL_ENDOGENOUS CONSIDER_ONLY_OBSERVED %token DATAFILE FILE SERIES DOUBLING DR_CYCLE_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_TOL DR_LOGARITHMIC_REDUCTION_MAXITER DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION DIFFERENTIATE_FORWARD_VARS %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR -%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME +%token FILENAME DIRNAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME %token FLOAT_NUMBER DATES %token DEFAULT FIXED_POINT OPT_ALGO %token FORECAST K_ORDER_SOLVER INSTRUMENTS SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN @@ -1712,6 +1712,7 @@ estimation_options : o_datafile | o_filter_algorithm | o_proposal_approximation | o_distribution_approximation + | o_dirname ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -2546,6 +2547,7 @@ o_qz_zero_threshold : QZ_ZERO_THRESHOLD EQUAL non_negative_number { driver.optio o_file : FILE EQUAL filename { driver.option_str("file", $3); }; o_series : SERIES EQUAL symbol { driver.option_str("series", $3); }; o_datafile : DATAFILE EQUAL filename { driver.option_str("datafile", $3); }; +o_dirname : DIRNAME EQUAL filename { driver.option_str("dirname", $3); }; o_nobs : NOBS EQUAL vec_int { driver.option_vec_int("nobs", $3); } | NOBS EQUAL vec_int_number diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 0e7a31c16..4428dd37d 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -236,6 +236,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 dates {dates_parens_nb=0; BEGIN DATES_STATEMENT; yylval->string_val = new string("dates");} file {return token::FILE;} datafile {return token::DATAFILE;} +dirname {return token::DIRNAME;} nobs {return token::NOBS;} last_obs {return token::LAST_OBS;} first_obs {return token::FIRST_OBS;} diff --git a/tests/pi2004/ireland.mod b/tests/pi2004/ireland.mod index ea17baad3..4c6552bde 100644 --- a/tests/pi2004/ireland.mod +++ b/tests/pi2004/ireland.mod @@ -87,4 +87,4 @@ oy (log(eta)); oc (log(eta)); end; -estimation(datafile=idata,mode_compute=1,nograph); \ No newline at end of file +estimation(datafile=idata,mode_compute=1,nograph,dirname='MYDIR/mysubdir'); \ No newline at end of file From c9b404fc1ba0a827e93d7bddf04b2ca267245580 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 27 Apr 2015 18:25:13 +0200 Subject: [PATCH 160/210] reporting: submodule update, #867 --- matlab/modules/reporting | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/reporting b/matlab/modules/reporting index d242c9249..05eef8cc7 160000 --- a/matlab/modules/reporting +++ b/matlab/modules/reporting @@ -1 +1 @@ -Subproject commit d242c92493693a8dc3b369f36b8762d8c31179fd +Subproject commit 05eef8cc719d75db120a41a63f8f3e2795e04766 From 1c25b7ddaae7ce84dfaf1b8f126800e45cc79613 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 27 Apr 2015 18:17:38 +0200 Subject: [PATCH 161/210] reporting: update test for fan charts, #867 --- tests/reporting/runDynareReport.m | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m index c1c48311f..61057946b 100644 --- a/tests/reporting/runDynareReport.m +++ b/tests/reporting/runDynareReport.m @@ -257,26 +257,46 @@ rep = rep.addSeries('graphHline', 460, ... 'graphLineColor', 'red', ... 'graphLineWidth', 1.5); +a=dseries([1:200]', '1984q1'); +b=a; +c=a; +d=a; +b(dates('2012q2'):dates('2015q2'))=b(dates('2012q2'):dates('2015q2'))+2; +c(dates('2012q2'):dates('2015q2'))=c(dates('2012q2'):dates('2015q2'))+4; +d(dates('2012q2'):dates('2015q2'))=d(dates('2012q2'):dates('2015q2'))+6; rep = rep.addGraph('title', 'Equilibrium World Real Food Price', ... 'xrange', prange, ... 'shade', srange, ... 'showLegend', true, ... 'xTickLabelRotation', 0); -rep = rep.addSeries('data', db_q{'LRPFOOD_BAR_WORLD'}, ... +rep = rep.addSeries('data', a, ... 'graphLineColor', 'blue', ... 'graphLineWidth', 1.5, ... 'graphLegendName', 'baseline', ... 'graphMiscTikzAddPlotOptions', 'mark=halfcircle*,color=red'); -rep = rep.addSeries('data', dc_q{'LRPFOOD_BAR_WORLD'}, ... +rep = rep.addSeries('data', b, ... 'graphLineColor', 'blue', ... 'graphLineStyle', 'dashed', ... 'graphLineWidth', 1.5, ... 'graphLegendName', 'control', ... - 'graphMiscTikzAddPlotOptions', 'mark=halfcircle*,mark options={rotate=90,scale=3}'); + 'graphMiscTikzAddPlotOptions', 'mark=halfcircle*,mark options={rotate=90,scale=3}', ... + 'graphFanShadeColor', 'red', 'graphFanShadeOpacity', 40); +rep = rep.addSeries('data', c, ... + 'graphLineColor', 'blue', ... + 'graphLineStyle', 'dashed', ... + 'graphLineWidth', 1.5, ... + 'graphLegendName', 'control', .... + 'graphFanShadeColor', 'red', 'graphFanShadeOpacity', 30); +rep = rep.addSeries('data', d, ... + 'graphLineColor', 'blue', ... + 'graphLineStyle', 'dashed', ... + 'graphLineWidth', 1.5, ... + 'graphLegendName', 'control', ... + 'graphFanShadeColor', 'red', 'graphFanShadeOpacity', 20); %% Write & Compile Report rep.write(); rep.compile(); toc -end \ No newline at end of file +end From ad2f7d4a157ff68be5d7488024d2ad021d38e083 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 27 Apr 2015 18:34:28 +0200 Subject: [PATCH 162/210] doc: reporting: add new fan chart options. closes #867 --- doc/dynare.texi | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 39178a0ef..1a4f02442 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -12000,7 +12000,7 @@ with the same base name as specified by @ref{tableName} with the ending @end defmethod @anchor{addSeries} -@defmethod Report addSeries data, graphBar, graphBarColor, graphBarFillColor, graphBarWidth, graphHline, graphLegendName, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, graphMiscTikzAddPlotOptions, graphShowInLegend, graphVline, tableDataRhs, tableRowColor, tableRowIndent, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, tableSubSectionHeader, zeroTol +@defmethod Report addSeries data, graphBar, graphBarColor, graphBarFillColor, graphBarWidth, graphFanShadeColor, graphFanShadeOpacity, graphHline, graphLegendName, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, graphMiscTikzAddPlotOptions, graphShowInLegend, graphVline, tableDataRhs, tableRowColor, tableRowIndent, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, tableSubSectionHeader, zeroTol Adds a @code{Series} to a @code{Graph} or a @code{Table}. NB: Options specific to graphs begin with `@code{graph}' while options specific to tables begin with `@code{table}'. @@ -12015,6 +12015,15 @@ to graphs begin with `@code{graph}' while options specific to tables begin with Whether or not to display this series as a bar graph as oppsed to the default of displaying it as a line graph. Default: @code{false} +@anchor{graphFanShadeColor} +@item graphFanShadeColor, @code{STRING} +The shading color to use between a series and the previously-added +series in a graph. Useful for making fan charts. Default: @code{empty} + +@item graphFanShadeOpacity, @code{INTEGER} +The opacity of the color passed in @ref{graphFanShadeColor}. Default: +@code{50} + @item graphBarColor, @code{STRING} The outline color of each bar in the bar graph. Only active if @ref{graphBar} is passed. Default: @code{`black'} From a2d055076410889124e0ccaf1b081abac96c29c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Tue, 28 Apr 2015 13:00:58 +0200 Subject: [PATCH 163/210] Cosmetic changes. Nicer output for the testsuite (with colors depending on the results). --- tests/Makefile.am | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index af4d71ab3..93aa22cd6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -435,30 +435,50 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) @echo 'Octave Tests Done' %.m.trs %.m.log: %.mod - DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ - $(MATLAB)/bin/matlab -nosplash -nodisplay -logfile $*.m.log -r run_test_matlab + @echo "`tput bold``tput setaf 7`MATLAB: $(PWD)/$*... `tput sgr0`" + @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ + $(MATLAB)/bin/matlab -nosplash -nodisplay -r run_test_matlab > $*.m.log 2> /dev/null + @if grep -q ":test-result: PASS" $*.m.trs; then \ + echo "`tput bold``tput setaf 2`MATLAB: $(PWD)/$* PASSED!" ; \ + else \ + echo "`tput bold``tput setaf 1`MATLAB: $(PWD)/$* FAILED!" ; \ + fi %.m.trs %.m.log : %.m - DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ - $(MATLAB)/bin/matlab -nosplash -nodisplay -logfile $*.m.log -r $* + @echo "`tput bold``tput setaf 7`MATLAB: $(PWD)/$*... `tput sgr0`" + @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ + $(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null + @echo "`tput bold`MATLAB: $(PWD)/$* Done!" %.o.trs %.o.log: %.mod - DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ + @echo "`tput bold``tput setaf 7`OCTAVE: $(PWD)/$*... `tput sgr0`" + @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ $(OCTAVE) --no-init-file --silent --no-history run_test_octave.m > $*.o.log 2>&1 + @if grep -q ":test-result: PASS" $*.o.trs; then \ + echo "`tput bold``tput setaf 2`OCTAVE: $(PWD)/$* PASSED!" ; \ + else \ + echo "`tput bold``tput setaf 1`OCTAVE: $(PWD)/$* FAILED!" ; \ + fi %.o.trs %.o.log : %.m - DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ + @echo "`tput bold``tput setaf 7`OCTAVE: $(PWD)/$*... `tput sgr0`" + @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ $(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1 + @echo "`tput bold`OCTAVE: $(PWD)/$* Done!" %.m.tls : %.m - TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ - $(MATLAB)/bin/matlab -nosplash -nodisplay -r run_m_script - touch $*.m.tls + @echo "`tput bold``tput setaf 7`MATLAB: $(PWD)/$*... `tput sgr0`" + @TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ + $(MATLAB)/bin/matlab -nosplash -nodisplay -r run_m_script 2> /dev/null + @touch $*.m.tls + @echo "`tput bold`MATLAB: $(PWD)/$* Done!" %.o.tls : %.m - TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ + @echo "`tput bold``tput setaf 7`OCTAVE: $(PWD)/$*... `tput sgr0`" + @TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ $(OCTAVE) --no-init-file --silent --no-history run_o_script.m 2>&1 - + @touch $*.o.tls + @echo "`tput bold`OCTAVE: $(PWD)/$* Done!" clean-local: rm -f $(M_TRS_FILES) \ From fa5eb67d912ed01f45a1d61d636c02041bf4906a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 28 Apr 2015 16:37:47 +0200 Subject: [PATCH 164/210] reporting: submodule update (to deal with Debian's outdated LaTeX distro. Revert when servers are updated), #867 --- matlab/modules/reporting | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/reporting b/matlab/modules/reporting index 05eef8cc7..0de30dc5c 160000 --- a/matlab/modules/reporting +++ b/matlab/modules/reporting @@ -1 +1 @@ -Subproject commit 05eef8cc719d75db120a41a63f8f3e2795e04766 +Subproject commit 0de30dc5c170695fb89bccfb41939224959aebfe From 07c74f7f7d5a9690274cfce131bc673aec39743d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 28 Apr 2015 17:39:04 +0200 Subject: [PATCH 165/210] reporting: submodule update (to be reverted when Debian tex distro is finally updated) --- matlab/modules/reporting | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/reporting b/matlab/modules/reporting index 0de30dc5c..5e50d25df 160000 --- a/matlab/modules/reporting +++ b/matlab/modules/reporting @@ -1 +1 @@ -Subproject commit 0de30dc5c170695fb89bccfb41939224959aebfe +Subproject commit 5e50d25df6f4c067fdd9f7ff9f3f59f2d0ea4edb From 6a17fe5de3e9834da01b6ad10abd891cff35be22 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 29 Apr 2015 11:33:14 +0200 Subject: [PATCH 166/210] Fix provisions for matlab 8.5 win32 bits. --- 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 ea9065a51..70f9fa7f5 100644 --- a/matlab/add_path_to_mex_files.m +++ b/matlab/add_path_to_mex_files.m @@ -29,7 +29,7 @@ if isoctave else % Add win32 specific paths for Dynare Windows package if strcmp(computer, 'PCWIN') - tmp = [dynareroot '../mex/matlab/win32-7.5-8.4/']; + tmp = [dynareroot '../mex/matlab/win32-7.5-8.5/']; if exist(tmp, 'dir') mexpath = tmp; if modifypath From 7570328c0d6583f769018ee867e4b96c4a4c361f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 29 Apr 2015 16:22:12 +0200 Subject: [PATCH 167/210] reporting: submodule update. closes #869 --- matlab/modules/reporting | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/modules/reporting b/matlab/modules/reporting index 5e50d25df..b7d539105 160000 --- a/matlab/modules/reporting +++ b/matlab/modules/reporting @@ -1 +1 @@ -Subproject commit 5e50d25df6f4c067fdd9f7ff9f3f59f2d0ea4edb +Subproject commit b7d5391051635207f088a493c92d7357f3bdd4e9 From 67b3c5deef244cd28648b5d296d6071c98bbacfd Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 30 Apr 2015 09:04:09 +0200 Subject: [PATCH 168/210] Cosmetic changes to masterParallel.m --- matlab/parallel/masterParallel.m | 49 ++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/matlab/parallel/masterParallel.m b/matlab/parallel/masterParallel.m index 6b218310e..75728bb0f 100644 --- a/matlab/parallel/masterParallel.m +++ b/matlab/parallel/masterParallel.m @@ -3,28 +3,38 @@ function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock, % This is the most important function for the management of DYNARE parallel % computing. % It is the top-level function called on the master computer when parallelizing a task. - -% This function has two main computational strategies for managing the matlab worker (slave process). +% +% This function has two main computational strategies for managing the +% matlab worker (slave process): +% % 0 Simple Close/Open Stategy: -% In this case the new Matlab instances (slave process) are open when -% necessary and then closed. This can happen many times during the -% simulation of a model. - +% In this case the new Matlab instances (slave process) are open when +% necessary and then closed. This can happen many times during the +% simulation of a model. +% % 1 Always Open Strategy: -% In this case we have a more sophisticated management of slave processes, -% which are no longer closed at the end of each job. The slave processes -% wait for a new job (if it exists). If a slave does not receive a new job after a -% fixed time it is destroyed. This solution removes the computational -% time necessary to Open/Close new Matlab instances. - +% In this case we have a more sophisticated management of slave processes, +% which are no longer closed at the end of each job. The slave processes +% wait for a new job (if it exists). If a slave does not receive a new job after a +% fixed time it is destroyed. This solution removes the computational +% time necessary to Open/Close new Matlab instances. +% % The first (point 0) is the default Strategy % i.e.(Parallel_info.leaveSlaveOpen=0). This value can be changed by the % user in xxx.mod file or it is changed by the programmer if it is necessary to % reduce the overall computational time. See for example the % prior_posterior_statistics.m. - +% % The number of parallelized threads will be equal to (nBlock-fBlock+1). % +% Treatment of global variables: +% Global variables used within the called function (e.g. +% objective_function_penalty_base) are wrapped and passed by storing their +% values at the start of the parallel computation in a file via +% storeGlobalVars.m. This file is then loaded in the separate, +% independent slave Matlab sessions. By keeping them separate, no +% interaction via global variables can take place. +% % INPUTS % o Parallel [struct vector] copy of options_.parallel % o fBlock [int] index number of the first thread @@ -53,7 +63,7 @@ function [fOutVar,nBlockPerCPU, totCPU] = masterParallel(Parallel,fBlock,nBlock, % the number of CPUs declared in "Parallel", if % the number of required threads is lower) -% Copyright (C) 2009-2013 Dynare Team +% Copyright (C) 2009-2015 Dynare Team % % This file is part of Dynare. % @@ -126,7 +136,7 @@ if isHybridMatlabOctave || isoctave end end - if exist('fGlobalVar') && ~isempty(fGlobalVar), + if exist('fGlobalVar','var') && ~isempty(fGlobalVar), fInputNames = fieldnames(fGlobalVar); for j=1:length(fInputNames), TargetVar = fGlobalVar.(fInputNames{j}); @@ -161,7 +171,7 @@ switch Strategy save([fname,'_input.mat'],'fInputVar','Parallel','-append') case 1 - if exist('fGlobalVar'), + if exist('fGlobalVar','var'), save(['temp_input.mat'],'fInputVar','fGlobalVar') else save(['temp_input.mat'],'fInputVar') @@ -540,7 +550,6 @@ else 'Renderer','Painters', ... 'Resize','off'); - vspace = 0.1; ncol = ceil(totCPU/10); hspace = 0.9/ncol; hstatus(1) = axes('position',[0.05/ncol 0.92 0.9/ncol 0.03], ... @@ -882,8 +891,4 @@ switch Strategy end end end -end - - - - +end \ No newline at end of file From 21870b39e8368e948a634bd7d85288ae4457dd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 30 Apr 2015 13:58:52 +0200 Subject: [PATCH 169/210] Cosmetic. Changed colored output. --- tests/Makefile.am | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 93aa22cd6..5907029f8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -435,50 +435,50 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) @echo 'Octave Tests Done' %.m.trs %.m.log: %.mod - @echo "`tput bold``tput setaf 7`MATLAB: $(PWD)/$*... `tput sgr0`" + @echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ $(MATLAB)/bin/matlab -nosplash -nodisplay -r run_test_matlab > $*.m.log 2> /dev/null @if grep -q ":test-result: PASS" $*.m.trs; then \ - echo "`tput bold``tput setaf 2`MATLAB: $(PWD)/$* PASSED!" ; \ + echo "`tput bold``tput setaf 2`MATLAB: $(PWD)/$* PASSED!`tput sgr0`" ; \ else \ - echo "`tput bold``tput setaf 1`MATLAB: $(PWD)/$* FAILED!" ; \ + echo "`tput bold``tput setaf 1`MATLAB: $(PWD)/$* FAILED!`tput sgr0`" ; \ fi %.m.trs %.m.log : %.m - @echo "`tput bold``tput setaf 7`MATLAB: $(PWD)/$*... `tput sgr0`" + @echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ $(MATLAB)/bin/matlab -nosplash -nodisplay -r $* > $*.m.log 2> /dev/null - @echo "`tput bold`MATLAB: $(PWD)/$* Done!" + @echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$* Done!`tput sgr0`" %.o.trs %.o.log: %.mod - @echo "`tput bold``tput setaf 7`OCTAVE: $(PWD)/$*... `tput sgr0`" + @echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ $(OCTAVE) --no-init-file --silent --no-history run_test_octave.m > $*.o.log 2>&1 @if grep -q ":test-result: PASS" $*.o.trs; then \ - echo "`tput bold``tput setaf 2`OCTAVE: $(PWD)/$* PASSED!" ; \ + echo "`tput bold``tput setaf 2`OCTAVE: $(PWD)/$* PASSED!`tput sgr0`" ; \ else \ - echo "`tput bold``tput setaf 1`OCTAVE: $(PWD)/$* FAILED!" ; \ + echo "`tput bold``tput setaf 1`OCTAVE: $(PWD)/$* FAILED!`tput sgr0`" ; \ fi %.o.trs %.o.log : %.m - @echo "`tput bold``tput setaf 7`OCTAVE: $(PWD)/$*... `tput sgr0`" + @echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ $(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1 - @echo "`tput bold`OCTAVE: $(PWD)/$* Done!" + @echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$* Done!`tput sgr0`" %.m.tls : %.m - @echo "`tput bold``tput setaf 7`MATLAB: $(PWD)/$*... `tput sgr0`" + @echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$*... `tput sgr0`" @TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ $(MATLAB)/bin/matlab -nosplash -nodisplay -r run_m_script 2> /dev/null @touch $*.m.tls - @echo "`tput bold`MATLAB: $(PWD)/$* Done!" + @echo "`tput bold`MATLAB`tput setaf 3`: $(PWD)/$* Done!`tput sgr0`" %.o.tls : %.m - @echo "`tput bold``tput setaf 7`OCTAVE: $(PWD)/$*... `tput sgr0`" + @echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$*... `tput sgr0`" @TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \ $(OCTAVE) --no-init-file --silent --no-history run_o_script.m 2>&1 @touch $*.o.tls - @echo "`tput bold`OCTAVE: $(PWD)/$* Done!" + @echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$* Done!`tput sgr0`" clean-local: rm -f $(M_TRS_FILES) \ From 445fd653f105853ff7a6bc213937ecdd61ccf5aa Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 30 Apr 2015 12:35:33 +0200 Subject: [PATCH 170/210] preprocessor: add dynare_version field to oo_, M_, and options_, #546 --- preprocessor/ModFile.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 847fc7e33..6d9eca0ec 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -574,6 +574,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo << "global M_ oo_ options_ ys0_ ex0_ estimation_info" << endl << "options_ = [];" << endl << "M_.fname = '" << basename << "';" << endl + << "M_.dynare_version = '" << PACKAGE_VERSION << "';" << endl + << "oo_.dynare_version = '" << PACKAGE_VERSION << "';" << endl + << "options_.dynare_version = '" << PACKAGE_VERSION << "';" << endl << "%" << endl << "% Some global variables initialization" << endl << "%" << endl; From a93e0157e4ea0d3a2ee4d5b10842066a0a39c2e9 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 30 Apr 2015 13:31:15 +0200 Subject: [PATCH 171/210] add utilities to convert oo_ between different versions of dynare, #546 --- matlab/check_valid_ver.m | 39 ++++++++++++++++++++++++ matlab/convert_oo_.m | 47 +++++++++++++++++++++++++++++ matlab/ver_greater_than.m | 63 +++++++++++++++++++++++++++++++++++++++ matlab/ver_less_than.m | 63 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 212 insertions(+) create mode 100644 matlab/check_valid_ver.m create mode 100644 matlab/convert_oo_.m create mode 100644 matlab/ver_greater_than.m create mode 100644 matlab/ver_less_than.m diff --git a/matlab/check_valid_ver.m b/matlab/check_valid_ver.m new file mode 100644 index 000000000..4cd75cd77 --- /dev/null +++ b/matlab/check_valid_ver.m @@ -0,0 +1,39 @@ +function check_valid_ver(ver) +%function check_valid_ver(ver) +% Checks that ver is valid +% +% INPUTS +% ver [string] dynare version number +% +% OUTPUTS +% none +% +% 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 . + +test_ver = splitver(ver); +errmsg = 'check_valid_ver: the desired version must be in the proper format'; +assert (length(test_ver) == 3 && ... + ~isempty(str2double(test_ver{1})) && ... + ~isempty(str2double(test_ver{2})), errmsg); +if isnan(str2double(test_ver{3})) + assert(strcmp(test_ver{3}, 'unstable'), errmsg); +end +end \ No newline at end of file diff --git a/matlab/convert_oo_.m b/matlab/convert_oo_.m new file mode 100644 index 000000000..1aa05340d --- /dev/null +++ b/matlab/convert_oo_.m @@ -0,0 +1,47 @@ +function oo_ = convert_oo_(oo_, ver) +%function oo_ = convert_oo_(oo_, ver) +% Converts oo_ from oo_.dynare_version to ver +% +% INPUTS +% oo_ [struct] dynare output struct +% ver [string] desired oo_ output version +% +% OUTPUTS +% oo_ [struct] dynare output struct +% +% 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 . + +check_valid_ver(ver); + +if isfield(oo_, 'dynare_version') + ver_orig = oo_.dynare_version; +else + ver_orig = '4.4.3'; +end + +if strcmp(ver_orig, ver) + return; +end + +if ver_greater_than(ver_orig, '4.5.0') && ver_less_than(ver, '4.5.0') + oo_.exo_simul = oo_.exo_simul'; +end +end diff --git a/matlab/ver_greater_than.m b/matlab/ver_greater_than.m new file mode 100644 index 000000000..91e26f56b --- /dev/null +++ b/matlab/ver_greater_than.m @@ -0,0 +1,63 @@ +function tf = ver_greater_than(ver1, ver2) +%function tf = ver_greater_than(ver1, ver2) +% ver1 > ver2 ? 1 : 0; +% +% INPUTS +% ver1 [string] software version number +% ver2 [string] software version number +% +% OUTPUTS +% tf [bool] true if ver1 > ver2 +% +% 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 . + +tf = true; +ver1 = strsplit(ver1, {'.', '-'}); +ver2 = strsplit(ver2, {'.', '-'}); + +maj_ver1 = str2double(ver1{1}); +maj_ver2 = str2double(ver2{1}); +if maj_ver1 > maj_ver2 + return; +end + +min_ver1 = str2double(ver1{2}); +min_ver2 = str2double(ver2{2}); +if (maj_ver1 == maj_ver2) && (min_ver1 > min_ver2) + return; +end + +ismaster1 = isnan(str2double(ver1{3})); +ismaster2 = isnan(str2double(ver2{3})); +if (maj_ver1 == maj_ver2) && (min_ver1 == min_ver2) && (ismaster1 && ~ismaster2) + return; +end + +if ~ismaster1 && ~ismaster2 + rev_ver1 = str2double(ver1{3}); + rev_ver2 = str2double(ver2{3}); + if (maj_ver1 == maj_ver2) && (min_ver1 == min_ver2) && (rev_ver1 > rev_ver2) + return; + end +end + +tf = false; +end \ No newline at end of file diff --git a/matlab/ver_less_than.m b/matlab/ver_less_than.m new file mode 100644 index 000000000..7ad2d6425 --- /dev/null +++ b/matlab/ver_less_than.m @@ -0,0 +1,63 @@ +function tf = ver_less_than(ver1, ver2) +%function tf = ver_less_than(ver1, ver2) +% ver1 < ver2 ? 1 : 0; +% +% INPUTS +% ver1 [string] software version number +% ver2 [string] software version number +% +% OUTPUTS +% tf [bool] true if ver1 < ver2 +% +% 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 . + +tf = true; +ver1 = strsplit(ver1, {'.', '-'}); +ver2 = strsplit(ver2, {'.', '-'}); + +maj_ver1 = str2double(ver1{1}); +maj_ver2 = str2double(ver2{1}); +if maj_ver1 < maj_ver2 + return; +end + +min_ver1 = str2double(ver1{2}); +min_ver2 = str2double(ver2{2}); +if (maj_ver1 == maj_ver2) && (min_ver1 < min_ver2) + return; +end + +ismaster1 = isnan(str2double(ver1{3})); +ismaster2 = isnan(str2double(ver2{3})); +if (maj_ver1 == maj_ver2) && (min_ver1 == min_ver2) && (~ismaster1 && ismaster2) + return; +end + +if ~ismaster1 && ~ismaster2 + rev_ver1 = str2double(ver1{3}); + rev_ver2 = str2double(ver2{3}); + if (maj_ver1 == maj_ver2) && (min_ver1 == min_ver2) && (rev_ver1 < rev_ver2) + return; + end +end + +tf = false; +end \ No newline at end of file From 9cf352e471a5d2f17211796b238a0165f48c0ae4 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 30 Apr 2015 15:23:43 +0200 Subject: [PATCH 172/210] bug fix in check_valid_ver --- matlab/check_valid_ver.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/check_valid_ver.m b/matlab/check_valid_ver.m index 4cd75cd77..9b61813ad 100644 --- a/matlab/check_valid_ver.m +++ b/matlab/check_valid_ver.m @@ -28,7 +28,7 @@ function check_valid_ver(ver) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -test_ver = splitver(ver); +test_ver = strsplit(ver, {'.', '-'}); errmsg = 'check_valid_ver: the desired version must be in the proper format'; assert (length(test_ver) == 3 && ... ~isempty(str2double(test_ver{1})) && ... From e550aa806afac9750725545fea2496f46abacf26 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 30 Apr 2015 15:25:14 +0200 Subject: [PATCH 173/210] change convert_oo_ to be forward compatible --- matlab/convert_oo_.m | 2 +- matlab/ver_greater_than_equal.m | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 matlab/ver_greater_than_equal.m diff --git a/matlab/convert_oo_.m b/matlab/convert_oo_.m index 1aa05340d..355f5a812 100644 --- a/matlab/convert_oo_.m +++ b/matlab/convert_oo_.m @@ -41,7 +41,7 @@ if strcmp(ver_orig, ver) return; end -if ver_greater_than(ver_orig, '4.5.0') && ver_less_than(ver, '4.5.0') +if ver_less_than(ver_orig, '4.5.0') && ver_greater_than_equal(ver, '4.5.0') oo_.exo_simul = oo_.exo_simul'; end end diff --git a/matlab/ver_greater_than_equal.m b/matlab/ver_greater_than_equal.m new file mode 100644 index 000000000..84c54040a --- /dev/null +++ b/matlab/ver_greater_than_equal.m @@ -0,0 +1,33 @@ +function tf = ver_greater_than_equal(ver1, ver2) +%function tf = ver_greater_than_equal(ver1, ver2) +% ver1 >= ver2 ? 1 : 0; +% +% INPUTS +% ver1 [string] software version number +% ver2 [string] software version number +% +% OUTPUTS +% tf [bool] true if ver1 > ver2 +% +% 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 . + +tf = ver_greater_than(ver1, ver2) || strcmp(ver1, ver2); +end \ No newline at end of file From 85422a2f7d975c0f1d9af3dfb0ca70f26d59ee64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 30 Apr 2015 16:19:49 +0200 Subject: [PATCH 174/210] Added two rules in tests/makefile.am A mod file distributed in the tests folder can be executed with ~$ make ramst.o.drs for Octave, or ~$ make ramst.m.drs for Matlab. The new rules call %.m.trs or %.o.trs and display the generated log file. --- tests/Makefile.am | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 5907029f8..bd6c716d7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -444,6 +444,9 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) echo "`tput bold``tput setaf 1`MATLAB: $(PWD)/$* FAILED!`tput sgr0`" ; \ fi +%.m.drs %.m.log: %.m.trs + @cat $*.m.log + %.m.trs %.m.log : %.m @echo "`tput bold``tput setaf 3`MATLAB: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ @@ -460,6 +463,9 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES) echo "`tput bold``tput setaf 1`OCTAVE: $(PWD)/$* FAILED!`tput sgr0`" ; \ fi +%.o.drs %.o.log: %.mod %.o.trs + @cat $*.o.log + %.o.trs %.o.log : %.m @echo "`tput bold``tput setaf 3`OCTAVE: $(PWD)/$*... `tput sgr0`" @DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \ From 50f0dadec805c4d6236a957e35815f144aa223cd Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 2 May 2015 14:23:23 +0200 Subject: [PATCH 175/210] Fix Geweke convergence when used with load_mh_file By accessing mh_replic instead of NumberOfDraws, the diagnostics were not correctly computed on the full chain --- matlab/McMCDiagnostics.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/matlab/McMCDiagnostics.m b/matlab/McMCDiagnostics.m index ed719034c..ce85ecbf3 100644 --- a/matlab/McMCDiagnostics.m +++ b/matlab/McMCDiagnostics.m @@ -86,14 +86,14 @@ if nblck == 1 % Brooks and Gelman tests need more than one block fprintf('\nCONVERGENCE DIAGNOSTICS: Invalid option for geweke_interval. Using the default of [0.2 0.5].\n') options_.convergence.geweke.geweke_interval=[0.2 0.5]; end - first_obs_begin_sample = max(1,ceil(options_.mh_drop*options_.mh_replic)); - last_obs_begin_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(1)*options_.mh_replic*(1-options_.mh_drop)); - first_obs_end_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(2)*options_.mh_replic*(1-options_.mh_drop)); + first_obs_begin_sample = max(1,ceil(options_.mh_drop*NumberOfDraws)); + last_obs_begin_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(1)*NumberOfDraws*(1-options_.mh_drop)); + first_obs_end_sample = first_obs_begin_sample+round(options_.convergence.geweke.geweke_interval(2)*NumberOfDraws*(1-options_.mh_drop)); param_name=[]; for jj=1:npar param_name = strvcat(param_name,get_the_name(jj,options_.TeX,M_,estim_params_,options_)); end - fprintf('\nGeweke (1992) Convergence Tests, based on means of draws %d to %d vs %d to %d.\n',first_obs_begin_sample,last_obs_begin_sample,first_obs_end_sample,options_.mh_replic); + fprintf('\nGeweke (1992) Convergence Tests, based on means of draws %d to %d vs %d to %d.\n',first_obs_begin_sample,last_obs_begin_sample,first_obs_end_sample,NumberOfDraws); fprintf('p-values are for Chi2-test for equality of means.\n'); Geweke_header={'Parameter', 'Post. Mean', 'Post. Std', 'p-val No Taper'}; print_string=['%',num2str(size(param_name,2)+3),'s \t %12.3f \t %12.3f \t %12.3f']; From 6d7cbe33c57416ebcede36343fad94ad66075755 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 4 May 2015 10:49:24 +0200 Subject: [PATCH 176/210] Add possibility to plot posterior density to trace_plot.m --- matlab/trace_plot.m | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/matlab/trace_plot.m b/matlab/trace_plot.m index 71fa7e742..bc7322737 100644 --- a/matlab/trace_plot.m +++ b/matlab/trace_plot.m @@ -1,13 +1,14 @@ function trace_plot(options_,M_,estim_params_,type,blck,name1,name2) -% This function build trace plot for the metropolis hastings draws. -% +% This function builds trace plot for the Metropolis-Hastings draws. % % INPUTS % % options_ [structure] Dynare structure. % M_ [structure] Dynare structure (related to model definition). % estim_params_ [structure] Dynare structure (related to estimation). -% type [string] 'DeepParameter', 'MeasurementError' (for measurement equation error) or 'StructuralShock' (for structural shock). +% type [string] 'DeepParameter', 'MeasurementError' (for measurement equation error), +% 'StructuralShock' (for structural shock) +% or 'PosteriorDensity (for posterior density)' % blck [integer] Number of the mh chain. % name1 [string] Object name. % name2 [string] Object name. @@ -17,7 +18,7 @@ function trace_plot(options_,M_,estim_params_,type,blck,name1,name2) % % SPECIAL REQUIREMENTS -% Copyright (C) 2003-2013 Dynare Team +% Copyright (C) 2003-2015 Dynare Team % % This file is part of Dynare. % @@ -35,10 +36,15 @@ function trace_plot(options_,M_,estim_params_,type,blck,name1,name2) % along with Dynare. If not, see . % Cet the column index: -if nargin<7 - column = name2index(options_, M_, estim_params_, type, name1); +if strcmpi(type,'PosteriorDensity') + column=0; + name1=''; else - column = name2index(options_, M_, estim_params_, type, name1, name2); + if nargin<7 + column = name2index(options_, M_, estim_params_, type, name1); + else + column = name2index(options_, M_, estim_params_, type, name1, name2); + end end if isempty(column) @@ -75,6 +81,8 @@ elseif strcmpi(type,'MeasurementError') else TYPE = 'the correlation between measurement errors '; end +elseif strcmpi(type,'PosteriorDensity') + TYPE='the posterior density'; end if nargin<7 @@ -111,9 +119,15 @@ legend({'MCMC draw';[num2str(N) ' period moving average']},'Location','NorthWest if ~exist(M_.fname, 'dir') mkdir('.',M_.fname); end -if ~exist([M_.fname filesep 'graphs']) +if ~exist([M_.fname filesep 'graphs'],'dir') mkdir(M_.fname,'graphs'); end -plot_name=get_the_name(column,0,M_,estim_params_,options_); + +%get name for plot +if strcmpi(type,'PosteriorDensity') + plot_name='Posterior'; +else + plot_name=get_the_name(column,0,M_,estim_params_,options_); +end dyn_saveas(hh,[M_.fname, filesep, 'graphs', filesep, 'TracePlot_' plot_name],options_) From b8c6c879083511f73919648b639b718d4a8f21a3 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 5 May 2015 16:02:37 +0200 Subject: [PATCH 177/210] Fix plotting of Bayesian IRFs where IRFs turn from negative to positive. --- matlab/PosteriorIRF_core2.m | 49 +++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/matlab/PosteriorIRF_core2.m b/matlab/PosteriorIRF_core2.m index c20702eb5..1fef8cdff 100644 --- a/matlab/PosteriorIRF_core2.m +++ b/matlab/PosteriorIRF_core2.m @@ -1,17 +1,28 @@ -function myoutput=PosteriorIRF_core2(myinputs,fpar,npar,whoiam, ThisMatlab) +function myoutput=PosteriorIRF_core2(myinputs,fpar,npar,whoiam,ThisMatlab) +% function myoutput=PosteriorIRF_core2(myinputs,fpar,npar,whoiam, ThisMatlab) % Generates the Posterior IRFs plot from the IRFs generated in % PosteriorIRF_core1 +% % PARALLEL CONTEXT -% Perform in parallel execution a portion of the PosteriorIRF.m code. -% See also the comment in random_walk_metropolis_hastings_core.m funtion. +% Performs in parallel execution a portion of the PosteriorIRF.m code. +% For more information, see the comment in random_walk_metropolis_hastings_core.m +% function. % % INPUTS -% See the comment in random_walk_metropolis_hastings_core.m funtion. +% o myimput [struc] The mandatory variables for local/remote +% parallel computing obtained from random_walk_metropolis_hastings.m +% function. +% o fblck and nblck [integer] The Metropolis-Hastings chains. +% o whoiam [integer] In concurrent programming a modality to refer to the differents thread running in parallel is needed. +% The integer whoaim is the integer that +% allows us to distinguish between them. Then it is the index number of this CPU among all CPUs in the +% cluster. +% o ThisMatlab [integer] Allows us to distinguish between the +% 'main' matlab, the slave matlab worker, local matlab, remote matlab, +% ... Then it is the index number of this slave machine in the cluster. % % OUTPUTS -% o myoutput [struc] -% Contained: -% OutputFileName (i.e. the figures without the file .txt). +% o myoutput [struc] Contained: OutputFileName (i.e. the figures without the file .txt). % % ALGORITHM % Portion of PosteriorIRF.m function code. Specifically the last 'for' cycle. @@ -19,7 +30,7 @@ function myoutput=PosteriorIRF_core2(myinputs,fpar,npar,whoiam, ThisMatlab) % SPECIAL REQUIREMENTS. % None. % -% Copyright (C) 2006-2013 Dynare Team +% Copyright (C) 2006-2015 Dynare Team % % This file is part of Dynare. % @@ -100,13 +111,9 @@ for i=fpar:npar, set(0,'CurrentFigure',hh) subplot(nn,nn,subplotnum); if ~MAX_nirfs_dsgevar - h1 = area(1:options_.irf,HPDIRF(:,2,j,i)); - set(h1,'FaceColor',[.9 .9 .9]); - set(h1,'BaseValue',min(HPDIRF(:,1,j,i))); + h1 = area(1:options_.irf,HPDIRF(:,2,j,i),'FaceColor',[.9 .9 .9],'BaseValue',min(HPDIRF(:,1,j,i))); %grey below HPDIsup and minimum of HPDIinf hold on - h2 = area(1:options_.irf,HPDIRF(:,1,j,i),'FaceColor',[1 1 1],'BaseValue',min(HPDIRF(:,1,j,i))); - set(h2,'FaceColor',[1 1 1]); - set(h2,'BaseValue',min(HPDIRF(:,1,j,i))); + h2 = area(1:options_.irf,HPDIRF(:,1,j,i),'FaceColor',[1 1 1],'BaseValue',min(HPDIRF(:,1,j,i))); %white below HPDIinf and minimum of HPDIinf plot(1:options_.irf,MeanIRF(:,j,i),'-k','linewidth',3) % plot([1 options_.irf],[0 0],'-r','linewidth',0.5); box on @@ -114,18 +121,14 @@ for i=fpar:npar, xlim([1 options_.irf]); hold off else - h1 = area(1:options_.irf,HPDIRF(:,2,j,i)); - set(h1,'FaceColor',[.9 .9 .9]); - set(h1,'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))])); - hold on; - h2 = area(1:options_.irf,HPDIRF(:,1,j,i)); - set(h2,'FaceColor',[1 1 1]); - set(h2,'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))])); + h1 = area(1:options_.irf,HPDIRF(:,2,j,i),'FaceColor',[.9 .9 .9],'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))])); %grey below HPDIsup and minimum of HPDIinf and HPDIRFdsgevar + hold on + h2 = area(1:options_.irf,HPDIRF(:,1,j,i),'FaceColor',[1 1 1],'BaseValue',min([min(HPDIRF(:,1,j,i)),min(HPDIRFdsgevar(:,1,j,i))])); %white below HPDIinf and minimum of HPDIinf and HPDIRFdsgevar plot(1:options_.irf,MeanIRF(:,j,i),'-k','linewidth',3) - % plot([1 options_.irf],[0 0],'-r','linewidth',0.5); plot(1:options_.irf,MeanIRFdsgevar(:,j,i),'--k','linewidth',2) plot(1:options_.irf,HPDIRFdsgevar(:,1,j,i),'--k','linewidth',1) plot(1:options_.irf,HPDIRFdsgevar(:,2,j,i),'--k','linewidth',1) + % plot([1 options_.irf],[0 0],'-r','linewidth',0.5); box on axis tight xlim([1 options_.irf]); @@ -156,6 +159,4 @@ for i=fpar:npar, end end% loop over exo_var - - myoutput.OutputFileName = OutputFileName; From 7d263dcd2f8414e4457e97c219acb506c7669e77 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 5 May 2015 16:09:05 +0200 Subject: [PATCH 178/210] Add check for field existence to dynasave.m Otherwise, if simulations do not exist, a cryptic crash happens --- matlab/dynasave.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/matlab/dynasave.m b/matlab/dynasave.m index 748b2e789..f2cc991ca 100644 --- a/matlab/dynasave.m +++ b/matlab/dynasave.m @@ -35,6 +35,10 @@ if size(var_list,1) == 0 var_list = M_.endo_names(1:M_.orig_endo_nbr, :); end +if ~isfield(oo_,'endo_simul') || isempty(oo_.endo_simul) + error('dynasave:: The results structure does not contain simulated series. Maybe the periods option has not been set.') +end + n = size(var_list,1); ivar=zeros(n,1); for i=1:n From f2617fcf74010d24d5b966352e1a25b9d0edc333 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Wed, 6 May 2015 11:16:53 +0200 Subject: [PATCH 179/210] deterministic simulations: more efficient manner to build the Jacobian matrix of the stacked system. Gains is not as much as expected. --- matlab/perfect-foresight-models/sim1.m | 30 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/matlab/perfect-foresight-models/sim1.m b/matlab/perfect-foresight-models/sim1.m index 481cffb4e..4e00befbe 100644 --- a/matlab/perfect-foresight-models/sim1.m +++ b/matlab/perfect-foresight-models/sim1.m @@ -69,7 +69,7 @@ i_cols_A1 = find(lead_lag_incidence(2:3,:)'); i_cols_T = nonzeros(lead_lag_incidence(1:2,:)'); i_cols_0 = nonzeros(lead_lag_incidence(2,:)'); i_cols_A0 = find(lead_lag_incidence(2,:)'); -i_cols_j = 1:nd; +i_cols_j = (1:nd)'; i_upd = maximum_lag*ny+(1:periods*ny); Y = endo_simul(:); @@ -86,7 +86,6 @@ z = Y(find(lead_lag_incidence')); [d1,jacobian] = model_dynamic(z,oo_.exo_simul, params, ... steady_state,maximum_lag+1); -A = sparse([],[],[],periods*ny,periods*ny,periods*nnz(jacobian)); res = zeros(periods*ny,1); o_periods = periods; @@ -94,26 +93,32 @@ o_periods = periods; ZERO = zeros(length(i_upd),1); h1 = clock ; +iA = zeros(periods*M_.NNZDerivatives(1),3); for iter = 1:options_.simul.maxit h2 = clock ; - i_rows = 1:ny; + i_rows = (1:ny)'; i_cols_A = find(lead_lag_incidence'); i_cols = i_cols_A+(maximum_lag-1)*ny; - + m = 0; for it = (maximum_lag+1):(maximum_lag+periods) - - [d1,jacobian] = model_dynamic(Y(i_cols), exo_simul, params, steady_state,it); + [d1,jacobian] = model_dynamic(Y(i_cols), exo_simul, params, ... + steady_state,it); if it == maximum_lag+periods && it == maximum_lag+1 - A(i_rows,i_cols_A0) = jacobian(:,i_cols_0); + [r,c,v] = find(jacobian(:,i_cols_0)); + iA((1:length(v))+m,:) = [i_rows(r),i_cols_A0(c),v]; elseif it == maximum_lag+periods - A(i_rows,i_cols_A(i_cols_T)) = jacobian(:,i_cols_T); + [r,c,v] = find(jacobian(:,i_cols_T)); + iA((1:length(v))+m,:) = [i_rows(r),i_cols_A(i_cols_T(c)),v]; elseif it == maximum_lag+1 - A(i_rows,i_cols_A1) = jacobian(:,i_cols_1); + [r,c,v] = find(jacobian(:,i_cols_1)); + iA((1:length(v))+m,:) = [i_rows(r),i_cols_A1(c),v]; else - A(i_rows,i_cols_A) = jacobian(:,i_cols_j); + [r,c,v] = find(jacobian(:,i_cols_j)); + iA((1:length(v))+m,:) = [i_rows(r),i_cols_A(c),v]; end - + m = m + length(v); + res(i_rows) = d1; if endogenous_terminal_period && iter>1 @@ -157,6 +162,9 @@ for iter = 1:options_.simul.maxit break end + iA = iA(1:m,:); + A = sparse(iA(:,1),iA(:,2),iA(:,3),periods*ny,periods*ny); + if endogenous_terminal_period && iter>1 dy = ZERO; dy(1:i_rows(end)) = -A(1:i_rows(end),1:i_rows(end))\res(1:i_rows(end)); From 0c7b4f542c6a8b41f0d9be928f898da5781ef306 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 6 May 2015 16:14:45 +0200 Subject: [PATCH 180/210] Add check for presence of NaN in JJ to identification_analysis.m Usually happens when model has a unit root and unconditional second moments are NaN --- matlab/identification_analysis.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index 070698838..f14e74f71 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -85,6 +85,9 @@ if info(1)==0, derivatives_info.DYss=dYss; if init, indJJ = (find(max(abs(JJ'),[],1)>1.e-8)); + if isempty(indJJ) && any(any(isnan(JJ))) + error('There are NaN in the JJ matrix. Please check whether your model has units roots and you forgot to set lik_init~=1.' ) + end while length(indJJ) Date: Sat, 9 May 2015 08:03:12 +0200 Subject: [PATCH 183/210] Make sure non_linear_dsge_likelihood.m and dsge_var_likelihood.m return correct error codes if prior or likelihood are Inf or NaN Closes #284 --- matlab/dsge_var_likelihood.m | 28 ++++++++++++++++++++++++++++ matlab/non_linear_dsge_likelihood.m | 18 +++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/matlab/dsge_var_likelihood.m b/matlab/dsge_var_likelihood.m index 07b5d1b73..a8a9e8710 100644 --- a/matlab/dsge_var_likelihood.m +++ b/matlab/dsge_var_likelihood.m @@ -239,10 +239,38 @@ else% Evaluation of the likelihood of the dsge-var model when the dsge prior wei lik = .5*lik;% Minus likelihood end +if isnan(lik) + info = 45; + fval = objective_function_penalty_base + 100; + exit_flag = 0; + return +end + +if imag(lik)~=0 + info = 46; + fval = objective_function_penalty_base + 100; + exit_flag = 0; + return +end + % Add the (logged) prior density for the dsge-parameters. lnprior = priordens(xparam1,BayesInfo.pshape,BayesInfo.p6,BayesInfo.p7,BayesInfo.p3,BayesInfo.p4); fval = (lik-lnprior); +if isnan(fval) + info = 47; + fval = objective_function_penalty_base + 100; + exit_flag = 0; + return +end + +if imag(fval)~=0 + info = 48; + fval = objective_function_penalty_base + 100; + exit_flag = 0; + return +end + if (nargout == 8) if isinf(dsge_prior_weight) iXX = iGXX; diff --git a/matlab/non_linear_dsge_likelihood.m b/matlab/non_linear_dsge_likelihood.m index f3122ec73..5ccddc18b 100644 --- a/matlab/non_linear_dsge_likelihood.m +++ b/matlab/non_linear_dsge_likelihood.m @@ -319,9 +319,11 @@ DynareOptions.warning_for_steadystate = 0; LIK = feval(DynareOptions.particle.algorithm,ReducedForm,Y,start,DynareOptions); set_dynare_random_generator_state(s1,s2); if imag(LIK) + info = 46; likelihood = objective_function_penalty_base; exit_flag = 0; elseif isnan(LIK) + info = 45; likelihood = objective_function_penalty_base; exit_flag = 0; else @@ -332,4 +334,18 @@ DynareOptions.warning_for_steadystate = 1; % Adds prior if necessary % ------------------------------------------------------------------------------ lnprior = priordens(xparam1(:),BayesInfo.pshape,BayesInfo.p6,BayesInfo.p7,BayesInfo.p3,BayesInfo.p4); -fval = (likelihood-lnprior); \ No newline at end of file +fval = (likelihood-lnprior); + +if isnan(fval) + info = 47; + fval = objective_function_penalty_base + 100; + exit_flag = 0; + return +end + +if imag(fval)~=0 + info = 48; + fval = objective_function_penalty_base + 100; + exit_flag = 0; + return +end From 120946dfb3c0fbd1015d907842245bb190bab603 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 9 May 2015 08:12:16 +0200 Subject: [PATCH 184/210] Add unit test for deterministic simulations with several leads and lags Tests #617 --- tests/Makefile.am | 1 + .../sim_several_leads_lags.mod | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/deterministic_simulations/sim_several_leads_lags.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index ec9640124..63b24805c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -182,6 +182,7 @@ MODFILES = \ deterministic_simulations/rbc_det_exo_lag_2a.mod \ deterministic_simulations/rbc_det_exo_lag_2b.mod \ deterministic_simulations/rbc_det_exo_lag_2c.mod \ + deterministic_simulations/sim_several_leads_lags.mod \ walsh.mod \ measurement_errors/fs2000_corr_me_ml_mcmc/fs2000_corr_ME.mod \ trend_var/fs2000_nonstationary.mod \ diff --git a/tests/deterministic_simulations/sim_several_leads_lags.mod b/tests/deterministic_simulations/sim_several_leads_lags.mod new file mode 100644 index 000000000..058315bd3 --- /dev/null +++ b/tests/deterministic_simulations/sim_several_leads_lags.mod @@ -0,0 +1,35 @@ +var c k z_forward z_backward; +varexo x z_shock; + +parameters alph gam delt bet aa; +alph=0.5; +gam=0.5; +delt=0.02; +bet=0.05; +aa=0.5; + +model; +c + k - aa*x*k(-1)^alph - (1-delt)*k(-1); // Resource constraint +c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam); // Euler equation +z_backward=0.1*1+0.3*z_backward(-1)+0.3*z_backward(-2)+0.3*z_backward(-3)+(x(-4)-1); +z_forward=0.1*1+0.45*z_forward(+1)+0.45*z_forward(+2)+(x(+4)-1); +end; + +initval; +c = 1.2; +k = 12; +x = 1; +end; + +histval; +x(-1)=1.30; +x(-2)=1.30; +end; + +shocks; +var x; +periods 2; +values 0.9; +end; + +simul(periods=200,maxit=100); \ No newline at end of file From 8aec696b95abd83d58d26ae9c2ce225761b9607a Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 9 May 2015 08:22:31 +0200 Subject: [PATCH 185/210] Fix various copy and paste errors in check_input_arguments.m During moving to a separate function, not all variables had been renamed --- .../private/check_input_arguments.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/matlab/perfect-foresight-models/private/check_input_arguments.m b/matlab/perfect-foresight-models/private/check_input_arguments.m index 795f84645..affb808e0 100644 --- a/matlab/perfect-foresight-models/private/check_input_arguments.m +++ b/matlab/perfect-foresight-models/private/check_input_arguments.m @@ -1,5 +1,7 @@ function check_input_arguments(DynareOptions, DynareModel, DynareResults) %function check_input_arguments(DynareOptions, DynareModel, DynareResults) +%Conducts checks for inconsistent/missing inputs to deterministic +%simulations % Copyright (C) 2015 Dynare Team % @@ -42,8 +44,8 @@ end if isempty(DynareResults.endo_simul) || any(size(DynareResults.endo_simul) ~= [ DynareModel.endo_nbr, DynareModel.maximum_lag+DynareOptions.periods+DynareModel.maximum_lead ]) - if options_.initval_file - disp(sprintf('PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Check whether your initval-file provides %d periods.',M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead)) + if DynareOptions.initval_file + fprintf('PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Check whether your initval-file provides %d periods.',DynareModel.maximum_endo_lag+DynareOptions.periods+DynareModel.maximum_endo_lead) error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') else error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') @@ -52,11 +54,10 @@ end if (DynareModel.exo_nbr > 0) && ... (isempty(DynareResults.exo_simul) || any(size(DynareResults.exo_simul) ~= [ DynareModel.maximum_lag+DynareOptions.periods+DynareModel.maximum_lead, DynareModel.exo_nbr ])) - if options_.initval_file - disp(sprintf('PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Check whether your initval-file provides %d periods.',M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead)) + if DynareOptions.initval_file + fprintf('PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Check whether your initval-file provides %d periods.',DynareModel.maximum_endo_lag+DynareOptions.periods+DynareModel.maximum_endo_lead) error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size.') else error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') end - error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?') end From fa1f7794d5a85de8c805947f600873032b3cf6bc Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 9 May 2015 15:13:59 +0200 Subject: [PATCH 186/210] Delete stale files from previous MCMC runs Closes #566. Also adds cosmetic changes to headers of affected routines --- matlab/PosteriorIRF.m | 24 +++++++------- ...ional_variance_decomposition_mc_analysis.m | 22 ++++++++++++- matlab/covariance_mc_analysis.m | 20 +++++++++-- ...tical_conditional_variance_decomposition.m | 12 ++++++- .../dsge_simulated_theoretical_correlation.m | 33 ++++++++++++------- .../dsge_simulated_theoretical_covariance.m | 10 +++++- ...lated_theoretical_variance_decomposition.m | 12 +++++-- matlab/utilities/general/delete_stale_file.m | 26 +++++++++++++++ matlab/variance_decomposition_mc_analysis.m | 24 +++++++++++++- 9 files changed, 150 insertions(+), 33 deletions(-) create mode 100644 matlab/utilities/general/delete_stale_file.m diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m index fc1c3bcf5..47da7e86f 100644 --- a/matlab/PosteriorIRF.m +++ b/matlab/PosteriorIRF.m @@ -16,7 +16,7 @@ function PosteriorIRF(type) % functions associated with it(the _core1 and _core2). % See also the comments random_walk_metropolis_hastings.m funtion. -% Copyright (C) 2006-2013 Dynare Team +% Copyright (C) 2006-2015 Dynare Team % % This file is part of Dynare. % @@ -93,8 +93,15 @@ elseif strcmpi(type,'gsa') else MhDirectoryName = CheckPath('prior',M_.dname); end -delete([MhDirectoryName filesep M_.fname '_IRF_DSGEs*.mat']); -delete([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs*.mat']); + +%delete old stale files before creating new ones +delete_stale_file([MhDirectoryName filesep M_.fname '_IRF_DSGEs*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_irf_dsge*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_irf_bvardsge*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_param_irf*.mat']); + + if strcmpi(type,'posterior') B = options_.sub_draws; options_.B = B; @@ -112,16 +119,7 @@ else% type = 'prior' B = options_.prior_draws; options_.B = B; end -try - delete([MhDirectoryName filesep M_.fname '_irf_dsge*.mat']) -catch - disp('No _IRFs (dsge) files to be deleted!') -end -try - delete([MhDirectoryName filesep M_.fname '_irf_bvardsge*.mat']) -catch - disp('No _IRFs (bvar-dsge) files to be deleted!') -end + irun = 0; IRUN = 0; irun2 = 0; diff --git a/matlab/conditional_variance_decomposition_mc_analysis.m b/matlab/conditional_variance_decomposition_mc_analysis.m index 004239800..22273f2be 100644 --- a/matlab/conditional_variance_decomposition_mc_analysis.m +++ b/matlab/conditional_variance_decomposition_mc_analysis.m @@ -1,7 +1,27 @@ function oo_ = ... conditional_variance_decomposition_mc_analysis(NumberOfSimulations, type, dname, fname, Steps, exonames, exo, var_list, endogenous_variable_index, mh_conf_sig, oo_) % This function analyses the (posterior or prior) distribution of the -% endogenous conditional variance decomposition. +% endogenous variables' conditional variance decomposition. +% +% INPUTS +% NumberOfSimulations [integer] scalar, number of simulations. +% type [string] 'prior' or 'posterior' +% dname [string] directory name where to save +% fname [string] name of the mod-file +% Steps [integers] horizons at which to conduct decomposition +% exonames [string] (n_exo*char_length) character array with names of exogenous variables +% exo [string] name of current exogenous +% variable +% var_list [string] (n_endo*char_length) character array with name +% of endogenous variables +% endogenous_variable_index [integer] index of the current +% endogenous variable +% mh_conf_sig [double] 2 by 1 vector with upper +% and lower bound of HPD intervals +% oo_ [structure] Dynare structure where the results are saved. +% +% OUTPUTS +% oo_ [structure] Dynare structure where the results are saved. % Copyright (C) 2009-2013 Dynare Team % diff --git a/matlab/covariance_mc_analysis.m b/matlab/covariance_mc_analysis.m index a24ec665e..d98992f0e 100644 --- a/matlab/covariance_mc_analysis.m +++ b/matlab/covariance_mc_analysis.m @@ -1,8 +1,24 @@ function oo_ = covariance_mc_analysis(NumberOfSimulations,type,dname,fname,vartan,nvar,var1,var2,mh_conf_sig,oo_) % This function analyses the (posterior or prior) distribution of the -% endogenous variables covariance matrix. +% endogenous variables' covariance matrix. +% +% INPUTS +% NumberOfSimulations [integer] scalar, number of simulations. +% type [string] 'prior' or 'posterior' +% dname [string] directory name where to save +% fname [string] name of the mod-file +% vartan [char] array of characters (with nvar rows). +% nvar [integer] nvar is the number of stationary variables. +% var1 [string] name of the first variable +% var2 [string] name of the second variable +% mh_conf_sig [double] 2 by 1 vector with upper +% and lower bound of HPD intervals +% oo_ [structure] Dynare structure where the results are saved. +% +% OUTPUTS +% oo_ [structure] Dynare structure where the results are saved. -% Copyright (C) 2008-2013 Dynare Team +% Copyright (C) 2008-2015 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m b/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m index 7ef623b81..1c0441361 100644 --- a/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m +++ b/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m @@ -1,10 +1,13 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ... dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type) +% function [nvar,vartan,NumberOfConditionalDecompFiles] = ... +% dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the conditional variance % decomposition of the endogenous variables (or a subset of the endogenous variables). % % INPUTS % SampleSize [integer] scalar, number of simulations. +% Steps [integers] horizons at which to conduct decomposition % M_ [structure] Dynare structure describing the model. % options_ [structure] Dynare structure defining global options. % oo_ [structure] Dynare structure where the results are saved. @@ -16,7 +19,7 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ... % vartan [char] array of characters (with nvar rows). % NumberOfConditionalDecompFiles [integer] scalar, number of prior or posterior data files (for covariance). -% Copyright (C) 2009-2012 Dynare Team +% Copyright (C) 2009-2015 Dynare Team % % This file is part of Dynare. % @@ -47,6 +50,13 @@ else error() end +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition*']) +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecomposition*']) +end + % Set varlist (vartan) if ~posterior if isfield(options_,'varlist') diff --git a/matlab/dsge_simulated_theoretical_correlation.m b/matlab/dsge_simulated_theoretical_correlation.m index 59ffa4e4e..265336dbb 100644 --- a/matlab/dsge_simulated_theoretical_correlation.m +++ b/matlab/dsge_simulated_theoretical_correlation.m @@ -1,21 +1,23 @@ function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type) +% function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the endogenous -% variables second order moments. +% variables' second order moments. % % INPUTS -% SampleSize [integer] -% nar [integer] -% M_ [structure] -% options_ [structure] -% oo_ [structure] -% type [string] +% SampleSize [integer] scalar, number of simulations. +% nar [integer] maximum number of autocorrelations to +% consider +% M_ [structure] Dynare structure describing the model. +% options_ [structure] Dynare structure defining global options +% oo_ [structure] Dynare structure where the results are saved. +% type [string] 'prior' or 'posterior' % % OUTPUTS -% nvar [integer] -% vartan [char] -% CorrFileNumber [integer] - -% Copyright (C) 2007-2012 Dynare Team +% nvar [integer] nvar is the number of stationary variables. +% vartan [char] array of characters (with nvar rows). +% CorrFileNumber [integer] scalar, number of prior or posterior data files (for correlation). + +% Copyright (C) 2007-2015 Dynare Team % % This file is part of Dynare. % @@ -48,6 +50,13 @@ else end NumberOfDrawsFiles = length(DrawsFiles); +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations*']); +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorCorrelations*']); +end + % Set varlist (vartan) if ~posterior if isfield(options_,'varlist') diff --git a/matlab/dsge_simulated_theoretical_covariance.m b/matlab/dsge_simulated_theoretical_covariance.m index 5d39e77fb..38ef7c3b6 100644 --- a/matlab/dsge_simulated_theoretical_covariance.m +++ b/matlab/dsge_simulated_theoretical_covariance.m @@ -1,4 +1,5 @@ function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,type) +% function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the endogenous % variables second order moments. % @@ -15,7 +16,7 @@ function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(S % vartan [char] array of characters (with nvar rows). % CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance). -% Copyright (C) 2007-2012 Dynare Team +% Copyright (C) 2007-2015 Dynare Team % % This file is part of Dynare. % @@ -48,6 +49,13 @@ else end NumberOfDrawsFiles = length(DrawsFiles); +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments*']) +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_Prior2ndOrderMoments*']) +end + % Set varlist (vartan) if ~posterior if isfield(options_,'varlist') diff --git a/matlab/dsge_simulated_theoretical_variance_decomposition.m b/matlab/dsge_simulated_theoretical_variance_decomposition.m index 7059e6d13..74335840e 100644 --- a/matlab/dsge_simulated_theoretical_variance_decomposition.m +++ b/matlab/dsge_simulated_theoretical_variance_decomposition.m @@ -1,5 +1,7 @@ function [nvar,vartan,NumberOfDecompFiles] = ... dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,type) +% function [nvar,vartan,NumberOfDecompFiles] = ... +% dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the variance % decomposition of the observed endogenous variables. % @@ -16,7 +18,7 @@ function [nvar,vartan,NumberOfDecompFiles] = ... % vartan [char] array of characters (with nvar rows). % CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance). -% Copyright (C) 2007-2012 Dynare Team +% Copyright (C) 2007-2015 Dynare Team % % This file is part of Dynare. % @@ -47,7 +49,13 @@ else disp('dsge_simulated_theoretical_variance_decomposition:: Unknown type!') error() end -NumberOfDrawsFiles = length(DrawsFiles); + +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecomposition*']); +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PosteriorVarianceDecomposition*']); +end % Set varlist (vartan) if ~posterior diff --git a/matlab/utilities/general/delete_stale_file.m b/matlab/utilities/general/delete_stale_file.m new file mode 100644 index 000000000..8ac8b7996 --- /dev/null +++ b/matlab/utilities/general/delete_stale_file.m @@ -0,0 +1,26 @@ +function delete_stale_file(fname) +% function delete_old_files(fname) +% Checks for presence of files and deletes them if necessary + +% 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 . + +Files_info = dir(fname); +if length(Files_info)>0 + delete(fname) +end + diff --git a/matlab/variance_decomposition_mc_analysis.m b/matlab/variance_decomposition_mc_analysis.m index b4f3f570d..798b28afe 100644 --- a/matlab/variance_decomposition_mc_analysis.m +++ b/matlab/variance_decomposition_mc_analysis.m @@ -1,6 +1,28 @@ function oo_ = variance_decomposition_mc_analysis(NumberOfSimulations,type,dname,fname,exonames,exo,vartan,var,mh_conf_sig,oo_) +% function oo_ = variance_decomposition_mc_analysis(NumberOfSimulations,type,dname,fname,exonames,exo,vartan,var,mh_conf_sig,oo_) % This function analyses the (posterior or prior) distribution of the -% endogenous variance decomposition. +% endogenous variables' variance decomposition. +% +% INPUTS +% NumberOfSimulations [integer] scalar, number of simulations. +% type [string] 'prior' or 'posterior' +% dname [string] directory name where to save +% fname [string] name of the mod-file +% exonames [string] (n_exo*char_length) character array with names of exogenous variables +% exo [string] name of current exogenous +% variable +% vartan [string] (n_endo*char_length) character array with name +% of endogenous variables +% var [integer] index of the current +% endogenous variable +% mh_conf_sig [double] 2 by 1 vector with upper +% and lower bound of HPD intervals +% oo_ [structure] Dynare structure where the results are saved. +% +% OUTPUTS +% oo_ [structure] Dynare structure where the results are saved. + + % Copyright (C) 2008-2013 Dynare Team % From de427b77f279636e48b91f7a9e3fa72c144b22c6 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 9 May 2015 17:59:24 +0200 Subject: [PATCH 187/210] Add unit test for differentiate_forward_vars Closes #727 --- tests/Makefile.am | 1 + .../RBC_differentiate_forward.mod | 92 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/diffentiate_forward_vars/RBC_differentiate_forward.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 63b24805c..4b5f9f2ae 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -219,6 +219,7 @@ MODFILES = \ optimizers/fs2000_101.mod \ optimizers/fs2000_102.mod \ optimizers/fs2000_w.mod \ + diffentiate_forward_vars/RBC_differentiate_forward \ reporting/example1.mod XFAIL_MODFILES = ramst_xfail.mod \ diff --git a/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod b/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod new file mode 100644 index 000000000..8303b9c01 --- /dev/null +++ b/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod @@ -0,0 +1,92 @@ +/* +* This model shows how to use the differentiate_forward_vars option to simulate +* perfect foresight models when the steady state is unknown +* or when the model is very persistent. In this file, we consider an RBC model +* with a CES technology and very persistent productivity shock. We set the +* autoregressive parameter of this exogenous productivity to 0.999, so that +* in period 400 the level of productivity, after an initial one percent shock, +* is still 0.67\% above its steady state level. +* +* Written by Stéphane Adjemian. For more information, see +* http://gitlab.ithaca.fr/Dynare/differentiate-forward-variables +*/ +var Capital, Output, Labour, Consumption, Efficiency, efficiency, ExpectedTerm; + +varexo EfficiencyInnovation; + +parameters beta, theta, tau, alpha, psi, delta, rho, effstar, sigma; + +/* +** Calibration +*/ + +beta = 0.990; +theta = 0.357; +tau = 30.000; +alpha = 0.450; +psi = -1.000; // So that the elasticity of substitution between inputs is 1/(1-psi)=1/10 +delta = 0.020; +rho = 0.999; +effstar = 1.000; +sigma = 0.010; + +model(differentiate_forward_vars); + + // Eq. n°1: + efficiency = rho*efficiency(-1) + sigma*EfficiencyInnovation; + + // Eq. n°2: + Efficiency = effstar*exp(efficiency); + + // Eq. n°3: + Output = Efficiency*(alpha*(Capital(-1)^psi)+(1-alpha)*(Labour^psi))^(1/psi); + + // Eq. n°4: + Consumption + Capital - Output - (1-delta)*Capital(-1); + + // Eq. n°5: + ((1-theta)/theta)*(Consumption/(1-Labour)) - (1-alpha)*(Output/Labour)^(1-psi); + + // Eq. n°6: + (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - ExpectedTerm(1); + + // Eq. n°7: + ExpectedTerm = beta*((((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption)*(alpha*((Output/Capital(-1))^(1-psi))+1-delta); + +end; + +steady_state_model; + + efficiency = 0; + Efficiency = effstar; + + // Compute some steady state ratios. + Output_per_unit_of_Capital=((1/beta-1+delta)/alpha)^(1/(1-psi)); + Consumption_per_unit_of_Capital=Output_per_unit_of_Capital-delta; + Labour_per_unit_of_Capital=(((Output_per_unit_of_Capital/Efficiency)^psi-alpha)/(1-alpha))^(1/psi); + Output_per_unit_of_Labour=Output_per_unit_of_Capital/Labour_per_unit_of_Capital; + Consumption_per_unit_of_Labour=Consumption_per_unit_of_Capital/Labour_per_unit_of_Capital; + + // Compute steady state share of capital. + ShareOfCapital=alpha/(alpha+(1-alpha)*Labour_per_unit_of_Capital^psi); + + // Compute steady state of the endogenous variables. + Labour=1/(1+Consumption_per_unit_of_Labour/((1-alpha)*theta/(1-theta)*Output_per_unit_of_Labour^(1-psi))); + Consumption = Consumption_per_unit_of_Labour*Labour; + Capital = Labour/Labour_per_unit_of_Capital; + Output = Output_per_unit_of_Capital*Capital; + ExpectedTerm = beta*((((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption)*(alpha*((Output/Capital)^(1-psi))+1-delta); + +end; + + +shocks; +var EfficiencyInnovation; +periods 1; +values 1; +end; + +steady; +check; + +simul(periods=500); From b8eb0ff72db535c41f5dd74ac106ecf97140db78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sat, 9 May 2015 22:26:59 +0200 Subject: [PATCH 188/210] Added online help to prior command (cli). --- matlab/cli/prior.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/matlab/cli/prior.m b/matlab/cli/prior.m index f490a570b..d00e0555b 100644 --- a/matlab/cli/prior.m +++ b/matlab/cli/prior.m @@ -28,6 +28,18 @@ function varargout = prior(varargin) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . +if isempty(varargin) || ( isequal(length(varargin), 1) && isequal(varargin{1},'help')) + skipline() + disp('Possible options are:') + disp(' + table Prints a table describing the priors.') + disp(' + moments Computes and displays moments of the endogenous variables at the prior mode.') + disp(' + optimize Optimizes the prior density (starting from a random initial guess).') + disp(' + simulate Computes the effective prior mass (using a Monte-Carlo).') + disp(' + plot Plots the marginal prior densities.') + skipline() + return +end + global options_ M_ estim_params_ bayestopt_ oo_ objective_function_penalty_base donesomething = false; From e91d92ba6dedc5493d51fc24fe0f147ca4d226c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sat, 9 May 2015 22:34:44 +0200 Subject: [PATCH 189/210] Changed encoding to utf-8. --- .../RBC_differentiate_forward.mod | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod b/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod index 8303b9c01..f95c85404 100644 --- a/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod +++ b/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod @@ -7,7 +7,7 @@ * in period 400 the level of productivity, after an initial one percent shock, * is still 0.67\% above its steady state level. * -* Written by Stéphane Adjemian. For more information, see +* Written by Stéphane Adjemian. For more information, see * http://gitlab.ithaca.fr/Dynare/differentiate-forward-variables */ var Capital, Output, Labour, Consumption, Efficiency, efficiency, ExpectedTerm; @@ -32,25 +32,25 @@ sigma = 0.010; model(differentiate_forward_vars); - // Eq. n°1: + // Eq. n°1: efficiency = rho*efficiency(-1) + sigma*EfficiencyInnovation; - // Eq. n°2: + // Eq. n°2: Efficiency = effstar*exp(efficiency); - // Eq. n°3: + // Eq. n°3: Output = Efficiency*(alpha*(Capital(-1)^psi)+(1-alpha)*(Labour^psi))^(1/psi); - // Eq. n°4: + // Eq. n°4: Consumption + Capital - Output - (1-delta)*Capital(-1); - // Eq. n°5: + // Eq. n°5: ((1-theta)/theta)*(Consumption/(1-Labour)) - (1-alpha)*(Output/Labour)^(1-psi); - // Eq. n°6: + // Eq. n°6: (((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption - ExpectedTerm(1); - // Eq. n°7: + // Eq. n°7: ExpectedTerm = beta*((((Consumption^theta)*((1-Labour)^(1-theta)))^(1-tau))/Consumption)*(alpha*((Output/Capital(-1))^(1-psi))+1-delta); end; From e76f81740f3d8baeb726ff710884ba52f7e45030 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 9 May 2015 15:34:37 +0200 Subject: [PATCH 190/210] Make sure that no variable is named hessian. --- matlab/dyn_second_order_solver.m | 16 ++++++++-------- matlab/maximize_prior_density.m | 6 +++--- matlab/mode_check.m | 10 +++++----- matlab/optimize_prior.m | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/matlab/dyn_second_order_solver.m b/matlab/dyn_second_order_solver.m index f4f1f8519..dd2d2bfb8 100644 --- a/matlab/dyn_second_order_solver.m +++ b/matlab/dyn_second_order_solver.m @@ -1,7 +1,7 @@ -function dr = dyn_second_order_solver(jacobia,hessian,dr,M_,threads_ABC,threads_BC) +function dr = dyn_second_order_solver(jacobia,hessian_mat,dr,M_,threads_ABC,threads_BC) %@info: -%! @deftypefn {Function File} {@var{dr} =} dyn_second_order_solver (@var{jacobia},@var{hessian},@var{dr},@var{M_},@var{threads_ABC},@var{threads_BC}) +%! @deftypefn {Function File} {@var{dr} =} dyn_second_order_solver (@var{jacobia},@var{hessian_mat},@var{dr},@var{M_},@var{threads_ABC},@var{threads_BC}) %! @anchor{dyn_second_order_solver} %! @sp 1 %! Computes the second order reduced form of the DSGE model @@ -11,7 +11,7 @@ function dr = dyn_second_order_solver(jacobia,hessian,dr,M_,threads_ABC,threads_ %! @table @ @var %! @item jacobia %! Matrix containing the Jacobian of the model -%! @item hessian +%! @item hessian_mat %! Matrix containing the second order derivatives of the model %! @item dr %! Matlab's structure describing the reduced form solution of the model. @@ -73,7 +73,7 @@ function dr = dyn_second_order_solver(jacobia,hessian,dr,M_,threads_ABC,threads_ kk1 = reshape([1:nk^2],nk,nk); kk1 = kk1(kk,kk); % reordering second order derivatives - hessian = hessian(:,kk1(:)); + hessian_mat = hessian_mat(:,kk1(:)); zx = zeros(np,np); zu=zeros(np,M_.exo_nbr); @@ -91,7 +91,7 @@ function dr = dyn_second_order_solver(jacobia,hessian,dr,M_,threads_ABC,threads_ zu=[zu; eye(M_.exo_nbr);zeros(M_.exo_det_nbr,M_.exo_nbr)]; [nrzx,nczx] = size(zx); - [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian,zx,threads_BC); + [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zx,threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err); rhs = -rhs; @@ -118,7 +118,7 @@ function dr = dyn_second_order_solver(jacobia,hessian,dr,M_,threads_ABC,threads_ %ghxu %rhs hu = dr.ghu(nstatic+1:nstatic+nspred,:); - [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian,zx,zu,threads_BC); + [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zx,zu,threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err); hu1 = [hu;zeros(np-nspred,M_.exo_nbr)]; @@ -136,7 +136,7 @@ function dr = dyn_second_order_solver(jacobia,hessian,dr,M_,threads_ABC,threads_ %ghuu %rhs - [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian,zu,threads_BC); + [rhs, err] = sparse_hessian_times_B_kronecker_C(hessian_mat,zu,threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err); [B1, err] = A_times_B_kronecker_C(B*dr.ghxx,hu1,threads_ABC); @@ -164,7 +164,7 @@ function dr = dyn_second_order_solver(jacobia,hessian,dr,M_,threads_ABC,threads_ hxx = dr.ghxx(nstatic+[1:nspred],:); [junk,k2a,k2] = find(M_.lead_lag_incidence(M_.maximum_endo_lag+2,order_var)); k3 = nnz(M_.lead_lag_incidence(1:M_.maximum_endo_lag+1,:))+(1:M_.nsfwrd)'; - [B1, err] = sparse_hessian_times_B_kronecker_C(hessian(:,kh(k3,k3)),gu(k2a,:),threads_BC); + [B1, err] = sparse_hessian_times_B_kronecker_C(hessian_mat(:,kh(k3,k3)),gu(k2a,:),threads_BC); mexErrCheck('sparse_hessian_times_B_kronecker_C', err); RHS = RHS + jacobia(:,k2)*guu(k2a,:)+B1; diff --git a/matlab/maximize_prior_density.m b/matlab/maximize_prior_density.m index 131e0422d..72df861a4 100644 --- a/matlab/maximize_prior_density.m +++ b/matlab/maximize_prior_density.m @@ -1,4 +1,4 @@ -function [xparams,lpd,hessian] = ... +function [xparams,lpd,hessian_mat] = ... maximize_prior_density(iparams, prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound,DynareOptions,DynareModel,BayesInfo,EstimatedParams,DynareResults) % Maximizes the logged prior density using Chris Sims' optimization routine. % @@ -13,7 +13,7 @@ function [xparams,lpd,hessian] = ... % OUTPUTS % xparams [double] vector, prior mode. % lpd [double] scalar, value of the logged prior density at the mode. -% hessian [double] matrix, Hessian matrix at the prior mode. +% hessian_mat [double] matrix, Hessian matrix at the prior mode. % Copyright (C) 2009-2015 Dynare Team % @@ -32,7 +32,7 @@ function [xparams,lpd,hessian] = ... % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -[xparams, lpd, exitflag, hessian]=dynare_minimize_objective('minus_logged_prior_density', ... +[xparams, lpd, exitflag, hessian_mat]=dynare_minimize_objective('minus_logged_prior_density', ... iparams, DynareOptions.mode_compute, DynareOptions, [prior_inf_bound, prior_sup_bound], ... BayesInfo.name, BayesInfo, [], ... prior_shape, prior_hyperparameter_1, prior_hyperparameter_2, prior_inf_bound, prior_sup_bound, ... diff --git a/matlab/mode_check.m b/matlab/mode_check.m index 180ba3592..0f50ca523 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -1,8 +1,8 @@ -function mode_check(fun,x,hessian,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults) +function mode_check(fun,x,hessian_mat,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults) % Checks the estimated ML mode or Posterior mode. %@info: -%! @deftypefn {Function File} mode_check (@var{fun}, @var{x}, @var{hessian}, @var{DynareDataset}, @var{DynareOptions}, @var{Model}, @var{EstimatedParameters}, @var{BayesInfo}, @var{DynareResults}) +%! @deftypefn {Function File} mode_check (@var{fun}, @var{x}, @var{hessian_mat}, @var{DynareDataset}, @var{DynareOptions}, @var{Model}, @var{EstimatedParameters}, @var{BayesInfo}, @var{DynareResults}) %! @anchor{mode_check} %! @sp 1 %! Checks the estimated ML mode or Posterior mode by plotting sections of the likelihood/posterior kernel. @@ -58,13 +58,13 @@ function mode_check(fun,x,hessian,DynareDataset,DatasetInfo,DynareOptions,Model, % along with Dynare. If not, see . TeX = DynareOptions.TeX; -if ~isempty(hessian); - [ s_min, k ] = min(diag(hessian)); +if ~isempty(hessian_mat); + [ s_min, k ] = min(diag(hessian_mat)); end fval = feval(fun,x,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults); -if ~isempty(hessian); +if ~isempty(hessian_mat); skipline() disp('MODE CHECK') skipline() diff --git a/matlab/optimize_prior.m b/matlab/optimize_prior.m index a3595d0f6..d5b5e0ac1 100644 --- a/matlab/optimize_prior.m +++ b/matlab/optimize_prior.m @@ -51,7 +51,7 @@ objective_function_penalty_base = minus_logged_prior_density(xinit, BayesInfo.ps BayesInfo.p4,DynareOptions,ModelInfo,EstimationInfo,DynareResults); % Maximization of the prior density -[xparams, lpd, hessian] = ... +[xparams, lpd, hessian_mat] = ... maximize_prior_density(xinit, BayesInfo.pshape, ... BayesInfo.p6, ... BayesInfo.p7, ... From 787f6d37c2ce27cf3b59f45f3a0c1a4274d1b1b3 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 10 May 2015 10:06:22 +0200 Subject: [PATCH 191/210] Add unit test for t-distribution as proposal density --- tests/Makefile.am | 1 + .../estimation/t_proposal/fs2000_student.mod | 120 ++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 tests/estimation/t_proposal/fs2000_student.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 4b5f9f2ae..73efb4ea4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,6 +7,7 @@ MODFILES = \ estimation/fs2000_initialize_from_calib.mod \ estimation/fs2000_calibrated_covariance.mod \ estimation/MH_recover/fs2000_recover.mod \ + estimation/t_proposal/fs2000_student.mod \ gsa/ls2003.mod \ gsa/ls2003a.mod \ ramst.mod \ diff --git a/tests/estimation/t_proposal/fs2000_student.mod b/tests/estimation/t_proposal/fs2000_student.mod new file mode 100644 index 000000000..e2a20bc82 --- /dev/null +++ b/tests/estimation/t_proposal/fs2000_student.mod @@ -0,0 +1,120 @@ +/* + * This file replicates the estimation of the cash in advance model described + * Frank Schorfheide (2000): "Loss function-based evaluation of DSGE models", + * Journal of Applied Econometrics, 15(6), 645-670. + * + * The data are in file "fsdat_simul.m", and have been artificially generated. + * They are therefore different from the original dataset used by Schorfheide. + * + * The equations are taken from J. Nason and T. Cogley (1994): "Testing the + * implications of long-run neutrality for monetary business cycle models", + * Journal of Applied Econometrics, 9, S37-S70. + * Note that there is an initial minus sign missing in equation (A1), p. S63. + * + * This implementation was written by Michel Juillard. Please note that the + * following copyright notice only applies to this Dynare implementation of the + * model. + */ + +/* + * Copyright (C) 2004-2010 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 . + */ + +var m P c e W R k d n l gy_obs gp_obs y dA; +varexo e_a e_m; + +parameters alp bet gam mst rho psi del; + +alp = 0.33; +bet = 0.99; +gam = 0.003; +mst = 1.011; +rho = 0.7; +psi = 0.787; +del = 0.02; + +model; +dA = exp(gam+e_a); +log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m; +-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0; +W = l/n; +-(psi/(1-psi))*(c*P/(1-n))+l/n = 0; +R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W; +1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0; +c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1); +P*c = m; +m-1+d = l; +e = exp(e_a); +y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a)); +gy_obs = dA*y/y(-1); +gp_obs = (P/P(-1))*m(-1)/dA; +end; + +shocks; +var e_a; stderr 0.014; +var e_m; stderr 0.005; +end; + +steady_state_model; + dA = exp(gam); + gst = 1/dA; + m = mst; + khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1)); + xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1); + nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp ); + n = xist/(nust+xist); + P = xist + nust; + k = khst*n; + + l = psi*mst*n/( (1-psi)*(1-n) ); + c = mst/P; + d = l - mst + 1; + y = k^alp*n^(1-alp)*gst^alp; + R = mst/bet; + W = l/n; + ist = y-c; + q = 1 - d; + + e = 1; + + gp_obs = m/dA; + gy_obs = dA; +end; + +steady; + +check; + +estimated_params; +alp, beta_pdf, 0.356, 0.02; +bet, beta_pdf, 0.993, 0.002; +gam, normal_pdf, 0.0085, 0.003; +mst, normal_pdf, 1.0002, 0.007; +rho, beta_pdf, 0.129, 0.223; +psi, beta_pdf, 0.65, 0.05; +del, beta_pdf, 0.01, 0.005; +stderr e_a, inv_gamma_pdf, 0.035449, inf; +stderr e_m, inv_gamma_pdf, 0.008862, inf; +end; + +varobs gp_obs gy_obs; + +options_.proposal_distribution='rand_multivariate_student'; +options_.student_degrees_of_freedom=5; + +estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=50000, mh_nblocks=2, mh_jscale=0.8,mode_compute=4); From b67e9626f772848229e48b4cf1cb29923de60ddf Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 10 May 2015 10:06:42 +0200 Subject: [PATCH 192/210] Add more information to header of rand_multivariate_student.m --- matlab/distributions/rand_multivariate_student.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/matlab/distributions/rand_multivariate_student.m b/matlab/distributions/rand_multivariate_student.m index 6d9b52df6..eca1d0585 100644 --- a/matlab/distributions/rand_multivariate_student.m +++ b/matlab/distributions/rand_multivariate_student.m @@ -1,4 +1,5 @@ function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df) +% function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df) % Pseudo random draws from a multivariate student distribution, % with expectation Mean, variance Sigma*df/(df-2) and degrees of freedom df>0. % @@ -13,10 +14,14 @@ function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df) % draw [double] 1*n vector drawn from a multivariate normal distribution with expectation Mean and % covariance Sigma. % -% REMARK This is certainly not the most efficient way... % % NOTE See Zellner (appendix B.2, 1971) for a definition. -% +% Computes the t-distributed random numbers from +% X = \mu + Y\sqrt{\frac{\nu}{U}} +% where +% Y~N(0,Sigma) with Sigma=Sigma_upper_chol'*Sigma_upper_chol +% U~\Chi^2_{\nu} +% The latter is constructed as the sum of \nu standard normals. % Copyright (C) 2003-2009 Dynare Team % From a5a5490a120c36075877c2243a8d1f82f4f2754a Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sun, 10 May 2015 18:16:11 +0200 Subject: [PATCH 193/210] adding feature to recompile MEX files only if the model has changed (not activated yet) detail of compilation code moved from preprocessor (ModFile.cc) to ./matlab/utilities/general/dyn_mex.m --- matlab/utilities/general/dyn_mex.m | 108 +++++++++++++++++ preprocessor/DynamicModel.cc | 94 ++++++++++++++ preprocessor/DynamicModel.hh | 3 + preprocessor/ModFile.cc | 189 +++++++++++++---------------- preprocessor/ModFile.hh | 9 ++ 5 files changed, 295 insertions(+), 108 deletions(-) create mode 100644 matlab/utilities/general/dyn_mex.m diff --git a/matlab/utilities/general/dyn_mex.m b/matlab/utilities/general/dyn_mex.m new file mode 100644 index 000000000..12e4c0b8d --- /dev/null +++ b/matlab/utilities/general/dyn_mex.m @@ -0,0 +1,108 @@ +function dyn_mex(win_compiler,basename,force) + +% Compile Dynare model dlls when model option use_dll is used +% if C file is fresher than mex file +% +% INPUTS +% o win_compiler str compiler used under Windows (unused under Linux or OSX): +% 'msvc' (MS Visual C) +% 'cygwin' +% o basename str filenames base +% o force bool recompile if 1 +% +% OUTPUTS +% 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 . + +Dc = dir([basename '_dynamic.c']); +Dmex = dir([basename '_dynamic.' mexext]); + +% compile only if date of C file is greater than date of mex file +% and force is not True +if (Dmex.datenum > Dc.datenum) && ~force + disp('Mex files are newer than the source: not recompiled') + return +end + +if ~exist('OCTAVE_VERSION') + % Some mex commands are enclosed in an eval(), because otherwise it will make Octave fail + if ispc + if msvc + % MATLAB/Windows + Microsoft Visual C++ + eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Dynamic" ' basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O LINKFLAGS="$LINKFLAGS /export:Dynamic" ' basename '_static.c ' basename '_static_mex.c']) + elseif cygwin + % MATLAB/Windows + Cygwin g++ + eval(['mex -O PRELINK_CMDS1="echo EXPORTS > mex.def & echo ' ... + 'mexFunction >> mex.def & echo Dynamic >> mex.def" ' ... + basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O PRELINK_CMDS1="echo EXPORTS > mex.def & echo ' ... + 'mexFunction >> mex.def & echo Dynamic >> mex.def" ' ... + basename '_static.c ' basename '_static_mex.c']) + else + error(['When using the USE_DLL option, you must give either ' ... + '''cygwin'' or ''msvc'' option to the ''dynare'' command']) + end + elseif isunix + % MATLAB/Linux + if matlab_ver_less_than('8.3') + eval(['mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' ' ... + basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' ' ... + basename '_static.c ' basename '_static_mex.c']) + else + eval(['mex -O LINKEXPORT='''' ' basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O LINKEXPORT='''' ' basename '_static.c ' basename '_static_mex.c']) + end + elseif ismac + % MATLAB/MacOS + if matlab_ver_less_than('8.3') + if matlab_ver_less_than('8.1') + eval(['mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined ' ... + 'error -arch $ARCHS -Wl,-syslibroot,$SDKROOT ' ... + '-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -bundle'' ' ... + basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined ' ... + 'error -arch $ARCHS -Wl,-syslibroot,$SDKROOT ' ... + '-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -bundle'' ' ... + basename '_static.c ' basename '_static_mex.c']) + else + eval(['mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined ' ... + 'error -arch $ARCHS -Wl,-syslibroot,$MW_SDKROOT ' ... + '-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -bundle'' ' ... + basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined ' ... + 'error -arch $ARCHS -Wl,-syslibroot,$MW_SDKROOT ' ... + '-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -bundle'' ' ... + basename '_static.c ' basename '_static_mex.c']) + end + else + eval(['mex -O LINKEXPORT='''' ' basename '_dynamic.c ' ... + basename '_dynamic_mex.c']) + eval(['mex -O LINKEXPORT='''' ' basename '_static.c ' basename ... + '_static_mex.c']) + end + end +else + % Octave + eval(['mex ' basename '_dynamic.c ' basename '_dynamic_mex.c']) + eval(['mex ' basename '_static.c ' basename '_static_mex.c']) +end diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index f4957557e..74d7a2c67 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -4221,5 +4221,99 @@ DynamicModel::dynamicOnlyEquationsNbr() const return eqs.size(); } +#ifndef PRIVATE_BUFFER_SIZE +#define PRIVATE_BUFFER_SIZE 1024 +#endif +bool +DynamicModel::isChecksumMatching(const string &basename) const +{ + boost::crc_32_type result; + std::stringstream buffer; + + // Write equation tags + for (size_t i = 0; i < equation_tags.size(); i++) + buffer << " " << equation_tags[i].first + 1 + << equation_tags[i].second.first + << equation_tags[i].second.second; + + ExprNodeOutputType buffer_type = oCDynamicModel; + + for (int eq = 0; eq < (int) equations.size(); eq++) + { + BinaryOpNode *eq_node = equations[eq]; + expr_t lhs = eq_node->get_arg1(); + expr_t rhs = eq_node->get_arg2(); + + // Test if the right hand side of the equation is empty. + double vrhs = 1.0; + try + { + vrhs = rhs->eval(eval_context_t()); + } + catch (ExprNode::EvalException &e) + { + } + + if (vrhs != 0) // The right hand side of the equation is not empty ==> residual=lhs-rhs; + { + buffer << "lhs ="; + lhs->writeOutput(buffer, buffer_type, temporary_terms); + buffer << ";" << endl; + + buffer << "rhs ="; + rhs->writeOutput(buffer, buffer_type, temporary_terms); + buffer << ";" << endl; + + buffer << "residual" << LEFT_ARRAY_SUBSCRIPT(buffer_type) + << eq + ARRAY_SUBSCRIPT_OFFSET(buffer_type) + << RIGHT_ARRAY_SUBSCRIPT(buffer_type) + << "= lhs-rhs;" << endl; + } + else // The right hand side of the equation is empty ==> residual=lhs; + { + buffer << "residual" << LEFT_ARRAY_SUBSCRIPT(buffer_type) + << eq + ARRAY_SUBSCRIPT_OFFSET(buffer_type) + << RIGHT_ARRAY_SUBSCRIPT(buffer_type) + << " = "; + lhs->writeOutput(buffer, buffer_type, temporary_terms); + buffer << ";" << endl; + } + } + + char private_buffer[PRIVATE_BUFFER_SIZE]; + while(buffer) + { + buffer.get(private_buffer,PRIVATE_BUFFER_SIZE); + result.process_bytes(private_buffer,strlen(private_buffer)); + } + + fstream checksum_file; + + string filename = basename + "/checksum"; + + // checksum_file.open(filename.c_str(), ios::in | ios::out | ios::binary); + checksum_file.open(filename.c_str(), ios::in | ios::binary); + unsigned int old_checksum = 0; + if (checksum_file.is_open()) + { + checksum_file >> old_checksum; + std::cout << "old_checksum " << old_checksum << endl; + } + if ((!checksum_file.is_open()) || (old_checksum != result.checksum())) + { + checksum_file.close(); + checksum_file.open(filename.c_str(), ios::out | ios::binary); + if (!checksum_file.is_open()) + { + cerr << "ERROR: Can't open file " << filename << endl; + exit(EXIT_FAILURE); + } + checksum_file << result.checksum(); + checksum_file.close(); + return false; + } + + return true; +} diff --git a/preprocessor/DynamicModel.hh b/preprocessor/DynamicModel.hh index 8efbc5d3c..d96a7d504 100644 --- a/preprocessor/DynamicModel.hh +++ b/preprocessor/DynamicModel.hh @@ -24,6 +24,7 @@ using namespace std; #define ZERO_BAND 1e-8 #include +#include #include "StaticModel.hh" @@ -479,6 +480,8 @@ public: void writeSecondDerivativesC_csr(const string &basename, bool cuda) const; //! Writes C file containing third order derivatives of model evaluated at steady state (compressed sparse column) void writeThirdDerivativesC_csr(const string &basename, bool cuda) const; + + bool isChecksumMatching(const string &basename) const; }; //! Classes to re-order derivatives for various sparse storage formats diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 6d9eca0ec..9f8f73f56 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -469,55 +469,55 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output) // Compute static model and its derivatives dynamic_model.toStatic(static_model); if (!no_static) - { - if (mod_file_struct.stoch_simul_present - || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present - || mod_file_struct.calib_smoother_present) - static_model.set_cutoff_to_zero(); + { + if (mod_file_struct.stoch_simul_present + || mod_file_struct.estimation_present || mod_file_struct.osr_present + || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present + || mod_file_struct.calib_smoother_present) + static_model.set_cutoff_to_zero(); - const bool static_hessian = mod_file_struct.identification_present - || mod_file_struct.estimation_analytic_derivation; - const bool paramsDerivatives = mod_file_struct.identification_present - || mod_file_struct.estimation_analytic_derivation; - static_model.computingPass(global_eval_context, no_tmp_terms, static_hessian, - false, paramsDerivatives, block, byte_code); - } + const bool static_hessian = mod_file_struct.identification_present + || mod_file_struct.estimation_analytic_derivation; + const bool paramsDerivatives = mod_file_struct.identification_present + || mod_file_struct.estimation_analytic_derivation; + static_model.computingPass(global_eval_context, no_tmp_terms, static_hessian, + false, paramsDerivatives, block, byte_code); + } // Set things to compute for dynamic model if (mod_file_struct.perfect_foresight_solver_present || mod_file_struct.check_present - || mod_file_struct.stoch_simul_present - || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present - || mod_file_struct.calib_smoother_present) - { - if (mod_file_struct.perfect_foresight_solver_present) - dynamic_model.computingPass(true, false, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code); - else - { - if (mod_file_struct.stoch_simul_present - || mod_file_struct.estimation_present || mod_file_struct.osr_present - || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present - || mod_file_struct.calib_smoother_present) - dynamic_model.set_cutoff_to_zero(); - if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3) - { - cerr << "ERROR: Incorrect order option..." << endl; - exit(EXIT_FAILURE); - } - bool hessian = mod_file_struct.order_option >= 2 - || mod_file_struct.identification_present - || mod_file_struct.estimation_analytic_derivation - || output == second - || output == third; - bool thirdDerivatives = mod_file_struct.order_option == 3 - || mod_file_struct.estimation_analytic_derivation - || output == third; - bool paramsDerivatives = mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation; - dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, block, use_dll, byte_code); - } - } - else // No computing task requested, compute derivatives up to 2nd order by default - dynamic_model.computingPass(true, true, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + || mod_file_struct.stoch_simul_present + || mod_file_struct.estimation_present || mod_file_struct.osr_present + || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present + || mod_file_struct.calib_smoother_present) + { + if (mod_file_struct.perfect_foresight_solver_present) + dynamic_model.computingPass(true, false, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + else + { + if (mod_file_struct.stoch_simul_present + || mod_file_struct.estimation_present || mod_file_struct.osr_present + || mod_file_struct.ramsey_model_present || mod_file_struct.identification_present + || mod_file_struct.calib_smoother_present) + dynamic_model.set_cutoff_to_zero(); + if (mod_file_struct.order_option < 1 || mod_file_struct.order_option > 3) + { + cerr << "ERROR: Incorrect order option..." << endl; + exit(EXIT_FAILURE); + } + bool hessian = mod_file_struct.order_option >= 2 + || mod_file_struct.identification_present + || mod_file_struct.estimation_analytic_derivation + || output == second + || output == third; + bool thirdDerivatives = mod_file_struct.order_option == 3 + || mod_file_struct.estimation_analytic_derivation + || output == third; + bool paramsDerivatives = mod_file_struct.identification_present || mod_file_struct.estimation_analytic_derivation; + dynamic_model.computingPass(true, hessian, thirdDerivatives, paramsDerivatives, global_eval_context, no_tmp_terms, block, use_dll, byte_code); + } + } + else // No computing task requested, compute derivatives up to 2nd order by default + dynamic_model.computingPass(true, true, false, false, global_eval_context, no_tmp_terms, block, use_dll, byte_code); } for (vector::iterator it = statements.begin(); @@ -649,18 +649,23 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo << " error('DYNARE: Can''t find bytecode DLL. Please compile it or remove the ''bytecode'' option.')" << endl << "end" << endl; - // Erase possible remnants of previous runs - unlink((basename + "_dynamic.m").c_str()); - unlink((basename + "_dynamic.cod").c_str()); - unlink((basename + "_dynamic.bin").c_str()); + bool hasModelChanged = !dynamic_model.isChecksumMatching(basename); + + if (hasModelChanged) + { + // Erase possible remnants of previous runs + unlink((basename + "_dynamic.m").c_str()); + unlink((basename + "_dynamic.cod").c_str()); + unlink((basename + "_dynamic.bin").c_str()); - unlink((basename + "_static.m").c_str()); - unlink((basename + "_static.cod").c_str()); - unlink((basename + "_static.bin").c_str()); - - unlink((basename + "_steadystate2.m").c_str()); - unlink((basename + "_set_auxiliary_variables.m").c_str()); + unlink((basename + "_static.m").c_str()); + unlink((basename + "_static.cod").c_str()); + unlink((basename + "_static.bin").c_str()); + unlink((basename + "_steadystate2.m").c_str()); + unlink((basename + "_set_auxiliary_variables.m").c_str()); + } + if (!use_dll) { mOutputFile << "erase_compiled_function('" + basename + "_static');" << endl; @@ -697,53 +702,19 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo // Compile the dynamic MEX file for use_dll option if (use_dll) { - mOutputFile << "if ~exist('OCTAVE_VERSION')" << endl; - // Some mex commands are enclosed in an eval(), because otherwise it will make Octave fail #if defined(_WIN32) || defined(__CYGWIN32__) if (msvc) // MATLAB/Windows + Microsoft Visual C++ - mOutputFile << " eval('mex -O LINKFLAGS=\"$LINKFLAGS /export:Dynamic\" " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl - << " eval('mex -O LINKFLAGS=\"$LINKFLAGS /export:Static\" " << basename << "_static.c "<< basename << "_static_mex.c')" << endl; + mOutputFile << "dyn_mex('msvc', '" << basename << ", 1)" << endl; else if (cygwin) // MATLAB/Windows + Cygwin g++ - mOutputFile << " eval('mex -O PRELINK_CMDS1=\"echo EXPORTS > mex.def & echo mexFunction >> mex.def & echo Dynamic >> mex.def\" " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl - << " eval('mex -O PRELINK_CMDS1=\"echo EXPORTS > mex.def & echo mexFunction >> mex.def & echo Static >> mex.def\" " << basename << "_static.c "<< basename << "_static_mex.c')" << endl; + mOutputFile << "dyn_mex('cygwin', '" << basename << "', 1)" << endl; else mOutputFile << " error('When using the USE_DLL option, you must give either ''cygwin'' or ''msvc'' option to the ''dynare'' command')" << endl; #else -# ifdef __linux__ - // MATLAB/Linux - mOutputFile << " if matlab_ver_less_than('8.3')" << endl - << " eval('mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl - << " eval('mex -O LDFLAGS=''-pthread -shared -Wl,--no-undefined'' " << basename << "_static.c "<< basename << "_static_mex.c')" << endl - << " else" << endl - << " eval('mex -O LINKEXPORT='''' " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl - << " eval('mex -O LINKEXPORT='''' " << basename << "_static.c "<< basename << "_static_mex.c')" << endl - << " end" << endl; -# else // MacOS - // MATLAB/MacOS - mOutputFile << " if matlab_ver_less_than('8.3')" << endl - << " if matlab_ver_less_than('8.1')" << endl - << " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' " - << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl - << " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' " - << basename << "_static.c " << basename << "_static_mex.c')" << endl - << " else" << endl - << " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$MW_SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' " - << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl - << " eval('mex -O LDFLAGS=''-Wl,-twolevel_namespace -undefined error -arch \\$ARCHS -Wl,-syslibroot,\\$MW_SDKROOT -mmacosx-version-min=\\$MACOSX_DEPLOYMENT_TARGET -bundle'' " - << basename << "_static.c " << basename << "_static_mex.c')" << endl - << " end" << endl - << " else" << endl - << " eval('mex -O LINKEXPORT='''' " << basename << "_dynamic.c " << basename << "_dynamic_mex.c')" << endl - << " eval('mex -O LINKEXPORT='''' " << basename << "_static.c "<< basename << "_static_mex.c')" << endl - << " end" << endl; -# endif + // other configurations + mOutputFile << "dyn_mex('', '" << basename << "', 1)" << endl; #endif - mOutputFile << "else" << endl // Octave - << " mex " << basename << "_dynamic.c " << basename << "_dynamic_mex.c" << endl - << " mex " << basename << "_static.c " << basename << "_static_mex.c" << endl - << "end" << endl; } // Add path for block option with M-files @@ -824,22 +795,24 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo mOutputFile.close(); - // Create static and dynamic files - if (dynamic_model.equation_number() > 0) + if (hasModelChanged) { - if (!no_static) - { - static_model.writeStaticFile(basename, block, byte_code, use_dll); - static_model.writeParamsDerivativesFile(basename); - } + // Create static and dynamic files + if (dynamic_model.equation_number() > 0) + { + if (!no_static) + { + static_model.writeStaticFile(basename, block, byte_code, use_dll); + static_model.writeParamsDerivativesFile(basename); + } - dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option); - dynamic_model.writeParamsDerivativesFile(basename); + dynamic_model.writeDynamicFile(basename, block, byte_code, use_dll, mod_file_struct.order_option); + dynamic_model.writeParamsDerivativesFile(basename); + } + + // Create steady state file + steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present); } - - // Create steady state file - steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present); - + cout << "done" << endl; } - diff --git a/preprocessor/ModFile.hh b/preprocessor/ModFile.hh index 722ea5341..0a384931b 100644 --- a/preprocessor/ModFile.hh +++ b/preprocessor/ModFile.hh @@ -24,6 +24,8 @@ using namespace std; #include #include +#include +#include #include "SymbolTable.hh" #include "NumericalConstants.hh" @@ -37,6 +39,11 @@ using namespace std; #include "WarningConsolidation.hh" #include "ExtendedPreprocessorTypes.hh" +// for checksum computation +#ifndef PRIVATE_BUFFER_SIZE +#define PRIVATE_BUFFER_SIZE 1024 +#endif + //! The abstract representation of a "mod" file class ModFile { @@ -153,6 +160,8 @@ public: //! Writes Cpp output files only => No further Matlab processing void writeCCOutputFiles(const string &basename) const; void writeModelCC(const string &basename) const; + + void computeChecksum(); }; #endif // ! MOD_FILE_HH From 530e314786cd0d0824c06c27e653b23ecddca3f6 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sun, 10 May 2015 20:29:03 +0200 Subject: [PATCH 194/210] adding dynare command line option 'fast' in order not to recompile MEX files if the lists of variables and the equations haven't changed between two runs of the same model file. --- doc/dynare.texi | 5 +++++ preprocessor/DynareMain.cc | 9 ++++++--- preprocessor/DynareMain2.cc | 9 +++++---- preprocessor/ModFile.cc | 16 ++++++++++------ preprocessor/ModFile.hh | 3 ++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 2635b8252..158850bd1 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -851,6 +851,11 @@ Allows Dynare to issue a warning and continue processing when @item there are more endogenous variables than equations @item an undeclared symbol is assigned in @code{initval} or @code{endval} @end enumerate + +@item fast +Only useful with model option @code{use_dll}. Don't recompile the MEX +files when running again the same model file and the lists of variables +and the equations haven't changed. @end table @outputhead diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc index 19d773b8b..9320a4afd 100644 --- a/preprocessor/DynareMain.cc +++ b/preprocessor/DynareMain.cc @@ -38,7 +38,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, const string ¶llel_config_file, const string &cluster_name, bool parallel_slave_open_mode, - bool parallel_test, bool nostrict, FileOutputType output_mode, LanguageOutputType lang + bool parallel_test, bool nostrict, bool check_model_changes, FileOutputType output_mode, LanguageOutputType lang #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -49,7 +49,7 @@ usage() { cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]" << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test] " - << " [-D[=]] [nostrict] [output=dynamic|first|second|third] [language=C|C++]" + << " [-D[=]] [nostrict] [fast] [output=dynamic|first|second|third] [language=C|C++]" #if defined(_WIN32) || defined(__CYGWIN32__) << " [cygwin] [msvc]" #endif @@ -97,6 +97,7 @@ main(int argc, char **argv) bool parallel_slave_open_mode = false; bool parallel_test = false; bool nostrict = false; + bool check_model_changes = false; map defines; FileOutputType output_mode = none; LanguageOutputType language = matlab; @@ -165,6 +166,8 @@ main(int argc, char **argv) parallel_test = true; else if (!strcmp(argv[arg], "nostrict")) nostrict = true; + else if (!strcmp(argv[arg], "fast")) + check_model_changes = true; else if (strlen(argv[arg]) >= 8 && !strncmp(argv[arg], "parallel", 8)) { parallel = true; @@ -285,7 +288,7 @@ main(int argc, char **argv) // Do the rest main2(macro_output, basename, debug, clear_all, clear_global, no_tmp_terms, no_log, no_warn, warn_uninit, console, nograph, nointeractive, - parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test, nostrict, output_mode, language + parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test, nostrict, check_model_changes, output_mode, language #if defined(_WIN32) || defined(__CYGWIN32__) , cygwin, msvc #endif diff --git a/preprocessor/DynareMain2.cc b/preprocessor/DynareMain2.cc index 376dd20a9..fe1c69427 100644 --- a/preprocessor/DynareMain2.cc +++ b/preprocessor/DynareMain2.cc @@ -27,7 +27,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, const string ¶llel_config_file, const string &cluster_name, bool parallel_slave_open_mode, - bool parallel_test, bool nostrict, FileOutputType output_mode, LanguageOutputType language + bool parallel_test, bool nostrict, bool check_model_changes, FileOutputType output_mode, LanguageOutputType language #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -60,11 +60,12 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear if (output_mode != none) mod_file->writeExternalFiles(basename, output_mode, language); else - mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph, nointeractive, config_file + mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph, + nointeractive, config_file, check_model_changes #if defined(_WIN32) || defined(__CYGWIN32__) - , cygwin, msvc + , cygwin, msvc #endif - ); + ); delete mod_file; diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 9f8f73f56..c6b7ca835 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -526,7 +526,8 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output) } void -ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file +ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, bool console, bool nograph, + bool nointeractive, const ConfigFile &config_file, bool check_model_changes #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -650,7 +651,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo << "end" << endl; bool hasModelChanged = !dynamic_model.isChecksumMatching(basename); - + if (!check_model_changes) + hasModelChanged = true; + if (hasModelChanged) { // Erase possible remnants of previous runs @@ -700,20 +703,21 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo #endif // Compile the dynamic MEX file for use_dll option + // When check_model_changes is true, don't force compile if MEX is fresher than source if (use_dll) { #if defined(_WIN32) || defined(__CYGWIN32__) if (msvc) // MATLAB/Windows + Microsoft Visual C++ - mOutputFile << "dyn_mex('msvc', '" << basename << ", 1)" << endl; + mOutputFile << "dyn_mex('msvc', '" << basename << "', " << !check_model_changes << ")" << endl; else if (cygwin) // MATLAB/Windows + Cygwin g++ - mOutputFile << "dyn_mex('cygwin', '" << basename << "', 1)" << endl; + mOutputFile << "dyn_mex('cygwin', '" << basename << "', " << !check_model_changes << ")" << endl; else mOutputFile << " error('When using the USE_DLL option, you must give either ''cygwin'' or ''msvc'' option to the ''dynare'' command')" << endl; #else - // other configurations - mOutputFile << "dyn_mex('', '" << basename << "', 1)" << endl; + // other configurations + mOutputFile << "dyn_mex('', '" << basename << "', " << !check_model_changes << ")" << endl; #endif } diff --git a/preprocessor/ModFile.hh b/preprocessor/ModFile.hh index 0a384931b..bf3636685 100644 --- a/preprocessor/ModFile.hh +++ b/preprocessor/ModFile.hh @@ -145,7 +145,8 @@ public: \param cygwin Should the MEX command of use_dll be adapted for Cygwin? \param msvc Should the MEX command of use_dll be adapted for MSVC? */ - void writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file + void writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, + bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, bool check_model_changes #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif From cf5a36a1a8a3cd49d457c2cb2cf33e24a10c1479 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 10 May 2015 21:43:06 +0200 Subject: [PATCH 195/210] Fix typos Makefile.am Prevents test suite from running --- tests/Makefile.am | 2 +- .../RBC_differentiate_forward.mod | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{diffentiate_forward_vars => differentiate_forward_vars}/RBC_differentiate_forward.mod (100%) diff --git a/tests/Makefile.am b/tests/Makefile.am index 4b5f9f2ae..258d5dc30 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -219,7 +219,7 @@ MODFILES = \ optimizers/fs2000_101.mod \ optimizers/fs2000_102.mod \ optimizers/fs2000_w.mod \ - diffentiate_forward_vars/RBC_differentiate_forward \ + differentiate_forward_vars/RBC_differentiate_forward.mod \ reporting/example1.mod XFAIL_MODFILES = ramst_xfail.mod \ diff --git a/tests/diffentiate_forward_vars/RBC_differentiate_forward.mod b/tests/differentiate_forward_vars/RBC_differentiate_forward.mod similarity index 100% rename from tests/diffentiate_forward_vars/RBC_differentiate_forward.mod rename to tests/differentiate_forward_vars/RBC_differentiate_forward.mod From 3171e8744867b3dd165b71fb3cb37b9cfcc54482 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Mon, 11 May 2015 08:52:50 +0200 Subject: [PATCH 196/210] fixing logic in creation of checksum file. Improving documentation. --- doc/dynare.texi | 5 ++++- preprocessor/DynamicModel.cc | 31 ++++++++++++++++++++++--------- preprocessor/ModFile.cc | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 158850bd1..2bc260882 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -855,7 +855,10 @@ Allows Dynare to issue a warning and continue processing when @item fast Only useful with model option @code{use_dll}. Don't recompile the MEX files when running again the same model file and the lists of variables -and the equations haven't changed. +and the equations haven't changed. We use a 32 bit checksum, stored in +@code{/checksum}. There is a very small probability that +the preprocessor misses a change in the model. In case of doubt, re-run +without the @code{fast} option. @end table @outputhead diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 74d7a2c67..b7eb27d85 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -4289,21 +4289,34 @@ DynamicModel::isChecksumMatching(const string &basename) const result.process_bytes(private_buffer,strlen(private_buffer)); } + // check whether basename directory exist. If not, create it. + // If it does, read old checksum if it exist fstream checksum_file; - string filename = basename + "/checksum"; - - // checksum_file.open(filename.c_str(), ios::in | ios::out | ios::binary); - checksum_file.open(filename.c_str(), ios::in | ios::binary); unsigned int old_checksum = 0; - if (checksum_file.is_open()) + struct stat sd; + if (stat(basename.c_str(), &sd) != 0) { - checksum_file >> old_checksum; - std::cout << "old_checksum " << old_checksum << endl; - } - if ((!checksum_file.is_open()) || (old_checksum != result.checksum())) + const int dir_err = mkdir(basename.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if (dir_err == -1) { + cerr << "ERROR: can't create directory " << basename << endl; + exit(EXIT_FAILURE); + } + } + else + { + // read old checksum if it exists + checksum_file.open(filename.c_str(), ios::in | ios::binary); + if (checksum_file.is_open()) + { + checksum_file >> old_checksum; checksum_file.close(); + } + } + // write new checksum file if none or different from old checksum + if (old_checksum != result.checksum()) + { checksum_file.open(filename.c_str(), ios::out | ios::binary); if (!checksum_file.is_open()) { diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index c6b7ca835..0a7860c4d 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -596,7 +596,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo if (nointeractive) mOutputFile << "options_.nointeractive = 1;" << endl; - cout << "Processing outputs ..."; + cout << "Processing outputs ..." << endl; symbol_table.writeOutput(mOutputFile); From 662c4e64ee5c6bc86234ce1eca29f8b010532a5c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 11 May 2015 16:39:06 +0200 Subject: [PATCH 197/210] preprocessor: organize external function code --- preprocessor/ExprNode.cc | 633 +++++++++++++++++++-------------------- 1 file changed, 316 insertions(+), 317 deletions(-) diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc index d61ebb56f..3805c1a6e 100644 --- a/preprocessor/ExprNode.cc +++ b/preprocessor/ExprNode.cc @@ -4297,15 +4297,6 @@ AbstractExternalFunctionNode::AbstractExternalFunctionNode(DataTree &datatree_ar { } -ExternalFunctionNode::ExternalFunctionNode(DataTree &datatree_arg, - int symb_id_arg, - const vector &arguments_arg) : - AbstractExternalFunctionNode(datatree_arg, symb_id_arg, arguments_arg) -{ - // Add myself to the external function map - datatree.external_function_node_map[make_pair(arguments, symb_id)] = this; -} - void AbstractExternalFunctionNode::prepareForDerivation() { @@ -4336,20 +4327,6 @@ AbstractExternalFunctionNode::computeDerivative(int deriv_id) return composeDerivatives(dargs); } -expr_t -ExternalFunctionNode::composeDerivatives(const vector &dargs) -{ - vector dNodes; - for (int i = 0; i < (int) dargs.size(); i++) - dNodes.push_back(datatree.AddTimes(dargs.at(i), - datatree.AddFirstDerivExternalFunction(symb_id, arguments, i+1))); - - expr_t theDeriv = datatree.Zero; - for (vector::const_iterator it = dNodes.begin(); it != dNodes.end(); it++) - theDeriv = datatree.AddPlus(theDeriv, *it); - return theDeriv; -} - expr_t AbstractExternalFunctionNode::getChainRuleDerivative(int deriv_id, const map &recursive_variables) { @@ -4361,76 +4338,6 @@ AbstractExternalFunctionNode::getChainRuleDerivative(int deriv_id, const map &reference_count, - temporary_terms_t &temporary_terms, - bool is_matlab) const -{ - temporary_terms.insert(const_cast(this)); -} - -void -AbstractExternalFunctionNode::writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type, - const temporary_terms_t &temporary_terms, - deriv_node_temp_terms_t &tef_terms) const -{ - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - { - if (it != arguments.begin()) - output << ","; - - (*it)->writeOutput(output, output_type, temporary_terms, tef_terms); - } -} - -void -AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType output_type, - const temporary_terms_t &temporary_terms, - deriv_node_temp_terms_t &tef_terms, const string &ending) const -{ - output << "mxArray *prhs"<< ending << "[nrhs"<< ending << "];" << endl; - int i = 0; - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - { - output << "prhs" << ending << "[" << i++ << "] = mxCreateDoubleScalar("; // All external_function arguments are scalars - (*it)->writeOutput(output, output_type, temporary_terms, tef_terms); - output << ");" << endl; - } -} - -void -ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_type, - const temporary_terms_t &temporary_terms, - deriv_node_temp_terms_t &tef_terms) const -{ - if (output_type == oMatlabOutsideModel || output_type == oSteadyStateFile - || output_type == oCSteadyStateFile || IS_LATEX(output_type)) - { - string name = IS_LATEX(output_type) ? datatree.symbol_table.getTeXName(symb_id) - : datatree.symbol_table.getName(symb_id); - output << name << "("; - writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms); - output << ")"; - return; - } - - temporary_terms_t::const_iterator it = temporary_terms.find(const_cast(this)); - if (it != temporary_terms.end()) - { - if (output_type == oMatlabDynamicModelSparse) - output << "T" << idx << "(it_)"; - else - output << "T" << idx; - return; - } - - if (IS_C(output_type)) - output << "*"; - output << "TEF_" << getIndxInTefTerms(symb_id, tef_terms); -} - unsigned int AbstractExternalFunctionNode::compileExternalFunctionArguments(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, @@ -4444,184 +4351,6 @@ AbstractExternalFunctionNode::compileExternalFunctionArguments(ostream &CompileC return (arguments.size()); } -void -ExternalFunctionNode::compile(ostream &CompileCode, unsigned int &instruction_number, - bool lhs_rhs, const temporary_terms_t &temporary_terms, - const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, - deriv_node_temp_terms_t &tef_terms) const -{ - temporary_terms_t::const_iterator it = temporary_terms.find(const_cast(this)); - if (it != temporary_terms.end()) - { - if (dynamic) - { - map_idx_t::const_iterator ii = map_idx.find(idx); - FLDT_ fldt(ii->second); - fldt.write(CompileCode, instruction_number); - } - else - { - map_idx_t::const_iterator ii = map_idx.find(idx); - FLDST_ fldst(ii->second); - fldst.write(CompileCode, instruction_number); - } - return; - } - - if (!lhs_rhs) - { - FLDTEF_ fldtef(getIndxInTefTerms(symb_id, tef_terms)); - fldtef.write(CompileCode, instruction_number); - } - else - { - FSTPTEF_ fstptef(getIndxInTefTerms(symb_id, tef_terms)); - fstptef.write(CompileCode, instruction_number); - } -} - -void -ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, - const temporary_terms_t &temporary_terms, - deriv_node_temp_terms_t &tef_terms) const -{ - int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); - assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); - - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - (*it)->writeExternalFunctionOutput(output, output_type, temporary_terms, tef_terms); - - if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) - { - tef_terms[make_pair(symb_id, arguments)] = (int) tef_terms.size(); - int indx = getIndxInTefTerms(symb_id, tef_terms); - int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); - assert(second_deriv_symb_id != eExtFunSetButNoNameProvided); - - if (IS_C(output_type)) - { - stringstream ending; - ending << "_tef_" << getIndxInTefTerms(symb_id, tef_terms); - if (symb_id == first_deriv_symb_id - && symb_id == second_deriv_symb_id) - output << "int nlhs" << ending.str() << " = 3;" << endl - << "double *TEF_" << indx << ", " - << "*TEFD_" << indx << ", " - << "*TEFDD_" << indx << ";" << endl; - else if (symb_id == first_deriv_symb_id) - output << "int nlhs" << ending.str() << " = 2;" << endl - << "double *TEF_" << indx << ", " - << "*TEFD_" << indx << "; " << endl; - else - output << "int nlhs" << ending.str() << " = 1;" << endl - << "double *TEF_" << indx << ";" << endl; - - output << "mxArray *plhs" << ending.str()<< "[nlhs"<< ending.str() << "];" << endl; - output << "int nrhs" << ending.str()<< " = " << arguments.size() << ";" << endl; - writePrhs(output, output_type, temporary_terms, tef_terms, ending.str()); - - output << "mexCallMATLAB(" - << "nlhs" << ending.str() << ", " - << "plhs" << ending.str() << ", " - << "nrhs" << ending.str() << ", " - << "prhs" << ending.str() << ", \"" - << datatree.symbol_table.getName(symb_id) << "\");" << endl; - - if (symb_id == first_deriv_symb_id - && symb_id == second_deriv_symb_id) - output << "TEF_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl - << "TEFD_" << indx << " = mxGetPr(plhs" << ending.str() << "[1]);" << endl - << "TEFDD_" << indx << " = mxGetPr(plhs" << ending.str() << "[2]);" << endl - << "int TEFDD_" << indx << "_nrows = (int)mxGetM(plhs" << ending.str()<< "[2]);" << endl; - else if (symb_id == first_deriv_symb_id) - output << "TEF_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl - << "TEFD_" << indx << " = mxGetPr(plhs" << ending.str() << "[1]);" << endl; - else - output << "TEF_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl; - } - else - { - if (symb_id == first_deriv_symb_id - && symb_id == second_deriv_symb_id) - output << "[TEF_" << indx << " TEFD_"<< indx << " TEFDD_"<< indx << "] = "; - else if (symb_id == first_deriv_symb_id) - output << "[TEF_" << indx << " TEFD_"<< indx << "] = "; - else - output << "TEF_" << indx << " = "; - - output << datatree.symbol_table.getName(symb_id) << "("; - writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms); - output << ");" << endl; - } - } -} - -void -ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number, - bool lhs_rhs, const temporary_terms_t &temporary_terms, - const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, - deriv_node_temp_terms_t &tef_terms) const -{ - int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); - assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); - - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - (*it)->compileExternalFunctionOutput(CompileCode, instruction_number, lhs_rhs, temporary_terms, - map_idx, dynamic, steady_dynamic, tef_terms); - - if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) - { - tef_terms[make_pair(symb_id, arguments)] = (int) tef_terms.size(); - int indx = getIndxInTefTerms(symb_id, tef_terms); - int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); - assert(second_deriv_symb_id != eExtFunSetButNoNameProvided); - - unsigned int nb_output_arguments = 0; - if (symb_id == first_deriv_symb_id - && symb_id == second_deriv_symb_id) - nb_output_arguments = 3; - else if (symb_id == first_deriv_symb_id) - nb_output_arguments = 2; - else - nb_output_arguments = 1; - unsigned int nb_input_arguments = compileExternalFunctionArguments(CompileCode, instruction_number, lhs_rhs, temporary_terms, - map_idx, dynamic, steady_dynamic, tef_terms); - - FCALL_ fcall(nb_output_arguments, nb_input_arguments, datatree.symbol_table.getName(symb_id), indx); - switch (nb_output_arguments) - { - case 1: - fcall.set_function_type(ExternalFunctionWithoutDerivative); - break; - case 2: - fcall.set_function_type(ExternalFunctionWithFirstDerivative); - break; - case 3: - fcall.set_function_type(ExternalFunctionWithFirstandSecondDerivative); - break; - } - fcall.write(CompileCode, instruction_number); - FSTPTEF_ fstptef(indx); - fstptef.write(CompileCode, instruction_number); - } -} - -void -ExternalFunctionNode::computeTemporaryTerms(map &reference_count, - temporary_terms_t &temporary_terms, - map > &first_occurence, - int Curr_block, - vector< vector > &v_temporary_terms, - int equation) const -{ - expr_t this2 = const_cast(this); - temporary_terms.insert(this2); - first_occurence[this2] = make_pair(Curr_block, equation); - v_temporary_terms[Curr_block][equation].insert(this2); -} - void AbstractExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set > &result) const { @@ -4650,45 +4379,6 @@ AbstractExternalFunctionNode::eval(const eval_context_t &eval_context) const thr throw EvalExternalFunctionException(); } -pair -AbstractExternalFunctionNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const -{ - vector > V_arguments; - vector V_expr_t; - bool present = false; - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - { - V_arguments.push_back((*it)->normalizeEquation(var_endo, List_of_Op_RHS)); - present = present || V_arguments[V_arguments.size()-1].first; - V_expr_t.push_back(V_arguments[V_arguments.size()-1].second); - } - if (!present) - return (make_pair(0, datatree.AddExternalFunction(symb_id, V_expr_t))); - else - return (make_pair(1, (expr_t) NULL)); -} - -expr_t -ExternalFunctionNode::toStatic(DataTree &static_datatree) const -{ - vector static_arguments; - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - static_arguments.push_back((*it)->toStatic(static_datatree)); - return static_datatree.AddExternalFunction(symb_id, static_arguments); -} - -expr_t -ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const -{ - vector dynamic_arguments; - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - dynamic_arguments.push_back((*it)->cloneDynamic(dynamic_datatree)); - return dynamic_datatree.AddExternalFunction(symb_id, dynamic_arguments); -} - int AbstractExternalFunctionNode::maxEndoLead() const { @@ -4811,12 +4501,6 @@ AbstractExternalFunctionNode::differentiateForwardVars(const vector &sub return buildSimilarExternalFunctionNode(arguments_subst, datatree); } -expr_t -ExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const -{ - return alt_datatree.AddExternalFunction(symb_id, alt_args); -} - bool AbstractExternalFunctionNode::alreadyWrittenAsTefTerm(int the_symb_id, deriv_node_temp_terms_t &tef_terms) const { @@ -4889,10 +4573,325 @@ AbstractExternalFunctionNode::isInStaticForm() const for (vector::const_iterator it = arguments.begin(); it != arguments.end(); ++it) if (!(*it)->isInStaticForm()) return false; - return true; } +pair +AbstractExternalFunctionNode::normalizeEquation(int var_endo, vector > > &List_of_Op_RHS) const +{ + vector > V_arguments; + vector V_expr_t; + bool present = false; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + { + V_arguments.push_back((*it)->normalizeEquation(var_endo, List_of_Op_RHS)); + present = present || V_arguments[V_arguments.size()-1].first; + V_expr_t.push_back(V_arguments[V_arguments.size()-1].second); + } + if (!present) + return (make_pair(0, datatree.AddExternalFunction(symb_id, V_expr_t))); + else + return (make_pair(1, (expr_t) NULL)); +} + +void +AbstractExternalFunctionNode::writeExternalFunctionArguments(ostream &output, ExprNodeOutputType output_type, + const temporary_terms_t &temporary_terms, + deriv_node_temp_terms_t &tef_terms) const +{ + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + { + if (it != arguments.begin()) + output << ","; + + (*it)->writeOutput(output, output_type, temporary_terms, tef_terms); + } +} + +void +AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType output_type, + const temporary_terms_t &temporary_terms, + deriv_node_temp_terms_t &tef_terms, const string &ending) const +{ + output << "mxArray *prhs"<< ending << "[nrhs"<< ending << "];" << endl; + int i = 0; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + { + output << "prhs" << ending << "[" << i++ << "] = mxCreateDoubleScalar("; // All external_function arguments are scalars + (*it)->writeOutput(output, output_type, temporary_terms, tef_terms); + output << ");" << endl; + } +} + +ExternalFunctionNode::ExternalFunctionNode(DataTree &datatree_arg, + int symb_id_arg, + const vector &arguments_arg) : + AbstractExternalFunctionNode(datatree_arg, symb_id_arg, arguments_arg) +{ + // Add myself to the external function map + datatree.external_function_node_map[make_pair(arguments, symb_id)] = this; +} + +expr_t +ExternalFunctionNode::composeDerivatives(const vector &dargs) +{ + vector dNodes; + for (int i = 0; i < (int) dargs.size(); i++) + dNodes.push_back(datatree.AddTimes(dargs.at(i), + datatree.AddFirstDerivExternalFunction(symb_id, arguments, i+1))); + + expr_t theDeriv = datatree.Zero; + for (vector::const_iterator it = dNodes.begin(); it != dNodes.end(); it++) + theDeriv = datatree.AddPlus(theDeriv, *it); + return theDeriv; +} + +void +ExternalFunctionNode::computeTemporaryTerms(map &reference_count, + temporary_terms_t &temporary_terms, + bool is_matlab) const +{ + temporary_terms.insert(const_cast(this)); +} + +void +ExternalFunctionNode::computeTemporaryTerms(map &reference_count, + temporary_terms_t &temporary_terms, + map > &first_occurence, + int Curr_block, + vector< vector > &v_temporary_terms, + int equation) const +{ + expr_t this2 = const_cast(this); + temporary_terms.insert(this2); + first_occurence[this2] = make_pair(Curr_block, equation); + v_temporary_terms[Curr_block][equation].insert(this2); +} + +void +ExternalFunctionNode::compile(ostream &CompileCode, unsigned int &instruction_number, + bool lhs_rhs, const temporary_terms_t &temporary_terms, + const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, + deriv_node_temp_terms_t &tef_terms) const +{ + temporary_terms_t::const_iterator it = temporary_terms.find(const_cast(this)); + if (it != temporary_terms.end()) + { + if (dynamic) + { + map_idx_t::const_iterator ii = map_idx.find(idx); + FLDT_ fldt(ii->second); + fldt.write(CompileCode, instruction_number); + } + else + { + map_idx_t::const_iterator ii = map_idx.find(idx); + FLDST_ fldst(ii->second); + fldst.write(CompileCode, instruction_number); + } + return; + } + + if (!lhs_rhs) + { + FLDTEF_ fldtef(getIndxInTefTerms(symb_id, tef_terms)); + fldtef.write(CompileCode, instruction_number); + } + else + { + FSTPTEF_ fstptef(getIndxInTefTerms(symb_id, tef_terms)); + fstptef.write(CompileCode, instruction_number); + } +} + +void +ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsigned int &instruction_number, + bool lhs_rhs, const temporary_terms_t &temporary_terms, + const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, + deriv_node_temp_terms_t &tef_terms) const +{ + int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); + assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); + + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + (*it)->compileExternalFunctionOutput(CompileCode, instruction_number, lhs_rhs, temporary_terms, + map_idx, dynamic, steady_dynamic, tef_terms); + + if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) + { + tef_terms[make_pair(symb_id, arguments)] = (int) tef_terms.size(); + int indx = getIndxInTefTerms(symb_id, tef_terms); + int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); + assert(second_deriv_symb_id != eExtFunSetButNoNameProvided); + + unsigned int nb_output_arguments = 0; + if (symb_id == first_deriv_symb_id + && symb_id == second_deriv_symb_id) + nb_output_arguments = 3; + else if (symb_id == first_deriv_symb_id) + nb_output_arguments = 2; + else + nb_output_arguments = 1; + unsigned int nb_input_arguments = compileExternalFunctionArguments(CompileCode, instruction_number, lhs_rhs, temporary_terms, + map_idx, dynamic, steady_dynamic, tef_terms); + + FCALL_ fcall(nb_output_arguments, nb_input_arguments, datatree.symbol_table.getName(symb_id), indx); + switch (nb_output_arguments) + { + case 1: + fcall.set_function_type(ExternalFunctionWithoutDerivative); + break; + case 2: + fcall.set_function_type(ExternalFunctionWithFirstDerivative); + break; + case 3: + fcall.set_function_type(ExternalFunctionWithFirstandSecondDerivative); + break; + } + fcall.write(CompileCode, instruction_number); + FSTPTEF_ fstptef(indx); + fstptef.write(CompileCode, instruction_number); + } +} + +void +ExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_type, + const temporary_terms_t &temporary_terms, + deriv_node_temp_terms_t &tef_terms) const +{ + if (output_type == oMatlabOutsideModel || output_type == oSteadyStateFile + || output_type == oCSteadyStateFile || IS_LATEX(output_type)) + { + string name = IS_LATEX(output_type) ? datatree.symbol_table.getTeXName(symb_id) + : datatree.symbol_table.getName(symb_id); + output << name << "("; + writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms); + output << ")"; + return; + } + + temporary_terms_t::const_iterator it = temporary_terms.find(const_cast(this)); + if (it != temporary_terms.end()) + { + if (output_type == oMatlabDynamicModelSparse) + output << "T" << idx << "(it_)"; + else + output << "T" << idx; + return; + } + + if (IS_C(output_type)) + output << "*"; + output << "TEF_" << getIndxInTefTerms(symb_id, tef_terms); +} + +void +ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, + const temporary_terms_t &temporary_terms, + deriv_node_temp_terms_t &tef_terms) const +{ + int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); + assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); + + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + (*it)->writeExternalFunctionOutput(output, output_type, temporary_terms, tef_terms); + + if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) + { + tef_terms[make_pair(symb_id, arguments)] = (int) tef_terms.size(); + int indx = getIndxInTefTerms(symb_id, tef_terms); + int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id); + assert(second_deriv_symb_id != eExtFunSetButNoNameProvided); + + if (IS_C(output_type)) + { + stringstream ending; + ending << "_tef_" << getIndxInTefTerms(symb_id, tef_terms); + if (symb_id == first_deriv_symb_id + && symb_id == second_deriv_symb_id) + output << "int nlhs" << ending.str() << " = 3;" << endl + << "double *TEF_" << indx << ", " + << "*TEFD_" << indx << ", " + << "*TEFDD_" << indx << ";" << endl; + else if (symb_id == first_deriv_symb_id) + output << "int nlhs" << ending.str() << " = 2;" << endl + << "double *TEF_" << indx << ", " + << "*TEFD_" << indx << "; " << endl; + else + output << "int nlhs" << ending.str() << " = 1;" << endl + << "double *TEF_" << indx << ";" << endl; + + output << "mxArray *plhs" << ending.str()<< "[nlhs"<< ending.str() << "];" << endl; + output << "int nrhs" << ending.str()<< " = " << arguments.size() << ";" << endl; + writePrhs(output, output_type, temporary_terms, tef_terms, ending.str()); + + output << "mexCallMATLAB(" + << "nlhs" << ending.str() << ", " + << "plhs" << ending.str() << ", " + << "nrhs" << ending.str() << ", " + << "prhs" << ending.str() << ", \"" + << datatree.symbol_table.getName(symb_id) << "\");" << endl; + + if (symb_id == first_deriv_symb_id + && symb_id == second_deriv_symb_id) + output << "TEF_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl + << "TEFD_" << indx << " = mxGetPr(plhs" << ending.str() << "[1]);" << endl + << "TEFDD_" << indx << " = mxGetPr(plhs" << ending.str() << "[2]);" << endl + << "int TEFDD_" << indx << "_nrows = (int)mxGetM(plhs" << ending.str()<< "[2]);" << endl; + else if (symb_id == first_deriv_symb_id) + output << "TEF_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl + << "TEFD_" << indx << " = mxGetPr(plhs" << ending.str() << "[1]);" << endl; + else + output << "TEF_" << indx << " = mxGetPr(plhs" << ending.str() << "[0]);" << endl; + } + else + { + if (symb_id == first_deriv_symb_id + && symb_id == second_deriv_symb_id) + output << "[TEF_" << indx << " TEFD_"<< indx << " TEFDD_"<< indx << "] = "; + else if (symb_id == first_deriv_symb_id) + output << "[TEF_" << indx << " TEFD_"<< indx << "] = "; + else + output << "TEF_" << indx << " = "; + + output << datatree.symbol_table.getName(symb_id) << "("; + writeExternalFunctionArguments(output, output_type, temporary_terms, tef_terms); + output << ");" << endl; + } + } +} + +expr_t +ExternalFunctionNode::toStatic(DataTree &static_datatree) const +{ + vector static_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + static_arguments.push_back((*it)->toStatic(static_datatree)); + return static_datatree.AddExternalFunction(symb_id, static_arguments); +} + +expr_t +ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const +{ + vector dynamic_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + dynamic_arguments.push_back((*it)->cloneDynamic(dynamic_datatree)); + return dynamic_datatree.AddExternalFunction(symb_id, dynamic_arguments); +} + +expr_t +ExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const +{ + return alt_datatree.AddExternalFunction(symb_id, alt_args); +} + FirstDerivExternalFunctionNode::FirstDerivExternalFunctionNode(DataTree &datatree_arg, int top_level_symb_id_arg, const vector &arguments_arg, From 3c3b255025fab93f3042534fd5ddaf1fa67f430d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 11 May 2015 17:39:26 +0200 Subject: [PATCH 198/210] Clarify that output of mode_check.m is minus likelihood/posterior --- matlab/mode_check.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/mode_check.m b/matlab/mode_check.m index 0f50ca523..39b40c4da 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -68,7 +68,7 @@ if ~isempty(hessian_mat); skipline() disp('MODE CHECK') skipline() - disp(sprintf('Fval obtained by the minimization routine: %f', fval)) + fprintf('Fval obtained by the minimization routine (minus the posterior/likelihood)): %f', fval); skipline() if s_min Date: Mon, 11 May 2015 17:40:03 +0200 Subject: [PATCH 199/210] Add missing deblank to disp_dr.m --- matlab/disp_dr.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/disp_dr.m b/matlab/disp_dr.m index 243a8f5b9..906431437 100644 --- a/matlab/disp_dr.m +++ b/matlab/disp_dr.m @@ -92,7 +92,7 @@ disp('POLICY AND TRANSITION FUNCTIONS') % variable names str = char(32*ones(1,var_name_width)); for i=1:nvar - str = [str sprintf(header_label_format,M_.endo_names(k1(ivar(i)),:))]; + str = [str sprintf(header_label_format,deblank(M_.endo_names(k1(ivar(i)),:)))]; end disp(str); % From 902a5d2788a928ec49ffcd81516cf1dfb64b07ce Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 12 May 2015 10:54:24 +0200 Subject: [PATCH 200/210] ensure that mex file exists before doing comparison --- matlab/utilities/general/dyn_mex.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/matlab/utilities/general/dyn_mex.m b/matlab/utilities/general/dyn_mex.m index 12e4c0b8d..fe6b0555d 100644 --- a/matlab/utilities/general/dyn_mex.m +++ b/matlab/utilities/general/dyn_mex.m @@ -37,9 +37,11 @@ Dmex = dir([basename '_dynamic.' mexext]); % compile only if date of C file is greater than date of mex file % and force is not True -if (Dmex.datenum > Dc.datenum) && ~force - disp('Mex files are newer than the source: not recompiled') - return +if ~isempty(Dmex) + if (Dmex.datenum > Dc.datenum) && ~force + disp('Mex files are newer than the source: not recompiled') + return + end end if ~exist('OCTAVE_VERSION') From 770ac5a4c8056d5e010d152e1eb41260a7fe2f53 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 12 May 2015 14:31:59 +0200 Subject: [PATCH 201/210] Delete whitespace in Makefile.am that crashes autoreconf --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 45dc5a1c6..97d9cb434 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -220,7 +220,7 @@ MODFILES = \ optimizers/fs2000_101.mod \ optimizers/fs2000_102.mod \ optimizers/fs2000_w.mod \ - differentiate_forward_vars/RBC_differentiate_forward.mod \ + differentiate_forward_vars/RBC_differentiate_forward.mod \ reporting/example1.mod XFAIL_MODFILES = ramst_xfail.mod \ From 2ab8e2a122afd253e7ea315ef49adccca5ced53f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 12 May 2015 16:36:03 +0200 Subject: [PATCH 202/210] =?UTF-8?q?preprocessor:=20external=20functions=20?= =?UTF-8?q?bug=20fix:=20fixes=20the=20case=20where=20an=20external=20funct?= =?UTF-8?q?ion=20is=20contained=20in=20a=20local=20variable=20that?= =?UTF-8?q?=E2=80=99s=20used=20in=20an=20equation=20with=20leads/lags=20th?= =?UTF-8?q?at=20require=20auxiliary=20equations.=20Closes=20#916?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preprocessor/ExprNode.cc | 39 +++++++++++++++++++++++++++++++++++++ preprocessor/ExprNode.hh | 11 ++++++++++- preprocessor/StaticModel.cc | 11 +++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc index 3805c1a6e..8798d7967 100644 --- a/preprocessor/ExprNode.cc +++ b/preprocessor/ExprNode.cc @@ -308,6 +308,12 @@ NumConstNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << datatree.num_constants.get(id); } +bool +NumConstNode::containsExternalFunction() const +{ + return false; +} + double NumConstNode::eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException) { @@ -571,6 +577,12 @@ VariableNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, t datatree.local_variables_table[symb_id]->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block); } +bool +VariableNode::containsExternalFunction() const +{ + return false; +} + void VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, @@ -1714,6 +1726,12 @@ UnaryOpNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, te arg->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block); } +bool +UnaryOpNode::containsExternalFunction() const +{ + return arg->containsExternalFunction(); +} + void UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, @@ -2885,6 +2903,13 @@ BinaryOpNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, t } } +bool +BinaryOpNode::containsExternalFunction() const +{ + return arg1->containsExternalFunction() + || arg2->containsExternalFunction(); +} + void BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, @@ -3963,6 +3988,14 @@ TrinaryOpNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, } } +bool +TrinaryOpNode::containsExternalFunction() const +{ + return arg1->containsExternalFunction() + || arg2->containsExternalFunction() + || arg3->containsExternalFunction(); +} + void TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, @@ -4626,6 +4659,12 @@ AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType outp } } +bool +AbstractExternalFunctionNode::containsExternalFunction() const +{ + return true; +} + ExternalFunctionNode::ExternalFunctionNode(DataTree &datatree_arg, int symb_id_arg, const vector &arguments_arg) : diff --git a/preprocessor/ExprNode.hh b/preprocessor/ExprNode.hh index b008333cd..0500ff6d5 100644 --- a/preprocessor/ExprNode.hh +++ b/preprocessor/ExprNode.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2014 Dynare Team + * Copyright (C) 2007-2015 Dynare Team * * This file is part of Dynare. * @@ -187,6 +187,9 @@ public: */ virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0; + //! returns true if the expr node contains an external function + virtual bool containsExternalFunction() const = 0; + //! Writes output of node (with no temporary terms and with "outside model" output type) void writeOutput(ostream &output) const; @@ -441,6 +444,7 @@ public: }; virtual void prepareForDerivation(); virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; + virtual bool containsExternalFunction() const; virtual void collectDynamicVariables(SymbolType type_arg, set > &result) const; virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const; virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException); @@ -486,6 +490,7 @@ public: VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg); virtual void prepareForDerivation(); virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; + virtual bool containsExternalFunction() const; virtual void collectDynamicVariables(SymbolType type_arg, set > &result) const; virtual void computeTemporaryTerms(map &reference_count, temporary_terms_t &temporary_terms, @@ -552,6 +557,7 @@ public: virtual void prepareForDerivation(); virtual void computeTemporaryTerms(map &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const; virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; + virtual bool containsExternalFunction() const; virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; @@ -630,6 +636,7 @@ public: virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const; virtual void computeTemporaryTerms(map &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const; virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; + virtual bool containsExternalFunction() const; virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; @@ -724,6 +731,7 @@ public: virtual int precedence(ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms) const; virtual void computeTemporaryTerms(map &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const; virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; + virtual bool containsExternalFunction() const; virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const; @@ -795,6 +803,7 @@ public: virtual void prepareForDerivation(); virtual void computeTemporaryTerms(map &reference_count, temporary_terms_t &temporary_terms, bool is_matlab) const = 0; virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0; + virtual bool containsExternalFunction() const; virtual void writeExternalFunctionOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_t &temporary_terms, deriv_node_temp_terms_t &tef_terms) const = 0; diff --git a/preprocessor/StaticModel.cc b/preprocessor/StaticModel.cc index 09fb9261b..045e63364 100644 --- a/preprocessor/StaticModel.cc +++ b/preprocessor/StaticModel.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -1927,9 +1927,16 @@ void StaticModel::writeAuxVarRecursiveDefinitions(const string &basename) const << "% from model file (.mod)" << endl << endl; + deriv_node_temp_terms_t tef_terms; + temporary_terms_t temporary_terms; + for (int i = 0; i < (int) aux_equations.size(); i++) + if (dynamic_cast(aux_equations[i])->containsExternalFunction()) + dynamic_cast(aux_equations[i])->writeExternalFunctionOutput(output, oMatlabStaticModel, + temporary_terms, tef_terms); + for (int i = 0; i < (int) aux_equations.size(); i++) { - dynamic_cast(aux_equations[i])->writeOutput(output, oMatlabStaticModel); + dynamic_cast(aux_equations[i])->writeOutput(output, oMatlabStaticModel, temporary_terms, tef_terms); output << ";" << endl; } } From 0120fc16c18845911cbf0554c1cf7227aeb2b206 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 12 May 2015 16:50:35 +0200 Subject: [PATCH 203/210] Cut number of draws in fs2000_student.mod unit test to speed it up --- tests/estimation/t_proposal/fs2000_student.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/estimation/t_proposal/fs2000_student.mod b/tests/estimation/t_proposal/fs2000_student.mod index e2a20bc82..47c90a403 100644 --- a/tests/estimation/t_proposal/fs2000_student.mod +++ b/tests/estimation/t_proposal/fs2000_student.mod @@ -117,4 +117,4 @@ varobs gp_obs gy_obs; options_.proposal_distribution='rand_multivariate_student'; options_.student_degrees_of_freedom=5; -estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=50000, mh_nblocks=2, mh_jscale=0.8,mode_compute=4); +estimation(order=1, datafile='../fsdat_simul',nobs=192, loglinear, mh_replic=2002, mh_nblocks=2, mh_jscale=0.8,mode_compute=4); From 027f1302d154e0971124ab0e91af257d6bdb2e3e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 May 2015 15:12:21 +0200 Subject: [PATCH 204/210] preprocessor: add dr_display_tol to stoch_simul. #924 --- preprocessor/DynareBison.yy | 4 +++- preprocessor/DynareFlex.ll | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index b7288da93..58f13f4b6 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -84,7 +84,7 @@ class ParsingDriver; %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR %token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION -%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION +%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED @@ -1094,6 +1094,7 @@ stoch_simul_primary_options : o_dr_algo | o_dr_logarithmic_reduction_tol | o_dr_logarithmic_reduction_maxiter | o_irf_plot_threshold + | o_dr_display_tol ; stoch_simul_options : stoch_simul_primary_options @@ -2966,6 +2967,7 @@ o_mcmc_jumping_covariance : MCMC_JUMPING_COVARIANCE EQUAL HESSIAN { driver.option_str("MCMC_jumping_covariance", $3); } ; o_irf_plot_threshold : IRF_PLOT_THRESHOLD EQUAL non_negative_number { driver.option_num("impulse_responses.plot_threshold", $3); }; +o_dr_display_tol : DR_DISPLAY_TOL EQUAL non_negative_number { driver.option_num("dr_display_tol", $3); }; o_consider_all_endogenous : CONSIDER_ALL_ENDOGENOUS { driver.option_str("endo_vars_for_moment_computations_in_estimation", "all_endogenous_variables"); }; o_consider_only_observed : CONSIDER_ONLY_OBSERVED { driver.option_str("endo_vars_for_moment_computations_in_estimation", "only_observed_variables"); }; o_no_homotopy : NO_HOMOTOPY { driver.option_num("no_homotopy", "1"); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 4428dd37d..7201350be 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -567,6 +567,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 period {return token::PERIOD;} outfile {return token::OUTFILE;} outvars {return token::OUTVARS;} +dr_display_tol {return token::DR_DISPLAY_TOL;} [\$][^$]*[\$] { strtok(yytext+1, "$"); From f239c1c368c49d8cb1a7cf6cd0c041c2cc040156 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 May 2015 15:14:34 +0200 Subject: [PATCH 205/210] preprocessor: add huge_number to estimation and osr. #924 --- preprocessor/DynareBison.yy | 5 ++++- preprocessor/DynareFlex.ll | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 58f13f4b6..740c65786 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -84,7 +84,7 @@ class ParsingDriver; %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR %token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION -%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL +%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED @@ -1714,6 +1714,7 @@ estimation_options : o_datafile | o_proposal_approximation | o_distribution_approximation | o_dirname + | o_huge_number ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -1770,6 +1771,7 @@ osr_options : stoch_simul_primary_options | o_osr_tolf | o_opt_algo | o_optim + | o_huge_number ; osr : OSR ';' @@ -2549,6 +2551,7 @@ o_file : FILE EQUAL filename { driver.option_str("file", $3); }; o_series : SERIES EQUAL symbol { driver.option_str("series", $3); }; o_datafile : DATAFILE EQUAL filename { driver.option_str("datafile", $3); }; o_dirname : DIRNAME EQUAL filename { driver.option_str("dirname", $3); }; +o_huge_number : HUGE_NUMBER EQUAL non_negative_number { driver.option_num("huge_number", $3); }; o_nobs : NOBS EQUAL vec_int { driver.option_vec_int("nobs", $3); } | NOBS EQUAL vec_int_number diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 7201350be..91de01a20 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -567,6 +567,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 period {return token::PERIOD;} outfile {return token::OUTFILE;} outvars {return token::OUTVARS;} +huge_number {return token::HUGE_NUMBER;} dr_display_tol {return token::DR_DISPLAY_TOL;} [\$][^$]*[\$] { From e5df26a6e8afff31838796c3a6127103340e6edf Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 May 2015 15:32:24 +0200 Subject: [PATCH 206/210] preprocessor: add use_tarb option to estimation. #940 --- matlab/global_initialization.m | 1 + preprocessor/DynareBison.yy | 5 +++-- preprocessor/DynareFlex.ll | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index c418da89c..690a30212 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -413,6 +413,7 @@ options_.recursive_estimation_restart = 0; options_.MCMC_jumping_covariance='hessian'; options_.use_calibration_initialization = 0; options_.endo_vars_for_moment_computations_in_estimation=[]; +options_.TaRB.use_TaRB = 0; % Prior restrictions options_.prior_restrictions.status = 0; diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 740c65786..7af460671 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -83,7 +83,7 @@ class ParsingDriver; } %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR -%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION +%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB %token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN @@ -1715,6 +1715,7 @@ estimation_options : o_datafile | o_distribution_approximation | o_dirname | o_huge_number + | o_use_tarb ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -2872,7 +2873,7 @@ o_equations : EQUATIONS EQUAL vec_int | EQUATIONS EQUAL vec_int_number { driver.option_vec_int("ms.equations",$3); } ; - +o_use_tarb : USE_TARB { driver.option_num("TaRB.use_TaRB", "1"); }; o_instruments : INSTRUMENTS EQUAL '(' symbol_list ')' {driver.option_symbol_list("instruments"); }; o_ext_func_name : EXT_FUNC_NAME EQUAL filename { driver.external_function_option("name", $3); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 91de01a20..992cdb030 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -569,6 +569,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 outvars {return token::OUTVARS;} huge_number {return token::HUGE_NUMBER;} dr_display_tol {return token::DR_DISPLAY_TOL;} +use_tarb {return token::USE_TARB;} [\$][^$]*[\$] { strtok(yytext+1, "$"); From 0d76e302486d3f373447c710730a58e09aa75533 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 May 2015 15:46:52 +0200 Subject: [PATCH 207/210] preprocessor: add tarb_mode_compute option to estimation. #940 --- preprocessor/DynareBison.yy | 4 +++- preprocessor/DynareFlex.ll | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 7af460671..47d241e6b 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -82,7 +82,7 @@ class ParsingDriver; #define yylex driver.lexer->lex } -%token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR +%token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR TARB_MODE_COMPUTE %token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB %token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA @@ -1716,6 +1716,7 @@ estimation_options : o_datafile | o_dirname | o_huge_number | o_use_tarb + | o_tarb_mode_compute ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -2874,6 +2875,7 @@ o_equations : EQUATIONS EQUAL vec_int { driver.option_vec_int("ms.equations",$3); } ; o_use_tarb : USE_TARB { driver.option_num("TaRB.use_TaRB", "1"); }; +o_tarb_mode_compute : TARB_MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("TaRB.mode_compute", $3); }; o_instruments : INSTRUMENTS EQUAL '(' symbol_list ')' {driver.option_symbol_list("instruments"); }; o_ext_func_name : EXT_FUNC_NAME EQUAL filename { driver.external_function_option("name", $3); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 992cdb030..05867db72 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -570,6 +570,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 huge_number {return token::HUGE_NUMBER;} dr_display_tol {return token::DR_DISPLAY_TOL;} use_tarb {return token::USE_TARB;} +tarb_mode_compute {return token::TARB_MODE_COMPUTE;} [\$][^$]*[\$] { strtok(yytext+1, "$"); From 12be4e6672bbe881fd8a4c7730baf3590afca330 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 May 2015 15:49:41 +0200 Subject: [PATCH 208/210] preprocessor: add tarb_new_block_probability option to estimation. #940 --- preprocessor/DynareBison.yy | 4 +++- preprocessor/DynareFlex.ll | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 47d241e6b..5585267e4 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -83,7 +83,7 @@ class ParsingDriver; } %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR TARB_MODE_COMPUTE -%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB +%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB TARB_NEW_BLOCK_PROBABILITY %token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN @@ -1717,6 +1717,7 @@ estimation_options : o_datafile | o_huge_number | o_use_tarb | o_tarb_mode_compute + | o_tarb_new_block_probability ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -2876,6 +2877,7 @@ o_equations : EQUATIONS EQUAL vec_int ; o_use_tarb : USE_TARB { driver.option_num("TaRB.use_TaRB", "1"); }; o_tarb_mode_compute : TARB_MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("TaRB.mode_compute", $3); }; +o_tarb_new_block_probability : TARB_NEW_BLOCK_PROBABILITY EQUAL non_negative_number {driver.option_num("TaRB.new_block_probability",$3); }; o_instruments : INSTRUMENTS EQUAL '(' symbol_list ')' {driver.option_symbol_list("instruments"); }; o_ext_func_name : EXT_FUNC_NAME EQUAL filename { driver.external_function_option("name", $3); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 05867db72..f6c67669b 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -571,6 +571,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 dr_display_tol {return token::DR_DISPLAY_TOL;} use_tarb {return token::USE_TARB;} tarb_mode_compute {return token::TARB_MODE_COMPUTE;} +tarb_new_block_probability {return token::TARB_NEW_BLOCK_PROBABILITY;} + [\$][^$]*[\$] { strtok(yytext+1, "$"); From 44790abbb7766fd4d694c19dc67a738b72103940 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 May 2015 16:09:50 +0200 Subject: [PATCH 209/210] preprocessor: add tarb_optim option to estimation. #940 --- preprocessor/DynareBison.yy | 14 +++++++++++++- preprocessor/DynareFlex.ll | 2 +- preprocessor/ParsingDriver.cc | 28 ++++++++++++++++++++++++++++ preprocessor/ParsingDriver.hh | 5 +++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 5585267e4..bd9300e1f 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -85,7 +85,7 @@ class ParsingDriver; %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR TARB_MODE_COMPUTE %token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB TARB_NEW_BLOCK_PROBABILITY %token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER -%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA +%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA TARB_OPTIM %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED %token CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF CYCLE_REDUCTION LOGARITHMIC_REDUCTION @@ -1718,6 +1718,7 @@ estimation_options : o_datafile | o_use_tarb | o_tarb_mode_compute | o_tarb_new_block_probability + | o_tarb_optim ; list_optim_option : QUOTED_STRING COMMA QUOTED_STRING @@ -1730,6 +1731,16 @@ optim_options : list_optim_option | optim_options COMMA list_optim_option; ; +list_tarb_optim_option : QUOTED_STRING COMMA QUOTED_STRING + { driver.tarb_optim_options_string($1, $3); } + | QUOTED_STRING COMMA signed_number + { driver.tarb_optim_options_num($1, $3); } + ; + +tarb_optim_options : list_tarb_optim_option + | tarb_optim_options COMMA list_tarb_optim_option; + ; + varobs : VAROBS { driver.check_varobs(); } varobs_list ';'; varobs_list : varobs_list symbol @@ -2621,6 +2632,7 @@ o_posterior_max_subsample_draws : POSTERIOR_MAX_SUBSAMPLE_DRAWS EQUAL INT_NUMBER o_mh_drop : MH_DROP EQUAL non_negative_number { driver.option_num("mh_drop", $3); }; o_mh_jscale : MH_JSCALE EQUAL non_negative_number { driver.option_num("mh_jscale", $3); }; o_optim : OPTIM EQUAL '(' optim_options ')'; +o_tarb_optim : TARB_OPTIM EQUAL '(' tarb_optim_options ')'; o_mh_init_scale : MH_INIT_SCALE EQUAL non_negative_number { driver.option_num("mh_init_scale", $3); }; o_mode_file : MODE_FILE EQUAL filename { driver.option_str("mode_file", $3); }; o_mode_compute : MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("mode_compute", $3); }; diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index f6c67669b..5466487d3 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -572,7 +572,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 use_tarb {return token::USE_TARB;} tarb_mode_compute {return token::TARB_MODE_COMPUTE;} tarb_new_block_probability {return token::TARB_NEW_BLOCK_PROBABILITY;} - +tarb_optim {return token::TARB_OPTIM;} [\$][^$]*[\$] { strtok(yytext+1, "$"); diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 67c4be456..ba541ec81 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -1630,6 +1630,34 @@ ParsingDriver::optim_options_num(string *name, string *value) delete value; } +void +ParsingDriver::tarb_optim_options_helper(const string &name) +{ + if (options_list.string_options.find("TaRB.optim_opt") == options_list.string_options.end()) + options_list.string_options["TaRB.optim_opt"] = ""; + else + options_list.string_options["TaRB.optim_opt"] += ","; + options_list.string_options["TaRB.optim_opt"] += "''" + name + "'',"; +} + +void +ParsingDriver::tarb_optim_options_string(string *name, string *value) +{ + tarb_optim_options_helper(*name); + options_list.string_options["TaRB.optim_opt"] += "''" + *value + "''"; + delete name; + delete value; +} + +void +ParsingDriver::tarb_optim_options_num(string *name, string *value) +{ + tarb_optim_options_helper(*name); + options_list.string_options["TaRB.optim_opt"] += *value; + delete name; + delete value; +} + void ParsingDriver::check_varobs() { diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index d4ebc05dc..dd93276c0 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -98,6 +98,7 @@ private: //! Creates option "optim_opt" in OptionsList if it doesn't exist, else add a comma, and adds the option name void optim_options_helper(const string &name); + void tarb_optim_options_helper(const string &name); //! Stores temporary symbol table SymbolList symbol_list; @@ -443,6 +444,10 @@ public: void optim_options_string(string *name, string *value); //! Adds an optimization option (numeric value) void optim_options_num(string *name, string *value); + //! Adds a TaRB optimization option (string value) + void tarb_optim_options_string(string *name, string *value); + //! Adds a TaRB optimization option (numeric value) + void tarb_optim_options_num(string *name, string *value); //! Check that no observed variable has yet be defined void check_varobs(); //! Add a new observed variable From 2fe7a4156d2c353cc3be402433b80537115d39e0 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Wed, 13 May 2015 17:11:39 +0200 Subject: [PATCH 210/210] changing code for making directory baseline in order to comply with mingw --- preprocessor/DynamicModel.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index b7eb27d85..339cbe976 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -4289,24 +4289,29 @@ DynamicModel::isChecksumMatching(const string &basename) const result.process_bytes(private_buffer,strlen(private_buffer)); } + bool basename_dir_exists = false; +#ifdef _WIN32 + int r = mkdir(basename.c_str()); +#else + int r = mkdir(basename.c_str(), 0777); +#endif + if (r < 0) + if (errno != EEXIST) + { + perror("ERROR"); + exit(EXIT_FAILURE); + } + else + basename_dir_exists = true; + // check whether basename directory exist. If not, create it. // If it does, read old checksum if it exist fstream checksum_file; string filename = basename + "/checksum"; unsigned int old_checksum = 0; - struct stat sd; - if (stat(basename.c_str(), &sd) != 0) + // read old checksum if it exists + if (basename_dir_exists) { - const int dir_err = mkdir(basename.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if (dir_err == -1) - { - cerr << "ERROR: can't create directory " << basename << endl; - exit(EXIT_FAILURE); - } - } - else - { - // read old checksum if it exists checksum_file.open(filename.c_str(), ios::in | ios::binary); if (checksum_file.is_open()) {