Commit Graph

276 Commits (6adf1c26392d737dc31844aa3add0441e040f4a8)

Author SHA1 Message Date
Sébastien Villemot c3d91d5ce8
Fix marginal linearization in the context of perfect_foresight_with_expectation_errors_solver with homotopy
If a solution corresponding to 100% of the shock can’t be found in the first
informational period, marginal linearization will be performed to extrapolate a
solution.

However, in subsequent informational periods, this extrapolated solution cannot
be used for the initial conditions of endogenous variables, because the initial
conditions are not a true solution of the nonlinear model. For those subsequent
informational periods, the correct approach is to compute the two solutions
needed for marginal linearization using as initial conditions the values
obtained in the same two solutions for the previous informational
periods (stored as oo_.deterministic_simulation.{sim1,sim2}).
2023-11-28 16:26:49 +01:00
Sébastien Villemot c6c6f4f549
perfect_foresight_solver + homotopy + (marginal) linearization: store intermediate simulations
First simulation before doing extrapolation is stored in several fields of
oo_.deterministic_simulation.sim1.

For marginal linearization, the second simulation used to compute the marginal
contribution is stored in oo_.deterministic_simulation.sim2.
2023-11-28 12:29:34 +01:00
Sébastien Villemot b513214570
perfect_foresight_homotopy: minor simplification 2023-11-22 20:34:03 +01:00
Sébastien Villemot 9545dcc8d9
perfect_foresight_solver.m: improve local functions documentation 2023-11-22 20:34:02 +01:00
Sébastien Villemot 08c9eca8ee
perfect foresight homotopy + marginal linearization: fix percentages in information messages 2023-11-22 20:34:02 +01:00
Sébastien Villemot 77a7d5c3de
For bytecode+block, use the LBJ implementation in .m
The latter is now much faster than the implementation in the bytecode
MEX (which this commit thus removes).
2023-11-08 17:21:44 +01:00
Sébastien Villemot be648d350b
Much faster .m implementation of LBJ with block option 2023-11-08 17:21:42 +01:00
Sébastien Villemot 0839ff78ae
🐛 sim1_lbj.m: use options_.dynatol.x and not options_.dynatol.f for terminal condition
The maximum error is computed over the change in endogenous (i.e. ΔY).
2023-11-08 17:15:18 +01:00
Sébastien Villemot 4bee919c31
sim1_lbj.m: misc cosmetic changes 2023-11-08 17:15:02 +01:00
Sébastien Villemot 158b7462bf
solve_two_boundaries.m: strip down the number of input arguments 2023-11-08 17:10:29 +01:00
Sébastien Villemot b1b76f7783 Merge branch 'naming_consistency' into 'master'
Implement even more naming consistency

See merge request Dynare/dynare!2203
2023-10-25 20:30:11 +00:00
Johannes Pfeifer 0561200f1c Implement even more naming consistency
Mostly removes M for M_
2023-10-25 17:29:55 +02:00
Sébastien Villemot aca148e8ef
Minor simplification 2023-10-25 15:57:57 +02:00
Sébastien Villemot 0295e5ede8 Merge branch 'variable_naming' into 'master'
Move many functions towards consistent naming

See merge request Dynare/dynare!2202
2023-10-25 13:56:17 +00:00
Johannes Pfeifer 879d92fbf8 Move many functions towards consistent naming
Related to #1776
2023-10-24 22:21:15 +02:00
Sébastien Villemot caaa70ab7e
Perfect foresight + block decomposition: minor simplifications 2023-10-24 17:36:51 +02:00
Sébastien Villemot 17b016d983
Perfect foresight: with stack_solve_algo={1,6}+bytecode (without block), use the same solver as without bytecode
The solver in the bytecode MEX is slower.
2023-10-24 15:26:55 +02:00
Sébastien Villemot 88ce107466
Rename ys0_ into oo_.initial_steady_state and ex0_ into oo_.initial_exo_steady_state
Also document these variables.
2023-10-24 09:38:51 +02:00
Sébastien Villemot 8c3429bb0f
Perfect foresight with expectation errors: change the semantics of endval(learnt_in=…)
Similarly to the regular “endval” block, any variable mentioned in this
block will jump to its new value in the period where the information is learnt.
In particular, this means that any temporary shock that may have been
anticipated on that variable (as specified through a “shocks(learnt_in=...)”
block for a previous informational period) will be overwritten.
2023-10-20 16:05:56 -04:00
Sébastien Villemot df9c7d85b8
Error out if perfect_foresight_solver is called with shocks(learnt_in=…) or endval(learnt_in=…) blocks
This is to prevent the accidental use of the regular perfect foresight solver
when one actually wants the one with expectation errors.
2023-10-20 16:05:53 -04:00
Sébastien Villemot 7449d26e51
Perfect foresight with homotopy + marginal linearization: improve info messages 2023-10-20 14:57:22 -04:00
Sébastien Villemot 5145bd0708
New option “relative_to_initval” to “mshocks” block 2023-10-18 16:45:06 -04:00
Sébastien Villemot daa6b5569d
mshocks: better match to the semantics given in the manual
Ensure that the block is always interpreted multiplicatively relative to the
steady state, and not relative to the pre-existing shock value (if there was
already a shock declared for the same exogenous and period(s)).
2023-10-18 14:28:54 -04:00
Sébastien Villemot 39f9d4352a
The “mshocks” block now accepts the “learnt_in” option 2023-10-17 17:24:15 -04:00
Sébastien Villemot 4875554a39
Perfect foresight homotopy: make marginal linearization more robust
For marginal linearization, an extra simulation is needed. This extra
simulation is first computed using the first simulation as guess value. If that
does not work, the present commits adds an additional attempt for computing
that extra simulation, using a full homotopy loop from the beginning.

As a consequence, the present commits puts the homotopy loop in a dedicated
function.
2023-10-13 15:31:44 -04:00
Sébastien Villemot 2ae485705e
Perfect foresight homotopy: turn a nested function into a local one
The behaviour of local functions is easier to understand, since they do not
have access to the workspace of the caller.
2023-10-13 14:40:45 -04:00
Sébastien Villemot cc7c024389
Perfect foresight homotopy: display the full output of every iteration
As a consequence, print the full iterations summary table after each iteration.
2023-10-13 09:19:10 -04:00
Sébastien Villemot 9ebd8a8372
Make perfect foresight hotomopy loop more readable
Only modify oo_ when the homotopy procedure is finished, now that oo_ is no
longer an input to perfect_foresight_solver_core.

By the way, fix the treatment of the exogenous steady state (it is now set
in a consistent way with the endogenous steady state, if the shock is not
simulated up to 100%).

Also fix the initial guess when doing a second attempt at recomputing the
terminal steady state and failing (in the absence of a permanent shock). It was
supposed to use the initial steady state as an initial guess for that second
attempt (through oo_.steady_state), but since that latter variable was modified
in the loop, it would actually correspond to the same initial guess as in the
first attempt.
2023-10-13 09:16:37 -04:00
Sébastien Villemot a6eb943aae
Remove oo_ as an input argument to perfect_foresight_solver_core 2023-10-12 15:44:53 -04:00
Sébastien Villemot e4a4d2d8e6
Bytecode MEX: get M_ and options_ through input arguments rather than as global variables 2023-10-11 18:50:32 -04:00
Sébastien Villemot b59dc2cf1a
det_cond_forecast: fix bug with bytecode+block
The plan must immediately follow the “extended_path” string in the input
arguments of bytecode. Bug introduced in f84753025d.
2023-10-11 18:50:32 -04:00
Sébastien Villemot 88146bcc6f
solve_block_decomposed_problem: drop oo_ as an input argument 2023-10-11 18:50:32 -04:00
Sébastien Villemot f94e7ae9a6
Perfect foresight homotopy: display duration of every iteration 2023-10-11 18:50:32 -04:00
Johannes Pfeifer cbf57b1af6
set_state_space.m: remove unused options_ input argument 2023-10-11 09:30:45 -04:00
Johannes Pfeifer 8da98057b9
Have computation of decision rules and smoother only input and output required arguments instead of full oo_ and M_ 2023-09-25 17:17:34 +02:00
Sébastien Villemot 6747f2130e
Perfect foresight: fix illegal memory read with bytecode + endval_steady
The exogenous steady state vector was passed as a row-vector to
evaluate_steady_state, thus leading to an incorrectly-sized matrix passed to
bytecode when checking the steady state on the dynamic model (when different
from the static model).
2023-09-01 14:52:57 +02:00
Johannes Pfeifer 0729ee72af det_cond_forecast.m: cosmetic changes to error messages 2023-08-24 12:38:50 +02:00
Sébastien Villemot d5a3a8e16a
Various improvements to perfect foresight homotopy
– new option “endval_steady” to pf_setup command to recompute terminal
  steady state in the homotopy loop

