matter-embryogenesis / src /make_gauge_figures.py
PureOne's picture
Release Matter Embryogenesis v3.0.0: theory, code, data and audit
52fc221 verified
Raw
History Blame Contribute Delete
4.04 kB
from pathlib import Path
import json
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from gauge_contracts import uniform_reserve_yield
ROOT=Path(__file__).resolve().parents[1]
DATA=ROOT/'results/gauge';FIG=ROOT/'figures'
plt.rcParams.update({'font.size':9,'axes.spines.top':False,
'axes.spines.right':False,'savefig.dpi':200})
phase=json.loads((DATA/'phase.json').read_text())
palette=['#17647f','#3c8d99','#768c45','#b07e3c','#9c4f6e']
fig,ax=plt.subplots(1,2,figsize=(10,3.65),layout='constrained')
for color,N in zip(palette,[4,16,64,256,1024]):
cs=np.linspace(.4,.65,301)
probability=[uniform_reserve_yield(N,.65,1.35,c,.04) for c in cs]
ax[0].plot(cs,probability,color=color,label=f'{N} modules')
rows=[r for r in phase['rows'] if r['modules']==N and r['capacity']<=.65]
ax[0].scatter([r['capacity'] for r in rows],
[r['passes']/r['trials'] for r in rows],s=10,color=color)
ax[0].axvline(phase['critical_capacity'],color='#263542',ls='--',lw=1)
ax[0].set(xlabel='Reachable additive reserve per module',
ylabel='Probability of G2 feasibility',ylim=(-.025,1.04),
title='Exact finite-size reserve transition')
ax[0].legend(frameon=False,fontsize=7,loc='upper left')
for color,c in zip(palette,[.55,.58,.59,.60]):
Ns=np.arange(2,1025,2)
ys=np.maximum([uniform_reserve_yield(int(N),.65,1.35,c,.04) for N in Ns],1e-40)
ax[1].semilogy(Ns,ys,color=color,label=f'Reserve = {c:.2f}')
ax[1].set(xlabel='Number of modules',ylabel='Exact feasibility probability',
ylim=(1e-32,1.5),title='Subcritical yield vanishes exponentially')
ax[1].legend(frameon=False,fontsize=8)
fig.savefig(FIG/'gauge_reserve_phase.png');plt.close(fig)
cal=json.loads((DATA/'calibration.json').read_text())
fig,ax=plt.subplots(1,2,figsize=(10,3.4),layout='constrained')
for dim,color in zip([1,2,3],palette):
rows=[r for r in cal['scaling'] if r['dimension']==dim]
ax[0].loglog([r['nodes'] for r in rows],[r['rho_max'] for r in rows],
'o-',color=color,label=f'{dim}D')
ax[1].loglog([r['nodes'] for r in rows],
[r['samples_for_radius_006'] for r in rows],
'o-',color=color,label=f'{dim}D')
ax[0].set(xlabel='Comparison nodes',ylabel='Maximum effective resistance',
title='Comparison topology controls noise amplification')
ax[1].set(xlabel='Comparison nodes',ylabel='Samples per edge',
title='Radius 0.006; 128 inspections; failure budget 0.005')
for a in ax:a.legend(frameon=False);a.grid(alpha=.18)
fig.savefig(FIG/'gauge_calibration.png');plt.close(fig)
summary=json.loads((DATA/'summary.json').read_text())
methods=['projective','common_detector_gain','common_material_scale',
'conventional_joint','fixed_representative','insufficient_reserve',
'differential_bias','early_reference_release']
labels=['Projective repair','Shared detector gain','Common material scale',
'Matched conventional','Fixed representative','Insufficient reserve',
'Differential bias','Early reference release']
fig,ax=plt.subplots(1,2,figsize=(10,4.4),layout='constrained',sharey=True)
y=np.arange(len(methods))
for d,shift,color in [(2,-.18,'#17647f'),(3,.18,'#b07e3c')]:
rows={r['method']:r for r in summary if r['dimension']==d}
ax[0].barh(y+shift,[rows[m]['functional']/32 for m in methods],
height=.32,color=color,label=f'{d}D')
ax[1].barh(y+shift,[rows[m]['false_certificates']/32 for m in methods],
height=.32,color=color)
ax[0].set(yticks=y,yticklabels=labels,xlim=(0,1.03),
xlabel='Completed functional objects / 32',
title='Model results with explicit negative controls')
ax[0].invert_yaxis()
ax[1].set(xlim=(0,1.03),xlabel='False local certificates / 32',
title='Differential bias remains a hard failure')
ax[0].legend(frameon=False,loc='lower right')
fig.savefig(FIG/'gauge_results.png');plt.close(fig)
print('Created three v3 scientific figures.')