def test_new_raphson(self):
     p = 0.1
     g = 0.95
     i = 0
     b = self.b_range[i]
     j = self.j_range[i] - 1
     n = self.n_range_b[i]
     x = np.random.random(n)
     x.sort()
     bound = hanson_koopmans_cmh(x, p, g, j=j, method='newton-raphson')[0]
     b_ = np.log(bound / x[j]) / np.log(x[0] / x[j])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
     bound = hanson_koopmans_cmh(x,
                                 p,
                                 g,
                                 j=j,
                                 method='newton-raphson',
                                 max_iter=50)[0]
     b_ = np.log(bound / x[j]) / np.log(x[0] / x[j])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
     bound = hanson_koopmans_cmh(x,
                                 p,
                                 g,
                                 j=j,
                                 method='newton-raphson',
                                 tol=1e-6)[0]
     b_ = np.log(bound / x[j]) / np.log(x[0] / x[j])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
 def test_fall_back(self):
     p = 0.01
     g = 0.95
     n = 300
     x = np.random.random(n)
     x.sort()
     bound = hanson_koopmans_cmh(x, p, g)[0]
     self.assertTrue(np.isclose(bound, x[0]))
 def test_random_shapes(self):
     M = [3, 10, 20]
     N = [5, 10, 20]
     J = [1, 2]
     for m in M:
         for n in N:
             for j in J:
                 x = np.random.random((m, n))
                 bounds = hanson_koopmans_cmh(x, 0.1, 0.95, j=j)
                 _m = bounds.size
                 self.assertTrue(_m == m)
 def test_a_basis(self):
     p = 0.01
     g = 0.95
     for i, b in enumerate(self.a_range):
         n = self.n_range[i]
         j = n - 1
         x = np.random.random(n)
         x.sort()
         bound = hanson_koopmans_cmh(x, p, g)[0]
         b_ = np.log(bound / x[j]) / np.log(x[0] / x[j])
         self.assertTrue(np.isclose(b, b_, rtol=1e-4, atol=1e-5))
 def test_b_basis(self):
     p = 0.1
     g = 0.95
     for i, b in enumerate(self.b_range):
         j = self.j_range[i] - 1
         n = self.n_range_b[i]
         x = np.random.random(n)
         x.sort()
         bound = hanson_koopmans_cmh(x, p, g, j=j)[0]
         b_ = np.log(bound / x[j]) / np.log(x[0] / x[j])
         self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
 def test_step_size(self):
     p = 0.1
     g = 0.95
     i = 0
     b = self.b_range[i]
     j = self.j_range[i] - 1
     n = self.n_range_b[i]
     x = np.random.random(n)
     x.sort()
     bound = hanson_koopmans_cmh(x, p, g, j=j, step_size=1e-5)[0]
     b_ = np.log(bound / x[j]) / np.log(x[0] / x[j])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
 def test_value_error_upper(self):
     with self.assertRaises(ValueError):
         x = np.random.random((10, 10))
         hanson_koopmans_cmh(x, 0.9, 0.95)
 def test_value_error_shape(self):
     with self.assertRaises(ValueError):
         x = np.random.random((1, 2, 4, 3))
         hanson_koopmans_cmh(x, 0.1, 0.9)