Пример #1
0
def test_unit_box_map():
    X = np.random.rand(5, 3)
    lb = -1 * np.ones((3, ))
    ub = 2 * np.ones((3, ))

    X1 = to_unit_box(X, lb, ub)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(
        X1, to_unit_box(X, np.atleast_2d(lb), np.atleast_2d(ub)))
    assert (X.max() <= 1.0 and X.min() >= 0)

    # Try to map back to what we started with
    X2 = from_unit_box(X1, lb, ub)
    np.testing.assert_equal(X.shape, X2.shape)
    np.testing.assert_almost_equal(
        X2, from_unit_box(X1, np.atleast_2d(lb), np.atleast_2d(ub)))
    np.testing.assert_almost_equal(X2, X)
Пример #2
0
def test_unit_box_map():
    X = np.random.rand(5, 3)
    lb = -1 * np.ones((3,))
    ub = 2 * np.ones((3,))

    X1 = to_unit_box(X, lb, ub)
    np.testing.assert_equal(X.shape, X1.shape)
    np.testing.assert_almost_equal(
        X1, to_unit_box(X, np.atleast_2d(lb), np.atleast_2d(ub)))
    assert(X.max() <= 1.0 and X.min() >= 0)

    # Try to map back to what we started with
    X2 = from_unit_box(X1, lb, ub)
    np.testing.assert_equal(X.shape, X2.shape)
    np.testing.assert_almost_equal(
        X2, from_unit_box(X1, np.atleast_2d(lb), np.atleast_2d(ub)))
    np.testing.assert_almost_equal(X2, X)
Пример #3
0
    def predict_std(self, x):
        """Predict standard deviation at points xx.

        :param xx: Prediction points, must be of size num_pts x dim or (dim, )
        :type xx: numpy.ndarray

        :return: Predicted standard deviation, of size num_pts x 1
        :rtype: numpy.ndarray
        """
        return self.model.predict_std(to_unit_box(x, self.lb, self.ub))
Пример #4
0
    def predict(self, xx):
        """Evaluate the surrogate model at the points xx

        :param xx: Prediction points, must be of size num_pts x dim or (dim, )
        :type xx: numpy.ndarray

        :return: Prediction of size num_pts x 1
        :rtype: numpy.ndarray
        """
        return self.model.predict(to_unit_box(xx, self.lb, self.ub))
Пример #5
0
    def predict_std(self, x):
        """Predict standard deviation at points xx.

        :param xx: Prediction points, must be of size num_pts x dim or (dim, )
        :type xx: numpy.ndarray

        :return: Predicted standard deviation, of size num_pts x 1
        :rtype: numpy.ndarray
        """
        return self.model.predict_std(
            to_unit_box(x, self.lb, self.ub))
Пример #6
0
    def predict(self, xx):
        """Evaluate the surrogate model at the points xx

        :param xx: Prediction points, must be of size num_pts x dim or (dim, )
        :type xx: numpy.ndarray

        :return: Prediction of size num_pts x 1
        :rtype: numpy.ndarray
        """
        return self.model.predict(
            to_unit_box(xx, self.lb, self.ub))
Пример #7
0
    def deriv(self, x, ds=None):
        """Evaluate the derivative of the rbf interpolant at x

        :param x: Point for which we want to compute the MARS gradient
        :type x: numpy.array
        :param ds: Not used
        :type ds: None
        :return: Derivative of the MARS interpolant at x
        :rtype: numpy.array
        """

        return self.model.deriv(to_unit_box(x, self.data), ds)
Пример #8
0
    def evals(self, x, ds=None):
        """Evaluate the capped rbf interpolant at the points xx

        :param x: Points where to evaluate, of size npts x dim
        :type x: numpy.array
        :param ds: Not used
        :type ds: None
        :return: Values of the MARS interpolant at x, of length npts
        :rtype: numpy.array
        """

        return self.model.evals(to_unit_box(x, self.data), ds)
Пример #9
0
    def eval(self, x, ds=None):
        """Evaluate the response surface at the point xx

        :param x: Point where to evaluate
        :type x: numpy.array
        :param ds: Not used
        :type ds: None
        :return: Value of the interpolant at x
        :rtype: float
        """

        return self.model.eval(to_unit_box(x, self.data), ds)
Пример #10
0
    def add_points(self, xx, fx):
        """Add new function evaluations.

        This method SHOULD NOT trigger a new fit, it just updates X and
        fX but leaves the original surrogate object intact

        :param xx: Points to add
        :type xx: numpy.ndarray
        :param fx: The function values of the point to add
        :type fx: numpy.array or float
        """
        super().add_points(xx, fx)
        self.model.add_points(to_unit_box(xx, self.lb, self.ub), fx)
Пример #11
0
    def predict_deriv(self, x):
        """Evaluate the derivative of the surrogate model at points xx

        Remember the chain rule:
            f'(x) = (d/dx) g((x-a)/(b-a)) = g'((x-a)/(b-a)) * 1/(b-a)

        :param xx: Prediction points, must be of size num_pts x dim or (dim, )
        :type xx: numpy.array

        :return: Derivative of the RBF interpolant at xx
        :rtype: numpy.array
        """
        return self.model.predict_deriv(to_unit_box(
            x, self.lb, self.ub)) / (self.ub - self.lb)
Пример #12
0
    def predict_deriv(self, x):
        """Evaluate the derivative of the surrogate model at points xx

        Remember the chain rule:
            f'(x) = (d/dx) g((x-a)/(b-a)) = g'((x-a)/(b-a)) * 1/(b-a)

        :param xx: Prediction points, must be of size num_pts x dim or (dim, )
        :type xx: numpy.array

        :return: Derivative of the RBF interpolant at xx
        :rtype: numpy.array
        """
        return self.model.predict_deriv(
            to_unit_box(x, self.lb, self.ub)) / (self.ub - self.lb)
Пример #13
0
    def add_points(self, xx, fx):
        """Add new function evaluations.

        This method SHOULD NOT trigger a new fit, it just updates X and
        fX but leaves the original surrogate object intact

        :param xx: Points to add
        :type xx: numpy.ndarray
        :param fx: The function values of the point to add
        :type fx: numpy.array or float
        """
        super().add_points(xx, fx)
        self.model.add_points(
            to_unit_box(xx, self.lb, self.ub), fx)
Пример #14
0
    def add_point(self, xx, fx):
        """Add a new function evaluation

        :param xx: Point to add
        :type xx: numpy.array
        :param fx: The function value of the point to add
        :type fx: float
        """

        if self.nump >= self.fvalues.shape[0]:
            self.fvalues.resize(2 * self.fvalues.shape[0], 1)
        self.fvalues[self.nump] = fx
        self.nump += 1
        self.updated = False
        self.model.add_point(to_unit_box(xx, self.data), fx)