"""Recreate the seven publication figures from recorded results. No selected plot colors or style package; Matplotlib's default cycle is used. """ from pathlib import Path import json import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt ROOT = Path(__file__).resolve().parents[1] OUT = ROOT / 'figures' OUT.mkdir(exist_ok=True) v = json.loads((ROOT/'data/mathematical_verification.json').read_text()) b = json.loads((ROOT/'data/neural_digits_results.json').read_text()) def save(fig, name): fig.tight_layout() fig.savefig(OUT/f'{name}.pdf', bbox_inches='tight') fig.savefig(OUT/f'{name}.png', dpi=180, bbox_inches='tight') plt.close(fig) curve = v['frontier_curve'] fig, ax = plt.subplots(figsize=(7.2,4.5)) ax.plot([r['B'] for r in curve],[r['exact'] for r in curve],label='Exact optimal frontier') ax.plot([r['B'] for r in curve],[r['uniform'] for r in curve],'--',label='Uniform contraction') ax.axvline(np.log(2),linestyle=':',label='Regime boundary: B = log 2') ax.set(xlabel='Total log-contraction budget B',ylabel='Worst-scenario information floor') ax.legend(); ax.grid(alpha=.2); save(fig,'noncommuting_frontier') fig,ax=plt.subplots(figsize=(7.2,4.5)); n=np.arange(1,21) ax.plot(n,(7/5)**(n/2),marker='o') ax.set(xlabel='Number of tensor factors',ylabel='Full-memory / compressed-memory information floor') ax.set_xticks([1,5,10,15,20]);ax.grid(alpha=.2);save(fig,'memory_amplification') for metric,ylabel,name in [ ('mean_accuracy','Mean held-out accuracy','neural_accuracy'), ('mean_reconstruction_RMSE','Mean latent-state reconstruction RMSE','neural_reconstruction'), ('mean_certified_stability','Certified prediction-stability fraction','neural_certificates')]: fig,ax=plt.subplots(figsize=(7.2,4.5)) for method in ['uniform','optimized']: rows=[r for r in b['aggregates'] if r['method']==method] ax.plot([r['noise_norm'] for r in rows],[r[metric] for r in rows],marker='o',label=method.capitalize()) ax.set(xlabel='Aggregate observation-noise norm',ylabel=ylabel) ax.legend();ax.grid(alpha=.2);save(fig,name) fig,ax=plt.subplots(figsize=(7.2,4.5)); h=np.linspace(0,1.2,301) d,s,R=4,.6,1.;tail=(d+1)**(-2*s) exact=np.where(h