diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index a22f3709e8e9f9836734273b54627349021f1745..96b5cb94d38b358cd58db2ccbdca22d93b6b8186 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -193,7 +193,7 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,d, % ----------------------------------------------------------------------------- % 4. Kalman smoother % ----------------------------------------------------------------------------- - if any(any(H ~= 0)) % should be replaced by a flag + if any(any(H ~= 0)) % should be replaced by a flag if kalman_algo == 1 [alphahat,epsilonhat,etahat,ahat,aK] = ... DiffuseKalmanSmootherH1(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf); @@ -288,17 +288,23 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,d, alphahat = QT*alphahat; ahat = QT*ahat; nk = options_.nk; +% $$$ if M_.exo_nbr<2 % Fix the crash of Dynare when the estimated model has only one structural shock (problem with +% $$$ % the squeeze function, that does not affect 2D arrays). +% $$$ size_decomp = 0; +% $$$ else +% $$$ size_decomp = size(decomp,4); +% $$$ end for jnk=1:nk aK(jnk,:,:) = QT*squeeze(aK(jnk,:,:)); for i=1:size(PK,4) - PK(jnk,:,:,i) = QT*squeeze(PK(jnk,:,:,i))*QT'; + PK(jnk,:,:,i) = QT*dynare_squeeze(PK(jnk,:,:,i))*QT'; end for i=1:size(decomp,4) - decomp(jnk,:,:,i) = QT*squeeze(decomp(jnk,:,:,i)); + decomp(jnk,:,:,i) = QT*dynare_squeeze(decomp(jnk,:,:,i)); end end for i=1:size(P,4) - P(:,:,i) = QT*squeeze(P(:,:,i))*QT'; + P(:,:,i) = QT*dynare_squeeze(P(:,:,i))*QT'; end end end diff --git a/matlab/dynare_squeeze.m b/matlab/dynare_squeeze.m new file mode 100644 index 0000000000000000000000000000000000000000..ae4d4b721a4dddb5a43038b0e975c856bddf1a80 --- /dev/null +++ b/matlab/dynare_squeeze.m @@ -0,0 +1,36 @@ +function B = dynare_squeeze(A); +% Same as matlab's squeeze function except that it also affects 2D arrays. + +% Copyright (C) 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 <http://www.gnu.org/licenses/>. + + sizA = size(A); + dimA = length(sizA); + switch dimA + case 1 + B = A; + case 2 + if sizA(1)==1 + B = transpose(A); + elseif sizA(2)==1 + B = A(:,1); + else + B = A; + end + otherwise + B = squeeze(A); + end \ No newline at end of file