def zonotope_quadrature_rule(vert, W1, N, NX=10000):
    """
    Description of zonotope_quadrature_rule

    Arguments:
        vert:
        W1:
        N:
        NX: (default=10000)
    Outputs:
        points:
        weights:
    """

    # 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
    Ysamp = np.dot(np.random.uniform(-1.0, 1.0, size=(NX, m)), W1)
    I = T.find_simplex(Ysamp)
    weights = np.zeros((T.nsimplex, 1))
    for i in range(T.nsimplex):
        weights[i] = np.sum(I == i) / float(NX)
    return points.reshape((T.nsimplex, n)), weights.reshape((T.nsimplex, 1))
def as_design(avmap, N, NMC=10):
    # interpret N as total number of points in the design
    if type(N) is not int:
        raise Exception('N 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
    
Пример #3
0
def zonotope_quadrature_rule(avmap, N, NX=10000):
    """
    Description of zonotope_quadrature_rule

    Arguments:
        vert:
        W1:
        N:
        NX: (default=10000)
    Outputs:
        points:
        weights:
    """
    
    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)
    return points.reshape((T.nsimplex,n)), weights.reshape((T.nsimplex,1))
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
Пример #5
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
Пример #6
0
def av_design(avmap, N, NMC=10):
    """
    A wrapper that returns the design for the response surface in the space of
    the active variables.

    :param ActiveVariableMap avmap: A domains.ActiveVariable map that includes
        the active variable domain, which includes the active and inactive
        subspaces.
    :param int N: The number of points used in the design-of-experiments for
        constructing the response surface.
    :param int NMC: 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)

    :return: Y, N-by-n matrix that contains the design points in the space of
        active variables.
    :rtype: ndarray

    :return: X, (N*NMC)-by-m matrix that contains points in the simulation input
        space to run the simulation.
    :rtype: ndarray

    :return: ind, Indices that map points in `X` to points in `Y`.
    :rtype: ndarray

    **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
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