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"
def test_initial_sample(m = 10): dom = BoxDomain(-np.ones(m), np.ones(m)) L1 = np.random.randn(1,m) L2 = np.random.randn(2,m) L3 = np.random.randn(3,m) Nsamp = 100 for L in [L1, L2, L3]: # Standard uniform sampling X1 = dom.sample(Nsamp) LX1 = L.dot(X1.T).T d1 = pdist(LX1) # initial sample algorithm X2 = initial_sample(dom, L, Nsamp = Nsamp) assert np.all(dom.isinside(X2)) LX2 = L.dot(X2.T).T d2 = pdist(LX2) print("uniform sampling mean distance", np.mean(d1), 'min', np.min(d1)) print("initial sampling mean distance", np.mean(d2), 'min', np.min(d2)) assert np.mean(d2) > np.mean(d1), "Initial sampling ineffective"