Approximate the posterior p(θ∣D)∝θN1(1−θ)N0Beta(θ∣a,b) of a coin's bias and compare against the exact Beta(a+N1,b+N0). Assume N1+a>1 and N0+b>1. The joint density includes the prior's normalizer: logp(θ,D)=(N1+a−1)logθ+(N0+b−1)log(1−θ)−logB(a,b) (a specific sequence, no binomial coefficient).
grid_posterior(N1, N0, a, b, K): the grid approximation on the K midpoints θk=(k+0.5)/K, k=0,…,K−1. Return (grid, masses) as arrays, with masses proportional to p(θk,D) and summing to one.
laplace_theta(N1, N0, a, b): the Laplace approximation in θ space. Return (mode, var, log_Z): the posterior mode, the inverse of the Hessian of E(θ)=−logp(θ,D) at the mode, and the Laplace estimate of the log evidence, logZ=−E(θ^)+21log(2π)−21logH.
laplace_logit(N1, N0, a, b): the same in α=logit(θ) space, where the density of α includes the Jacobian dθ/dα=θ(1−θ). Return (mode, var, log_Z) for α.
laplace_tv(N1, N0, a, b, space, K=2000): total variation between the exact posterior density p and the Laplace approximation's density q over θ, evaluated at the K midpoints above as 2K1∑k∣p(θk)−q(θk)∣. For space == "theta", q is the Gaussian density in θ; for space == "logit", q(θ)=N(logitθ∣m,v)/(θ(1−θ)).
Return floats (arrays for the grid).