Datasets:
Formats:
csv
Languages:
English
Size:
100K - 1M
Tags:
research-artifact
synthetic-data
mathematical-proofs
system-identification
inverse-problems
nonlinear-dynamics
License:
Download tests/test_nonlinear.py from PureOne/EVE-Obstruction-Tomography: direct link, hf CLI and curl.
- Browser
- Download file 3.12 kB
-
https://huggingface.co/datasets/PureOne/EVE-Obstruction-Tomography/resolve/main/tests/test_nonlinear.py
- Command line
-
hf download hf://datasets/PureOne/EVE-Obstruction-Tomography/tests/test_nonlinear.py
-
curl -L -o test_nonlinear.py https://huggingface.co/datasets/PureOne/EVE-Obstruction-Tomography/resolve/main/tests/test_nonlinear.py
3.12 kB
| import unittest | |
| import numpy as np | |
| from scipy.integrate import solve_ivp | |
| from scipy.optimize import brentq | |
| from ot.nonlinear import (oscillator_flow, delay_embedding, distance_squared, | |
| recover_grid, recover_anchored_map, drift_certificate) | |
| class NonlinearTests(unittest.TestCase): | |
| def test_flow_against_independent_ode_integration(self): | |
| for x in [[.6,.2],[-.1,.8],[1.,0.]]: | |
| def f(t,y): | |
| omega=1+.5*np.dot(y,y) | |
| return [-omega*y[1],omega*y[0]] | |
| sol=solve_ivp(f,[0,2],x,rtol=1e-11,atol=1e-13) | |
| np.testing.assert_allclose(oscillator_flow(x,2),sol.y[:,-1],atol=3e-11) | |
| def test_delay_embedding_inversion(self): | |
| for x in [[.3,.4],[-.8,.1],[0.,-.9]]: | |
| z=delay_embedding(x) | |
| limit=np.sqrt(1-z[0]**2) | |
| recovered=brentq(lambda v:delay_embedding([z[0],v])[1]-z[1],-limit,limit) | |
| self.assertAlmostEqual(recovered,x[1],places=11) | |
| def test_common_oracle_different_topology(self): | |
| delta=.003; hole=np.sqrt(2*delta) | |
| r=np.linspace(0,2,2001); pts=np.column_stack([r,r*0]) | |
| d0=distance_squared(pts,"disk");d1=distance_squared(pts,"annulus",hole) | |
| common=(d0+d1)/2 | |
| self.assertLessEqual(np.max(np.abs(common-d0)),delta+1e-15) | |
| self.assertLessEqual(np.max(np.abs(common-d1)),delta+1e-15) | |
| self.assertAlmostEqual(d1[0],2*delta) | |
| def test_squared_loss_recovers_hole_lost_by_support(self): | |
| angles=np.linspace(0,2*np.pi,501) | |
| a=np.column_stack([np.cos(angles),np.sin(angles)]) | |
| # The maximizing unit-circle point is feasible in BOTH worlds. | |
| np.testing.assert_allclose(np.sum(a*a,axis=1),1,atol=1e-15) | |
| self.assertEqual(distance_squared([[0,0]],"circle")[0],1) | |
| self.assertEqual(distance_squared([[0,0]],"disk")[0],0) | |
| def test_adversarial_probe_noise_attains_map_bound(self): | |
| y=np.array([.3,-.5]);delta=.01 | |
| targets=np.stack([-np.eye(2),np.eye(2)],axis=1) | |
| losses=np.sum((y-targets)**2,axis=-1) | |
| losses[:,0]+=delta;losses[:,1]-=delta | |
| error=np.linalg.norm(recover_anchored_map(losses)-y) | |
| bound,_=drift_certificate(.1,delta,2,3,4) | |
| self.assertAlmostEqual(error,bound,places=14) | |
| def test_grid_certificate_under_adversarial_noise(self): | |
| a=np.linspace(-1.1,1.1,101);X,Y=np.meshgrid(a,a) | |
| grid=np.column_stack([X.ravel(),Y.ravel()]) | |
| h=np.sqrt(2)*(a[1]-a[0])/2;delta=.0003 | |
| exact=distance_squared(grid,"circle") | |
| for sign in [-1,1]: | |
| selected,mask,bound=recover_grid(grid,exact+sign*delta,h,delta) | |
| self.assertLessEqual(np.sqrt(distance_squared(selected,"circle")).max(),bound+1e-14) | |
| # Dense sample provides an additional empirical check of the reverse direction. | |
| from scipy.spatial import cKDTree | |
| theta=np.linspace(0,2*np.pi,2001) | |
| circle=np.column_stack([np.cos(theta),np.sin(theta)]) | |
| self.assertLessEqual(cKDTree(selected).query(circle)[0].max(),h+1e-14) | |
| if __name__=="__main__": | |
| unittest.main() | |