SpikeAndSlabPrior._initial_scales#
- SpikeAndSlabPrior._initial_scales(context, reference)[source]#
Anchor both widths to the reference scale; start everything in.
The semiautomatic default:
referenceholds each coefficient’s least-squares standard error on the raw scale, and dividing by the unit ratio puts it on the standardized scale the indicators see. Spike and slab arespikeandslabtimes that, floored at \(10^{-8}\) so a degenerate column cannot produce a zero width. Every indicator starts in the slab, so the first coefficient draw is essentially least squares, and the first sweep decides which coefficients leave.- Parameters:
- Return type:
- Returns:
{"tau0", "tau1", "gamma", "prob"}, each of shape(k * p, k): the two widths, the indicators (all one), and the conditional inclusion probabilities (allinclusion).- Raises:
SpecificationError – If a hyperparameter is out of range.
Example
With a standard error of
0.05everywhere, the spike is a two-hundredth and the slab a half:>>> import numpy as np >>> from cultivars.bayes.priors import PriorContext >>> ctx = PriorContext( ... k_endog=2, order=1, scales=np.ones(2), presample_mean=np.zeros(2) ... ) >>> state = SpikeAndSlabPrior()._initial_scales(ctx, np.full((3, 2), 0.05)) >>> state["tau0"].round(6)[0, 0], state["tau1"][0, 0], state["gamma"].sum() (np.float64(0.005), np.float64(0.5), np.float64(4.0))