gEconpy.model.perturbation.linearize_model#
- gEconpy.model.perturbation.linearize_model(variables, equations, shocks, cache=None, loglin_variables=None, order=1, eq_order=None, var_order=None)#
Compute the log-linearized Jacobian matrices of a DSGE model using pytensor autodiff.
Builds four Jacobian matrices
A, B, C, Drepresenting the first-order approximation of the model around its steady state:\[A \hat{y}_{t-1} + B \hat{y}_t + C \hat{y}_{t+1} + D \varepsilon_t = 0\]Log-linearization applies the chain rule directly: \(\partial F / \partial (\log y) = (\partial F / \partial y) \cdot y_{ss}\). Each Jacobian is built by symbolic differentiation of the model equations, evaluated at the steady state, with the column for every log-linearized variable scaled by its steady-state value. Variables not in the loglin set keep their bare derivatives (scale factor one).
For a log-linearized variable whose steady-state sign is not statically known from the GCN Assumptions block, the column scale is guarded as \(\mathrm{switch}(y_{ss} > 0,\; y_{ss},\; 1)\), so a non-positive steady state falls back to a level (un-logged) derivative rather than implying \(\log\) of a non-positive value.
- Parameters:
- variables
listofTimeAwareSymbol Model variables, expressed at time t.
- equations
listofsp.Expr Model equations as sympy expressions.
- shocks
listofTimeAwareSymbol Exogenous shocks.
- cache
dict, optional Sympytensor cache mapping
(name, assumptions)tuples to pytensor nodes. If provided, sympy-to-pytensor conversion reuses existing nodes. If None, a new cache is created.- loglin_variables
listofTimeAwareSymbol, optional Variables to log-linearize. If None, all variables are log-linearized.
- order
int, default 1 Order of approximation. Only
order=1is currently supported.- eq_order
ndarrayofint, optional Permutation of equation indices placing equations in
[static | lag-only | lead-only | both]order so A’s and C’s structural-zero row blocks become contiguous. Computed from the equations if not supplied.- var_order
ndarrayofint, optional Permutation of variable indices placing variables in
[static | predetermined-only | mixed | forward-only]order so A’s and C’s structural-zero column blocks become contiguous. Computed from the equations if not supplied.
- variables
- Returns:
- jacobians
listofTensorVariable Four pytensor matrix graph nodes
[A, B, C, D]. Rows are ineq_orderand the variable axis (cols of A/B/C) is invar_order; D’s columns are shocks (no permutation).- ss_input_nodes
listofTensorVariable Steady-state variable input nodes needed to evaluate the Jacobians. Parameter nodes are also embedded in the graph but must be discovered by the caller via
explicit_graph_inputs.- eq_order_out
ndarrayofint The equation permutation actually applied (same as
eq_orderif supplied).- var_order_out
ndarrayofint The variable permutation actually applied (same as
var_orderif supplied).
- jacobians