# Section 4: the glow of an orthogonal matrix U is the law of Omega = , with a, b uniform sign vectors. We check, by exact enumeration, # that its moments of order 2 and 4 are N and 3N^2 - 6N + 4||U||_4^4, for the Fano matrices and for a random orthogonal matrix. # Usage: python3 glow.py import numpy as np, itertools from designs import SETS, matrices def moments(U): n = len(U); B = np.array(list(itertools.product([-1.0, 1.0], repeat=n))); X = B @ U.T # the vectors Ub return (X**2).sum(1).mean(), (3*(X**2).sum(1)**2 - 2*(X**4).sum(1)).mean() # exact averages over a if __name__ == "__main__": rng = np.random.default_rng(1); P, T = matrices(*SETS["Fano plane (7,3,1)"]) for name, U in (("Fano, plain", P), ("Fano, twisted", T), ("random, order 7", np.linalg.qr(rng.normal(size=(7, 7)))[0]), ("random, order 10", np.linalg.qr(rng.normal(size=(10, 10)))[0])): n = len(U); m2, m4 = moments(U); f = 3*n*n - 6*n + 4*(U**4).sum() print("%-18s second moment %.6f (N=%d), fourth moment %.6f, formula %.6f" % (name, m2, n, m4, f)); assert np.isclose(m4, f)