"""Information and certificate controls; no mechanism fitted to test outcomes.""" import json from pathlib import Path import numpy as np from certified_folding import data,candidates,fold,explicit,loss,lower_bound def main(): rows=[]; phase_maxerr=0. for seed in range(20): splits=data(seed,'linear');(X,y),_,(Xa,ya),_=splits H0=X.T@X/len(y);b=X.T@y/len(y) parent=fold(H0+.001*np.eye(len(b)),b,.8/np.max(np.sum(np.abs(H0+.001*np.eye(len(b))),axis=1)),512) threshold=loss(Xa,ya,parent)+.025 rng=np.random.default_rng(900000+seed);shuffled=rng.permutation(ya) for H,lam,eta in candidates(seed,40,H0): end=fold(H,b,eta,512);p=explicit(H,b,eta,16);prev=explicit(H,b,eta,15) r=np.max(abs(1-eta*np.linalg.eigvalsh(H))) good=loss(Xa,ya,end)<=threshold+1e-12 naive=loss(Xa,ya,p)>threshold+1e-12 certified=lower_bound(Xa,ya,p,p-prev,r,496,np.linalg.norm(Xa,2))>threshold+1e-12 wrong_anchor=loss(Xa,shuffled,end)>loss(Xa,shuffled,parent)+.025 residual=Xa@end-ya phase=rng.uniform(-np.pi,np.pi,len(residual)) coded=np.exp(1j*phase)*np.fft.fft(residual,norm='ortho') err=abs(np.linalg.norm(coded)**2/len(ya)-loss(Xa,ya,end));phase_maxerr=max(phase_maxerr,err) rows.append((good,naive,certified,wrong_anchor)) a=np.array(rows,bool) out=dict(n=len(a),semantically_acceptable=int(a[:,0].sum()),naive_prefix_false_rejections=int((a[:,0]&a[:,1]).sum()),certified_prefix_false_rejections=int((a[:,0]&a[:,2]).sum()),shuffled_anchor_rejects_semantically_acceptable=int((a[:,0]&a[:,3]).sum()),shuffled_anchor_accepts_semantically_unacceptable=int((~a[:,0]&~a[:,3]).sum()),phase_norm_max_abs_error=float(phase_maxerr),interpretation='Random unit-modulus phase codes applied to a unitary Fourier transform preserve squared residual norm; therefore they add no information to this digital gate. Shuffling target labels changes the capability contract, not just the code. Naive prefix loss can reject slow starters; a valid tail certificate is essential.') Path(__file__).with_name('controls.json').write_text(json.dumps(out,indent=2));print(json.dumps(out,indent=2)) if __name__=='__main__':main()