* Added initialization of the newton steps (for the extended path

algorithm) with the solution of the linearized model.
* Bug fixes
* Cosmetic changes.


git-svn-id: https://www.dynare.org/svn/dynare/trunk@3295 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
stepan 2009-12-29 16:33:08 +00:00
parent 2d0fff0292
commit 9d77d667e7
3 changed files with 30 additions and 14 deletions

View File

@ -60,6 +60,7 @@ if init
oldopt = options_; oldopt = options_;
options_.order = 1; options_.order = 1;
[dr,info]=resol(oo_.steady_state,0); [dr,info]=resol(oo_.steady_state,0);
oo_.dr = dr;
options_ = oldopt; options_ = oldopt;
if init==2 if init==2
lambda = .8; lambda = .8;
@ -96,14 +97,18 @@ for t=1:sample_size
oo_.endo_simul = initial_path(:,1:end-1)*lambda + oo_.endo_simul*(1-lambda); oo_.endo_simul = initial_path(:,1:end-1)*lambda + oo_.endo_simul*(1-lambda);
end end
end end
info = perfect_foresight_simulation; if init
info = perfect_foresight_simulation(dr,oo_.steady_state);
else
info = perfect_foresight_simulation;
end
time = info.time; time = info.time;
if verbose if verbose
t t
info info
end end
if ~info.convergence if ~info.convergence
info = homotopic_steps(tdx,positive_var_indx,shocks,norme,.5); info = homotopic_steps(tdx,positive_var_indx,shocks,norme,.5,init);
if verbose if verbose
norme norme
info info
@ -122,7 +127,7 @@ end
function info = homotopic_steps(tdx,positive_var_indx,shocks,init_weight,step) function info = homotopic_steps(tdx,positive_var_indx,shocks,init_weight,step,init)
global oo_ global oo_
weight = init_weight; weight = init_weight;
verbose = 1; verbose = 1;
@ -134,7 +139,11 @@ function info = homotopic_steps(tdx,positive_var_indx,shocks,init_weight,step)
old_weight = weight; old_weight = weight;
weight = weight+step; weight = weight+step;
oo_.exo_simul(tdx,positive_var_indx) = weight*shocks+(1-weight); oo_.exo_simul(tdx,positive_var_indx) = weight*shocks+(1-weight);
info = perfect_foresight_simulation; if init
info = perfect_foresight_simulation(oo_.dr,oo_.steady_state);
else
info = perfect_foresight_simulation;
end
time = time+info.time; time = time+info.time;
if verbose if verbose
[iter,step] [iter,step]
@ -157,11 +166,15 @@ function info = homotopic_steps(tdx,positive_var_indx,shocks,init_weight,step)
end end
if reduce_step if reduce_step
step=step/1.5; step=step/1.5;
info = homotopic_steps(tdx,positive_var_indx,shocks,old_weight,step); info = homotopic_steps(tdx,positive_var_indx,shocks,old_weight,step,init);
time = time+info.time; time = time+info.time;
elseif weight<1 && iter<100 elseif weight<1 && iter<100
oo_.exo_simul(tdx,positive_var_indx) = shocks; oo_.exo_simul(tdx,positive_var_indx) = shocks;
info = perfect_foresight_simulation; if init
info = perfect_foresight_simulation(oo_.dr,oo_.steady_state);
else
info = perfect_foresight_simulation;
end
info.time = info.time+time; info.time = info.time+time;
else else
info.time = time; info.time = time;

View File

@ -48,7 +48,7 @@ elseif size(oo_.endo_simul,2) < M_.maximum_lag+M_.maximum_lead+options_.periods
case 0 case 0
oo_.endo_simul = [oo_.endo_simul ... oo_.endo_simul = [oo_.endo_simul ...
oo_.steady_state*ones(1,M_.maximum_lag+options_.periods+M_.maximum_lead-size(oo_.endo_simul,2),1)]; oo_.steady_state*ones(1,M_.maximum_lag+options_.periods+M_.maximum_lead-size(oo_.endo_simul,2),1)];
case 1% A linear approximation is used to initiate the solution. case 1% A linear approximation is used to initialize the solution.
oldopt = options_; oldopt = options_;
options_.order = 1; options_.order = 1;
dr = oo_.dr; dr = oo_.dr;

