Ejemplo n.º 1
0
 def test_infer_box_polydomain(self):
     bounds = [(-0.1, 0.4), (0.4, 1), (-0.7, -0.4), (-0.7, 0.4), (0.1, 0.2),
               (-0.1, 0.2), (-0.3, 1.1), (-1.1, -0.3)]
     x = standard_poly_monomials(8)
     gp_gs = [
         0.4**2 - x[0]**2, 1 - x[1]**2, x[1]**2 - 0.4**2, 0.7**2 - x[2]**2,
         x[2]**2 - 0.4**2, 0.7**2 - x[3]**2, 0.2**2 - x[4]**2,
         x[4]**2 - 0.1**2, 0.2**2 - x[5]**2, 1.1**2 - x[6]**2,
         1.1**2 - x[7]**2, x[7]**2 - 0.3**2
     ]
     lower_gs = [x[i] - lb for i, (lb, ub) in enumerate(bounds)]
     upper_gs = [ub - x[i] for i, (lb, ub) in enumerate(bounds)]
     gts = lower_gs + upper_gs + gp_gs
     dummy_f = x[0]
     dom = infer_domain(dummy_f, gts, [])
     assert dom.A.shape == (12, 8)
     assert len(dom.gts) == 12
     assert len(dom.eqs) == 0
     x0 = np.array([-0.1, 1, -0.6, 0, 0.2, 0.2, -0.3, -1.05])
     is_in = dom.check_membership(x0, tol=1e-10)
     assert is_in
     x1 = x0.copy()
     x1[7] = -1.11
     is_in = dom.check_membership(x1, tol=1e-5)
     assert not is_in
     x2 = x0.copy()
     x2[7] = 11.11
     is_in = dom.check_membership(x2, tol=1e-5)
     assert not is_in
Ejemplo n.º 2
0
 def test_infer_expcone_polydomain(self):
     x = standard_poly_monomials(4)
     g = 1 - np.sum(np.power(x, 2))
     dummy_f = x[0] * 0
     dom = infer_domain(dummy_f, [g], [])
     assert len(dom.K) == 5
     assert dom.A.shape == (13, 8)
     assert dom.K[0].type == '+'
     assert dom.K[0].len == 1
     for i in [1, 2, 3, 4]:
         assert dom.K[i].type == 'e'
     assert dom.b[0] == 1