def test_maximin_design_random_state(self):
     vert = np.array([[-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0]])
     np.random.seed(99)
     Y1 = dn.maximin_design(vert, 3)
     np.random.seed(999)
     Y2 = dn.maximin_design(vert, 3)
     np.testing.assert_almost_equal(Y1, Y2, decimal=6)
 def test_maximin_design_random_state(self):
     vert = np.array([[-1.0,-1.0], [1.0,-1.0], [-1.0,1.0], [1.0,1.0]])
     np.random.seed(99)
     Y1 = dn.maximin_design(vert, 3)
     np.random.seed(999)
     Y2 = dn.maximin_design(vert, 3)
     np.testing.assert_almost_equal(Y1, Y2, decimal=6)
Beispiel #3
0
def zonotope_quadrature_rule(avmap, N, NX=10000):
    """Quadrature rule on a zonotope.
    
    Quadrature when the dimension of the active subspace is greater than 1 and
    the simulation parameter space is bounded.

    Parameters
    ----------
    avmap : ActiveVariableMap 
        a domains.ActiveVariableMap
    N : int 
        the number of quadrature nodes in the active variables
    NX : int, optional 
        the number of samples to use to estimate the quadrature weights (default
        10000)

    Returns
    -------
    Yp : ndarray
        quadrature nodes on the active variables
    Yw : ndarray 
        quadrature weights on the active variables

    See Also
    --------
    integrals.quadrature_rule
    """

    vert = avmap.domain.vertY
    W1 = avmap.domain.subspaces.W1

    # number of dimensions
    m, n = W1.shape

    # points
    y = np.vstack((vert, maximin_design(vert, N)))
    T = Delaunay(y)
    c = []
    for t in T.simplices:
        c.append(np.mean(T.points[t], axis=0))
    points = np.array(c)

    # approximate weights
    Y_samples = np.dot(np.random.uniform(-1.0, 1.0, size=(NX,m)), W1)
    I = T.find_simplex(Y_samples)
    weights = np.zeros((T.nsimplex, 1))
    for i in range(T.nsimplex):
        weights[i] = np.sum(I==i) / float(NX)

    Yp, Yw = points.reshape((T.nsimplex,n)), weights.reshape((T.nsimplex,1))
    return Yp, Yw
 def test_maximin_design_repeatable(self):
     vert = np.array([[-1.0,-1.0], [1.0,-1.0], [-1.0,1.0], [1.0,1.0]])
     Y1 = dn.maximin_design(vert, 10)
     Y2 = dn.maximin_design(vert, 10)
     np.testing.assert_equal(Y1, Y2)
 def test_maximin_design(self):
     vert = np.array([[-1.0,-1.0], [1.0,-1.0], [-1.0,1.0], [1.0,1.0]])
     Y = dn.maximin_design(vert, 1)
     np.testing.assert_almost_equal(Y, np.zeros((1,2)), decimal=6)
 def test_maximin_design_repeatable(self):
     vert = np.array([[-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0]])
     Y1 = dn.maximin_design(vert, 10)
     Y2 = dn.maximin_design(vert, 10)
     np.testing.assert_almost_equal(Y1, Y2)
 def test_maximin_design(self):
     vert = np.array([[-1.0, -1.0], [1.0, -1.0], [-1.0, 1.0], [1.0, 1.0]])
     Y = dn.maximin_design(vert, 1)
     np.testing.assert_almost_equal(Y, np.zeros((1, 2)), decimal=4)
Beispiel #8
0
def av_design(avmap, N, NMC=10):
    """Design on active variable space.
    
    A wrapper that returns the design for the response surface in the space of
    the active variables.

    Parameters
    ----------
    avmap : ActiveVariableMap 
        a domains.ActiveVariable map that includes the active variable domain, 
        which includes the active and inactive subspaces
    N : int 
        the number of points used in the design-of-experiments for constructing 
        the response surface
    NMC : int, optional
        the number of points used to estimate the conditional expectation and 
        conditional variance of the function given a value of the active 
        variables (Default is 10)

    Returns
    -------
    Y : ndarray 
        N-by-n matrix that contains the design points in the space of active 
        variables
    X : ndarray 
        (N*NMC)-by-m matrix that contains points in the simulation input space 
        to run the simulation
    ind : ndarray 
        indices that map points in `X` to points in `Y`

    See Also
    --------
    utils.designs.gauss_hermite_design
    utils.designs.interval_design
    utils.designs.maximin_design
    """

    if not isinstance(avmap, ActiveVariableMap):
        raise TypeError('avmap should be an ActiveVariableMap.')

    # interpret N as total number of points in the design
    if not isinstance(N, int):
        raise Exception('N should be an integer.')

    if not isinstance(NMC, int):
        raise Exception('NMC should be an integer.')

    m, n = avmap.domain.subspaces.W1.shape

    if isinstance(avmap.domain, UnboundedActiveVariableDomain):
        NN = [int(np.floor(np.power(N, 1.0 / n))) for i in range(n)]
        Y = dn.gauss_hermite_design(NN)

    elif isinstance(avmap.domain, BoundedActiveVariableDomain):

        if n == 1:
            a, b = avmap.domain.vertY[0, 0], avmap.domain.vertY[1, 0]
            Y = dn.interval_design(a, b, N)
        else:
            vertices = avmap.domain.vertY
            Y = dn.maximin_design(vertices, N)
    else:
        raise Exception('There is a problem with the avmap.domain.')

    X, ind = avmap.inverse(Y, NMC)
    return Y, X, ind