"""Make separate, default-color figures from the delivered observed-data tables.""" from pathlib import Path import json import numpy as np import pandas as pd import matplotlib.pyplot as plt ROOT=Path(__file__).resolve().parents[1] def figures(show=False): out=ROOT/'figures';out.mkdir(exist_ok=True) g=pd.read_csv(ROOT/'results/full_gradient.csv');e=pd.read_csv(ROOT/'results/full_evaluation.csv') p=np.load(ROOT/'data/pca.npy');s=pd.read_csv(ROOT/'data/selected_checkpoint_metrics.csv');c=pd.read_csv(ROOT/'data/corner_sensitivity.csv') def finish(fig,name): fig.tight_layout();fig.savefig(out/name,dpi=210) if show and name=='01_full_gradient.png':plt.show() plt.close(fig) fig,ax=plt.subplots(figsize=(8.6,4.6));ax.plot(g.step,g.grad_norm,lw=.75,alpha=.55,label='Original-source observations');ax.plot(g.step,g.mean_11,lw=1.7,label='11-step centered average');ax.axvline(169,lw=1,ls=':',label='Gradient maximum: 169');ax.axvline(190,lw=1,ls='--',label='Filtered path-bend maximum: 190');ax.set(xlabel='Training step',ylabel='Logged gradient norm',title='Full 792-step training record');ax.legend(fontsize=8.5);finish(fig,'01_full_gradient.png') fig,ax=plt.subplots(figsize=(8.6,4.2));ax.plot(e.step,e.eval_loss,marker='.',lw=1);ax.set(xlabel='Training step',ylabel='Logged evaluation loss',title='Evaluation loss across 79 recorded observations');finish(fig,'02_full_loss.png') fig,ax=plt.subplots(figsize=(8.6,4.5));ax.plot(p[:,1],p[:,2],lw=1);ax.scatter(p[:,1],p[:,2],s=9) for st in [5,150,180,190,300,500,790]: row=p[p[:,0]==st][0];ax.annotate(str(st),(row[1],row[2]),xytext=(5,7 if st!=180 else -16),textcoords='offset points',fontsize=8) ax.set(xlabel='Principal component 1 (81.09% variance)',ylabel='Principal component 2 (13.90% variance)',title='B-factor trajectory: all 158 regularly sampled checkpoints');finish(fig,'03_B_pca.png') fig,ax=plt.subplots(figsize=(8.6,4.2));ax.plot(s.step,s.effective_update_frobenius_norm,marker='o',markersize=3.5);ax.set(xlabel='Training step',ylabel='Frobenius norm of effective update',title='Effective weight-update magnitude: 16 selected checkpoints');finish(fig,'04_effective_norm_selected.png') fig,ax=plt.subplots(figsize=(8.6,4.4));thresholds=[0,.0001,.0005,.001,.002,.005] for lag in [5,10,15]: z=c[c.lag==lag];ax.plot(range(len(z)),z.peak_step_B_and_effective,marker='o',label=f'Lag {lag} training steps') ax.set_xticks(range(6),['0','0.0001','0.0005','0.001','0.002','0.005']);ax.set(xlabel='Factor-amplitude eligibility threshold',ylabel='Training step of maximum local bend',title='The selected turning point depends on the measurement rule');ax.legend(fontsize=8.5);finish(fig,'05_peak_sensitivity.png') fig,ax=plt.subplots(figsize=(8.6,4.2));ax.plot(s.step,s.cosine_with_final_effective_update,marker='o',markersize=3.5);ax.set(xlabel='Training step',ylabel='Cosine with final effective weight update',title='Direction continues evolving after the early episode');ax.set_ylim(0,1.04);finish(fig,'06_alignment_selected.png') if __name__=='__main__':figures()