Skip to content
Snippets Groups Projects
Verified Commit 63564e7d authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Discretionary policy: use sparse representation for the dynamic Jacobian

Ref. #1859
parent 14518f55
No related branches found
No related tags found
No related merge requests found
...@@ -76,32 +76,20 @@ g2_v = feval([M_.fname,'.objective.sparse.static_g2'], y, [], params, T_order, T ...@@ -76,32 +76,20 @@ g2_v = feval([M_.fname,'.objective.sparse.static_g2'], y, [], params, T_order, T
W = build_two_dim_hessian(M_.objective_g2_sparse_indices, g2_v, 1, M_.endo_nbr); W = build_two_dim_hessian(M_.objective_g2_sparse_indices, g2_v, 1, M_.endo_nbr);
W=reshape(W,M_.endo_nbr,M_.endo_nbr); W=reshape(W,M_.endo_nbr,M_.endo_nbr);
klen = M_.maximum_lag + M_.maximum_lead + 1;
iyv=M_.lead_lag_incidence';
% Find the jacobian % Find the jacobian
z = repmat(ys,1,klen); y3n = repmat(ys, 1, 3);
iyr0 = find(iyv(:)) ; x = zeros(M_.exo_nbr+M_.exo_det_nbr, 1);
[resid, T_order, T] = feval([M_.fname '.sparse.dynamic_resid'], y3n, x, M_.params, ys);
z = z(iyr0); if max(abs(resid)) > options_.solve_tolf
it_ = M_.maximum_lag + 1 ;
[junk,jacobia_] = feval([M_.fname '.dynamic'],z,zeros(M_.exo_nbr+M_.exo_det_nbr,klen), M_.params, ys, it_);
if max(abs(junk))>options_.solve_tolf
info = 65; %the model must be written in deviation form and not have constant terms or have a steady state provided info = 65; %the model must be written in deviation form and not have constant terms or have a steady state provided
return; return;
end end
g1 = feval([M_.fname '.sparse.dynamic_g1'], y3n, x, M_.params, ys, M_.dynamic_g1_sparse_rowval, M_.dynamic_g1_sparse_colval, M_.dynamic_g1_sparse_colptr, T_order, T);
Indices={'lag','contemp','lead'}; A.lag = full(g1(:,1:M_.endo_nbr));
iter=1; A.contemp = full(g1(:,M_.endo_nbr+(1:M_.endo_nbr)));
for j=1:numel(Indices) A.lead = full(g1(:,2*M_.endo_nbr+(1:M_.endo_nbr)));
A.(Indices{j})=zeros(M_.eq_nbr,M_.endo_nbr); B = full(g1(:,3*M_.endo_nbr+1:end));
if strcmp(Indices{j},'contemp')||(strcmp(Indices{j},'lag') && M_.maximum_lag)||(strcmp(Indices{j},'lead') && M_.maximum_lead)
[~,row,col]=find(M_.lead_lag_incidence(iter,:));
A.(Indices{j})(:,row)=jacobia_(:,col);
iter=iter+1;
end
end
B=jacobia_(:,nnz(iyv)+1:end);
%%% MAIN ENGINE %%% %%% MAIN ENGINE %%%
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment