From f56ae63f568c4b391fdcc5868f23814533bc5021 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 3 Jul 2013 09:18:44 +0200 Subject: [PATCH 1/9] Bugfix for calls to evaluate smoother in shock_decomposition In shock_decomposition, oo_ is local. Thus, if requested, make evaluate_smoother return oo_ --- matlab/evaluate_smoother.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/evaluate_smoother.m b/matlab/evaluate_smoother.m index 474deaa65..32f58a280 100644 --- a/matlab/evaluate_smoother.m +++ b/matlab/evaluate_smoother.m @@ -1,4 +1,4 @@ -function evaluate_smoother(parameters,var_list) +function oo_=evaluate_smoother(parameters,var_list) % Evaluate the smoother at parameters. % % INPUTS From 4ba1b3feb4a7f15f42ae8d5c14549a9b9012005e Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 3 Jul 2013 09:20:48 +0200 Subject: [PATCH 2/9] Move axis command after plot in graph_decomp for not overriding it --- matlab/graph_decomp.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/graph_decomp.m b/matlab/graph_decomp.m index f69c8d833..33240cf6e 100644 --- a/matlab/graph_decomp.m +++ b/matlab/graph_decomp.m @@ -41,8 +41,8 @@ for j=1:nvar end fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition: ',endo_names(i_var(j),:)]); ax=axes('Position',[0.1 0.1 0.6 0.8]); - axis(ax,[xmin xmax ymin ymax]); plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2) + axis(ax,[xmin xmax ymin ymax]); hold on; for i=1:gend i_1 = i-1; From 38cc6add5fbd708a9944976138b581f523d5f4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 5 Jul 2013 10:12:56 +0200 Subject: [PATCH 3/9] Added a loop in name2tex so that the first argument can be a cell of string. --- matlab/name2tex.m | 82 ++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/matlab/name2tex.m b/matlab/name2tex.m index ed8b259e5..00cbde688 100644 --- a/matlab/name2tex.m +++ b/matlab/name2tex.m @@ -27,40 +27,56 @@ if isempty(id) tex = name; return end - -if info - tex = name; - n = length(id); - if id(1)==1 - tex = ['\_', tex(2:end)]; - if n>1 - id = id(2:end)+1; - n = n-1; - else - return - end - end - if id(end)==length(tex) - tex = [tex(1:end-1) '\_']; - if n>1 - id = id(1:end-1); - n = n-1; - else - return - end - end - if n==1 - tex = [ tex(1:(id-1)) '_{' tex((id+1):end) '}' ]; - return - else - for i=1:n-1 - tex = [tex(1:id(1)-1) '\_' tex((id(1)+1):end)]; - id = id(2:end)+1; - end - tex = [tex(1:(id-1)) '_{' tex((id+1):end) '}']; - end + +if iscell(name) + nn = length(name); else - tex = strrep(name, '_', '\_'); + nn = 1; +end + +for i=1:nn + if info + if iscell(name) + tex = name{i}; + else + tex = name; + end + n = length(id); + if id(1)==1 + tex = ['\_', tex(2:end)]; + if n>1 + id = id(2:end)+1; + n = n-1; + else + return + end + end + if id(end)==length(tex) + tex = [tex(1:end-1) '\_']; + if n>1 + id = id(1:end-1); + n = n-1; + else + return + end + end + if n==1 + tex = [ tex(1:(id-1)) '_{' tex((id+1):end) '}' ]; + return + else + for i=1:n-1 + tex = [tex(1:id(1)-1) '\_' tex((id(1)+1):end)]; + id = id(2:end)+1; + end + tex = [tex(1:(id-1)) '_{' tex((id+1):end) '}']; + end + else + if iscell(name) + tex = strrep(name{i}, '_', '\_'); + else + tex = strrep(name, '_', '\_'); + end + end end %@test:1 From c93f972ee5a5f571587d4cefbe0bdddf6f70e3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 5 Jul 2013 12:37:44 +0200 Subject: [PATCH 4/9] Fixed bug introduced in 72a02846a810c3968040fd900e9f2b5a5fe9b432 and other bugs. --- matlab/name2tex.m | 64 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/matlab/name2tex.m b/matlab/name2tex.m index 00cbde688..426520001 100644 --- a/matlab/name2tex.m +++ b/matlab/name2tex.m @@ -22,57 +22,87 @@ if nargin<2 info = 0; end -id = findstr('_',name); +if iscell(name) + nn = length(name); + id = findstr(cell2mat(transpose(name)),'_'); +else + nn = 1; + id = findstr(name,'_'); +end + if isempty(id) tex = name; return end if iscell(name) - nn = length(name); -else - nn = 1; + tex = cell(nn,1); end for i=1:nn if info if iscell(name) - tex = name{i}; + tex(i) = {name{i}}; + id = findstr(name{i},'_'); + len = length(tex{i}); else tex = name; + id = findstr(name,'_'); + len = length(tex); end n = length(id); if id(1)==1 - tex = ['\_', tex(2:end)]; + if iscell(name) + tex(i) = {['\_', tex{i}(2:end)]}; + else + tex = ['\_', tex(2:end)]; + end if n>1 id = id(2:end)+1; n = n-1; + len = len+1; else - return + continue end end - if id(end)==length(tex) - tex = [tex(1:end-1) '\_']; + if id(end)==len + if iscell(name) + tex(i) = {[tex{i}(1:end-1) '\_']}; + else + tex = [tex(1:end-1) '\_']; + end if n>1 id = id(1:end-1); n = n-1; else - return + continue end end if n==1 - tex = [ tex(1:(id-1)) '_{' tex((id+1):end) '}' ]; - return + if iscell(name) + tex(i) = {[ tex{i}(1:(id-1)) '_{' tex{i}((id+1):end) '}' ]}; + else + tex = [ tex(1:(id-1)) '_{' tex((id+1):end) '}' ]; + end + continue else - for i=1:n-1 - tex = [tex(1:id(1)-1) '\_' tex((id(1)+1):end)]; + for j=1:n-1 + if iscell(name) + tex(i) = {[tex{i}(1:id(j)-1) '\_' tex{i}((id(j)+1):end)]}; + else + tex = [tex(1:id(j)-1) '\_' tex((id(j)+1):end)]; + end id = id(2:end)+1; end - tex = [tex(1:(id-1)) '_{' tex((id+1):end) '}']; + if iscell(name) + tex(i) = {[tex{i}(1:(id-1)) '_{' tex{i}((id+1):end) '}']}; + else + tex = [tex(1:(id-1)) '_{' tex((id+1):end) '}']; + end end else if iscell(name) - tex = strrep(name{i}, '_', '\_'); + tex(i) = {strrep(name{i}, '_', '\_')}; else tex = strrep(name, '_', '\_'); end @@ -108,7 +138,7 @@ end %$ t(8) = dyn_assert(strcmp(t8,'\\_azert\\_uiop\\_qsdfg\\_'),1); %$ t(9) = dyn_assert(strcmp(t11,'\\_azert'),1); %$ t(10) = dyn_assert(strcmp(t12,'azert\\_'),1); -%$ t(11) = dyn_assert(strcmp(t13,'\\_azert\\_'),1); +%$ t(11) = dyn_assert(strcmp(t13,'\\_azert\\_'),1); %$ t(12) = dyn_assert(strcmp(t14,'azert_{uiop}'),1); %$ t(13) = dyn_assert(strcmp(t15,'azert\\_uiop_{qsdfg}'),1); %$ t(14) = dyn_assert(strcmp(t16,'azert\\_uiop_{qsdfg\\_}'),1); From e75df484e9ae59aa1e473a81d00b17a3e52393bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 5 Jul 2013 12:38:32 +0200 Subject: [PATCH 5/9] Code factorization. --- matlab/@dynSeries/dynSeries.m | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/matlab/@dynSeries/dynSeries.m b/matlab/@dynSeries/dynSeries.m index 58454cfa6..72d5253ab 100644 --- a/matlab/@dynSeries/dynSeries.m +++ b/matlab/@dynSeries/dynSeries.m @@ -124,13 +124,18 @@ switch nargin ts.vobs = length(varlist); ts.nobs = size(data,1); if isempty(tex) - ts.tex = cell(ts.vobs,1); - for i=1:ts.vobs - ts.tex(i) = {name2tex(varlist{i})}; - end + ts.tex = name2tex(varlist); else - ts.tex = tex; + ts.tex = tex; end + elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2) + ts.data = varargin{1}; + [ts.nobs, ts.vobs] = size(ts.data); + ts.freq = 1; + ts.init = dynDate(1); + ts.time = ts.init:ts.init+ts.nobs; + ts.name = default_name(ts.vobs); + ts.tex = name2tex(ts.name); end case {2,3,4} a = varargin{1}; @@ -177,9 +182,7 @@ switch nargin error('dynSeries::dynSeries: The number of declared names does not match the number of variables!') end else - for i=1:ts.vobs - ts.name = vertcat(ts.name, {['Variable_' int2str(i)]}); - end + ts.name = default_name(ts.vobs); end if ~isempty(d) if ts.vobs==length(d) @@ -190,9 +193,7 @@ switch nargin error('dynSeries::dynSeries: The number of declared tex names does not match the number of variables!') end else - for i=1:ts.vobs - ts.tex = vertcat(ts.tex, {name2tex(ts.name{i})}); - end + ts.tex = name2tex(ts.name); end otherwise error('dynSeries::dynSeries: Can''t instantiate the class, wrong calling sequence!') From e9dca040a6a661a8150f2692ccbb53b5167b5be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 5 Jul 2013 12:39:21 +0200 Subject: [PATCH 6/9] Added missing routine in commit c19905725fd91e91a7fb42437ff8155921a5b8bd. --- matlab/@dynSeries/private/default_name.m | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 matlab/@dynSeries/private/default_name.m diff --git a/matlab/@dynSeries/private/default_name.m b/matlab/@dynSeries/private/default_name.m new file mode 100644 index 000000000..c5093ccf4 --- /dev/null +++ b/matlab/@dynSeries/private/default_name.m @@ -0,0 +1,27 @@ +function names = default_name(dim) + +% Copyright (C) 2011-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 . + + +names = {}; +for i=1:dim + names = vertcat(names, {['Variable_' int2str(i)]}); +end + + + From 141d720b7720982e311f94e3a9e746888db7f075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 5 Jul 2013 12:40:12 +0200 Subject: [PATCH 7/9] Fixed error in copyright. --- matlab/@dynSeries/private/default_name.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/@dynSeries/private/default_name.m b/matlab/@dynSeries/private/default_name.m index c5093ccf4..1711195c4 100644 --- a/matlab/@dynSeries/private/default_name.m +++ b/matlab/@dynSeries/private/default_name.m @@ -1,6 +1,6 @@ function names = default_name(dim) -% Copyright (C) 2011-2013 Dynare Team +% Copyright (C) 2013 Dynare Team % % This file is part of Dynare. % From 67ee48cddc40172ce2f56ceb673dc669729e22fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 5 Jul 2013 13:34:13 +0200 Subject: [PATCH 8/9] Added unitary tests. --- matlab/name2tex.m | 70 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/matlab/name2tex.m b/matlab/name2tex.m index 426520001..082828fe7 100644 --- a/matlab/name2tex.m +++ b/matlab/name2tex.m @@ -146,4 +146,72 @@ end %$ t(16) = dyn_assert(strcmp(t18,'\\_azert\\_uiop_{qsdfg\\_}'),1); %$ %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 + +%@test:2 +%$ t = zeros(16,1); +%$ t1 = name2tex({'_azert'}); +%$ t2 = name2tex({'azert_'}); +%$ t3 = name2tex({'_azert_'}); +%$ t4 = name2tex({'azert_uiop'}); +%$ t5 = name2tex({'azert_uiop_qsdfg'}); +%$ t6 = name2tex({'azert_uiop_qsdfg_'}); +%$ t7 = name2tex({'_azert_uiop_qsdfg'}); +%$ t8 = name2tex({'_azert_uiop_qsdfg_'}); +%$ t11 = name2tex({'_azert'},1); +%$ t12 = name2tex({'azert_'},1); +%$ t13 = name2tex({'_azert_'},1); +%$ t14 = name2tex({'azert_uiop'},1); +%$ t15 = name2tex({'azert_uiop_qsdfg'},1); +%$ t16 = name2tex({'azert_uiop_qsdfg_'},1); +%$ t17 = name2tex({'_azert_uiop_qsdfg'},1); +%$ t18 = name2tex({'_azert_uiop_qsdfg_'},1); +%$ +%$ t(1) = dyn_assert(t1,{'\\_azert'}); +%$ t(2) = dyn_assert(t2,{'azert\\_'}); +%$ t(3) = dyn_assert(t3,{'\\_azert\\_'}); +%$ t(4) = dyn_assert(t4,{'azert\\_uiop'}); +%$ t(5) = dyn_assert(t5,{'azert\\_uiop\\_qsdfg'}); +%$ t(6) = dyn_assert(t6,{'azert\\_uiop\\_qsdfg\\_'}); +%$ t(7) = dyn_assert(t7,{'\\_azert\\_uiop\\_qsdfg'}); +%$ t(8) = dyn_assert(t8,{'\\_azert\\_uiop\\_qsdfg\\_'}); +%$ t(9) = dyn_assert(t11,{'\\_azert'}); +%$ t(10) = dyn_assert(t12,{'azert\\_'}); +%$ t(11) = dyn_assert(t13,{'\\_azert\\_'}); +%$ t(12) = dyn_assert(t14,{'azert_{uiop}'}); +%$ t(13) = dyn_assert(t15,{'azert\\_uiop_{qsdfg}'}); +%$ t(14) = dyn_assert(t16,{'azert\\_uiop_{qsdfg\\_}'}); +%$ t(15) = dyn_assert(t17,{'\\_azert\\_uiop_{qsdfg}'}); +%$ t(16) = dyn_assert(t18,{'\\_azert\\_uiop_{qsdfg\\_}'}); +%$ +%$ T = all(t); +%@eof:2 + +%@test:3 +%$ t = zeros(4,1); +%$ try +%$ t1 = name2tex({'_azert';'azert_';'_azert_';'azert_uiop';'azert_uiop_qsdfg';'azert_uiop_qsdfg_'}); +%$ t(1) = 1; +%$ catch +%$ % Nothing to do here. +%$ end +%$ +%$ if t(1) +%$ try +%$ t2 = name2tex({'_azert';'azert_';'_azert_';'azert_uiop';'azert_uiop_qsdfg';'azert_uiop_qsdfg_'},1); +%$ t(2) = 1; +%$ catch +%$ % Nothing to do here. +%$ end +%$ end +%$ +%$ if t(1) +%$ t(3) = dyn_assert(t1,{'\\_azert';'azert\\_';'\\_azert\\_';'azert\\_uiop';'azert\\_uiop\\_qsdfg';'azert\\_uiop\\_qsdfg\\_'}); +%$ end +%$ +%$ if t(2) +%$ t(4) = dyn_assert(t2,{'\\_azert';'azert\\_';'\\_azert\\_';'azert_{uiop}';'azert\\_uiop_{qsdfg}';'azert\\_uiop_{qsdfg\\_}'}); +%$ end +%$ +%$ T = all(t); +%@eof:3 \ No newline at end of file From a80ed38f5b716603141353c6ef17fdcea275f154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Fri, 5 Jul 2013 13:36:44 +0200 Subject: [PATCH 9/9] Moved name2tex in matlab/utilities/general --- matlab/{ => utilities/general}/name2tex.m | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename matlab/{ => utilities/general}/name2tex.m (100%) diff --git a/matlab/name2tex.m b/matlab/utilities/general/name2tex.m similarity index 100% rename from matlab/name2tex.m rename to matlab/utilities/general/name2tex.m