diff --git a/tests/test_fuzzifier.py b/test/test_fuzzifier.py similarity index 68% rename from tests/test_fuzzifier.py rename to test/test_fuzzifier.py index 894606b..298afe7 100644 --- a/tests/test_fuzzifier.py +++ b/test/test_fuzzifier.py @@ -1,12 +1,12 @@ -from unittest import TestCase -from tests.fuzzifier import * -from tests.__init__ import * +import numpy as np +import unittest +from mulearn import FuzzyInductor +import mulearn.fuzzifier as fuzz - -class TestCrispFuzzifier(TestCase): +class TestCrispFuzzifier(unittest.TestCase): def test_compute(self): X = np.array([[0.91232935], @@ -25,27 +25,28 @@ def test_compute(self): [0.95579843], [0.23678875]]) - mus = np.array([0.00836525, 0.99818461, 0.00124992, 0.5013639 , 0.91687722, - 0.83942725, 0.25137643, 0.0040433 , 0.35836777, 0.98317438, - 0.72841124, 0.77240852, 0.16950794, 0.00289302, 0.14237189]) + mus = np.array( + [0.00836525, 0.99818461, 0.00124992, 0.5013639 , 0.91687722, + 0.83942725, 0.25137643, 0.0040433 , 0.35836777, 0.98317438, + 0.72841124, 0.77240852, 0.16950794, 0.00289302, 0.14237189]) - f = CrispFuzzifier() + f = fuzz.CrispFuzzifier() m = FuzzyInductor(fuzzifier=f).fit(X, mus) - - result = list(m.fuzzifier.get_membership()(X)) + result = m.predict(X) self.assertEqual(result, [0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1]) - f = CrispFuzzifier(profile='infer') + f = fuzz.CrispFuzzifier(profile='infer') m = FuzzyInductor(fuzzifier=f).fit(X, mus) - result = list(m.fuzzifier.get_membership()(X)) + result = m.predict(X) - self.assertEqual(result, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) + self.assertEqual(result, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) -class TestLinearFuzzifier(TestCase): +class TestLinearFuzzifier(unittest.TestCase): def test_compute(self): X = np.array([[0.91232935], @@ -64,15 +65,16 @@ def test_compute(self): [0.95579843], [0.23678875]]) - mus = np.array([0.00836525, 0.99818461, 0.00124992, 0.5013639 , 0.91687722, - 0.83942725, 0.25137643, 0.0040433 , 0.35836777, 0.98317438, - 0.72841124, 0.77240852, 0.16950794, 0.00289302, 0.14237189]) + mus = np.array( + [0.00836525, 0.99818461, 0.00124992, 0.5013639 , 0.91687722, + 0.83942725, 0.25137643, 0.0040433 , 0.35836777, 0.98317438, + 0.72841124, 0.77240852, 0.16950794, 0.00289302, 0.14237189]) - f = LinearFuzzifier() + f = fuzz.LinearFuzzifier() m = FuzzyInductor(fuzzifier=f).fit(X, mus) - result = list(m.fuzzifier.get_membership()(X)) + result = m.predict(X) correct = [0.19171390089298312, 0.9623537182595308, @@ -91,13 +93,13 @@ def test_compute(self): 0.5148178265851036] for chi, chi_opt in zip(result, correct): - self.assertAlmostEqual(chi, chi_opt, places=5) + self.assertAlmostEqual(float(chi), chi_opt, places=5) - f = LinearFuzzifier(profile='infer') + f = fuzz.LinearFuzzifier(profile='infer') m = FuzzyInductor(fuzzifier=f).fit(X, mus) - result = list(m.fuzzifier.get_membership()(X)) + result = m.predict(X) correct = [0.0, 1.0, @@ -111,12 +113,13 @@ def test_compute(self): 0.9709822271100618, 0.7436342714864057, 0.7436342709951314, - 0.16644887611636805, - 0.0, - 0.11758680761161522] + 0.16644887611636805, + 0.0, + 0.11758680761161522] for chi, chi_opt in zip(result, correct): self.assertAlmostEqual(chi, chi_opt, places=5) - \ No newline at end of file +if __name__ == '__main__': + unittest.main() diff --git a/test/test_kernel.py b/test/test_kernel.py new file mode 100644 index 0000000..78fac48 --- /dev/null +++ b/test/test_kernel.py @@ -0,0 +1,149 @@ + +import numpy as np +import unittest + +import mulearn.kernel as kernel + + +class Test_LinearKernel(unittest.TestCase): + def test_compute(self): + k =kernel.LinearKernel() + self.assertEqual(k.compute(np.array([1, 0, 1]).reshape(1,-1), + np.array([2, 2, 2]).reshape(1,-1)), 4) + self.assertEqual(k.compute(np.array((1, 0, 2)).reshape(1,-1), + np.array((-1, 2, 5)).reshape(1,-1)), 9) + + self.assertAlmostEqual(k.compute( + np.array([1.2, -0.4, -2]).reshape(1,-1), + np.array([4, 1.2, .5]).reshape(1,-1))[0], 3.32) + self.assertAlmostEqual(k.compute( + np.array((1.2, -0.4, -2)).reshape(1,-1), + np.array([4, 1.2, .5]).reshape(1,-1))[0], 3.32) + + with self.assertRaises(ValueError): + k.compute(np.array([1, 0, 1]).reshape(1,-1), + np.array([2, 2]).reshape(1,-1)) + + +class TestPolynomialKernel(unittest.TestCase): + def test_compute(self): + with self.assertRaises(ValueError): + kernel.PolynomialKernel(3.2) + + with self.assertRaises(ValueError): + kernel.PolynomialKernel(-2) + + p = kernel.PolynomialKernel(2) + self.assertEqual(p.compute(np.array((1, 0, 2)).reshape(1,-1), + np.array((-1, 2, 5)).reshape(1,-1)), 100) + self.assertAlmostEqual(p.compute( + np.array([1.2, -0.4, -2]).reshape(1,-1), + np.array([4, 1.2, .5]).reshape(1,-1)), 18.6624) + + p = kernel.PolynomialKernel(5) + self.assertEqual(p.compute(np.array((1, 0, 2)).reshape(1,-1), + np.array([-1, 2, 5]).reshape(1,-1)), 10 ** 5) + self.assertAlmostEqual(p.compute( + np.array((1.2, -0.4, -2)).reshape(1,-1), + np.array((4, 1.2, .5)).reshape(1,-1)), + 1504.59195, delta=10**-6) + + with self.assertRaises(ValueError): + p.compute(np.array((1, 0, 2)).reshape(1,-1), + np.array((-1, 2)).reshape(1,-1)) + + + +class TestHomogeneousPolynomialKernel(unittest.TestCase): + def test_compute(self): + with self.assertRaises(ValueError): + kernel.HomogeneousPolynomialKernel(3.2) + + with self.assertRaises(ValueError): + kernel.HomogeneousPolynomialKernel(-2) + + h = kernel.HomogeneousPolynomialKernel(2) + self.assertEqual(h.compute(np.array((1, 0, 2)).reshape(1,-1), + np.array((-1, 2, 5)).reshape(1,-1)), 81.0) + self.assertAlmostEqual(h.compute( + np.array([1.2, -0.4, -2]).reshape(1,-1), + np.array([4, 1.2, .5]).reshape(1,-1))[0], 11.0224) + + h = kernel.HomogeneousPolynomialKernel(5) + self.assertEqual(h.compute( + np.array((1, 0, 2)).reshape(1,-1), + np.array([-1, 2, 5]).reshape(1,-1)) , 59049.0) + self.assertAlmostEqual(h.compute( + np.array((1.2, -0.4, -2)).reshape(1,-1), + np.array((4, 1.2, .5)).reshape(1,-1)), + 403.357761, delta=10**-6) + + with self.assertRaises(ValueError): + h.compute(np.array((1, 0, 2)).reshape(1,-1), + np.array((-1, 2)).reshape(1,-1)) + + +class TestGaussianKernel(unittest.TestCase): + def test_compute(self): + with self.assertRaises(ValueError): + kernel.GaussianKernel(-5) + + k = kernel.GaussianKernel(1) + self.assertAlmostEqual(k.compute(np.array((1, 0, 1)).reshape(1,-1), + np.array((0, 0, 1)).reshape(1,-1))[0], + 0.60653065) + self.assertAlmostEqual(k.compute( + np.array([-3, 1, 0.5]).reshape(1,-1), + np.array([1, 1.2, -8]).reshape(1,-1))[0], 6.73e-20) + self.assertAlmostEqual(k.compute( + np.array([-1, -4, 3.5]).reshape(1,-1), + np.array((1, 3.2, 6)).reshape(1,-1))[0], 3.29e-14) + + with self.assertRaises(ValueError): + k.compute(np.array([-1, 3.5]).reshape(1,-1), + np.array((1, 3.2, 6)).reshape(1,-1)) + + +class TestHyperbolicKernel(unittest.TestCase): + def test_compute(self): + k = kernel.HyperbolicKernel(1, 5) + self.assertAlmostEqual(k.compute( + np.array((1, 0, 1)).reshape(1,-1), + np.array((0, 0, 1)).reshape(1,-1))[0], 0.9999877) + self.assertAlmostEqual(k.compute( + np.array([-3, 1, 0.5]).reshape(1,-1), + np.array([1, 1.2, -8]).reshape(1,-1))[0], + -0.6640367, delta=10**-7) + self.assertAlmostEqual(k.compute( + np.array([-1, -4, 3.5]).reshape(1,-1), + np.array((1, 3.2, 6)).reshape(1,-1))[0], + 0.9999999, delta=10**-7) + + with self.assertRaises(ValueError): + k.compute(np.array([-1, 3.5]).reshape(1,-1), + np.array((1, 3.2, 6)).reshape(1,-1)) + + +class TestPrecomputedKernel(unittest.TestCase): + def test_compute(self): + with self.assertRaises(ValueError): + kernel.PrecomputedKernel(np.array(((1, 2), (3, 4, 5)))) + + k = kernel.PrecomputedKernel(np.array(((1, 2), (3, 4)))) + self.assertEqual(k.compute( + np.array([1]).reshape(1,-1), + np.array([1]).reshape(1,-1)), 4.0) + self.assertEqual(k.compute( + np.array([1]).reshape(1,-1), + np.array([0]).reshape(1,-1)), 3.0) + + with self.assertRaises(IndexError): + k.compute(np.array([1]).reshape(1,-1), np.array([2]).reshape(1,-1)) + + with self.assertRaises(IndexError): + k.compute(np.array([0]).reshape(1,-1), + np.array([1.6]).reshape(1,-1)) + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_optimization.py b/test/test_optimization.py new file mode 100644 index 0000000..58a0926 --- /dev/null +++ b/test/test_optimization.py @@ -0,0 +1,98 @@ + +import numpy as np +import unittest + +from mulearn import FuzzyInductor +from mulearn.optimization import GurobiSolver + + +class TestGurobiSolver(unittest.TestCase): + + def testCompute(self): + + s = GurobiSolver() + + xs = np.array([[0.2526861], [0.77908776], [0.5120937], + [0.52646533], [0.01438627]]) + + mus = np.array([0.63883086, 0.56515446, 0.99892903, + 0.99488161, 0.17768801]) + + c = 1 + + #obtained from the original mulearn module + chis_opt = [0.26334825774012194, 0.5651531004941153, + -0.0010709737624955377, -0.00511839469274798, + 0.17768801022078584] + + k = np.array([[1. , 0.8706202, 0.9669135, 0.9632160, 0.9720059], + [0.8706202, 1. , 0.9649848, 0.9685946, 0.7464816], + [0.9669135, 0.9649848, 1. , 0.9998967, 0.8835067], + [0.9632160, 0.9685946, 0.9998967, 1. , 0.8771191], + [0.9720059 ,0.7464816, 0.8835067, 0.8771191, 1. ]]) + + for chi, chi_opt in zip(s.solve(xs, mus, c, k), chis_opt): + self.assertAlmostEqual(chi, chi_opt, places=5) + + + self.assertEqual(GurobiSolver().__repr__(), 'GurobiSolver()') + + self.assertEqual(GurobiSolver(adjustment='auto').__repr__(), + 'GurobiSolver(adjustment=auto)') + + self.assertEqual(GurobiSolver(time_limit=1000).__repr__(), + 'GurobiSolver(time_limit=1000)') + + self.assertEqual(GurobiSolver(initial_values=(1,2,3,4,5)).__repr__(), + 'GurobiSolver(initial_values=(1, 2, 3, 4, 5))') + + self.assertEqual(GurobiSolver(initial_values=(1,2,3,4,5), + adjustment='auto').__repr__(), + 'GurobiSolver(adjustment=auto, initial_values=(1, 2, 3, 4, 5))') + + + model = FuzzyInductor() + xs = np.array([ + [0.0529931],[0.0083108],[0.5267421],[0.2486910],[0.0251151], + [0.1652516],[0.6417665],[0.1196049],[0.9794178],[0.1612251], + [0.4119931],[0.3356147],[0.4766746],[0.7740397],[0.6974139], + [0.0767959],[0.4183671],[0.0911699],[0.8647524],[0.7957013], + [0.6492061],[0.0777168],[0.0107658],[0.3432774],[0.5856382], + [0.2890628],[0.0132868],[0.4368564],[0.6674424],[0.6966816], + [0.0819116],[0.2468026],[0.3826838],[0.8054723],[0.4339475], + [0.8033825],[0.8945941],[0.3637644],[0.8285576],[0.1784889], + [0.1342601],[0.8580456],[0.2053696],[0.5880164],[0.1460810], + [0.1117827],[0.5497901],[0.0229859],[0.2912594],[0.1610982]]) + + mus = np.array([0.0085146, 0.0031310, 0.9830871, 0.2217082, 0.0046125, + 0.0690616, 0.6191740, 0.0317020, 0.0041603, 0.0647358, + 0.8313222, 0.5249052, 0.9871067, 0.1667561, 0.3947267, + 0.0139551, 0.8530416, 0.0185618, 0.0418628, 0.1242336, + 0.5880158, 0.0142166, 0.0033161, 0.5566333, 0.8395180, + 0.3460139, 0.0035165, 0.9092821, 0.5123567, 0.3974534, + 0.0154637, 0.2167269, 0.7201648, 0.1079920, 0.9011676, + 0.1113196, 0.0243836, 0.6423038, 0.0761680, 0.0849619, + 0.0411487, 0.0469942, 0.1261214, 0.8312888, 0.0504056, + 0.0274667, 0.9425840, 0.0043948, 0.3537064, 0.0646031]) + + chis_opt = np.array( + [ 0.0085146, 0.0031310, -0.0169128, 0.2217082, 0.0046125, + 0.0690616, -0.3808259, 0.0317020, 0.0041603, 0.0647358, + -0.1686777, 0.0723333, -0.0128932, 0.1667561, 0.3947267, + 0.0139551, -0.1469583, 0.0185618, 0.0418628, 0.1242336, + -0.4119841, 0.0142166, 0.0033161, -0.4433666, -0.1604819, + 0.3460139, 0.0035165, -0.0907178, 0.4388794, 0.3974534, + 0.0154637, 0.2167269, -0.2798351, 0.1079920, -0.0988323, + 0.1113196, 0.0243836, -0.3576962, 0.0761680, 0.0849619, + 0.0411487, 0.0469942, 0.1261214, -0.1687111, 0.0504056, + 0.0274667, -0.0574159, 0.0043948, 0.3537064, 0.0646031]) + + model.fit(xs, mus) + + for chi, chi_opt in zip(model.chis_, chis_opt): + self.assertAlmostEqual(chi, chi_opt, places=5) + + +if __name__ == '__main__': + unittest.main() + \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_kernel.py b/tests/test_kernel.py deleted file mode 100644 index 26d6451..0000000 --- a/tests/test_kernel.py +++ /dev/null @@ -1,126 +0,0 @@ -from unittest import TestCase - -from tests.kernel import * - - -class TestLinearKernel(TestCase): - def test_compute(self): - k = LinearKernel() - self.assertEqual(k.compute(np.array([1, 0, 1]).reshape(1,-1), - np.array([2, 2, 2]).reshape(1,-1)), 4) - self.assertEqual(k.compute(np.array((1, 0, 2)).reshape(1,-1), - np.array((-1, 2, 5)).reshape(1,-1)), 9) - - self.assertAlmostEqual(k.compute(np.array([1.2, -0.4, -2]).reshape(1,-1), - np.array([4, 1.2, .5]).reshape(1,-1))[0], 3.32) - self.assertAlmostEqual(k.compute(np.array((1.2, -0.4, -2)).reshape(1,-1), - np.array([4, 1.2, .5]).reshape(1,-1))[0], 3.32) - - with self.assertRaises(ValueError): - k.compute(np.array([1, 0, 1]).reshape(1,-1), - np.array([2, 2]).reshape(1,-1)) - - -class TestPolynomialKernel(TestCase): - def test_compute(self): - with self.assertRaises(ValueError): - PolynomialKernel(3.2) - - with self.assertRaises(ValueError): - PolynomialKernel(-2) - - p = PolynomialKernel(2) - self.assertEqual(p.compute(np.array((1, 0, 2)).reshape(1,-1), - np.array((-1, 2, 5)).reshape(1,-1)), 100) - self.assertAlmostEqual(p.compute(np.array([1.2, -0.4, -2]).reshape(1,-1), - np.array([4, 1.2, .5]).reshape(1,-1)), - 18.6624) - - p = PolynomialKernel(5) - self.assertEqual(p.compute(np.array((1, 0, 2)).reshape(1,-1), - np.array([-1, 2, 5]).reshape(1,-1)), 10 ** 5) - self.assertAlmostEqual(p.compute(np.array((1.2, -0.4, -2)).reshape(1,-1), - np.array((4, 1.2, .5)).reshape(1,-1)), - 1504.59195, delta=10**-6) - - with self.assertRaises(ValueError): - p.compute(np.array((1, 0, 2)).reshape(1,-1), - np.array((-1, 2)).reshape(1,-1)) - - - -class TestHomogeneousPolynomialKernel(TestCase): - def test_compute(self): - with self.assertRaises(ValueError): - HomogeneousPolynomialKernel(3.2) - - with self.assertRaises(ValueError): - HomogeneousPolynomialKernel(-2) - - h = HomogeneousPolynomialKernel(2) - self.assertEqual(h.compute(np.array((1, 0, 2)).reshape(1,-1), - np.array((-1, 2, 5)).reshape(1,-1)), 81.0) - self.assertAlmostEqual(h.compute(np.array([1.2, -0.4, -2]).reshape(1,-1), - np.array([4, 1.2, .5]).reshape(1,-1))[0], 11.0224) - - h = HomogeneousPolynomialKernel(5) - self.assertEqual(h.compute(np.array((1, 0, 2)).reshape(1,-1), - np.array([-1, 2, 5]).reshape(1,-1)) , 59049.0) - self.assertAlmostEqual(h.compute(np.array((1.2, -0.4, -2)).reshape(1,-1), - np.array((4, 1.2, .5)).reshape(1,-1)), - 403.357761, delta=10**-6) - - with self.assertRaises(ValueError): - h.compute(np.array((1, 0, 2)).reshape(1,-1), - np.array((-1, 2)).reshape(1,-1)) - - -class TestGaussianKernel(TestCase): - def test_compute(self): - with self.assertRaises(ValueError): - GaussianKernel(-5) - - k = GaussianKernel(1) - self.assertAlmostEqual(k.compute(np.array((1, 0, 1)).reshape(1,-1), - np.array((0, 0, 1)).reshape(1,-1))[0], 0.60653065) - self.assertAlmostEqual(k.compute(np.array([-3, 1, 0.5]).reshape(1,-1), - np.array([1, 1.2, -8]).reshape(1,-1))[0], 6.73e-20) - self.assertAlmostEqual(k.compute(np.array([-1, -4, 3.5]).reshape(1,-1), - np.array((1, 3.2, 6)).reshape(1,-1))[0], 3.29e-14) - - with self.assertRaises(ValueError): - k.compute(np.array([-1, 3.5]).reshape(1,-1), - np.array((1, 3.2, 6)).reshape(1,-1)) - - -class TestHyperbolicKernel(TestCase): - def test_compute(self): - k = HyperbolicKernel(1, 5) - self.assertAlmostEqual(k.compute(np.array((1, 0, 1)).reshape(1,-1), - np.array((0, 0, 1)).reshape(1,-1))[0], 0.9999877) - self.assertAlmostEqual(k.compute(np.array([-3, 1, 0.5]).reshape(1,-1), - np.array([1, 1.2, -8]).reshape(1,-1))[0], - -0.6640367, delta=10**-7) - self.assertAlmostEqual(k.compute(np.array([-1, -4, 3.5]).reshape(1,-1), - np.array((1, 3.2, 6)).reshape(1,-1))[0], - 0.9999999, delta=10**-7) - - with self.assertRaises(ValueError): - k.compute(np.array([-1, 3.5]).reshape(1,-1), - np.array((1, 3.2, 6)).reshape(1,-1)) - - -class TestPrecomputedKernel(TestCase): - def test_compute(self): - with self.assertRaises(ValueError): - PrecomputedKernel(np.array(((1, 2), (3, 4, 5)))) - - k = PrecomputedKernel(np.array(((1, 2), (3, 4)))) - self.assertEqual(k.compute(np.array([1]).reshape(1,-1), np.array([1]).reshape(1,-1)), 4.0) - self.assertEqual(k.compute(np.array([1]).reshape(1,-1), np.array([0]).reshape(1,-1)), 3.0) - - with self.assertRaises(IndexError): - k.compute(np.array([1]).reshape(1,-1), np.array([2]).reshape(1,-1)) - - with self.assertRaises(IndexError): - k.compute(np.array([0]).reshape(1,-1), np.array([1.6]).reshape(1,-1)) diff --git a/tests/test_optimization.py b/tests/test_optimization.py deleted file mode 100644 index 9bc0c8d..0000000 --- a/tests/test_optimization.py +++ /dev/null @@ -1,97 +0,0 @@ -from unittest import TestCase - -#from mulearn import * -from tests.optimization import GurobiSolver -import numpy as np -from tests.__init__ import * - - - -class TestGurobiSolver(TestCase): - - def testCompute(self): - - s = GurobiSolver() - - xs = np.array([[0.2526861], [0.77908776], [0.5120937], [0.52646533], [0.01438627]]) - - mus = np.array([0.63883086, 0.56515446, 0.99892903, 0.99488161, 0.17768801]) - - c = 1 - - #obtained from the original mulearn module - chis_opt = [0.26334825774012194, 0.5651531004941153, -0.0010709737624955377,\ - -0.00511839469274798, 0.17768801022078584] - - k = np.array([[1. , 0.87062028, 0.96691358, 0.96321606, 0.9720059 ], - [0.87062028, 1. , 0.96498481, 0.96859468, 0.74648169], - [0.96691358, 0.96498481, 1. , 0.99989673, 0.88350675], - [0.96321606, 0.96859468, 0.99989673, 1. , 0.87711911], - [0.9720059 , 0.74648169, 0.88350675, 0.87711911, 1. ]]) - - for chi, chi_opt in zip(s.solve(xs, mus, c, k), chis_opt): - self.assertAlmostEqual(chi, chi_opt, places=5) - - - self.assertEqual(GurobiSolver().__repr__(), 'GurobiSolver()') - - self.assertEqual(GurobiSolver(adjustment='auto').__repr__(), 'GurobiSolver(, adjustment=auto)') - - self.assertEqual(GurobiSolver(time_limit=1000).__repr__(), 'GurobiSolver(, time_limit=1000)') - - self.assertEqual(GurobiSolver(initial_values=(1,2,3,4,5)).__repr__(),\ - 'GurobiSolver(, initial_values=(1, 2, 3, 4, 5))') - - self.assertEqual(GurobiSolver(initial_values=(1,2,3,4,5), adjustment='auto').__repr__(),\ - 'GurobiSolver(, adjustment=auto, initial_values=(1, 2, 3, 4, 5))') - - - model = FuzzyInductor() - - - xs = np.array([[0.05299316],[0.00831087],[0.52674217],[0.24869108],[0.02511512], - [0.16525169],[0.64176653],[0.11960495],[0.97941782],[0.16122519], - [0.41199312],[0.33561475],[0.47667467],[0.77403978],[0.69741396], - [0.07679596],[0.41836717],[0.09116998],[0.8647524 ],[0.79570139], - [0.6492061 ],[0.07771681],[0.01076581],[0.34327746],[0.58563821], - [0.28906288],[0.0132868 ],[0.43685648],[0.66744242],[0.6966816 ], - [0.08191166],[0.24680265],[0.38268386],[0.80547232],[0.43394755], - [0.80338255],[0.8945941 ],[0.36376442],[0.82855769],[0.17848898], - [0.13426014],[0.85804564],[0.20536965],[0.58801646],[0.14608102], - [0.1117827 ],[0.54979014],[0.02298591],[0.29125949],[0.16109822]]) - - mus = np.array([0.00851467, 0.00313106, 0.98308714, 0.22170827, 0.00461257, - 0.06906167, 0.61917405, 0.03170202, 0.00416038, 0.06473584, - 0.83132226, 0.52490529, 0.98710673, 0.1667561 , 0.39472675, - 0.01395511, 0.85304163, 0.01856181, 0.04186289, 0.12423366, - 0.58801588, 0.01421668, 0.00331616, 0.55663332, 0.83951804, - 0.34601392, 0.00351659, 0.90928211, 0.51235678, 0.39745347, - 0.01546376, 0.21672692, 0.72016484, 0.10799205, 0.90116766, - 0.11131967, 0.02438362, 0.6423038 , 0.07616806, 0.08496194, - 0.04114879, 0.04699423, 0.1261214 , 0.83128883, 0.0504056 , - 0.02746675, 0.94258406, 0.00439489, 0.35370642, 0.06460311]) - - chis_opt = np.array([ 0.00851467, 0.00313106, -0.01691286, 0.22170827, 0.00461257, - 0.06906167, -0.38082595, 0.03170202, 0.00416038, 0.06473584, - -0.16867774, 0.07233336, -0.01289327, 0.1667561 , 0.39472674, - 0.01395511, -0.14695837, 0.01856181, 0.04186288, 0.12423366, - -0.41198412, 0.01421668, 0.00331616, -0.44336667, -0.16048196, - 0.34601391, 0.00351659, -0.09071789, 0.43887946, 0.39745346, - 0.01546376, 0.21672692, -0.27983515, 0.10799205, -0.09883234, - 0.11131967, 0.02438362, -0.3576962 , 0.07616806, 0.08496194, - 0.04114879, 0.04699423, 0.1261214 , -0.16871117, 0.0504056 , - 0.02746675, -0.05741593, 0.00439489, 0.35370641, 0.06460311]) - - model.fit(xs, mus) - - for chi, chi_opt in zip(model.chis_, chis_opt): - self.assertAlmostEqual(chi, chi_opt, places=5) - - - - - - - - - \ No newline at end of file