Writing a Custom Prior¶
Impulso uses typing.Protocol for extensibility. You can write your own prior by implementing the Prior protocol.
The Prior protocol¶
from impulso.protocols import Prior
class MyPrior:
def build_priors(self, n_vars: int, n_lags: int) -> dict:
...
Your build_priors method must return a dictionary with keys "B_mu" and "B_sigma", both NumPy arrays of shape (n_vars, n_vars * n_lags).
B_mu: Prior mean for VAR coefficient matrixB_sigma: Prior standard deviation for VAR coefficient matrix
Example: Flat prior¶
import numpy as np
class FlatPrior:
def build_priors(self, n_vars: int, n_lags: int) -> dict:
n_coeffs = n_vars * n_lags
return {
"B_mu": np.zeros((n_vars, n_coeffs)),
"B_sigma": np.ones((n_vars, n_coeffs)) * 10.0,
}