View File

@ -70,8 +70,14 @@ else
end end
end end
if compute_linear_solution if ~isstruct(compute_linear_solution) && compute_linear_solution
[dr,info]=resol(steady_state,0); [dr,info]=resol(steady_state,0);
elseif isstruct(compute_linear_solution)
dr = compute_linear_solution;
compute_linear_solution = 1;
end
if compute_linear_solution
ghx = dr.ghx(end-dr.nfwrd+1:end,:); ghx = dr.ghx(end-dr.nfwrd+1:end,:);
end end
@ -104,7 +110,7 @@ for iter = 1:options_.maxit_
ic = 1:ny; ic = 1:ny;
icp = iyp; icp = iyp;
c(ic,:) = jacobian(:,is)\jacobian(:,isf1) ; c(ic,:) = jacobian(:,is)\jacobian(:,isf1) ;
for it_ = it_init+(1:periods-1) for it_ = it_init+(1:periods-1-(options_.terminal_condition==2))
z = [ oo_.endo_simul(iyp,it_-1) ; oo_.endo_simul(:,it_) ; oo_.endo_simul(iyf,it_+1)]; z = [ oo_.endo_simul(iyp,it_-1) ; oo_.endo_simul(:,it_) ; oo_.endo_simul(iyf,it_+1)];
[d1,jacobian] = feval(dynamic_model,z,oo_.exo_simul, M_.params, it_); [d1,jacobian] = feval(dynamic_model,z,oo_.exo_simul, M_.params, it_);
jacobian = [jacobian(:,iz) , -d1]; jacobian = [jacobian(:,iz) , -d1];
@ -120,6 +126,7 @@ for iter = 1:options_.maxit_
ic = ic + ny; ic = ic + ny;
c(ic,nrc) = s\c(ic,nrc); c(ic,nrc) = s\c(ic,nrc);
else% Terminal condition is Y_{T+1}-Y^{\star} = TransitionMatrix*(Y_{T}-Y^{\star}) else% Terminal condition is Y_{T+1}-Y^{\star} = TransitionMatrix*(Y_{T}-Y^{\star})
it_ = it_+1;
z = [ oo_.endo_simul(iyp,it_-1) ; oo_.endo_simul(:,it_) ; oo_.endo_simul(iyf,it_+1) ] ; z = [ oo_.endo_simul(iyp,it_-1) ; oo_.endo_simul(:,it_) ; oo_.endo_simul(iyf,it_+1) ] ;
[d1,jacobian] = feval(dynamic_model,z,oo_.exo_simul, M_.params, it_); [d1,jacobian] = feval(dynamic_model,z,oo_.exo_simul, M_.params, it_);
jacobian = [jacobian(:,iz) -d1]; jacobian = [jacobian(:,iz) -d1];
@ -127,16 +134,12 @@ for iter = 1:options_.maxit_
ic = ic + ny; ic = ic + ny;
icp = icp + ny; icp = icp + ny;
s = jacobian(:,is); s = jacobian(:,is);
iyp
nyp
isf
iyp-nyp
s(:,iyp-nyp) = s(:,iyp-nyp)+jacobian(:,isf)*ghx; s(:,iyp-nyp) = s(:,iyp-nyp)+jacobian(:,isf)*ghx;
c (ic,:) = s\jacobian(:,isf1); c (ic,:) = s\jacobian(:,isf1);
end end
c = bksup0(c,ny,nrc,iyf,icf,periods); c = bksup0(c,ny,nrc,iyf,icf,periods);
c = reshape(c,ny,periods+1); c = reshape(c,ny,periods+1);
endo_simul(:,it_init+(0:periods)) = endo_simul(:,it_init+(0:periods))+options_.slowc*c; oo_.endo_simul(:,it_init+(0:periods)) = oo_.endo_simul(:,it_init+(0:periods))+options_.slowc*c;
else% Terminal condition is Y_{T}=Y^{\star} else% Terminal condition is Y_{T}=Y^{\star}
c = bksup0(c,ny,nrc,iyf,icf,periods); c = bksup0(c,ny,nrc,iyf,icf,periods);
c = reshape(c,ny,periods); c = reshape(c,ny,periods);