Automatic relevance determination (ARD) gives every weight its own prior precision, wj∼N(0,1/αj), and learns the precisions by maximizing the marginal likelihood (evidence) of a linear regression with known noise variance σ2:
p(y∣X,α)=N(y∣0, σ2IN+XA−1X⊤),A=diag(α)
Implement ard_fit(X, y, sigma2, n_iter, alpha_cap=1e8) using MacKay's fixed-point updates. Start with αj=1 for all j. Each iteration:
- compute the posterior Σ=(A+X⊤X/σ2)−1 and m=ΣX⊤y/σ2 for the current α;
- compute γj=1−αjΣjj and set αj←γj/mj2, then clip every αj to at most
alpha_cap (a capped weight is effectively pruned).
Return (m, alpha, log_ev) where m is the posterior mean recomputed with the final α, and log_ev is the list of log evidences logp(y∣X,α), one per iteration, evaluated with the α used at the start of that iteration.