With a prior on a coin's bias and heads, tails observed, the posterior is . Implement the predictive and model-comparison quantities built on it. Work in log space with math.lgamma; .
beta_binom_pmf(x, M, a, b): the beta-binomial probability of heads in future tosses when ,
plugin_pmf(x, M, theta): the binomial probability of the plug-in approximation.log_evidence(N1, N0, a, b): the log marginal likelihood of one particular sequence with heads and tails under the beta-Bernoulli model (no binomial coefficient).mixture_posterior(weights, components, N1, N0): the prior is with components = [(a_1, b_1), ...]. Return (post_weights, post_components): the posterior mixing weights as a list of floats, and the list of updated (a, b) pairs.mixture_prob_above(weights, components, t): under the mixture . All passed here are positive integers; the result must be accurate to .Return floats everywhere.