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


Python KrigingSurrogate.train方法代码示例

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


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

示例1: test_one_pt

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:12,代码来源:test_kriging.py

示例2: test_vector_derivs

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:12,代码来源:test_kriging.py

示例3: test_vector_derivs

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:12,代码来源:test_kriging.py

示例4: test_scalar_derivs

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:12,代码来源:test_kriging.py

示例5: test_1d_ill_conditioned

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
 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,代码行数:12,代码来源:test_kriging.py

示例6: test_1d_training

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:13,代码来源:test_kriging.py

示例7: test_1d_training

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:13,代码来源:test_kriging.py

示例8: test_1d_predictor

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:14,代码来源:test_kriging.py

示例9: test_vector_output

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:14,代码来源:test_kriging.py

示例10: test_1d_predictor

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:14,代码来源:test_kriging.py

示例11: test_vector_input

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:14,代码来源:test_kriging.py

示例12: test_vector_output

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:14,代码来源:test_kriging.py

示例13: test_2d

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:20,代码来源:test_kriging.py

示例14: test_2d

# 需要导入模块: from openmdao.api import KrigingSurrogate [as 别名]
# 或者: from openmdao.api.KrigingSurrogate import train [as 别名]
    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,代码行数:20,代码来源:test_kriging.py


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