Datasets:
Formats:
csv
Languages:
English
Size:
< 1K
Tags:
mathematics
linear-algebra
convex-optimization
optimal-recovery
neural-representations
robustness
Download research/tests/test_core.py from PureOne/luminous-hypercontinuum-foundation-v3: direct link, hf CLI and curl.
- Browser
- Download file 2.82 kB
-
https://huggingface.co/datasets/PureOne/luminous-hypercontinuum-foundation-v3/resolve/main/research/tests/test_core.py
- Command line
-
hf download hf://datasets/PureOne/luminous-hypercontinuum-foundation-v3/research/tests/test_core.py
-
curl -L -o test_core.py https://huggingface.co/datasets/PureOne/luminous-hypercontinuum-foundation-v3/resolve/main/research/tests/test_core.py
2.82 kB
| import math | |
| import numpy as np | |
| import pytest | |
| from lhf.core import * | |
| from lhf.recovery import * | |
| from lhf.memory import prune_dominated | |
| def test_flagship_frontier(budget): | |
| from lhf.core import flagship_contraction | |
| family,_,_=flagship_family() | |
| assert robust_floor(family,flagship_contraction(budget))==pytest.approx(flagship_frontier(budget),abs=1e-12) | |
| def test_determinant_and_contraction(d,budget): | |
| y=np.diag(np.geomspace(.25,8,d)) | |
| c=contraction_from_lower_bound(y,budget) | |
| assert np.linalg.slogdet(c)[1]==pytest.approx(-budget,abs=1e-9) | |
| assert np.linalg.norm(c,2)<=1+1e-10 | |
| assert np.linalg.eigvalsh(c.T@y@c)[0]>=frontier_from_lower_bound(y,budget)-1e-10 | |
| def test_pair_duality(a,b): | |
| y,z=envelope_pair(a,b) | |
| assert logdet_dual_bound([a,b],z)==pytest.approx(np.linalg.slogdet(y)[1],abs=1e-10) | |
| def test_validation_rejects_bad_family(invalid): | |
| with pytest.raises(ValueError):validate_family(invalid) | |
| def test_budget_rejection(budget): | |
| with pytest.raises(ValueError):contraction_from_lower_bound(np.eye(2),budget) | |
| def test_sobolev_radius(d,h): | |
| r=sobolev_radius(d,1.,1.,h) | |
| expected=1. if h>=1 else np.sqrt(h*h+(1-h*h)/(d+1)**2) | |
| assert r==pytest.approx(expected) | |
| def test_nonassociativity(): | |
| a,b=np.diag([4.,1.]),np.diag([1.,4.]); n=np.array([[4.,3.],[3.,4.]])/5 | |
| ab,_=envelope_pair(a,b); left,_=envelope_pair(ab,n) | |
| bn,_=envelope_pair(b,n);right,_=envelope_pair(a,bn) | |
| assert not np.allclose(left,right) | |
| assert np.allclose(right,n) | |
| def test_pruning_witnesses(): | |
| ms=[3*np.eye(2),np.diag([1.,2.]),np.eye(2),2*np.eye(2)] | |
| keep,witnesses=prune_dominated(ms) | |
| assert keep==[2] | |
| for j,i in witnesses.items(): | |
| assert np.linalg.eigvalsh(ms[j]-ms[i])[0]>=-1e-10 | |
| def test_bad_dilation(): | |
| with pytest.raises(ValueError):unitary_dilation(2*np.eye(2)) | |
| def test_bad_requested_floor(): | |
| with pytest.raises(ValueError):contraction_from_lower_bound(np.eye(2),1.,floor=1.) | |
| with pytest.raises(ValueError):contraction_from_lower_bound(np.eye(2),0.,floor=2.) | |
| with pytest.raises(ValueError):contraction_from_lower_bound(np.eye(2),0.,floor=float("nan")) | |