Prior#
- class cultivars.bayes.priors.Prior[source]#
A prior on a vector autoregression’s coefficients.
Stated as moments – a mean and a variance over the coefficient matrix – rather than as artificial observations. The distinction is not stylistic. Banbura-Giannone-Reichlin dummy rows are convenient because stacking them under the sample turns the posterior into an ordinary least-squares solve, but that convenience is exactly what forces Litterman’s cross-equation weight to one: a weight that differs between own and cross lags breaks the Kronecker structure the dummy form depends on. Choosing moments as the interface keeps that hyperparameter, and it is also what the sparse and global-local priors need, since a Gibbs sampler redraws their conditional variances every sweep and has nowhere to put that in a fixed block of rows.
Dummy observations do not disappear – a restriction on a sum of coefficients has no diagonal-variance form and must be rows – so a prior supplies both hooks and leaves the one it does not use empty. That is what Giannone, Lenza and Primiceri do, and it is why the two coexist here.
Addition composes, and composition flattens.
Every array a prior returns is indexed the same way. Rows are design columns: the deterministic block, then the lags ordered lag-major (every variable at lag one, then every variable at lag two), then the exogenous regressors. Columns are equations. So entry
[lag_offset + j, i]is equation \(i\)’s coefficient on the first lag of variable \(j\).A subclass implements
coefficient_mean(),coefficient_variance(), and_label(), and overridesdummy_observations()only if it restricts a combination of coefficients. An instance should be immutable and hold hyperparameters only. Everything that depends on the sample arrives through the_PriorContext, which is what lets one prior object serve many fits.Note
+always returns a_CompositePrior, even when one side is_NoPrior. There is no__radd__, so the built-insumneeds a prior as its start value:sum(priors, _NoPrior()).See also
Prior– the public name of this class.HierarchicalBVAR._prior_at()– returns an instance.
Example
A ridge prior, the same variance on every coefficient, and what composing it with itself does to the moments:
>>> import numpy as np >>> class Ridge(_Prior): ... def coefficient_mean(self, context): ... return np.zeros((context.width, context.k_endog)) ... ... def coefficient_variance(self, context): ... return np.full((context.width, context.k_endog), 0.25) ... ... def _label(self): ... return "ridge(0.25)" >>> context = _PriorContext( ... k_endog=2, order=1, scales=np.ones(2), presample_mean=np.zeros(2) ... ) >>> Ridge().coefficient_variance(context).shape (3, 2) >>> stacked = Ridge() + Ridge() >>> stacked._label() 'ridge(0.25) + ridge(0.25)' >>> float(stacked.coefficient_variance(context)[0, 0]) 0.125
Methods#
|
Prior mean of the coefficient matrix, shaped like the design. |
|
Prior variance of each coefficient, shaped like the design. |
|
Artificial rows this prior contributes, for restrictions on sums. |