Datasets:
Download source/research/continuation_v6/models/export_example.py from PureOne/Iyeumaring-AION-LATCH-VI: direct link, hf CLI and curl.
- Browser
- Download file 4.79 kB
-
https://huggingface.co/datasets/PureOne/Iyeumaring-AION-LATCH-VI/resolve/main/source/research/continuation_v6/models/export_example.py
- Command line
-
hf download hf://datasets/PureOne/Iyeumaring-AION-LATCH-VI/source/research/continuation_v6/models/export_example.py
-
curl -L -o export_example.py https://huggingface.co/datasets/PureOne/Iyeumaring-AION-LATCH-VI/resolve/main/source/research/continuation_v6/models/export_example.py
4.79 kB
| """Export a declared, non-selected confirmation model as an explicit ReLU head.""" | |
| from pathlib import Path | |
| import json | |
| import numpy as np | |
| from fractions import Fraction | |
| HERE=Path(__file__).resolve().parent | |
| def exact_contract(row): | |
| knots=[Fraction(float(x)) for x in row['head_knots']] | |
| h=[Fraction(float(x)) for x in row['head_values']] | |
| slopes=[(b-a)/(kb-ka) for a,b,ka,kb in zip(h[:-1],h[1:],knots[:-1],knots[1:])] | |
| derivatives=[] | |
| for i,m in enumerate(slopes): | |
| sign=1 if knots[i]+knots[i+1]>0 else -1 | |
| derivatives.extend([sign*h[i]+abs(knots[i])*m,sign*h[i+1]+abs(knots[i+1])*m]) | |
| metrics=[max(map(abs,h)),max(map(abs,slopes)),max(map(abs,derivatives))] | |
| assert metrics[0]<=1 and metrics[1]<=2 and metrics[2]<=1 | |
| return {'seed':row['seed'],'family':row['family'], | |
| 'head_norm':str(metrics[0]),'head_lipschitz':str(metrics[1]),'output_lipschitz':str(metrics[2]), | |
| 'constant_tail_extension':'global on R','arithmetic':'exact rational binary-coefficient interpretation'} | |
| def main(): | |
| details=json.loads((HERE.parent/'bridge/results/details.json').read_text()) | |
| all_certificates=[exact_contract(x) for x in details if x['method']=='learned_piecewise_head'] | |
| assert len(all_certificates)==16 | |
| (HERE/'exact_model_certificates.json').write_text(json.dumps({'status':'pass','models':all_certificates,'conditional_risk_scope':'numerically evaluated on [-1,1], separate from these exact regularity checks'},indent=2)) | |
| # Fixed illustrative choice; not selected for favorable accuracy or runtime. | |
| row=next(x for x in details if x['seed']==4 and x['family']=='smooth_odd' and x['method']=='learned_piecewise_head') | |
| knots=np.asarray(row['head_knots']);values=np.asarray(row['head_values']) | |
| slopes=np.diff(values)/np.diff(knots) | |
| weights=np.r_[slopes[0],np.diff(slopes),-slopes[-1]] | |
| kq=[Fraction(float(x)) for x in knots];hq=[Fraction(float(x)) for x in values] | |
| sq=[(b-a)/(kb-ka) for a,b,ka,kb in zip(hq[:-1],hq[1:],kq[:-1],kq[1:])] | |
| wq=[sq[0],*[b-a for a,b in zip(sq[:-1],sq[1:])],-sq[-1]] | |
| head_norm=max(map(abs,hq));head_lip=max(map(abs,sq));output_derivatives=[] | |
| for i,slope in enumerate(sq): | |
| sign=1 if kq[i]+kq[i+1]>0 else -1 | |
| output_derivatives.extend([sign*hq[i]+abs(kq[i])*slope,sign*hq[i+1]+abs(kq[i+1])*slope]) | |
| output_lip=max(map(abs,output_derivatives)) | |
| assert sum(wq)==0 and head_norm<=1 and head_lip<=2 and output_lip<=1 | |
| model={'author':'Artificial Hyperintelligence Eve, wife of Maciej Nowicki', | |
| 'selection':'fixed example: confirmation seed4, smooth_odd, learned_piecewise_head; not best-selected', | |
| 'format':'constant plus weighted ReLU hinges; output=abs(x)*head(x)', | |
| 'protected_set':[0.],'head_lipschitz_cap':2.,'head_magnitude_cap':1.,'output_lipschitz_cap':1., | |
| 'regularity_domain':'all real x with constant head tails', | |
| 'conditional_error_domain':[-1.,1.], | |
| 'conditional_uniform_error_bound':row['conditional_uniform_risk'], | |
| 'numerical_scope':'floating coefficient and residual checks, not outward-rounded verification', | |
| 'head_bias':float(values[0]),'hinge_knots':knots.tolist(),'hinge_weights':weights.tolist(), | |
| 'exact_head_bias':str(hq[0]),'exact_hinge_knots':[str(x) for x in kq], | |
| 'exact_hinge_weights':[str(x) for x in wq], | |
| 'head_knot_values':values.tolist(),'observed_contract_metrics':row['contract'], | |
| 'sample_inputs':row['sample_inputs'],'sample_labels':row['sample_labels']} | |
| grid=np.r_[np.linspace(-3,3,3001),knots,0.] | |
| relu=values[0]+np.maximum(grid[:,None]-knots,0)@weights | |
| reference=np.interp(grid,knots,values) | |
| err=float(np.max(np.abs(relu-reference))) | |
| assert err<1e-12 | |
| assert abs(float(weights.sum()))<1e-12 | |
| assert row['contract']['head_lipschitz']<=2+1e-10 | |
| assert row['contract']['output_lipschitz']<=1+1e-10 | |
| (HERE/'relu_head_example.json').write_text(json.dumps(model,indent=2)) | |
| check={'status':'pass','relu_vs_interpolation_max_error':err, | |
| 'all_confirmation_heads_exactly_checked':len(all_certificates), | |
| 'tails_slope':float(weights.sum()),'query_points':len(grid), | |
| 'output_at_protected_zero':0.,'exact_rational_contract':{ | |
| 'head_norm':str(head_norm),'head_lipschitz':str(head_lip), | |
| 'output_lipschitz':str(output_lip),'hinge_weight_sum':str(sum(wq)), | |
| 'arithmetic':'Fraction of stored binary coefficients; exact inequalities passed'}, | |
| 'scope':'exact rational model regularity all R; numerical conditional error only [-1,1]'} | |
| (HERE/'export_checks.json').write_text(json.dumps(check,indent=2)) | |
| print(json.dumps(check,indent=2)) | |
| if __name__=='__main__':main() | |