File size: 8,796 Bytes
19591f3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | #!/usr/bin/env python3
"""Rebuild the manuscript's static scientific figures.
Requires matplotlib (optional; the selection and certificate code uses only the
Python standard library). All rational sample values are computed with Fraction.
figure_data.json stores rational values as strings and irrational lower bounds
as exact quadratic-surd records. Floating conversion is used only for plotting.
Curves join the displayed sample points; they do not assert interpolation laws.
Run: python make_figures.py
"""
from fractions import Fraction as F
from pathlib import Path
import json
import math
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
from selection import coefficient
from profile_minimax import solve_profile
HERE=Path(__file__).resolve().parent
FIGURES=HERE/'figures'
NAVY='#173654'
TEAL='#087E8B'
AMBER='#C88026'
SLATE='#647382'
GRID='#E4EAF0'
def surd(rational_part,radical_coefficient,radicand):
return {'rational_part':str(F(rational_part)),
'radical_coefficient':str(F(radical_coefficient)),
'radicand':str(F(radicand)),
'interpretation':'rational_part + radical_coefficient * sqrt(radicand)'}
def surd_float(record):
return float(F(record['rational_part']))+float(F(record['radical_coefficient']))*math.sqrt(float(F(record['radicand'])))
def style_axes(ax):
ax.set_facecolor('white')
ax.grid(axis='y',color=GRID,linewidth=.65,zorder=0)
ax.set_axisbelow(True)
for spine in ('top','right'):
ax.spines[spine].set_visible(False)
for spine in ('left','bottom'):
ax.spines[spine].set_color('#ABB7C3')
ax.spines[spine].set_linewidth(.7)
ax.tick_params(axis='both',colors=NAVY,length=3,width=.6,pad=3)
def save_figure(fig,stem):
fig.savefig(FIGURES/(stem+'.pdf'),facecolor='white',bbox_inches='tight',pad_inches=.07)
fig.savefig(FIGURES/(stem+'.png'),dpi=250,facecolor='white',bbox_inches='tight',pad_inches=.07)
plt.close(fig)
def main():
FIGURES.mkdir(exist_ok=True)
plt.rcParams.update({
'font.family':'DejaVu Sans','font.size':9,
'axes.labelsize':9,'axes.titlesize':10,
'xtick.labelsize':8,'ytick.labelsize':8,
'text.color':NAVY,'axes.labelcolor':NAVY,
'pdf.fonttype':42,'ps.fonttype':42,
'mathtext.fontset':'dejavusans',
})
budget_data=[]
for n in range(2,41):
# n*B_(4,n) = (4n-1 - sqrt(4n^2-8n+1))/(4n).
lower=surd(F(4*n-1,4*n),F(-1,4*n),4*n*n-8*n+1)
upper=F(n)*coefficient(4,n)
budget_data.append({'n':n,'scaled_lower':lower,
'scaled_upper':str(upper),'scaled_iid':str(F(1))})
dimension_data=[]
for k in range(4,33):
gamma=surd(F(2*(k-2),k),F(-1,k),2*(k-2)*(k-3))
dimension_data.append({'k':k,'gamma_lower':gamma,'planar_reference':str(F(1,2))})
fig,axes=plt.subplots(1,2,figsize=(7,3.18),gridspec_kw={'wspace':.32})
left,right=axes
ns=[row['n'] for row in budget_data]
lowers=[surd_float(row['scaled_lower']) for row in budget_data]
uppers=[float(F(row['scaled_upper'])) for row in budget_data]
style_axes(left)
left.fill_between(ns,lowers,uppers,color=TEAL,alpha=.10,linewidth=0,zorder=1)
left.axhline(1,color=SLATE,linewidth=1.1,linestyle=(0,(4,3)),zorder=2)
left.plot(ns,uppers,color=NAVY,linewidth=1.8,zorder=3)
left.plot(ns,lowers,color=TEAL,linewidth=1.9,zorder=4)
left.scatter([2],[lowers[0]],color=TEAL,s=18,zorder=5)
left.set_xlim(1.3,40.7)
left.set_ylim(.475,1.065)
left.set_xticks([2,10,20,30,40])
left.set_yticks([.5,.6,.7,.8,.9,1.0])
left.set_xlabel('Selection budget n',labelpad=6)
left.set_ylabel('Scaled excess-loss coefficient',labelpad=5)
left.set_title('(a) Dimension four: certified bounds',loc='left',pad=11,fontweight='bold')
left.text(39.8,1.012,'Independent sampling: 1',ha='right',va='bottom',color=SLATE,fontsize=7.5)
left.text(39.8,.780,r'Upper bound $nU_4(n)$',ha='right',va='bottom',color=NAVY,fontsize=8)
left.text(39.8,.535,r'Lower bound $nB_{4,n}$',ha='right',va='bottom',color=TEAL,fontsize=8)
left.text(22,.640,'Unresolved interval',ha='center',va='center',color=SLATE,fontsize=7.7)
ks=[row['k'] for row in dimension_data]
gammas=[surd_float(row['gamma_lower']) for row in dimension_data]
style_axes(right)
right.axhline(.5,color=AMBER,linewidth=1.25,linestyle=(0,(4,3)),zorder=2)
right.plot(ks,gammas,color=TEAL,linewidth=1.9,zorder=3)
right.scatter([4,8,16,32],[gammas[k-4] for k in [4,8,16,32]],color=TEAL,s=15,zorder=4)
right.set_xlim(3.3,32.7)
right.set_ylim(.491,.59)
right.set_xticks([4,8,16,24,32])
right.set_yticks([.50,.52,.54,.56,.58])
right.set_xlabel('Ambient dimension k',labelpad=6)
right.set_ylabel(r'Asymptotic lower coefficient $\gamma_k$',labelpad=5)
right.set_title('(b) Fixed-dimension asymptotics',loc='left',pad=11,fontweight='bold')
right.text(31.8,.505,'Planar coefficient: 1/2',ha='right',va='bottom',color=AMBER,fontsize=8)
right.text(15,.582,r'$\liminf_{n\to\infty}n(F(k,n)-1)\geq\gamma_k$',
ha='center',va='center',fontsize=8.1,color=NAVY)
fig.subplots_adjust(left=.085,right=.99,bottom=.19,top=.87)
save_figure(fig,'selection_bounds')
profile_data=[]
for j in range(1,100):
t=F(j,100)
solution=solve_profile(5,4,t)
c=F(solution['excess_minimax'])
profile_data.append({'t':str(t),'excess_minimax':str(c),
'axial_fraction':solution['primal']['axial_fraction'],
'dual_count_types':solution['dual']['types']})
ts=[float(F(row['t'])) for row in profile_data]
cs=[float(F(row['excess_minimax'])) for row in profile_data]
fig,ax=plt.subplots(figsize=(7,3.8))
style_axes(ax)
ax.axhline(float(F(1,7)),color=AMBER,linewidth=1.3,linestyle=(0,(5,3)),zorder=2)
ax.plot(ts,cs,color=TEAL,linewidth=2,zorder=3)
ax.scatter([.5],[float(F(3,20))],color=NAVY,s=42,zorder=5,
edgecolors='white',linewidths=.9)
ax.plot([.5,.5],[0,float(F(3,20))],color=NAVY,linewidth=.7,
linestyle=(0,(2,4)),alpha=.45,zorder=1)
ax.annotate(r'$\mathfrak{C}_{5,4}(1/2)=3/20$',xy=(.5,.15),xytext=(.65,.166),
ha='center',va='center',color=NAVY,fontsize=10,
arrowprops={'arrowstyle':'-','color':NAVY,'linewidth':.8,
'connectionstyle':'angle3,angleA=0,angleB=60'})
ax.text(.985,float(F(1,7))+.005,'Planar excess reference: 1/7',
ha='right',va='bottom',color=AMBER,fontsize=8.6)
ax.set_xlim(0,1)
ax.set_ylim(0,.18)
ax.set_xticks([0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1])
ax.yaxis.set_major_locator(MultipleLocator(.03))
ax.set_xlabel(r'Total rare-point probability $t$',labelpad=7)
ax.set_ylabel('Exact fixed-profile minimax excess',labelpad=7)
ax.set_title(r'Symmetric profile: $k=5$, $n=4$, $p=(1-t,t/5,\ldots,t/5)$',
loc='left',pad=12,fontweight='bold',fontsize=10.5)
ax.text(.02,.169,'Worst case over all support geometries',
color=SLATE,ha='left',va='center',fontsize=8.5)
fig.subplots_adjust(left=.105,right=.985,bottom=.18,top=.86)
save_figure(fig,'profile_minimax')
data={
'schema':'neiru-siha-figure-data-v1',
'exact_arithmetic':'All rational values are Fraction strings. Surds are stored as exact rational parts, radical coefficients, and radicands.',
'plotting_note':'Floating conversion is used only to draw figures. Lines join sampled values; no interpolation theorem is asserted.',
'selection_bounds':{
'dimension_four_budget_samples':budget_data,
'asymptotic_dimension_samples':dimension_data,
'claim_scope':'These are lower and upper bounds, not the exact unrestricted profile.'},
'profile_minimax':{
'k':5,'n':4,'sampling_grid':'t=j/100, j=1,...,99',
'planar_reference':str(F(1,7)),
'marked_exact_point':{'t':str(F(1,2)),'excess_minimax':str(F(3,20))},
'samples':profile_data,
'claim_scope':'Exact minimax over every support geometry for the specified symmetric mass vector; not the unrestricted F(d,n).'}
}
(HERE/'figure_data.json').write_text(json.dumps(data,indent=2)+'\n',encoding='utf-8')
print(json.dumps({'status':'PASS','files':['figures/selection_bounds.pdf','figures/selection_bounds.png',
'figures/profile_minimax.pdf','figures/profile_minimax.png','figure_data.json'],
'budget_samples':len(budget_data),'dimension_samples':len(dimension_data),
'exact_profile_samples':len(profile_data)},indent=2))
if __name__=='__main__':
main()
|