// // BayesTests.swift // Metrika // // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Copyright © 2026 Simon-Pierre Boucher. All rights reserved. // import Foundation import Testing import ZQEngine import ZQGPU import ZQStats @Suite("Bayesian regression", .serialized) struct BayesTests { @Test("Philox stream normals and gammas match their theoretical moments") func variateGenerators() { var stream = PhiloxStream(seed: 42) let n = 200_000 var normalSum = 0.0, normalSquares = 0.0 for _ in 0.. 0.9 && sdRatio < 1.15, "sd[\(posterior.name)] ratio \(sdRatio)" ) // The 95% credible interval brackets the OLS estimate. #expect(posterior.credibleLower < frequentist.estimate) #expect(posterior.credibleUpper > frequentist.estimate) } // σ posterior around the DGP value 0.8. #expect(abs(bayes.sigma.posteriorMean - 0.8) < 0.1) } @Test("a tight prior shrinks coefficients toward zero") func priorShrinkage() throws { var stream = PhiloxStream(seed: 9) let n = 60 let x = (0..