The steady state#

The steady state search can be evoked by calling the function econpizza.PizzaModel.solve_stst() documented below. The function collects all available information from steady_state key of the YAML and attempts to find a set of variables and parameters that satisfies the aggregate equations using the routine outlined in the paper.

Upon failure, the function tries to be as informative as possible. If the search is not successful, a possible path to find the error is to set the function’s keyword argument raise_errors to False. The function then raises a warning instead of failing with an exception, and returns a dictionary containing the results from the root finding routine, such as, e.g. the last Jacobian matrix.

Note

A classic complaint is “Function returns NaNs” or “The Jacobian contains NaNs”. This is usually either due infinite/non-existent derivatives or invalid values (e.g. sqrt(-1) or 1/0) along the way. While the package tries to provide more information about where the error occurred, a good idea is to follow JAX’s hints on how to debug NaNs.

Tip

  • A common gotcha for heterogeneous agent models is that the distribution contains negative values. The routine will be informative about that. This is usually due to rather excessive interpolation outside the grid and can often be fixed by using a grid with larger minimum/maximum values.

  • To avoid NaNs, ensure that parameter values produce valid results on an unbounded domain. E.g., instead of declaring a parameter nu when calling sqrt(nu), declare a parameter nu_log and define nu = exp(nu_log) in the aux_equations block. This ensures that nu is always positive.

  • A known problem is that for steady state values set to zero (either as fixed value or initial guess), the Jacobian matrix may contain NaNs. This is due to how JAX internally calculates Jacobians via Jacobian-vector-products. It then often helps to set these values to 1e-8 instead of 0.

  • The steady state procedure is based on the pseudoinverse of the Jacobian. If the procedure fails, it will try to tell you the rank of the Jacobian and the number of degrees of freedom. More degrees of freedom than the Jacobian rank normally implies that you should fix more steady state values and vice versa.

  • If the desired precision is not reached, the error message will tell you in which equation the maximum error did arise. You can use the equations key to get the list of equations (as strings), e.g. print(model['equations'][17]) to get the equation with index 17.

econpizza.PizzaModel.solve_stst(self, tol=1e-08, maxit=15, tol_backwards=None, maxit_backwards=2000, tol_forwards=None, maxit_forwards=5000, force=False, raise_errors=True, check_rank=False, verbose=True, **newton_kwargs)#

Solves for the steady state.

Parameters:
  • tol (float, optional) – tolerance of the Newton method, defaults to 1e-8

  • maxit (int, optional) – maximum of iterations for the Newton method, defaults to 15

  • tol_backwards (float, optional) – tolerance required for backward iteration. Heterogeneous agent models only. Defaults to tol

  • maxit_backwards (int, optional) – maximum of iterations for the backward iteration. Heterogeneous agent models only. Defaults to 2000

  • tol_forwards (float, optional) – tolerance required for forward iteration. Heterogeneous agent models only. Defaults to tol*1e-2. Note that this default is somewhat arbitrary and may not be sufficient.

  • maxit_forwards (int, optional) – maximum of iterations for the forward iteration. Heterogeneous agent models only. Defaults to 5000

  • force (bool, optional) – force recalculation of steady state, even if it is already evaluated. Defaults to False

  • raise_errors (bool, optional) – raise an error if Newton method does not converge. Useful for debugging models. Defaults to True

  • check_rank (bool, optional) – force checking the rank of the Jacobian, even if the Newton method was successful. Defualts to False

  • verbose (bool, optional) – level of verbosity. Defaults to True

  • newton_kwargs (keyword arguments) – keyword arguments passed on to the Newton method

Returns:

rdict – a dictionary containing information about the root finding result. Note that the results are added to the model (PizzaModel instance) automatically, rdict is hence only useful for model debugging.

Return type:

dict