当前位置: 首页>>代码示例>>Python>>正文


Python api.KrigingSurrogate类代码示例

本文整理汇总了Python中openmdao.api.KrigingSurrogate的典型用法代码示例。如果您正苦于以下问题:Python KrigingSurrogate类的具体用法?Python KrigingSurrogate怎么用?Python KrigingSurrogate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了KrigingSurrogate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_vector_derivs

    def test_vector_derivs(self):
        surrogate = KrigingSurrogate()

        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)
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:10,代码来源:test_kriging.py

示例2: test_one_pt

    def test_one_pt(self):
        surrogate = KrigingSurrogate()
        x = [[0.]]
        y = [[1.]]

        with self.assertRaises(ValueError) as cm:
            surrogate.train(x, y)

        self.assertEqual(str(cm.exception), 'KrigingSurrogate require at least'
                                            ' 2 training points.')
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:10,代码来源:test_kriging.py

示例3: test_vector_derivs

    def test_vector_derivs(self):
        surrogate = KrigingSurrogate()
        n = 15
        x = np.array([[a, b] for a, b in
                   itertools.product(np.linspace(0, 1, n), repeat=2)])
        y = np.array([[a+b, a-b, a+2*b] for a, b in x])

        surrogate.train(x, y)
        jac = surrogate.linearize(np.array([[0.5, 0.5]]))
        assert_rel_error(self, jac, np.array([[1, 1], [1, -1], [1, 2]]), 5e-4)
开发者ID:aa-savelyev,项目名称:OpenMDAO,代码行数:10,代码来源:test_kriging.py

示例4: test_scalar_derivs

    def test_scalar_derivs(self):
        surrogate = KrigingSurrogate()

        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)
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:10,代码来源:test_kriging.py

示例5: test_1d_ill_conditioned

 def test_1d_ill_conditioned(self):
     # Test for least squares solver utilization when ill-conditioned
     x = np.array([[case] for case in np.linspace(0., 1., 40)])
     y = np.sin(x)
     surrogate = KrigingSurrogate()
     surrogate.train(x, y)
     new_x = np.array([0.5])
     mu, sigma = surrogate.predict(new_x)
     self.assertTrue(sigma < 3.e-8)
     assert_rel_error(self, mu, np.sin(0.5), 1e-6)
开发者ID:colinxs,项目名称:OpenMDAO,代码行数:10,代码来源:test_kriging.py

示例6: test_no_training_data

    def test_no_training_data(self):
        surrogate = KrigingSurrogate()

        try:
            surrogate.predict([0., 1.])
        except RuntimeError as err:
            self.assertEqual(str(err),
                             "KrigingSurrogate has not been trained, "
                             "so no prediction can be made.")
        else:
            self.fail("RuntimeError Expected")
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:11,代码来源:test_kriging.py

示例7: test_1d_training

    def test_1d_training(self):

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

        for x0, y0 in zip(x, y):
            mu, sigma = surrogate.predict(x0)
            assert_rel_error(self, mu, y0, 1e-9)
            assert_rel_error(self, sigma, 0, 1e-6)
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:11,代码来源:test_kriging.py

示例8: test_1d_training

    def test_1d_training(self):

        x = np.array([[0.0], [2.0], [3.0], [4.0], [6.0]])
        y = np.array([[branin_1d(case)] for case in x])
        surrogate = KrigingSurrogate(nugget=0., eval_rmse=True)
        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu, sigma = surrogate.predict(x0)
            assert_rel_error(self, mu, [y0], 1e-9)
            assert_rel_error(self, sigma, [[0]], 1e-5)
开发者ID:OpenMDAO,项目名称:OpenMDAO,代码行数:11,代码来源:test_kriging.py

示例9: test_1d_predictor

    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 = KrigingSurrogate()
        surrogate.train(x, y)

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

        assert_rel_error(self, mu, 0.397887, 1e-1)
        assert_rel_error(self, sigma, 0.0294172, 1e-2)
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:12,代码来源:test_kriging.py

示例10: test_vector_output

    def test_vector_output(self):
        surrogate = KrigingSurrogate()

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

        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu, sigma = surrogate.predict(x0)
            assert_rel_error(self, mu, y0, 1e-9)
            assert_rel_error(self, sigma, 0, 1e-6)
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:12,代码来源:test_kriging.py

示例11: test_1d_predictor

    def test_1d_predictor(self):
        x = np.array([[0.0], [2.0], [3.0], [4.0], [6.0]])
        y = np.array([[branin_1d(case)] for case in x])

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

        new_x = np.array([3.5])
        mu, sigma = surrogate.predict(new_x)

        assert_rel_error(self, mu, branin_1d(new_x), 1e-1)
        assert_rel_error(self, sigma, 0.07101449, 1e-2)
开发者ID:colinxs,项目名称:OpenMDAO,代码行数:12,代码来源:test_kriging.py

示例12: test_vector_input

    def test_vector_input(self):
        surrogate = KrigingSurrogate(nugget=0.)

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

        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu, sigma = surrogate.predict(x0)
            assert_rel_error(self, mu, y0, 1e-9)
            assert_rel_error(self, sigma, 0, 1e-6)
开发者ID:colinxs,项目名称:OpenMDAO,代码行数:12,代码来源:test_kriging.py

示例13: test_vector_output

    def test_vector_output(self):
        surrogate = KrigingSurrogate(nugget=0., eval_rmse=True)

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

        surrogate.train(x, y)

        for x0, y0 in zip(x, y):
            mu, sigma = surrogate.predict(x0)
            assert_rel_error(self, mu, [y0], 1e-9)
            assert_rel_error(self, sigma, [[0, 0]], 1e-6)
开发者ID:OpenMDAO,项目名称:OpenMDAO,代码行数:12,代码来源:test_kriging.py

示例14: test_2d

    def test_2d(self):

        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])

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

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

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

        assert_rel_error(self, mu, branin([5., 5.]), 1e-1)
        assert_rel_error(self, sigma, 5.79, 1e-2)
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:18,代码来源:test_kriging.py

示例15: test_2d

    def test_2d(self):

        x = np.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 = np.array([[branin(case)] for case in x])

        surrogate = KrigingSurrogate(nugget=0., eval_rmse=True)
        surrogate.train(x, y)

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

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

        assert_rel_error(self, mu, 16.72, 1e-1)
        assert_rel_error(self, sigma, 15.27, 1e-2)
开发者ID:Satadru-Roy,项目名称:OpenMDAO,代码行数:18,代码来源:test_kriging.py


注:本文中的openmdao.api.KrigingSurrogate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。