bartz.testing.SpikeSlab

class bartz.testing.SpikeSlab(pi)[source]

Two-point distribution over the scales 0 and 1/sqrt(pi).

The scale is 1/sqrt(pi) with probability pi and 0 otherwise. This is hard variable selection: a fraction pi of the predictors is active, the others are exactly inert.

pi: Float[Array, ''] | float

Probability that a scale is nonzero, in (0, 1].

property fourth_moment: Float[Array, ''] | float[source]

E[s ** 4] = 1 / pi.

classmethod from_peff(peff, p)[source]

Set the scale dispersion from an effective number of active predictors.

peff is the participation ratio of the squared scales,

\[p_{\mathrm{eff}} = \frac{(\sum_j s_j^2)^2}{\sum_j s_j^4} \;\xrightarrow{\,p \to \infty\,}\; \frac p{E[s^4]},\]

an effective count that ranges in [1, p]: p when all predictors are equally important (Constant), shrinking towards 1 as the importance concentrates on fewer predictors. The deterministic large-p limit p / E[s ** 4] is the analytic target inverted here; for SpikeSlab it equals the expected number of nonzero scales exactly.

Parameters:
  • peff (Float[Array, ''] | float) – Effective number of active predictors, in [1, p].

  • p (Integer[Array, ''] | int) – Total number of predictors.

Returns:

ScaleDistr – A member of the family with fourth_moment equal to p / peff.

sample(key, shape)[source]

Sample i.i.d. two-point scales.

Return type:

Float[Array, '*shape']