BVARResult._from_fit#
- classmethod BVARResult._from_fit(fit, model)[source]#
Assemble the public result from a raw fit and the model that produced it.
The single construction point for
BVARResult.BVAR.fit()runs the conjugate update through_BayesianVectorAutoRegressionModel._fit_conjugate(), which returns a_VectorConjugateFitholding only what the numerics produced, and this method joins that with the specification the model holds – the panel, the labels, the order, the trend, and the prior’s label – to make the frozen public record. Keeping assembly here rather than in__init__keeps the result a plain dataclass with no logic of its own, and keeps the raw fit free of anything the sampler does not need.The mapping is one-to-one, with a single rename:
fit.coefficient_stackbecomescoefficients. Arrays are passed through by reference, not copied; both containers are frozen, so the aliasing is safe.Nothing is validated. The fit is trusted to be consistent with the model that produced it – same
k, samep, same trend, draws already laid out in the model’s design order – because_fit_conjugateis the only producer and it guarantees exactly that. Passing a fit from a different model or specification produces a result whose arrays disagree with its labels, silently.- Parameters:
fit (
_VectorConjugateFit) – The raw conjugate posterior output: posterior-mean blocks, the(S, w, k)and(S, k, k)draws, the closed-form log marginal likelihood, and the sample accounting.model (
_BayesianVectorAutoRegressionModel[BVARResult]) – The specification the fit was computed under. Suppliesendog,names,order,trend, and, throughmodel.prior._label(),prior_label.
- Return type:
- Returns:
The assembled
BVARResult, sharing the fit’s arrays.
Example
Round-tripping a fit through the assembler is a pure field mapping:
>>> import numpy as np >>> from cultivars.multivariate.large_dim.bayesian import BVAR >>> from cultivars.multivariate.large_dim.bayesian import BVARResult >>> model = BVAR(np.random.default_rng(0).standard_normal((60, 2)), order=1) >>> fit = model._fit_conjugate(n_draws=20, seed=0) >>> res = BVARResult._from_fit(fit, model) >>> res.nobs == fit.nobs and res.n_kept == fit.beta_draws.shape[0] True >>> res.beta_draws is fit.beta_draws and res.endog is model.endog True >>> res.prior_label 'niw(l1=0.2, l3=1, l4=100)'