Exemple #1
0
def generate_delaunay(variables, num=10, **kwds):
    """
    Generate a Delaunay triangulation of the D-dimensional
    bounded variable domain given a list of D variables.

    Requires numpy and scipy.

    Args:
        variables: A list of variables, each having a finite
            upper and lower bound.
        num (int): The number of grid points to generate for
            each variable (default=10).
        **kwds: All additional keywords are passed to the
          scipy.spatial.Delaunay constructor.

    Returns:
        A scipy.spatial.Delaunay object.
    """
    linegrids = []
    for v in variables:
        if v.has_lb() and v.has_ub():
            linegrids.append(numpy.linspace(v.lb, v.ub, num))
        else:
            raise ValueError("Variable %s does not have a "
                             "finite lower and upper bound.")
    # generates a meshgrid and then flattens and transposes
    # the meshgrid into an (npoints, D) shaped array of
    # coordinates
    points = numpy.vstack(numpy.meshgrid(*linegrids)).\
             reshape(len(variables),-1).T
    return scipy.spatial.Delaunay(points, **kwds)
Exemple #2
0
def _get_XYgrid(x, y, ncells):
    xlin = np.linspace(
        min(x) - abs(max(x) - min(x)) / 2,
        max(x) + abs(max(x) - min(x)) / 2, ncells)
    ylin = np.linspace(
        min(y) - abs(max(y) - min(y)) / 2,
        max(y) + abs(max(y) - min(y)) / 2, ncells)
    X, Y = np.meshgrid(xlin, ylin)

    return X, Y