From 54b813d3d77ca11baecdd6afcb8b15f74782599b Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Tue, 2 Aug 2011 10:49:50 +0200 Subject: [PATCH] MS-SBVAR: correcting bug in handling of exclusion of constants. Changed options_.ms.Qi and options_.ms.Ri from 3 dimension arrays into cellarray of matrices. --- matlab/ms-sbvar/identification/exclusions.m | 31 ++++++++++++--------- preprocessor/ComputingTasks.cc | 8 +++--- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/matlab/ms-sbvar/identification/exclusions.m b/matlab/ms-sbvar/identification/exclusions.m index 8672225c6..4f040a213 100644 --- a/matlab/ms-sbvar/identification/exclusions.m +++ b/matlab/ms-sbvar/identification/exclusions.m @@ -3,7 +3,7 @@ function [Ui,Vi,n0,np,ixmC0Pres] = exclusions(nvar,nexo,options_ms) indxC0Pres = options_ms.cross_restrictions; nlags = options_ms.nlags; -Qi = options_ms.Qi; +Qi1 = options_ms.Qi; Ri1 = options_ms.Ri; Ui = cell(nvar,1); @@ -13,19 +13,24 @@ np = zeros(nvar,1); k = nlags*nvar+1; -Ri = zeros(k,k,nvar); -sR = size(Ri1); -Ri(1:sR(1),1:sR(2),1:sR(3)) = Ri1; - -if options_ms.constants_exclusion - for i=1:nvar - Ri(i,k,i) = 1; - end -end - for n=1:nvar - Ui{n} = null(Qi(:,:,n)); - Vi{n} = null(Ri(:,:,n)); + Qi{n} = zeros(nvar,nvar); + sQ = size(Qi1{n}); + if all(sQ) > 0 + Qi{n}(1:sQ(1),1:sQ(2)) = Qi1{n}; + end + Ri{n} = zeros(k,k); + sR = size(Ri1{n}); + if all(sR) > 0 + Ri{n}(1:sR(1),1:sR(2)) = Ri1{n}; + end + + if options_ms.constants_exclusion + Ri{n}(sR(1)+1,k) = 1; + end + + Ui{n} = null(Qi{n}); + Vi{n} = null(Ri{n}); n0(n) = size(Ui{n},2); np(n) = size(Vi{n},2); end diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index cbf289640..e6c4102c9 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -1226,8 +1226,8 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename << "error in the specification of the .mod file, please report it to the Dynare Team." << endl; exit(EXIT_FAILURE); } - output << "options_.ms.Qi = zeros(" << n << ", " << n << ", " << n << ");" << endl; - output << "options_.ms.Ri = zeros(" << k << ", " << k << ", " << n << ");" << endl; + output << "options_.ms.Qi = cell(" << n << ",1);" << endl; + output << "options_.ms.Ri = cell(" << n << ",1);" << endl; vector rows(n); fill(rows.begin(),rows.end(),1); @@ -1251,7 +1251,7 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename } if (lag == 0) - output << "options_.ms.Qi(" << h+1 << ", " << j << ", "<< i << ") = 1;" << endl; + output << "options_.ms.Qi{" << i << "}(" << h+1 << ", " << j << ") = 1;" << endl; else if (lag > 0) { if ((lag-1)*n+j > k) @@ -1259,7 +1259,7 @@ SvarIdentificationStatement::writeOutput(ostream &output, const string &basename cerr << "ERROR: lag =" << lag << ", num endog vars = " << n << "current endog var index = " << j << ". Index " << "out of bounds. If the above does not represent a logical error, please report this to the Dyanre Team." << endl; } - output << "options_.ms.Ri(" << rows[i-1] << ", " << (lag-1)*n+j << ", "<< i << ") = 1;" << endl; + output << "options_.ms.Ri{" << i << "}(" << rows[i-1] << ", " << (lag-1)*n+j << ") = 1;" << endl; rows[i-1]++; } else