Exemplo n.º 1
0
    def test_1d_1fi_cokriging(self):
        # CoKrigingSurrogate with one fidelity could be used as a KrigingSurrogate
        # Same test as for KrigingSurrogate...  well with predicted test value adjustment

        x = array([[0.05], [.25], [0.61], [0.95]])
        y = array([0.738513784857542, -0.210367746201974, -0.489015457891476, 12.3033138316612])
        krig1 = MultiFiCoKrigingSurrogate()
        krig1.train(x, y)
        new_x = array([0.5])

        mu, sigma = krig1.predict(x[0])
        assert_rel_error(self, mu, y[0], 1e-4)
        assert_rel_error(self, sigma, 0., 1e-4)

        mu, sigma = krig1.predict(new_x)
        assert_rel_error(self, mu, -2.0279, 1e-3)
        assert_rel_error(self, sigma, 1.3408, 1e-3)

        # Test with theta setting instead of estimation
        krig2 = MultiFiCoKrigingSurrogate(theta=0.1)
        krig2.train(x, y)

        mu, sigma = krig2.predict(x[0])
        assert_rel_error(self , mu, y[0], 1e-4)
        assert_rel_error(self, sigma, .0, 1e-4)

        mu, sigma = krig2.predict(new_x)
        assert_rel_error(self, mu, -1.2719, 1e-3)
        assert_rel_error(self, sigma, 0.0439, 1e-3)
Exemplo n.º 2
0
    def test_2d_1fi_cokriging(self):
        # CoKrigingSurrogate with one fidelity could be used as a KrigingSurrogate
        # Same test as for KrigingSurrogate...  well with predicted test value adjustment

        def branin(x):
            y = (x[1]-(5.1/(4.*pi**2.))*x[0]**2.+5.*x[0]/pi-6.)**2.+10.*(1.-1./(8.*pi))*cos(x[0])+10.
            return y

        x = array([[-2., 0.], [-0.5, 1.5], [1., 3.], [8.5, 4.5],
                   [-3.5, 6.], [4., 7.5], [-5., 9.], [5.5, 10.5],
                   [10., 12.], [7., 13.5], [2.5, 15.]])
        y = array([branin(case) for case in x])
        krig1 = MultiFiCoKrigingSurrogate()
        krig1.train(x, y)

        mu, sigma = krig1.predict([-2., 0.])
        assert_rel_error(self, mu, branin(x[0]), 1e-5)
        assert_rel_error(self, sigma, 0., 1e-5)

        mu, sigma = krig1.predict([5., 5.])
        assert_rel_error(self, mu, 22, 1)
        assert_rel_error(self, sigma, 13, 1)

        # Test with theta setting instead of estimation
        krig2 = MultiFiCoKrigingSurrogate(theta=[0.1])
        krig1.train(x, y)

        mu, sigma = krig1.predict([-2., 0.])
        assert_rel_error(self, mu, branin(x[0]), 1e-5)
        assert_rel_error(self, sigma, 0., 1e-5)

        mu, sigma = krig1.predict([5., 5.])
        assert_rel_error(self, mu, 22, 1)
        assert_rel_error(self, sigma, 13, 1)