gcubed.linearisation.model_solver

This module contains the ModelSolver class.

It is used to find a point that solves the equations in the model using a numeric search algorithm.

This is experimental functionality that can be used to adjust the point around which the model is linearised.

class ModelSolver(gcubed.base.Base):

Overview

Note that this class is not used to find the SolvedModel.

This model solver just finds a point (a value for each variable in the model) that simultaneously solves the nonlinear equations in the model, taking as given the values for the vectors:

  • yxr
  • yjr
  • exz
  • exo

If a solution can be found, it will be values for the following vectors:

  • x1r
  • j1r
  • zer
  • z1r

The process is:

  1. Populate all vectors using database values for the linearisation year.
  2. Select just those model equations that involve a LHS variable on the RHS.
  3. Solve for roots of those equations using the least squares algorithm.
  4. Check that the roots are indeed roots (least squares could converge to values that minimise the sum of squares while not producing roots) by ensuring that the RHS values that are the proposed solution to the equations are the LHS values for those RHS values.
ModelSolver( model: gcubed.model.Model, linearisation_year: int, use_neutral_real_interest_rate: bool = True)

Arguments

model: The model to linearise.

linearisation_year: The year to linearise around.

use_neutral_real_interest_rate: If True, the neutral real interest rate will be used, otherwise the real interest rates will be the value from the database. This parameter defaults to True.

database
equations

The model that needs a solution to linearise around.

linearisation_year: int

The return value, the 4 digit linearisation year.

solution_found: bool

True if the model solution has been found and False otherwise.

def original_vector(self, vector_name: str) -> numpy.ndarray:

Returns the original values for the given vector name.

def solution_vector(self, vector_name: str) -> numpy.ndarray:

Returns the solution values for the given vector name.

Exceptions

Raises a runtime error if no solution has been found.

def index_of(self, variable: tuple[str, int]) -> int:

Arguments

variable: The vector and index pair that identifies the variable.

Returns

The return value, equal to the index of the variable in the vector of variables that we are adjusting to find a model solution.