Various optimizations.

parent 7c83ba7e
...@@ -126,7 +126,8 @@ if estimated_model ...@@ -126,7 +126,8 @@ if estimated_model
qz_criterium_old=options_.qz_criterium; qz_criterium_old=options_.qz_criterium;
options_=select_qz_criterium_value(options_); options_=select_qz_criterium_value(options_);
options_smoothed_state_uncertainty_old = options_.smoothed_state_uncertainty; options_smoothed_state_uncertainty_old = options_.smoothed_state_uncertainty;
[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,M_,oo_,options_,bayestopt_] = DsgeSmoother(xparam,gend,data,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_); [atT, ~, ~, ~,ys, ~, ~, ~, ~, ~, ~, ~, ~, ~,M_,oo_,options_,bayestopt_] = ...
DsgeSmoother(xparam, gend, data, data_index, missing_value, M_, oo_, options_, bayestopt_, estim_params_);
options_.smoothed_state_uncertainty = options_smoothed_state_uncertainty_old; options_.smoothed_state_uncertainty = options_smoothed_state_uncertainty_old;
%get constant part %get constant part
if options_.noconstant if options_.noconstant
...@@ -148,7 +149,7 @@ if estimated_model ...@@ -148,7 +149,7 @@ if estimated_model
end end
% add trend to constant % add trend to constant
for obs_iter=1:length(options_.varobs) for obs_iter=1:length(options_.varobs)
j = strmatch(options_.varobs{obs_iter}, M_.endo_names, 'exact'); j = strcmp(options_.varobs{obs_iter}, M_.endo_names);
constant(j,:) = constant(j,:) + trend_addition(obs_iter,:); constant(j,:) = constant(j,:) + trend_addition(obs_iter,:);
end end
trend = constant(oo_.dr.order_var,:); trend = constant(oo_.dr.order_var,:);
...@@ -170,7 +171,7 @@ if options_.logged_steady_state %if steady state was previously logged, undo thi ...@@ -170,7 +171,7 @@ if options_.logged_steady_state %if steady state was previously logged, undo thi
options_.logged_steady_state=0; options_.logged_steady_state=0;
end end
[T,R,ys,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_); [T, R, ys, ~, M_, options_, oo_] = dynare_resolve(M_, options_, oo_);
if options_.loglinear && isfield(oo_.dr,'ys') && options_.logged_steady_state==0 %log steady state if options_.loglinear && isfield(oo_.dr,'ys') && options_.logged_steady_state==0 %log steady state
oo_.dr.ys=log_variable(1:M_.endo_nbr,oo_.dr.ys,M_); oo_.dr.ys=log_variable(1:M_.endo_nbr,oo_.dr.ys,M_);
...@@ -216,25 +217,21 @@ ExoSize = M_.exo_nbr; ...@@ -216,25 +217,21 @@ ExoSize = M_.exo_nbr;
n1 = size(constrained_vars,1); n1 = size(constrained_vars,1);
n2 = size(options_cond_fcst.controlled_varexo,1); n2 = size(options_cond_fcst.controlled_varexo,1);
constrained_vars(:,1)=oo_.dr.inv_order_var(constrained_vars); % must be in decision rule order
constrained_vars = oo_.dr.inv_order_var(constrained_vars); % must be in decision rule order
if n1 ~= n2 if n1 ~= n2
error(['imcforecast:: The number of constrained variables doesn''t match the number of controlled shocks']) error('imcforecast:: The number of constrained variables doesn''t match the number of controlled shocks')
end end
idx = []; % Get indices of controlled varexo.
jdx = []; [~, controlled_varexo] = ismember(options_cond_fcst.controlled_varexo,M_.exo_names);
for i = 1:n1 mv = zeros(n1, NumberOfStates);
idx = [idx ; constrained_vars(i,:)]; mu = zeros(ExoSize, n2);
% idx = [idx ; oo_.dr.inv_order_var(constrained_vars(i,:))];
jdx = [jdx ; strmatch(options_cond_fcst.controlled_varexo{i},M_.exo_names,'exact')];
end
mv = zeros(n1,NumberOfStates);
mu = zeros(ExoSize,n2);
for i=1:n1 for i=1:n1
mv(i,idx(i)) = 1; mv(i,constrained_vars(i)) = 1;
mu(jdx(i),i) = 1; mu(controlled_varexo(i),i) = 1;
end end
% number of periods with constrained values % number of periods with constrained values
...@@ -243,7 +240,7 @@ cL = size(constrained_paths,2); ...@@ -243,7 +240,7 @@ cL = size(constrained_paths,2);
%transform constrained periods into deviations from steady state; note that %transform constrained periods into deviations from steady state; note that
%trend includes last actual data point and therefore we need to start in %trend includes last actual data point and therefore we need to start in
%period 2 %period 2
constrained_paths = bsxfun(@minus,constrained_paths,trend(idx,2:1+cL)); constrained_paths = bsxfun(@minus,constrained_paths,trend(constrained_vars,2:1+cL));
FORCS1_shocks = zeros(n1,cL,options_cond_fcst.replic); FORCS1_shocks = zeros(n1,cL,options_cond_fcst.replic);
...@@ -251,7 +248,7 @@ FORCS1_shocks = zeros(n1,cL,options_cond_fcst.replic); ...@@ -251,7 +248,7 @@ FORCS1_shocks = zeros(n1,cL,options_cond_fcst.replic);
for b=1:options_cond_fcst.replic %conditional forecast using cL set to constrained values for b=1:options_cond_fcst.replic %conditional forecast using cL set to constrained values
shocks = sQ*randn(ExoSize,options_cond_fcst.periods); shocks = sQ*randn(ExoSize,options_cond_fcst.periods);
shocks(jdx,:) = zeros(length(jdx),options_cond_fcst.periods); shocks(controlled_varexo,:) = zeros(n1, options_cond_fcst.periods);
[FORCS1(:,:,b), FORCS1_shocks(:,:,b)] = mcforecast3(cL,options_cond_fcst.periods,constrained_paths,shocks,FORCS1(:,:,b),T,R,mv, mu); [FORCS1(:,:,b), FORCS1_shocks(:,:,b)] = mcforecast3(cL,options_cond_fcst.periods,constrained_paths,shocks,FORCS1(:,:,b),T,R,mv, mu);
FORCS1(:,:,b)=FORCS1(:,:,b)+trend; %add trend FORCS1(:,:,b)=FORCS1(:,:,b)+trend; %add trend
end end
...@@ -283,11 +280,9 @@ clear FORCS1 mFORCS1_shocks; ...@@ -283,11 +280,9 @@ clear FORCS1 mFORCS1_shocks;
FORCS2 = zeros(NumberOfStates,options_cond_fcst.periods+1,options_cond_fcst.replic); FORCS2 = zeros(NumberOfStates,options_cond_fcst.periods+1,options_cond_fcst.replic);
FORCS2(:,1,:) = repmat(InitState,1,options_cond_fcst.replic); %set initial steady state to deviations from steady state in first period FORCS2(:,1,:) = repmat(InitState,1,options_cond_fcst.replic); %set initial steady state to deviations from steady state in first period
%randn('state',0);
for b=1:options_cond_fcst.replic %conditional forecast using cL set to 0 for b=1:options_cond_fcst.replic %conditional forecast using cL set to 0
shocks = sQ*randn(ExoSize,options_cond_fcst.periods); shocks = sQ*randn(ExoSize,options_cond_fcst.periods);
shocks(jdx,:) = zeros(length(jdx),options_cond_fcst.periods); shocks(controlled_varexo,:) = zeros(n1, options_cond_fcst.periods);
FORCS2(:,:,b) = mcforecast3(0,options_cond_fcst.periods,constrained_paths,shocks,FORCS2(:,:,b),T,R,mv, mu)+trend; FORCS2(:,:,b) = mcforecast3(0,options_cond_fcst.periods,constrained_paths,shocks,FORCS2(:,:,b),T,R,mv, mu)+trend;
end end
...@@ -298,8 +293,8 @@ for i = 1:EndoSize ...@@ -298,8 +293,8 @@ for i = 1:EndoSize
tmp = sort(squeeze(FORCS2(i,:,:))'); tmp = sort(squeeze(FORCS2(i,:,:))');
forecasts.uncond.ci.(M_.endo_names{oo_.dr.order_var(i)}) = [tmp(t1,:)' ,tmp(t2,:)' ]'; forecasts.uncond.ci.(M_.endo_names{oo_.dr.order_var(i)}) = [tmp(t1,:)' ,tmp(t2,:)' ]';
end end
forecasts.graph.title=graph_title; forecasts.graph.title = graph_title;
forecasts.graph.fname=M_.fname; forecasts.graph.fname = M_.fname;
%reset qz_criterium %reset qz_criterium
options_.qz_criterium=qz_criterium_old; options_.qz_criterium=qz_criterium_old;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment