예제 #1
0
 def test_fall_back(self):
     p = 0.01
     g = 0.95
     n = 300
     x = np.random.random(n)
     x.sort()
     bound = hanson_koopmans(x, p, g)[0]
     self.assertTrue(np.isclose(bound, x[0]))
예제 #2
0
 def test_halley(self):
     i = 0
     row = self.data[i]
     n = int(row[0])
     j = n-1
     p = row[1]
     g = row[2]
     b = row[3]
     x = np.random.random(n)
     x.sort()
     bound = hanson_koopmans(x, p, g, method='halley')[0]
     b_ = (x[j] - bound) / (x[j] - x[0])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
     bound = hanson_koopmans(x, p, g, method='halley', max_iter=50)[0]
     b_ = (x[j] - bound) / (x[j] - x[0])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
     bound = hanson_koopmans(x, p, g, method='halley', tol=1e-6)[0]
     b_ = (x[j] - bound) / (x[j] - x[0])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
예제 #3
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(x, 0.1, 0.95, j=j)
                 _m = bounds.size
                 self.assertTrue(_m == m)
예제 #4
0
 def test_upper_table_bounds(self):
     j = 1
     for i, row in enumerate(self.data):
         n = int(row[0])
         p = 1.0-row[1]
         g = row[2]
         b = row[3]
         x = np.random.random(n) + 1000.
         x.sort()
         bound = hanson_koopmans(x, p, g, j=1)[0]
         b_ = (bound - x[n-j-1]) / (x[-1] - x[n-j-1])
         self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
예제 #5
0
 def test_step_size(self):
     i = 0
     row = self.data[i]
     n = int(row[0])
     j = n-1
     p = row[1]
     g = row[2]
     b = row[3]
     x = np.random.random(n)
     x.sort()
     bound = hanson_koopmans(x, p, g, step_size=1e-6)[0]
     b_ = (x[j] - bound) / (x[j] - x[0])
     self.assertTrue(np.isclose(b, b_, rtol=1e-3, atol=1e-4))
예제 #6
0
 def test_value_error(self):
     with self.assertRaises(ValueError):
         x = np.random.random((1, 2, 4, 3))
         hanson_koopmans(x, 0.1, 0.9)