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 is implemented as a change-of-variables: for each variable to be log-linearized, the substitution \(y \to \exp(\tilde{y})\) is applied before differentiation, then \(\tilde{y} \to \log(y)\) is substituted back. The chain rule produces the classical T-matrix multiplication \(\partial F / \partial (\log y) = (\partial F / \partial y) \cdot y_{ss}\). Variables not in the loglin set use identity substitutions, yielding bare derivatives.
A
pt.switchguard on the steady-state value preventslog(negative)for variables whose steady states are not know to be non-positive. This is a numerical safety net:rewrite_pregraddoes not simplifyexp(log(x))whenx < 0. This is avoided if a variable is known to be positive or negative via the Assumptions block of the GCN file.- 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