Model’s second intialisation method called by newMOD() function call. The model’s __init__() method only creates the instance and adds information, but does no parsing and computations whatsoever. init2() parses and ready’s the model for calculating the steady state and the dynamic solution to the model.
init_lev = 0: only parsing, no calculations, but preparing for manual SS solution init_lev = 1: parsing and steady state calculations init_lev = 2: parsing, steady state calculations and dynamic solution computation
This is the macrolab DSGEmodel class. It is the main class of the packages and instantiates DSGE model instances which possess many features such as model file parsers, solvers, etc. The __init__ function first called mostly attaches the passed arguments to the DSGE model instance in form of private _X data fields.
Note
Notice that the various init method, i.e. init1, init1a, etc. are not called here, but they are called externally in the pymaclab package when instantiating a new DSGE model using pymaclab.newMOD().
Parameters: 


Return self:  (dsge_inst)  A populated DSGE model instance with fields and methods 
This is just a convenience method which allows the current preferred dynamic solution method to be stored (attached) here and made accessible without having to traverse too deeply into the model instance tree structure.
A convenience method which uses the vtiming attribute in order to create a number of lists of variables with their time definitions (subscripts) for which derivates have to be taken using the nonlinear system of FOCs.
Parameters:  self (dsge_inst) – object instance 

Return self.jAA:  
(arr2d)  attaches numerical AA matrix used in Forkleind solution method  
Return self.jBB:  
(arr2d)  attaches numerical BB matrix used in Forkleind solution method 
A simple method which allows you to delete the current tex file associated with this model. Will ask for confirmation though, so cannot be used in a fireandforget batch file.
The is a method which can be called to find the risky steady state
Parameters:  self (dsge_inst) – The DSGE model instance itself. 

A convience method for collecting and displaying the model’s properties in a browser using html language.
An unparallelized method using native Python and Sympycore in oder to calculate the numerical and analytical Jacobian and Hessian of the model.
Parameters:  self (dsge_inst) – object instance 

Return self.numj:  
(arr2d)  attaches numerical model Jacobian to instance  
Return self.jdic:  
(dic)  attaches the analytical model Jacobian to instance  
Return self.numh:  
(arr2d)  attaches numerical model Hessian to instance  
Return self.hdic:  
(dic)  attaches the analytical 3D Hessian to instance  
Return self.jAA:  
(arr2d)  attaches numerical AA matrix used in Forkleind solution method  
Return self.jBB:  
(arr2d)  attaches numerical BB matrix used in Forkleind solution method 
An unparallelized method using native Python and Sympycore in oder to calculate the numerical and analytical Jacobian and Hessian of the model. This is the corresponding method to “self.mkjahe()” but is only called when some parameters were changed and the model needs dynamic updating. In particular in this case the expensive computation of the analytical expressions can be avoided, as only parameters affecting the steady state may have been altered. Uses existing self.jdic for Jacobian and self.hdic for Hessian of model.
A method using mlabwrap to call an external Matlab code in oder to calculate the numerical Jacobian and Hessian of the model.
A parallelized method using native Python and Sympy in oder to calculate the numerical and analytical Jacobian and Hessian of the model. This is the parallelized version of method self.mkjahe using the Python pp library.
A parallelized method using native Python and Sympycore in oder to calculate the numerical and analytical Jacobian and Hessian of the model. This is the corresponding method to “self.mkjahe()” but is only called when some parameters were changed and the model needs dynamic updating. In particular in this case the expensive computation of the analytical expressions can be avoided, as only parameters affecting the steady state may have been altered. Uses existing self.jdic for Jacobian and self.hdic for Hessian of model.
This will pdflatex the model’s tex file and then view it in the system’s pdf viewer.
Convience method for setting the model’s author’s name.
A convenience method which allows users to launch the model’s tex file in an editor specified in the configuration settings of pymaclab.
A convience method for launching an editor editing the model’s associated model txt file. If the file gets saved (even if unaltered) the model is reinitialized.
Method useful for completely reinitializing model based on a different or else altered external modfile. It is also perceivable to load the existing modfile at runtime, change it in a program, save it as a temporary file and then reload it using this method.
The regex function for variable detection out of strings
This is the factoredout macrolab DSGEmodel Initialisation class. This used to be part of the DSGEmodel class itself in the form of methods, but has been factored out into a separate class which takes a newly instantiated DSGEmodel instance as and argument. It then possess several init methods which “work on the instance” and produce desired attributes
Note
Notice that the various init method, i.e. init1, init1a, etc. are not called here, but they are called externally in the pymaclab package when instantiating a new DSGE model using pymaclab.newMOD().
Parameters:  other (DSGEmodel) – The DSGEmodel instance to be passed to the Inits instance 

