예제 #1
0
    def test_one_pt(self):
        surrogate = ResponseSurface()
        x = array([[0.]])
        y = array([[1.]])

        surrogate.train(x, y)
        assert_rel_error(self, surrogate.betas, array([[1.], [0.], [0.]]), 1e-9)
예제 #2
0
    def test_one_pt(self):
        surrogate = ResponseSurface()
        x = array([[0.0]])
        y = array([[1.0]])

        surrogate.train(x, y)
        assert_rel_error(self, surrogate.betas, array([[1.0], [0.0], [0.0]]), 1e-9)
예제 #3
0
    def test_vector_derivs(self):
        surrogate = ResponseSurface()

        x = array([[a, b] for a, b in itertools.product(linspace(0, 1, 10), repeat=2)])
        y = array([[a + b, a - b] for a, b in x])

        surrogate.train(x, y)
        jac = surrogate.jacobian(array([[0.5, 0.5]]))
        assert_rel_error(self, jac, array([[1, 1], [1, -1]]), 1e-5)
예제 #4
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)
예제 #5
0
    def test_vector_derivs(self):
        surrogate = ResponseSurface()

        x = array([[a, b] for a, b in
                   itertools.product(linspace(0, 1, 10), repeat=2)])
        y = array([[a + b, a - b] for a, b in x])

        surrogate.train(x, y)
        jac = surrogate.linearize(array([[0.5, 0.5]]))
        assert_rel_error(self, jac, array([[1, 1], [1, -1]]), 1e-5)
예제 #6
0
    def test_scalar_derivs(self):
        surrogate = ResponseSurface()

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

        surrogate.train(x, y)
        jac = surrogate.linearize(array([[0.]]))

        assert_rel_error(self, jac[0][0], 1., 1e-3)
예제 #7
0
    def test_1d_ill_conditioned(self):
        # Test for least squares solver utilization when ill-conditioned
        x = array([[case] for case in linspace(0.0, 1.0, 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)
예제 #8
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)
예제 #9
0
    def test_scalar_derivs(self):
        surrogate = ResponseSurface()

        x = array([[0.0], [1.0], [2.0], [3.0]])
        y = x.copy()

        surrogate.train(x, y)
        jac = surrogate.jacobian(array([[0.0]]))

        assert_rel_error(self, jac[0][0], 1.0, 1e-3)
예제 #10
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)
예제 #11
0
    def test_scalar_derivs(self):
        surrogate = ResponseSurface()

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

        surrogate.train(x, y)
        jac = surrogate.linearize(array([[0.]]))

        assert_rel_error(self, jac[0][0], 1., 1e-3)
예제 #12
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)
예제 #13
0
    def test_vector_output(self):
        surrogate = ResponseSurface()

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

        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu = surrogate.predict(x0)
            assert_near_equal(mu, y0, 1e-9)
예제 #14
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)
예제 #15
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)
예제 #16
0
    def test_vector_input(self):
        surrogate = ResponseSurface()

        x = array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
        y = array([[0.0], [3.0]])

        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu = surrogate.predict(x0)
            assert_rel_error(self, mu, y0, 1e-9)
예제 #17
0
    def test_2d(self):

        x = array([[-2.0, 0.0], [-0.5, 1.5], [1.0, 1.0], [0.0, 0.25], [0.25, 0.0], [0.66, 0.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([0.5, 0.5]))

        assert_rel_error(self, mu, branin([0.5, 0.5]), 1e-1)
예제 #18
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)