"""Finite strict-covering checks and floating kernel diagnostics. Covering uses the stated epsilon condition and samples the trimmed simplex V. The reciprocal identity is checked separately with exact Fractions in endtoend.py. Kernel eigenvalues near machine precision can have roundoff signs; they are diagnostics, not a certificate of positive definiteness. """ import numpy as np, itertools rng = np.random.default_rng(0) def family(n, eps, kappa): w = 1 / (n + eps * (n + kappa) ** 2) T = [] for a in range(n): s = np.ones(n); s[a] += kappa T.append(w * (np.eye(n) + eps * np.outer(s, s))) return T def F(T, p): q = p @ T; return q / q.sum() # 1 for n in (3, 4, 5): kappa = 1.0; eps = 0.5 / ((1 + kappa) * (n + kappa) * n) T = family(n, eps, kappa); S = sum(T) hat = np.array([(np.ones(n) + kappa * np.eye(n)[a]) / (n + kappa) for a in range(n)]) assert all((t > 0).all() for t in T) and np.allclose(S.sum(1), 1) and np.allclose(S, S.T) dets = [np.linalg.det(t) for t in T] # covering: sample points of Sigma', check each has a preimage in Sigma' under some F_a bad = 0; worst = 1.0 for _ in range(20000): lam = np.full(n, 1/(4*n)) + 0.75*rng.dirichlet(np.ones(n)); y = lam @ hat ok = False; best = -1 for a in range(n): q = y @ np.linalg.inv(T[a]); if (q <= 0).any(): continue q = q / q.sum(); bc = np.linalg.solve(hat.T, q) # barycentric coordinates in Sigma' best = max(best, bc.min()) if bc.min() > 1/(4*n): ok = True bad += not ok; worst = min(worst, best) assert bad == 0, (n, bad, worst) print(f"n={n}: eps={eps:.4f}, min entry {min(t.min() for t in T):.4f}, det {dets[0]:.3e}, " f"points of trimmed V without a preimage in int(V): {bad} of 20000 (worst margin {worst:+.4f})") # Floating diagnostics for small product-grid kernels. for m in (1, 2, 3): for K in (2, 4, 6): t = 0.3 * np.cos(np.pi * (2 * np.arange(K + 1) + 1) / (2 * K + 2)) grid = np.array(list(itertools.product(t, repeat=m))) Z0 = 1 / (1 - grid @ grid.T) ev = np.linalg.eigvalsh(Z0) print(f"m={m}, K={K}: nodes {len(grid)}, smallest eigenvalue {ev[0]:.2e}") print("PASS: strict-covering finite samples; kernel spectra are floating diagnostics only.")