Datasets:
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
mathematics
optimization
gradient-descent
convex-optimization
learning-theory
recursive-self-improvement
Download research/code/explore_transcripts.py from PureOne/Nhoryun-Omega-III: direct link, hf CLI and curl.
- Browser
- Download file 3.37 kB
-
https://huggingface.co/datasets/PureOne/Nhoryun-Omega-III/resolve/main/research/code/explore_transcripts.py
- Command line
-
hf download hf://datasets/PureOne/Nhoryun-Omega-III/research/code/explore_transcripts.py
-
curl -L -o explore_transcripts.py https://huggingface.co/datasets/PureOne/Nhoryun-Omega-III/resolve/main/research/code/explore_transcripts.py
3.37 kB
| #!/usr/bin/env python3 | |
| """Optional numerical exploration of the exact finite model (not a proof). | |
| Requires numpy and cvxpy with a semidefinite solver. Solver results and their | |
| residuals are reported as numerical estimates. Exact certificates must be | |
| checked separately with trajectory_certificates.py or the dedicated verifiers. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| from fractions import Fraction as Q | |
| import numpy as np | |
| import cvxpy as cp | |
| from trajectory_certificates import gd_coefficients, interpolation_form | |
| def model(h, horizon, mu=0, observations=None): | |
| n=horizon+1 | |
| G=cp.Variable((n,n),symmetric=True) | |
| f=cp.Variable(n) | |
| con=[G>>0,f[0]==0,G[0,0]<=1] | |
| coeff=gd_coefficients(h,horizon) | |
| forms=[] | |
| for i in range(n): | |
| for j in range(n): | |
| if i==j: | |
| continue | |
| form=interpolation_form(coeff,i,j,mu) | |
| val=np.array(form.loss,dtype=float)@f+cp.sum(cp.multiply(np.array(form.gram,dtype=float),G)) | |
| con.append(val>=0) | |
| forms.append(form) | |
| if observations: | |
| for i,value in observations.items(): | |
| con.append(f[int(i)]==float(value)) | |
| return G,f,con,forms | |
| def solve_objective(h,horizon,mu,c,observations=None,maximize=False): | |
| G,f,con,forms=model(h,horizon,mu,observations) | |
| expression=np.array(c,dtype=float)@f | |
| problem=cp.Problem(cp.Maximize(expression) if maximize else cp.Minimize(expression),con) | |
| problem.solve(solver='CLARABEL',tol_feas=1e-10,tol_gap_abs=1e-10,tol_gap_rel=1e-10,max_iter=500) | |
| result={'status':problem.status,'value_approx':problem.value, | |
| 'proof_status':'numerical exploration only'} | |
| if G.value is not None and f.value is not None: | |
| values=[float(np.array(z.loss,dtype=float)@f.value+np.sum(np.array(z.gram,dtype=float)*G.value)) for z in forms] | |
| result.update(min_gram_eigenvalue_approx=float(np.linalg.eigvalsh(G.value).min()), | |
| min_interpolation_slack_approx=min(values), | |
| loss_values_approx=f.value.tolist()) | |
| return result | |
| def main(): | |
| p=argparse.ArgumentParser(description=__doc__) | |
| p.add_argument('--mode',choices=['compensation','forecast'],default='compensation') | |
| p.add_argument('--h',default='9/5') | |
| p.add_argument('--output',type=Path) | |
| args=p.parse_args() | |
| if args.mode=='compensation': | |
| h=Q(args.h) | |
| report={'mode':args.mode,'h':str(h),'result':solve_objective(h,3,Q(0),[Q(2,3),-1,0,Q(1,3)])} | |
| else: | |
| h=Q(1,5) | |
| obs={0:Q(0),1:Q(-9,50),2:Q(-369,1250)} | |
| c=[Q(0)]*7;c[2]=1;c[6]=-1 | |
| lower=solve_objective(h,6,Q(1,10),c,obs) | |
| upper=solve_objective(h,6,Q(1,10),c,obs,maximize=True) | |
| known=(Q(1,2)*(Q(4,5)**4-Q(4,5)**12)) | |
| report={'mode':args.mode,'h':str(h),'mu':'1/10','L':1, | |
| 'observed_shifted_values':{str(k):str(v) for k,v in obs.items()}, | |
| 'query':'f_2 - f_6','lower':lower,'upper':upper, | |
| 'one_known_quadratic_continuation_exact':str(known), | |
| 'one_known_quadratic_continuation_approx':float(known)} | |
| if args.output: | |
| args.output.parent.mkdir(parents=True,exist_ok=True) | |
| args.output.write_text(json.dumps(report,indent=2)+'\n') | |
| print(json.dumps(report,indent=2)) | |
| if __name__=='__main__': | |
| main() | |