Пример #1
0
def test_vertex_eq(m = 5):
	np.random.seed(0)
	dom = BoxDomain(-np.ones(m), np.ones(m))
	dom = dom.add_constraints(A_eq = np.ones(m), b_eq = [0])
	Xhat = dom.sample(10)
	X0 = dom.sample(5)
	check_vertex_sample(dom, Xhat, X0)
Пример #2
0
def test_box(m=10):
    dom = BoxDomain(-np.ones(m), np.ones(m))
    assert len(dom) == m

    x = dom.corner(np.ones(m))
    assert np.all(np.isclose(x, np.ones(m)))

    A = np.ones((1, m))
    b = np.zeros(1)
    dom2 = dom.add_constraints(A_eq=A, b_eq=b)
    x = dom2.sample()
    assert np.isclose(np.dot(A, x), b)
Пример #3
0
def test_point(m=3):
    lb = 0 * np.ones(m)
    ub = 1 * np.ones(m)

    dom = BoxDomain(lb, ub)
    assert dom.is_point == False

    dom = BoxDomain(ub, ub)
    assert dom.is_point == True

    dom = BoxDomain(lb, ub)
    dom = dom.add_constraints(A_eq=np.ones((1, m)), b_eq=[0])
    assert dom.is_point == True
Пример #4
0
def no_test_lipschitz_sample(N = 5, m = 3):
	dom = BoxDomain(-np.ones(m), np.ones(m))
	# Add an inequality constraint so some combinations aren't feasible
	dom = dom.add_constraints(A = np.ones((1,m)), b = np.ones(1))
	Ls = [np.random.randn(1,m) for j in range(2)]

	# Limit the number of iterations to reduce computational cost
	X = psdr.lipschitz_sample(dom, N, Ls, maxiter = 3, jiggle = False)
	print(X)
	assert np.all(dom.isinside(X))

	# Verify that each point is distinct in projections
	for L in Ls:
		y = L.dot(X.T).T
		print(y)
		assert np.min(pdist(y)) > 0, "points not distinct in projection"
Пример #5
0
def test_cheb(m=5):
    lb = -np.ones(m)
    ub = np.ones(m)
    dom = BoxDomain(lb, ub)
    A = np.ones((1, m))
    b = np.zeros(1, )

    dom2 = dom.add_constraints(A, b)

    center, radius = dom2.chebyshev_center()
    print center
    print radius

    assert dom2.isinside(center), "Center must be inside"

    for i in range(100):
        p = np.random.randn(m)
        p /= np.linalg.norm(p)
        assert dom2.extent(center, p) >= radius, "violated radius assumption"
Пример #6
0
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))