The init1 method. Model population proceeds from the __init__function here. In particular the data gets read in (not implemented at the moment) and the model parsing begins.
Note
The other.vardic gets created and the manual as well as the numerical steady state sections gets parsed and attached to the DSGE model instance. So the most import fields created here using function populate_model_stage_one() are:
 other.vardic  variable names dictionary with transform and filtering info
 other.mod_name  short name of the DSGE model from mod file
 other.mod_desc  longer model description from mod file
 other.paramdic  dic of defined parameters with their numerical values
 other.manss_sys  list of equations from the closed form steady state section
 other.ssys_list  list of equations from the numerical steady state section
Also the updaters and updaters_queued branches are opened here and the other.vardic gets wrapped for dynamic updating behaviour.
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

The init1a method. Model population proceeds from the init1 method here. The only field which get created here is the raw (i.e. unsubstituted) substitution dictionary.
Note
Field which are created here using the function populate_model_stage_one_a() which in turn calls mk_subs_dic():
 other.nlsubs_raw1  a list of the @items and their replacements
 other.nlsubsdic  the above just expressed as a keyed list
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

The init1b method. Model population proceeds from the init1a method here.
Note
The only thing which gets done here purposefully after calling init1a() is to wrap these fields:
 other.nlsubsdic  the above just expressed as a keyed list
 other.paramdic  dic of defined parameters with their numerical values
in order to give them dynamic updating behaviour. No more is done in this init method call.
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

The init1c method. Model population proceeds from the init1b method here. We call populate_model_stage_one_bb() which does quite a bit of substitution/replacement of the @prefixed variables. It does this in the numerical and closed form steady state calculation sections, as well as in the actual FOCs themselves.
Note
After that we can wrap various fields for updating which are:
 other.foceqs  list of firsorder conditions with @ replacements done
 other.manss_sys  the list of equations from closed form SS section
 other.syss_list  the list of equations from numerical SS section
Notice also that here we replace or generate fields in case the FOCs are supposed to be used directly in SS calculation because the “use_focs” parameter was not passed empty.
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

The init2 method. Model population proceeds from the init1c method here. In this initialisation method the only thing which is being done is to open up the sssolvers branch and pass down required objects to the manuals closed from solver and the numerical rootfinding solver depending on whether information for this has been included in the DSGE model file. No attempt is made at solving for the steady state, the respective solvers are only being prepared.
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

Initialisation method init3 is quite complex and goes through a number of logical tests in order to determine how to solve for the steady state of the model.
Note
There are 7 different ways a DSGE model can obtain its steady state solution depending on what information has been provided:
 The steady state values dictionary has been passed as argument, then init3() will NEVER be called
 Information has been provided using the “use_focs” parameter to use FOCs directly, externally passed using use_focs
 Information has been provided using the “use_focs” parameter to use FOCs directly, but inside model file
 Information has only been provided in the numerical SS section
 Information has only been provided in the closed form SS section
 Both CFSS and NUMSS info are present and NUMSS is subset if CFSS
 Both CFSS and NUMSS info are present and CF is residual
These options are better explained in the documentation to PyMacLab in the steady state solver section.
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

This model instance subinitializor only calls the section which use the computed steady state in order to compute derivatives and open dynamic solver branches on the instance. But Jacobian and Hessian are not computed here, this is postponed to the next init level.
Note
The following last field is wrapped for dynamic execution:
 other.sigma  the variancecovariance matrix of the iid shocks
Notice that after wrapping this last field the process_queue class is instantiated at last, because it needs to have access to all of the wrapped fields. Also in this method, the function populate_model_stage_two() is called which prepares the nonlinear FOCs for derivativetaking.
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

This model instance initialisation step is the last substantial one in which the dynamic solution of the DSGE model instance is finally computed using a choice of methods which can be called at runtime.
Parameters:  other (dsge_inst) – The DSGE model instance itother. 

The final intializor section does some extra stuff after all has been done.
Parameters:  self (dsge_inst) – The DSGE model instance itself. 

returns conjugate transpose
To ensure matlab compatibility, we need to swap matrices A and B around !!
Calculates generalized eigenvalues of pair (A,B).
This should correspond to Matlab’s lambda = eig(A,B), and also to some (the same?) scipy function.
Eigenvalues will be of complex type, are unsorted, and are returned as 1d.
Function to get the nullspace of a matrix.
Usage: B = nullspace(A,eps)
where A is some matrix, B is the returned corresponding nullspace and eps is the optional machine precision (smallest number).
Sort the rows of a matrix using the column given by the index number