shrinkage¶
Empirical-Bayes shrinkage strength estimation (spec section 4).
The support weight w = tau^2 / (tau^2 + v) is the posterior weight an empirical-Bayes observer puts on a fitted bin value versus the population prior 0 (terms are centered). tau^2 is the between-bin signal variance, estimated per term; v is the bin's sampling variance.
Shrinkage
dataclass
¶
Shrinkage(tau2: float, sigma2: float, k: float)
Per-term shrinkage summary (audit payload, spec section 4.4).
estimate_tau2 ¶
estimate_tau2(
f: ndarray,
v: ndarray,
n: ndarray,
*,
method: str = "mom"
) -> float
Estimate the between-bin signal variance tau^2 for one term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
ndarray
|
Bin values, bin sampling variances, bin training masses (any shape, flattened internally). |
required |
v
|
ndarray
|
Bin values, bin sampling variances, bin training masses (any shape, flattened internally). |
required |
n
|
ndarray
|
Bin values, bin sampling variances, bin training masses (any shape, flattened internally). |
required |
method
|
str
|
|
'mom'
|
Source code in src/triadxai/shrinkage.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
estimate_tau2_shap ¶
estimate_tau2_shap(
phi_ref: ndarray, v_ref: ndarray
) -> np.ndarray
Per-feature tau^2 for approximate mode, from a reference population.
Method of moments about the zero prior:
tau2_j = max(0, mean(phi_j^2) - mean(v_j)). SHAP attributions are
centered on the training population, so a strongly nonzero mean signals
a reference-population mismatch and is logged as a warning.
Source code in src/triadxai/shrinkage.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
fit_shrinkage ¶
fit_shrinkage(
term: TermData, *, method: str = "mom"
) -> Shrinkage
Estimate tau^2 and the count-form shrinkage strength k for one term.
Source code in src/triadxai/shrinkage.py
74 75 76 77 78 79 80 81 82 83 84 85 | |