Exemple #1
0
def weighted_distance_merit(num_pts,
                            surrogate,
                            X,
                            fX,
                            cand,
                            weights,
                            Xpend=None,
                            dtol=1e-3):
    """Compute the weighted distance merit function.

    :param num_pts: Number of points to generate
    :type num_pts: int
    :param surrogate: Surrogate model object
    :type surrogate: object
    :param X: Previously evaluated points, of size n x dim
    :type X: numpy.array
    :param fX: Values at previously evaluated points, of size n x 1
    :type fX: numpy.array
    :param cand: Candidate points to select from, of size m x dim
    :type cand: numpy.array
    :param weights: num_pts weights in [0, 1] for merit function
    :type weights: list or numpy.array
    :param Xpend: Pending evaluation, of size k x dim
    :type Xpend: numpy.array
    :param dtol: Minimum distance between evaluated and pending points
    :type dtol: float

    :return: The num_pts new points chosen from the candidate points
    :rtype: numpy.array of size num_pts x dim
    """
    # Distance
    dim = X.shape[1]
    if Xpend is None:  # cdist can't handle None arguments
        Xpend = np.empty([0, dim])
    dists = scpspatial.distance.cdist(cand, np.vstack((X, Xpend)))
    dmerit = np.amin(dists, axis=1, keepdims=True)

    # Values
    fvals = surrogate.predict(cand)
    fvals = unit_rescale(fvals)

    # Pick candidate points
    new_points = np.ones((num_pts, dim))
    for i in range(num_pts):
        w = weights[i]
        merit = w * fvals + (1.0 - w) * (1.0 - unit_rescale(np.copy(dmerit)))

        merit[dmerit < dtol] = np.inf
        jj = np.argmin(merit)
        fvals[jj] = np.inf
        new_points[i, :] = cand[jj, :].copy()

        # Update distances and weights
        ds = scpspatial.distance.cdist(cand, np.atleast_2d(new_points[i, :]))
        dmerit = np.minimum(dmerit, ds)

    return new_points
Exemple #2
0
def weighted_distance_merit(num_pts, surrogate, X, fX, cand,
                            weights, Xpend=None, dtol=1e-3):
    """Compute the weighted distance merit function.

    :param num_pts: Number of points to generate
    :type num_pts: int
    :param surrogate: Surrogate model object
    :type surrogate: object
    :param X: Previously evaluated points, of size n x dim
    :type X: numpy.array
    :param fX: Values at previously evaluated points, of size n x 1
    :type fX: numpy.array
    :param cand: Candidate points to select from, of size m x dim
    :type cand: numpy.array
    :param weights: num_pts weights in [0, 1] for merit function
    :type weights: list or numpy.array
    :param Xpend: Pending evaluation, of size k x dim
    :type Xpend: numpy.array
    :param dtol: Minimum distance between evaluated and pending points
    :type dtol: float

    :return: The num_pts new points chosen from the candidate points
    :rtype: numpy.array of size num_pts x dim
    """
    # Distance
    dim = X.shape[1]
    if Xpend is None:  # cdist can't handle None arguments
        Xpend = np.empty([0, dim])
    dists = scpspatial.distance.cdist(cand, np.vstack((X, Xpend)))
    dmerit = np.amin(dists, axis=1, keepdims=True)

    # Values
    fvals = surrogate.predict(cand)
    fvals = unit_rescale(fvals)

    # Pick candidate points
    new_points = np.ones((num_pts,  dim))
    for i in range(num_pts):
        w = weights[i]
        merit = w*fvals + (1.0-w)*(1.0 - unit_rescale(np.copy(dmerit)))

        merit[dmerit < dtol] = np.inf
        jj = np.argmin(merit)
        fvals[jj] = np.inf
        new_points[i, :] = cand[jj, :].copy()

        # Update distances and weights
        ds = scpspatial.distance.cdist(
            cand, np.atleast_2d(new_points[i, :]))
        dmerit = np.minimum(dmerit, ds)

    return new_points
Exemple #3
0
def test_unit_rescale():
    X = np.random.rand(5, 3)
    X1 = unit_rescale(X)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(X1.max(), 1.0)
    np.testing.assert_almost_equal(X1.min(), 0.0)

    X = X.flatten()  # Test for 1D array as well
    X1 = unit_rescale(X)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(X1.max(), 1.0)
    np.testing.assert_almost_equal(X1.min(), 0.0)

    X = 0.5 * np.ones((5, 3))
    X1 = unit_rescale(X)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(X1.max(), 1.0)
    np.testing.assert_almost_equal(X1.min(), 1.0)
Exemple #4
0
def test_unit_rescale():
    X = np.random.rand(5, 3)
    X1 = unit_rescale(X)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(X1.max(), 1.0)
    np.testing.assert_almost_equal(X1.min(), 0.0)

    X = X.flatten()  # Test for 1D array as well
    X1 = unit_rescale(X)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(X1.max(), 1.0)
    np.testing.assert_almost_equal(X1.min(), 0.0)

    X = 0.5 * np.ones((5, 3))
    X1 = unit_rescale(X)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(X1.max(), 1.0)
    np.testing.assert_almost_equal(X1.min(), 1.0)