Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
recursive-self-improvement
artificial-intelligence
homotopy-theory
statistical-experiments
quantum-error-correction
reproducible-research
Download research/src/optional_lp.py from PureOne/Xhorielun-Sigma: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/datasets/PureOne/Xhorielun-Sigma/resolve/main/research/src/optional_lp.py
- Command line
-
hf download hf://datasets/PureOne/Xhorielun-Sigma/research/src/optional_lp.py
-
curl -L -o optional_lp.py https://huggingface.co/datasets/PureOne/Xhorielun-Sigma/resolve/main/research/src/optional_lp.py
2 kB
| """Optional SciPy synthesis, followed by an EXACT rational primal check. | |
| The optimization result is not a formal optimality certificate. The returned | |
| recovery and its recomputed rational error ARE exactly checkable upper bounds. | |
| """ | |
| from fractions import Fraction as Q | |
| from exact import shape | |
| from channels import validate_channel, recovery_error | |
| def synthesize_recovery(old, new, max_denominator=1_000_000): | |
| import numpy as np | |
| from scipy.optimize import linprog | |
| validate_channel(old);validate_channel(new) | |
| m,s=shape(old);n,s2=shape(new) | |
| if s!=s2:raise ValueError('State spaces differ') | |
| nr=m*n;nz=m*s;nv=nr+nz+1;eps=nv-1 | |
| c=np.zeros(nv);c[eps]=1 | |
| aeq=[];beq=[] | |
| for j in range(n): | |
| row=np.zeros(nv) | |
| for i in range(m):row[i*n+j]=1 | |
| aeq.append(row);beq.append(1) | |
| aub=[];bub=[] | |
| for i in range(m): | |
| for t in range(s): | |
| z=nr+i*s+t | |
| for sign in [-1,1]: | |
| row=np.zeros(nv) | |
| for j in range(n):row[i*n+j]=sign*float(new[j][t]) | |
| row[z]=-1 | |
| aub.append(row);bub.append(sign*float(old[i][t])) | |
| for t in range(s): | |
| row=np.zeros(nv) | |
| for i in range(m):row[nr+i*s+t]=1 | |
| row[eps]=-2;aub.append(row);bub.append(0) | |
| res=linprog(c,A_ub=aub,b_ub=bub,A_eq=aeq,b_eq=beq, | |
| bounds=[(0,None)]*(nv-1)+[(0,1)],method='highs') | |
| if not res.success:raise RuntimeError(res.message) | |
| # Rationalize then normalize each column exactly. No tolerance in final check. | |
| r=[[Q(max(0,float(res.x[i*n+j]))).limit_denominator(max_denominator) | |
| for j in range(n)] for i in range(m)] | |
| for j in range(n): | |
| total=sum(r[i][j] for i in range(m)) | |
| if not total:raise RuntimeError('Numerical recovery column vanished') | |
| for i in range(m):r[i][j]/=total | |
| e=recovery_error(old,new,r) | |
| return {'recovery':r,'certified_error':e,'numerical_objective':float(res.fun), | |
| 'optimality_certified':False} | |