# Verification: vectorised WCB t* equals a brute-force loop building y* explicitly (one sample). import numpy as np rng = np.random.default_rng(1); n = np.array([8,16,32,64,8]); G, N = 5, n.sum(); gid = np.repeat(np.arange(G), n) y = rng.normal(size=G)[gid]*np.sqrt(.2) + rng.normal(size=N)*np.sqrt(.8); yb = y.mean(); e = y - yb S = np.bincount(gid, weights=e); W = rng.integers(0,2,(50,G))*2-1 d = (W*S).sum(1)/N; v = G/(G-1)*np.sum((W*S-np.outer(d,n))**2,1)/N**2; t_vec = d/np.sqrt(v) t_bf = [] for w in W: ys = yb + w[gid]*e; m = ys.mean(); r = ys - m vs = G/(G-1)*np.sum(np.bincount(gid, weights=r)**2)/N**2; t_bf.append((m-yb)/np.sqrt(vs)) print("max abs diff:", np.max(np.abs(t_vec-np.array(t_bf))))