Merge pull request #1148 from JohannesPfeifer/foresight_imaginary
Add check whether real part of complex solution solves the modeltime-shift
commit
62efd9930e
|
@ -173,7 +173,31 @@ if ~oo_.deterministic_simulation.status && ~options_.no_homotopy
|
||||||
warning(warning_old_state);
|
warning(warning_old_state);
|
||||||
end
|
end
|
||||||
|
|
||||||
if oo_.deterministic_simulation.status == 1
|
|
||||||
|
if ~isreal(oo_.endo_simul(:)) %can only happen without bytecode
|
||||||
|
y0 = real(oo_.endo_simul(:,1));
|
||||||
|
yT = real(oo_.endo_simul(:,options_.periods+2));
|
||||||
|
yy = real(oo_.endo_simul(:,2:options_.periods+1));
|
||||||
|
illi = M_.lead_lag_incidence';
|
||||||
|
[i_cols,junk,i_cols_j] = find(illi(:));
|
||||||
|
illi = illi(:,2:3);
|
||||||
|
[i_cols_J1,junk,i_cols_1] = find(illi(:));
|
||||||
|
i_cols_T = nonzeros(M_.lead_lag_incidence(1:2,:)');
|
||||||
|
residuals = perfect_foresight_problem(yy(:),str2func([M_.fname '_dynamic']), y0, yT, ...
|
||||||
|
oo_.exo_simul,M_.params,oo_.steady_state, ...
|
||||||
|
M_.maximum_lag,options_.periods,M_.endo_nbr,i_cols, ...
|
||||||
|
i_cols_J1, i_cols_1, i_cols_T, i_cols_j, ...
|
||||||
|
M_.NNZDerivatives(1));
|
||||||
|
if max(abs(residuals))< options_.dynatol.f
|
||||||
|
oo_.deterministic_simulation.status = 1;
|
||||||
|
oo_.endo_simul=real(oo_.endo_simul);
|
||||||
|
else
|
||||||
|
oo_.deterministic_simulation.status = 0;
|
||||||
|
disp('Simulation terminated with imaginary parts in the residuals or endogenous variables.')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if oo_.deterministic_simulation.status == 1
|
||||||
disp('Perfect foresight solution found.')
|
disp('Perfect foresight solution found.')
|
||||||
else
|
else
|
||||||
disp('Failed to solve perfect foresight model')
|
disp('Failed to solve perfect foresight model')
|
||||||
|
|
|
@ -186,7 +186,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
if stop
|
if stop
|
||||||
if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y)) || ~isreal(res) || ~isreal(Y)
|
if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y))
|
||||||
oo.deterministic_simulation.status = false;% NaN or Inf occurred
|
oo.deterministic_simulation.status = false;% NaN or Inf occurred
|
||||||
oo.deterministic_simulation.error = err;
|
oo.deterministic_simulation.error = err;
|
||||||
oo.deterministic_simulation.iterations = iter;
|
oo.deterministic_simulation.iterations = iter;
|
||||||
|
@ -195,11 +195,7 @@ if stop
|
||||||
if verbose
|
if verbose
|
||||||
skipline()
|
skipline()
|
||||||
disp(sprintf('Total time of simulation: %s.', num2str(etime(clock,h1))))
|
disp(sprintf('Total time of simulation: %s.', num2str(etime(clock,h1))))
|
||||||
if ~isreal(res) || ~isreal(Y)
|
disp('Simulation terminated with NaN or Inf in the residuals or endogenous variables.')
|
||||||
disp('Simulation terminated with imaginary parts in the residuals or endogenous variables.')
|
|
||||||
else
|
|
||||||
disp('Simulation terminated with NaN or Inf in the residuals or endogenous variables.')
|
|
||||||
end
|
|
||||||
disp('There is most likely something wrong with your model. Try model_diagnostics or another simulation method.')
|
disp('There is most likely something wrong with your model. Try model_diagnostics or another simulation method.')
|
||||||
printline(105)
|
printline(105)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue