Block decomposition: static and dynamic files are now pure wrappers around the per-block files
Systematically call top-level static/dynamic files, instead of per-block ones.time-shift
parent
ebc0b7ecb2
commit
41fe087106
|
@ -77,8 +77,7 @@ else
|
|||
it_=M_.maximum_lag+1;
|
||||
y=dynvars_from_endo_simul(z, it_, M_);
|
||||
for blk = 1:length(M_.block_structure.block)
|
||||
funcname = sprintf('%s.block.dynamic_%d', M_.fname, blk);
|
||||
[~, T, data(blk).g1, data(blk).g1_x, data(blk).g1_xd, data(blk).g1_o]=feval(funcname, y, zx, M_.params, dr.ys, T, it_, true);
|
||||
[~, ~, T, data(blk).g1, data(blk).g1_x, data(blk).g1_xd, data(blk).g1_o]=feval([M_.fname '.dynamic'], blk, y, zx, M_.params, dr.ys, T, it_, true);
|
||||
end
|
||||
end
|
||||
dr.full_rank = 1;
|
||||
|
|
|
@ -37,7 +37,7 @@ if options.block && ~options.bytecode
|
|||
ss(M.block_structure_stat.block(b).variable) = y;
|
||||
else
|
||||
n = length(M.block_structure_stat.block(b).variable);
|
||||
[ss, T, ~, check] = solve_one_boundary([M.fname '.block.static_' int2str(b)], ss, exo, ...
|
||||
[ss, T, ~, check] = solve_one_boundary([M.fname '.static' ], ss, exo, ...
|
||||
params, [], T, M.block_structure_stat.block(b).variable, n, 1, false, b, 0, options.simul.maxit, ...
|
||||
options.solve_tolf, ...
|
||||
options.slowc, 0, options.solve_algo, true, false, false, M, options, []);
|
||||
|
@ -47,8 +47,9 @@ if options.block && ~options.bytecode
|
|||
end
|
||||
end
|
||||
end
|
||||
% In particular, the following updates the temporary terms vector (for the dynare_solve case)
|
||||
[r, x, T, g1] = feval([M.fname '.static'], b, ss, exo, params, T);
|
||||
% Compute endogenous if the block is of type evaluate forward/backward
|
||||
% Also update the temporary terms vector (needed for the dynare_solve case)
|
||||
[~, x, T, g1] = feval([M.fname '.static'], b, ss, exo, params, T);
|
||||
end
|
||||
elseif options.bytecode
|
||||
if options.solve_algo > 4
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
function r = lnsrch1_wrapper_one_boundary(ya, ll_index, fname, y, x, params, steady_state, T, it_)
|
||||
function r = lnsrch1_wrapper_one_boundary(ya, ll_index, fname, blk, y, x, params, steady_state, T, it_)
|
||||
% wrapper for solve_one_boundary m-file when it is used with a dynamic
|
||||
% model
|
||||
%
|
||||
% INPUTS
|
||||
% ya [vector] The endogenous of the current block
|
||||
% ll_index [vector] M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)
|
||||
% fname [string] name of the file containing the block
|
||||
% to simulate
|
||||
% fname [string] name of the static/dynamic file
|
||||
% blk [int] block number
|
||||
% y [vector] Dynamic endogenous variables of the model
|
||||
% x [matrix] All the exogenous variables of the model
|
||||
% params [vector] All the parameters of the model
|
||||
|
@ -40,4 +40,4 @@ function r = lnsrch1_wrapper_one_boundary(ya, ll_index, fname, y, x, params, ste
|
|||
% along with Dynare. If not, see <http://www.gnu.org/licen
|
||||
|
||||
y2(nonzeros(ll_index)) = ya(find(ll_index));
|
||||
[r, ~, g1]=feval(fname, y, x, params, steady_state, T, it_, false);
|
||||
[r, ~, ~, g1]=feval(fname, blk, y, x, params, steady_state, T, it_, false);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
|
||||
function ra = lnsrch1_wrapper_two_boundaries(ya, fname, blk, y, y_index, x, ...
|
||||
params, steady_state, T, periods, ...
|
||||
y_size, M_)
|
||||
% wrapper for solve_one_boundary m-file when it is used with a dynamic
|
||||
|
@ -8,8 +8,8 @@ function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
|
|||
% ya [vector] The endogenous of the current block
|
||||
% y_index [vector of int] The index of the endogenous variables of
|
||||
% the block
|
||||
% fname [string] name of the file containing the block
|
||||
% to simulate
|
||||
% fname [string] name of the dynamic file
|
||||
% blk [int] block number
|
||||
% y [matrix] All the endogenous variables of the model
|
||||
% x [matrix] All the exogenous variables of the model
|
||||
% params [vector] All the parameters of the model
|
||||
|
@ -51,5 +51,5 @@ function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
|
|||
y(y_index, M_.maximum_lag+(1:periods)) = reshape(ya',length(y_index),periods);
|
||||
ra = NaN(periods*y_size, 1);
|
||||
for it_ = M_.maximum_lag+(1:periods)
|
||||
[ra((it_-M_.maximum_lag-1)*y_size+(1:y_size)), ~, g1]=feval(fname, dynvars_from_endo_simul(y, it_, M_), x, params, steady_state, T(:, it_), it_, false);
|
||||
[ra((it_-M_.maximum_lag-1)*y_size+(1:y_size)), ~, ~, g1]=feval(fname, blk, dynvars_from_endo_simul(y, it_, M_), x, params, steady_state, T(:, it_), it_, false);
|
||||
end
|
||||
|
|
|
@ -43,9 +43,9 @@ y=oo_.endo_simul;
|
|||
T=NaN(M_.block_structure.dyn_tmp_nbr, options_.periods+M_.maximum_lag+M_.maximum_lead);
|
||||
oo_.deterministic_simulation.status = 0;
|
||||
|
||||
funcname = [ M_.fname '.dynamic'];
|
||||
|
||||
for blk = 1:length(M_.block_structure.block)
|
||||
funcname = sprintf('%s.block.dynamic_%d', M_.fname, blk);
|
||||
|
||||
recursive_size = M_.block_structure.block(blk).endo_nbr - M_.block_structure.block(blk).mfs;
|
||||
y_index = M_.block_structure.block(blk).variable((recursive_size+1):end);
|
||||
|
||||
|
@ -64,7 +64,7 @@ for blk = 1:length(M_.block_structure.block)
|
|||
end
|
||||
for it_ = range
|
||||
y2 = dynvars_from_endo_simul(y, it_, M_);
|
||||
[y2, T(:, it_)] = feval(funcname, y2, oo_.exo_simul, M_.params, oo_.steady_state, T(:, it_), it_, false);
|
||||
[~, y2, T(:, it_)] = feval(funcname, blk, y2, oo_.exo_simul, M_.params, oo_.steady_state, T(:, it_), it_, false);
|
||||
y(find(M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)), it_) = y2(nonzeros(M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)));
|
||||
end
|
||||
elseif M_.block_structure.block(blk).Simulation_Type == 3 || ... % solveForwardSimple
|
||||
|
|
|
@ -71,11 +71,16 @@ if options_.block && ~options_.bytecode
|
|||
z = zeros(M_.endo_nbr,1);
|
||||
T = NaN(M_.block_structure_stat.tmp_nbr, 1);
|
||||
for i = 1:length(M_.block_structure_stat.block)
|
||||
[r, yy, T, g, var_indx] = feval([M_.fname '.static'],...
|
||||
i,...
|
||||
oo_.steady_state,...
|
||||
[oo_.exo_steady_state; ...
|
||||
oo_.exo_det_steady_state], M_.params, T);
|
||||
[r, yy, T, g] = feval([M_.fname '.static'],...
|
||||
i,...
|
||||
oo_.steady_state,...
|
||||
[oo_.exo_steady_state; ...
|
||||
oo_.exo_det_steady_state], M_.params, T);
|
||||
if M_.block_structure_stat.block(i).Simulation_Type == 1 || ... % evaluateForward
|
||||
M_.block_structure_stat.block(i).Simulation_Type == 2 % evaluateBackward
|
||||
vidx = M_.block_structure_stat.block(i).variable;
|
||||
r = yy(vidx) - oo_.steady_state(vidx);
|
||||
end
|
||||
idx = M_.block_structure_stat.block(i).equation;
|
||||
z(idx) = r;
|
||||
end
|
||||
|
|
|
@ -92,9 +92,9 @@ for it_=start:incr:finish
|
|||
g1=spalloc( Blck_size, Blck_size, nze);
|
||||
while ~(cvg==1 || iter>maxit_)
|
||||
if is_dynamic
|
||||
[r, T(:, it_), g1] = feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
|
||||
[r, ~, T(:, it_), g1] = feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
|
||||
else
|
||||
[r, T, g1] = feval(fname, y, x, params, T);
|
||||
[r, ~, T, g1] = feval(fname, Block_Num, y, x, params, T);
|
||||
end
|
||||
if ~isreal(r)
|
||||
max_res=(-(max(max(abs(r))))^2)^0.5;
|
||||
|
@ -203,9 +203,9 @@ for it_=start:incr:finish
|
|||
p = -g1\r ;
|
||||
[ya,f,r,check]=lnsrch1(ya,f,g,p,stpmax, ...
|
||||
'lnsrch1_wrapper_one_boundary',nn, ...
|
||||
y_index_eq, options.solve_tolx, M.lead_lag_incidence(M.maximum_endo_lag+1, :), fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_);
|
||||
y_index_eq, options.solve_tolx, M.lead_lag_incidence(M.maximum_endo_lag+1, :), fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_);
|
||||
%% Recompute temporary terms, since they are not given as output of lnsrch1
|
||||
[~, T(:, it_)] = feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
|
||||
[~, ~, T(:, it_)] = feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
|
||||
dx = ya' - y(index_eq, it_);
|
||||
y(index_eq, it_) = ya;
|
||||
elseif (is_dynamic && (stack_solve_algo==1 || stack_solve_algo==0)) || (~is_dynamic && options.solve_algo==6)
|
||||
|
@ -262,10 +262,10 @@ for it_=start:incr:finish
|
|||
y(y_index_eq) = phat;
|
||||
end
|
||||
if is_dynamic
|
||||
[r, T(:, it_), g1] = feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, ...
|
||||
[r, ~, T(:, it_), g1] = feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, ...
|
||||
steady_state, T(:, it_), it_, false);
|
||||
else
|
||||
[r, T, g1] = feval(fname, y, x, params, T);
|
||||
[r, ~, T, g1] = feval(fname, Block_Num, y, x, params, T);
|
||||
end
|
||||
if max(abs(r))>=options.solve_tolf
|
||||
[dx,flag1] = bicgstab(g1,-r,1e-7,Blck_size,L1,U1);
|
||||
|
|
|
@ -83,7 +83,7 @@ while ~(cvg==1 || iter>maxit_)
|
|||
r = NaN(Blck_size, periods);
|
||||
g1a = spalloc(Blck_size*periods, Blck_size*periods, nze*periods);
|
||||
for it_ = y_kmin+(1:periods)
|
||||
[r(:, it_-y_kmin), T(:, it_), g1]=feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
|
||||
[r(:, it_-y_kmin), ~, T(:, it_), g1]=feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
|
||||
if periods == 1
|
||||
g1a = g1(:, Blck_size+(1:Blck_size));
|
||||
elseif it_ == y_kmin+1
|
||||
|
@ -314,7 +314,7 @@ while ~(cvg==1 || iter>maxit_)
|
|||
g = (ra'*g1a)';
|
||||
f = 0.5*ra'*ra;
|
||||
p = -g1a\ra;
|
||||
[yn,f,ra,check]=lnsrch1(ya,f,g,p,stpmax,'lnsrch1_wrapper_two_boundaries',nn,nn, options.solve_tolx, fname, y, y_index,x, params, steady_state, T, periods, Blck_size, M);
|
||||
[yn,f,ra,check]=lnsrch1(ya,f,g,p,stpmax,'lnsrch1_wrapper_two_boundaries',nn,nn, options.solve_tolx, fname, Block_Num, y, y_index,x, params, steady_state, T, periods, Blck_size, M);
|
||||
dx = ya - yn;
|
||||
y(y_index, y_kmin+(1:periods))=reshape(yn',length(y_index),periods);
|
||||
end
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f4d2ce70dafd1331791b2fd96f3468b3f6c103da
|
||||
Subproject commit f098329c74225d68fe84f2a5aa32721c2b76036c
|
Loading…
Reference in New Issue