SPB Git

spb/wp29_uqo

Public
715 B · 12 lines python
1# Verification: vectorised WCB t* equals a brute-force loop building y* explicitly (one sample).2import numpy as np3rng = 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)4y = rng.normal(size=G)[gid]*np.sqrt(.2) + rng.normal(size=N)*np.sqrt(.8); yb = y.mean(); e = y - yb5S = np.bincount(gid, weights=e); W = rng.integers(0,2,(50,G))*2-16d = (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)7t_bf = []8for w in W:9    ys = yb + w[gid]*e; m = ys.mean(); r = ys - m10    vs = G/(G-1)*np.sum(np.bincount(gid, weights=r)**2)/N**2; t_bf.append((m-yb)/np.sqrt(vs))11print("max abs diff:", np.max(np.abs(t_vec-np.array(t_bf))))12
Files · main
Menu

Theme