Esempio n. 1
0
def test_corner():
    dom = NormalDomain([5], [[0.1]], truncate=1e-2)
    print dom.norm_lb
    print dom.norm_ub
    print dom._center()
    print "lower bound", dom.corner([-1])
    print "upper bound", dom.corner([1])
    print dom.sample(10)
Esempio n. 2
0
def test_normalized_domain(m=5):
    mean = np.random.randn(m)
    L = np.random.randn(m, m)
    cov = L.dot(L.T)

    dom = NormalDomain(mean, cov, truncate=1e-2)
    dom_norm = dom.normalized_domain()
    print dom_norm.norm_lb
    assert np.all(np.isclose(dom_norm.norm_lb, -np.ones(len(dom_norm))))
    print dom_norm.norm_ub
    assert np.all(np.isclose(dom_norm.norm_ub, np.ones(len(dom_norm))))
    print dom_norm.mean
    assert np.all(np.isclose(dom_norm.mean, np.zeros(len(dom_norm))))

    X_norm = dom_norm.sample(1e4)
    X = dom.unnormalize(X_norm)
    assert np.all(dom.isinside(X))
Esempio n. 3
0
def test_sampling(m=5):
    np.random.seed(0)
    mean = np.random.randn(m)
    L = np.random.randn(m, m)
    cov = L.dot(L.T)

    dom = NormalDomain(mean, cov)

    X = dom.sample(1e6)

    mean_est = np.mean(X, axis=0)
    print('mean')
    print(mean)
    print(mean_est)
    print(
        np.isclose(mean,
                   np.mean(X, axis=0),
                   rtol=50 / np.sqrt(X.shape[0]),
                   atol=50 / np.sqrt(X.shape[0])))
    assert np.all(
        np.isclose(mean,
                   np.mean(X, axis=0),
                   rtol=50 / np.sqrt(X.shape[0]),
                   atol=50 / np.sqrt(X.shape[0]))), "Mean not correct"

    print("Covariance")
    cov_est = np.cov(X.T)
    print(cov)
    print(cov_est)
    print(
        np.isclose(cov,
                   cov_est,
                   rtol=100 / np.sqrt(X.shape[0]),
                   atol=100 / np.sqrt(X.shape[0])))
    assert np.all(
        np.isclose(cov,
                   cov_est,
                   rtol=100 / np.sqrt(X.shape[0]),
                   atol=100 / np.sqrt(X.shape[0]))), "Covariance not correct"

    # Now check with a truncation parameter
    truncate = 1e-2
    dom2 = NormalDomain(mean, cov, truncate=truncate)
    print(dom2.clip)
    X2 = dom2.sample(1e5)
    assert np.all(dom2.isinside(
        X2)), "Sampling did not place all points inside the constraints"

    frac_inside = np.sum(dom2.isinside(X)) / len(X)

    assert np.isclose(
        1 - frac_inside, truncate, atol=100 * truncate / np.sqrt(X.shape[0])
    ), "Constraint doesn't seem to get right fraction included"
Esempio n. 4
0
def build_golinski_random_domain(clip=None):
    return TensorProductDomain([
        NormalDomain(0, 21e-4**2, clip=clip),
        NormalDomain(0, 1e-4**2, clip=clip),
        NormalDomain(0, 30e-4**2, clip=clip),
        NormalDomain(0, 30e-4**2, clip=clip),
        NormalDomain(0, 21e-4**2, clip=clip),
        NormalDomain(0, 30e-4**2, clip=clip)
    ])
Esempio n. 5
0
def build_borehole_uncertain_domain():
    r""" Constructs an uncertain domain associated with the borehole function

	Returns
	-------
	dom: TensorProductDomain
		Uncertain domain associated with the borehole function
	"""
    return TensorProductDomain([
        NormalDomain(0.10, 0.0161812**2, names='r_w'),
        LogNormalDomain(7.71, 1.0056**2, names='r'),
        UniformDomain(63070, 115600, names='T_u'),
        UniformDomain(990, 1110, names='H_u'),
        UniformDomain(63.1, 116, names='T_l'),
        UniformDomain(700, 820, names='H_l'),
        UniformDomain(1120, 1680, names='L'),
        UniformDomain(9855, 12045, names='K_w')
    ])