Choose the degree of a 1D polynomial regression by its marginal likelihood, as in Murphy's book. The model for degree uses the features , the prior , and Gaussian noise of precision , so that .
log_evidence_poly(x, y, degree, alpha, beta): , computed with a Cholesky factorization.fit_alpha_beta(x, y, degree): empirical Bayes (type-II maximum likelihood) by the fixed-point updates below, starting from . Each iteration computes , , where are the eigenvalues of , then sets and . Stop after the first update in which both and change by at most relative to their previous values, or after 2000 iterations. Return (alpha, beta).posterior_over_degrees(x, y, degrees): for each degree, fit by empirical Bayes and compute the log evidence at those values. With a uniform prior over the candidate degrees, return (probs, log_evidences) as numpy arrays in the order of degrees.