def test_sample_grid(m=3): lb = 0 * np.ones(m) ub = 1 * np.ones(m) dom = BoxDomain(lb, ub) X = dom.sample_grid(5) assert len(X) == 5**m
def test_isinside(m=5): np.random.seed(0) dom = BoxDomain(-10 * np.ones(m), -5 * np.ones(m)) X = dom.sample(10) Xg = dom.sample_grid(2) hull = ConvexHullDomain(Xg) assert np.all(hull.isinside(X))
def test_constraints(m=3): np.random.seed(0) dom = BoxDomain(-1 * np.ones(m), np.ones(m)) # Lower pyramid portion dom_con = dom.add_constraints(A=np.ones((1, m)), b=np.ones(1)) # Convex hull describes the same space as dom_con X = dom.sample_grid(2) hull = ConvexHullDomain(X, A=dom_con.A, b=dom_con.b) # Check that the same points are inside X = dom.sample(100) assert np.all(hull.isinside(X) == dom_con.isinside(X)) # Check sampling X = hull.sample(100) assert np.all(dom_con.isinside(X))