|
<< Click to Display Table of Contents >> Model parse/emit/solve |
![]() ![]()
|
This section explains model parsing and emitting, including the concept of a- and b-arrays containing the data.
The model solver used to be the most complicated piece of source code in Gekko, but as the other functionality of Gekko has grown over time, this is probably not the case anymore. Or at least, the solver solves a problem that is easy to state in a clear an unambiguous way. We have n simultaneous equations, and n endogenous variables, and we want Gekko to find the values of the endogenous variables that are consistent with the equations.
At the moment, there are three kinds of solvers in Gekko.
•The first one is a Gauss-Seidel solver that in essence just runs the equations one by one (iteratively), until the endogenous variables do not move (much) anymore corresponding to convergence.
•The second one is a Newton solver that uses first order derivatives and matrix inversion to solve the problem. This solver is somewhat slower on typical/easy problems, but it is able to solve hard problems (including problems with goals and means), and it can deliver results that are numerically very accurate.
•The last solver is a Fair-Taylor solver for solving with leaded endogenous variables. This solver can be thought of as Gauss-Seidel over time, where an outer loop deals with the variables containing leads, and an inner loop deals with solving the equations as if there were no leads (both Gauss-Seidel and Newton can be used for the inner iteratione).
The most complicated of the solvers is the Newton solver, whereas the other solvers are iterative solvers with less complexity.
When simulating, to speed up the simulations all the relevant data for all the relevant periods is first copied to a n x t array of double precision numbers called a, where n is the number of endogenous variables, and t is the number of simulated periods. Doing this provides fast copying of data from period to period while simulating, and after the simulation has finished, the data is copied back to the respective time series. Since the internal data storage in the Series objects is an array of double precision numbers, the data can be copied in an out of the a array in larger blocks (array copying).