From 4e1122f0141b011c03f7c26b9b504d21fd61cf42 Mon Sep 17 00:00:00 2001 From: michel Date: Sun, 11 Feb 2007 12:48:41 +0000 Subject: [PATCH] v4: merge changes to dynare_estimation.m git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1183 ac1d8469-bf42-47a9-8791-bf33cf982152 --- matlab/DiffuseKalmanSmoother3.m | 2 +- matlab/DiffuseKalmanSmootherH1.m | 9 +++------ matlab/DiffuseKalmanSmootherH3.m | 28 ++++++++++++++++++---------- matlab/DsgeLikelihood.m | 5 +++-- matlab/DsgeLikelihood_hh.m | 3 ++- matlab/DsgeSmoother.m | 2 +- matlab/dynare_estimation.m | 2 -- matlab/global_initialization.m | 7 +++++-- matlab/set_prior.m | 8 ++++++++ 9 files changed, 41 insertions(+), 25 deletions(-) diff --git a/matlab/DiffuseKalmanSmoother3.m b/matlab/DiffuseKalmanSmoother3.m index fdbb0d112..84a031656 100644 --- a/matlab/DiffuseKalmanSmoother3.m +++ b/matlab/DiffuseKalmanSmoother3.m @@ -113,7 +113,7 @@ while newRank & t < smpl % options_.diffuse_d=i; %this is buggy % end % end new terminiation criteria by M. Ratto - else + elseif Fstar(i,t) > crit %% Note that : (1) rank(Pinf)=0 implies that Finf = 0, (2) outside this loop (when for some i and t the condition %% rank(Pinf)=0 is satisfied we have P = Pstar and F = Fstar and (3) Finf = 0 does not imply that %% rank(Pinf)=0. [stéphane,11-03-2004]. diff --git a/matlab/DiffuseKalmanSmootherH1.m b/matlab/DiffuseKalmanSmootherH1.m index 9981f340b..84bb8b24c 100644 --- a/matlab/DiffuseKalmanSmootherH1.m +++ b/matlab/DiffuseKalmanSmootherH1.m @@ -55,8 +55,7 @@ while rank(Pinf(:,:,t+1),crit1) & t crit %% Note that : (1) rank(Pinf)=0 implies that Finf = 0, (2) outside this loop (when for some i and t the condition %% rank(Pinf)=0 is satisfied we have P = Pstar and F = Fstar and (3) Finf = 0 does not imply that %% rank(Pinf)=0. [stéphane,11-03-2004]. @@ -149,8 +156,8 @@ while notsteady & t crit Li(:,:,i,t) = eye(mm)-Ki(:,i,t)*Z(i,:)/Fi(i,t); a(:,t) = a(:,t) + Ki(:,i,t)*v(i,t)/Fi(i,t); @@ -253,3 +260,4 @@ else end epsilonhat = Y-alphahat(mf,:)-trend; +a=a(:,1:end-1); \ No newline at end of file diff --git a/matlab/DsgeLikelihood.m b/matlab/DsgeLikelihood.m index cb242a802..a58941a5b 100644 --- a/matlab/DsgeLikelihood.m +++ b/matlab/DsgeLikelihood.m @@ -28,13 +28,13 @@ function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data return; end Q = M_.Sigma_e; + H = M_.H; for i=1:estim_params_.nvx k =estim_params_.var_exo(i,1); Q(k,k) = xparam1(i)*xparam1(i); end offset = estim_params_.nvx; if estim_params_.nvn - H = zeros(nobs,nobs); for i=1:estim_params_.nvn k = estim_params_.var_endo(i,1); H(k,k) = xparam1(i+offset)*xparam1(i+offset); @@ -87,6 +87,7 @@ function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data % M_.params(estim_params_.param_vals(i,1)) = xparam1(i+offset); %end M_.Sigma_e = Q; + M_.H = H; %------------------------------------------------------------------------------ % 2. call model setup & reduction program %------------------------------------------------------------------------------ @@ -150,7 +151,7 @@ function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data %------------------------------------------------------------------------------ % 4. Likelihood evaluation %------------------------------------------------------------------------------ - if estim_params_.nvn + if any(any(H ~= 0)) % should be replaced by a flag if options_.kalman_algo == 1 LIK = DiffuseLikelihoodH1(T,R,Q,H,Pinf,Pstar,data,trend,start); if isinf(LIK) & ~estim_params_.ncn %% The univariate approach considered here doesn't diff --git a/matlab/DsgeLikelihood_hh.m b/matlab/DsgeLikelihood_hh.m index 5bf1f255a..43295ffa9 100644 --- a/matlab/DsgeLikelihood_hh.m +++ b/matlab/DsgeLikelihood_hh.m @@ -87,6 +87,7 @@ function [fval,llik,cost_flag,ys,trend_coeff,info] = DsgeLikelihood_hh(xparam1,g % M_.params(estim_params_.param_vals(i,1)) = xparam1(i+offset); %end M_.Sigma_e = Q; + M_.H = H; %------------------------------------------------------------------------------ % 2. call model setup & reduction program %------------------------------------------------------------------------------ @@ -152,7 +153,7 @@ function [fval,llik,cost_flag,ys,trend_coeff,info] = DsgeLikelihood_hh(xparam1,g %------------------------------------------------------------------------------ % 4. Likelihood evaluation %------------------------------------------------------------------------------ - if estim_params_.nvn + if any(any(H ~= 0)) if options_.kalman_algo == 1 [LIK, lik] = DiffuseLikelihoodH1(T,R,Q,H,Pinf,Pstar,data,trend,start); if isinf(LIK) & ~estim_params_.ncn %% The univariate approach considered here doesn't diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m index 78620d273..ecbb2155c 100644 --- a/matlab/DsgeSmoother.m +++ b/matlab/DsgeSmoother.m @@ -70,7 +70,7 @@ function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoo % ----------------------------------------------------------------------------- % 4. Kalman smoother % ----------------------------------------------------------------------------- - if estim_params_.nvn + if any(any(H ~= 0)) % should be replaced by a flag if options_.kalman_algo == 1 [alphahat,epsilonhat,etahat,ahat,aK] = DiffuseKalmanSmootherH1(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf); if all(alphahat(:)==0) diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m index 69d93ae04..37c70c21d 100644 --- a/matlab/dynare_estimation.m +++ b/matlab/dynare_estimation.m @@ -3,8 +3,6 @@ function dynare_estimation(var_list_) global M_ options_ oo_ estim_params_ global bayestopt_ dsge_prior_weight -% temporary fix until M_.H is initialized by the parser -M_.H = []; options_.varlist = var_list_; options_.lgyidx2varobs = zeros(size(M_.endo_names,1),1); diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 68ebe0691..2c63568b5 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -13,7 +13,7 @@ function global_initialization() options_.slowc = 1; options_.timing = 0; options_.gstep = 1e-2; - options_.debug = 0 + options_.debug = 0; options_.initval_file = 0; options_.Schur_vec_tol = 1e-8; % used to find nonstationary variables % in Schur decomposition of the @@ -134,4 +134,7 @@ function global_initialization() oo_.endo_simul = []; oo_.dr = []; oo_.exo_det_steady_state = []; - oo_.exo_det_simul = []; \ No newline at end of file + oo_.exo_det_simul = []; + + % Variance matrix for measurement errors + M_.H = 0; \ No newline at end of file diff --git a/matlab/set_prior.m b/matlab/set_prior.m index 6568cc419..6cf6d951d 100644 --- a/matlab/set_prior.m +++ b/matlab/set_prior.m @@ -38,6 +38,10 @@ function [xparam1,estim_params_,bayestopt_,lb,ub]=set_prior(estim_params_) bayestopt_.name = cellstr(M_.exo_names(estim_params_.var_exo(:,1),:)); end if nvn + if M_.H == 0 + nvarobs = size(options_.varobs,1); + M_.H = zeros(nvarobs,nvarobs); + end for i=1:nvn estim_params_.var_endo(i,1) = strmatch(deblank(M_.endo_names(estim_params_.var_endo(i,1),:)),deblank(options_.varobs),'exact'); end @@ -69,6 +73,10 @@ function [xparam1,estim_params_,bayestopt_,lb,ub]=set_prior(estim_params_) cellstr(M_.exo_names(estim_params_.corrx(:,2),:)))))); end if ncn + if M_.H == 0 + nvarobs = size(options_.varobs,1); + M_.H = zeros(nvarobs,nvarobs); + end xparam1 = [xparam1; estim_params_.corrn(:,3)]; ub = [ub; max(min(estim_params_.corrn(:,5),1),-1)]; lb = [lb; max(min(estim_params_.corrn(:,4),1),-1)];