Ejemplo n.º 1
0
    def test_no_training_data(self):
        surrogate = ResponseSurface()

        try:
            surrogate.predict([0., 1.])
        except RuntimeError as err:
            self.assertEqual(str(err),
                             "ResponseSurface has not been trained, so no prediction can be made.")
        else:
            self.fail("RuntimeError Expected")
Ejemplo n.º 2
0
    def test_2d(self):

        x = array([[-2., 0.], [-0.5, 1.5], [1., 1.], [0., .25], [.25, 0.], [.66, .33]])
        y = array([[branin(case)] for case in x])

        surrogate = ResponseSurface()
        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu = surrogate.predict(x0)
            assert_rel_error(self, mu, y0, 1e-9)

        mu = surrogate.predict(array([.5, .5]))

        assert_rel_error(self, mu, branin([.5, .5]), 1e-1)
Ejemplo n.º 3
0
    def test_training(self):

        lr = ResponseSurface(self.X_train, self.Y_train)

        training_reconstruction = [lr.predict(x) for x in self.X_train]
        residual = sum([x - y for x, y in zip(training_reconstruction, self.Y_train)])

        self.assertTrue(residual < 1e-5)
Ejemplo n.º 4
0
    def test_1d_ill_conditioned(self):
        # Test for least squares solver utilization when ill-conditioned
        x = array([[case] for case in linspace(0., 1., 40)])
        y = sin(x)
        surrogate = ResponseSurface()
        surrogate.train(x, y)
        new_x = array([0.5])
        mu = surrogate.predict(new_x)

        assert_rel_error(self, mu, sin(0.5), 1e-3)
Ejemplo n.º 5
0
    def test_1d_training(self):

        x = array([[0.0], [2.0], [3.0]])
        y = array([[branin_1d(case)] for case in x])
        surrogate = ResponseSurface()
        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu = surrogate.predict(x0)
            assert_rel_error(self, mu, y0, 1e-9)
Ejemplo n.º 6
0
    def test_vector_input(self):
        surrogate = ResponseSurface()

        x = array([[0., 0., 0.], [1., 1., 1.]])
        y = array([[0.], [3.]])

        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu = surrogate.predict(x0)
            assert_rel_error(self, mu, y0, 1e-9)
Ejemplo n.º 7
0
    def test_1d_predictor(self):
        x = array([[0.0], [2.0], [3.0], [4.0], [6.0]])
        y = array([[branin_1d(case)] for case in x])

        surrogate = ResponseSurface()
        surrogate.train(x, y)

        new_x = array([pi])
        mu = surrogate.predict(new_x)

        assert_rel_error(self, mu, 1.73114, 1e-4)