– new options “homotopy_linearization_fallback” and
  “homotopy_marginal_linearization_fallback” to pf_solver and pfwee_solver
  commands, to get an approximate solution when homotopy fails to go to 100%

– new options “homotopy_initial_step_size”, “homotopy_min_step_size”,
  “homotopy_step_size_increase_success_count” and “homotopy_max_completion_share”
  to pf_solver and pfwee_solver commands to fine tune the homotopy behaviour

– removed option “homotopy_alt_starting_point” to pf_solver command, not really
  useful

– new options “steady_solve_algo”, “steady_tolf”, “steady_tolx”,
  “steady_maxit”, “steady_markowitz” to pf_solver and pfwee_solver commands, to
  control the computation of the terminal steady state (and remove the
  equivalent options which previously had different names in pfwee_solver command)
2023-06-21 15:58:23 +02:00
Sébastien Villemot 8fa37a0439
perfect_foresight_with_expectation_errors_solver: remove obsolete code
This should have been removed in c1b78e26ac
2023-06-16 16:45:04 +02:00
Sébastien Villemot d4b5e156d1
perfect_foresight_with_expectation_errors_solver: check convergence of informational iterations
Error out if an iteration failed.

Also display an informative message about those iterations.
2023-06-16 16:45:04 +02:00
Sébastien Villemot c1b78e26ac
perfect_foresight_with_expectation_errors_{setup,solver}: streamline handling of guess values
– Remove the terminal_steady_state_as_guess_value option to pfwee_solver
– pfwee_setup now sets the same guess values as pf_setup (i.e. terminal steady
  state at all periods)
– With constant_simulation_length option, pfwee_solver uses terminal steady
  state as guess values for periods that are added to the simulation
2023-06-15 15:37:48 +02:00
Sébastien Villemot dcf56b89cd
Bytecode: rework message verbosity
Now uses options_.verbosity to decide what to print:
– if options_.verbosity == 0, prints nothing
– if options_.verbosity >= 1, prints iteration counter and duration, and fatal errors
– if options_.verbosity >= 2, additionally print floating point exceptions and
  details about algorithmic decisions
2023-06-13 16:59:07 +02:00
Sébastien Villemot d81e3992c3
perfect_foresight_solver_core: fix crash when bytecode does not converge
The bug was introduced in commit 7722e8e36b
2023-06-12 19:19:21 +02:00
Sébastien Villemot 4431a89e87
perfect_foresight_solver_core.m: when relevant, use bytecode MEX to recompute ∞-norm of residuals
Since commit 7722e8e36b it would always use the
perfect_foresight_problem MEX, but the latter is less efficient than bytecode.
2023-06-12 19:18:45 +02:00
Sébastien Villemot 8cf8731c65
det_cond_forecast.m: use better syntax for ignored outputs 2023-06-12 19:18:44 +02:00
Sébastien Villemot 37870e4a40
evaluate_steady_state: accept exogenous steady state as argument instead of whole oo_ structure
This is a move towards a more functional programming style.
2023-06-07 17:58:19 +02:00
Sébastien Villemot 7722e8e36b
Perfect foresight: inner functions no longer return a modified oo_
They now only return what’s really their output (simulated paths, maximum
residual error…). This is a move towards a more functional programming style.
2023-06-06 18:13:10 +02:00
Sébastien Villemot fe142b663e
Perfect foresight: allow homotopy for purely backward/forward/static models
This was previously disabled, but the code seems to work.
2023-06-06 17:26:07 +02:00
Sébastien Villemot 1cf83dc278
perfect_foresight_solver: always use perfect_foresight_problem MEX for computing residuals
The MEX no works on models without leads or lags.

This is essentially a revert of 74dc4f81f0.

Ref. #1850
2023-06-06 17:06:10 +02:00
Sébastien Villemot 80a6967827
Remove unused options_.scalv 2023-04-14 16:38:14 +02:00