lag_matrices#

impulso.lag_matrices(B, n_lags)[source]#

Split a stacked VAR coefficient matrix into its per-lag blocks.

Impulso stores the reduced-form coefficients as a single matrix whose trailing axis concatenates the lag blocks in lag order, matching the regressor layout built in VAR.fit (lag 1 first). This helper recovers the individual lag matrices A_1, …, A_p that the moving-average recursion in compute_ma_phi consumes.

Like sigma_from_cholesky, the split is rank-agnostic: only the last axis is partitioned, so leading batch axes pass through untouched.

Parameters:
  • B (ndarray) – Stacked coefficient matrix. The last two dimensions are (n, n * n_lags); all preceding dimensions are batch axes. Common shapes are (n, n * n_lags) for a single draw and (chains, draws, n, n * n_lags) for a posterior tensor.

  • n_lags (int) – Number of lag blocks stacked along the trailing axis. Must be positive and divide the trailing axis exactly.

Returns:

List of n_lags arrays in lag order, A_1 first. Each entry has the same leading batch axes as B and trailing shape (n, n).

Raises:

ValueError – If n_lags is not positive, or if the trailing axis of B is not divisible by n_lags.

Return type:

list[ndarray]