PureOne's picture
Publish EVE Obstruction Tomography v2.0.0 research release
b6abf2d verified
Raw History Blame Contribute Delete
4.52 kB
#!/usr/bin/env python3
"""Regenerate publication figures from saved CSV results, no hidden model inputs."""
from pathlib import Path
import csv
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)
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':10,'axes.spines.top':False,
'axes.spines.right':False,'savefig.bbox':'tight','figure.dpi':140,
'axes.titleweight':'bold','axes.labelcolor':'#182D3B'})
colors=['#165C7D','#D66D34','#2A8E75','#835AA5']
def read(path):
with path.open() as f:return list(csv.DictReader(f))
def save(fig,name):
fig.savefig(OUT/(name+'.pdf'));fig.savefig(OUT/(name+'.png'),dpi=190)
plt.close(fig)
rows=read(ROOT/'data/alias/separation_curves.csv')
fig,axs=plt.subplots(1,2,figsize=(10,3.4),constrained_layout=True)
for j,w in enumerate(sorted({float(r['omega']) for r in rows})):
sub=[r for r in rows if float(r['omega'])==w]
t=[float(r['time']) for r in sub]
axs[0].plot(t,[float(r['singleton_support_squared']) for r in sub],color=colors[j],ls=['-','--'][j],lw=2,label=f'frequency {w:.3f}')
axs[1].plot(t,[float(r['cross_kernel_0t']) for r in sub],color=colors[j],ls=['-','--'][j],lw=2,label=f'frequency {w:.3f}')
axs[0].set(title='A Separate limits coincide',xlabel='Time',ylabel='Squared support',ylim=(.8,1.2))
axs[1].set(title='B Joint geometry separates',xlabel='Time gap',ylabel=r'$K(0,t)$')
for ax in axs:ax.legend(frameon=False,fontsize=8);ax.grid(alpha=.15)
save(fig,'01_joint_separation')
rows=read(ROOT/'results/divergence_spectra.csv')
fig,axs=plt.subplots(1,2,figsize=(10,3.6),constrained_layout=True)
for ax,name,title in zip(axs,['scalar_chain','two_output_chain'],['A One output: depths 0, 1, 2, 3','B Two outputs: depths 0, 0, 1, 1']):
for mode in range(4):
sub=[r for r in rows if r['design']==name and int(r['mode'])==mode]
ax.loglog([float(r['epsilon']) for r in sub],[float(r['principal_cost_estimate']) for r in sub],color=colors[mode],marker='o',ms=2.5,
label=f"mode {mode+1}: exponent {sub[0]['predicted_cost_exponent']}")
ax.set(title=title,xlabel='Probe time scale',ylabel='Unit-task principal cost');ax.invert_xaxis();ax.grid(alpha=.15);ax.legend(fontsize=7,frameon=False)
save(fig,'02_divergence_spectrum')
rows=read(ROOT/'results/noise_stability.csv')
fig,axs=plt.subplots(1,2,figsize=(10,3.5),constrained_layout=True)
deltas=sorted({float(r['delta']) for r in rows if float(r['delta'])>0})
for key,label,c in [('A_error','Observed generator error',colors[0]),('A_bound','Certified upper bound',colors[1])]:
med=[];lo=[];hi=[]
for d in deltas:
vals=[float(r[key]) for r in rows if float(r['delta'])==d]
med.append(np.median(vals));lo.append(min(vals));hi.append(max(vals))
axs[0].loglog(deltas,med,'o-',color=c,label=label);axs[0].fill_between(deltas,lo,hi,color=c,alpha=.12)
axs[0].set(title='A Conditional stability bound',xlabel='Squared-support error bound',ylabel='Generator error (spectral norm)');axs[0].legend(fontsize=7,frameon=False)
seq=read(ROOT/'results/near_alias_sequence.csv')
axs[1].loglog([float(r['frequency_gap']) for r in seq],[float(r['joint_kernel_spectral_difference']) for r in seq],'o-',color=colors[2])
axs[1].set(title='B Unbounded frequencies approach aliases',xlabel='Frequency separation',ylabel='Joint-kernel discrepancy')
for ax in axs:ax.grid(alpha=.15)
save(fig,'03_stability_and_aliasing')
rows=read(ROOT/'results/precision_tradeoff.csv')
fig,ax=plt.subplots(figsize=(7,3.7),constrained_layout=True)
for j,eps in enumerate(sorted({float(r['epsilon']) for r in rows})):
sub=[r for r in rows if float(r['epsilon'])==eps]
ax.semilogx([float(r['scaled_information']) for r in sub],[float(r['empirical_error']) for r in sub],'o',color=colors[j],label=f'time scale {eps:g}',ms=4)
from scipy.special import ndtr
x=np.geomspace(min(float(r['scaled_information']) for r in rows),max(float(r['scaled_information']) for r in rows),400)
ax.semilogx(x,ndtr(-np.sqrt(x)/2),color='#263746',lw=1.5,label='Exact Gaussian error')
ax.set(title='Hidden-state detection follows the predicted precision scale',xlabel=r'Scaled information $R d^2 / \sigma^2$',ylabel='Classification error',ylim=(-.015,.53))
ax.grid(alpha=.15);ax.legend(fontsize=8,frameon=False,ncol=2)
save(fig,'04_precision_tradeoff')
print('Saved four figures in PDF and PNG formats.')