"""Independent algebraic and negative-control checks of the finite audit.""" import unittest from fractions import Fraction as F from pathlib import Path import sys sys.path.insert(0, str(Path(__file__).resolve().parents[1])) import exact_kernel as e class ExactKernelTests(unittest.TestCase): def test_witness_cannot_separate_a_representable_target(self): one,x1,x2,x3,z12=e.features() target=[F(3)*a-F(2)*b+F(7) for a,b in zip(x1,x3)] self.assertEqual(e.predict_fit([one,x1,x2,x3],target),target) self.assertEqual(sum(a*b for a,b in zip(z12,target)),0) def test_rank_is_coordinate_invariant_under_scaling(self): cols=list(e.features()) changed=[[F(j+2)*x for x in col] for j,col in enumerate(cols)] self.assertEqual(e.rank(e.transpose(cols)),e.rank(e.transpose(changed))) changed.append(changed[1]) self.assertEqual(e.rank(e.transpose(changed)),5) def test_zero_support_reweighting_can_destroy_dimension(self): cols=list(e.features()) rows=[i for i,x in enumerate(e.DOMAIN) if x[0]==x[1]] self.assertLess(e.rank([[c[i] for c in cols] for i in rows]),5) def test_determinant_detects_nontrivial_dependence(self): self.assertEqual(e.det([[1,2,3],[2,4,6],[0,1,1]]),0) self.assertEqual(e.det([[1,2],[3,4]]),-2) def test_full_exact_audit(self): out=e.run() self.assertEqual(out['tract']['grassmann_pluecker_relations_checked'],1960) self.assertEqual(out['evaluation']['optimal_two_step_expected_remaining'],'1') self.assertEqual(out['aionvita']['lineage_max_prediction_error'],'0') if __name__=='__main__': unittest.main()