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


Python Problem.check_partial_derivatives方法代码示例

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


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

示例1: test_derivatives

# 需要导入模块: from openmdao.core import Problem [as 别名]
# 或者: from openmdao.core.Problem import check_partial_derivatives [as 别名]
    def test_derivatives(self):
        meta = MetaModel()
        meta.add_param('x', 0.)
        meta.add_output('f', 0.)
        meta.default_surrogate = FloatKrigingSurrogate()

        prob = Problem(Group())
        prob.root.add('meta', meta, promotes=['x'])
        prob.root.add('p', IndepVarComp('x', 0.), promotes=['x'])
        prob.setup(check=False)

        prob['meta.train:x'] = [0., .25, .5, .75, 1.]
        prob['meta.train:f'] = [1., .75, .5, .25, 0.]
        prob['x'] = 0.125
        prob.run()

        Jf = prob.calc_gradient(['x'], ['meta.f'], mode='fwd')
        Jr = prob.calc_gradient(['x'], ['meta.f'], mode='rev')

        assert_rel_error(self, Jf[0][0], -1.00011, 1.0e-5)
        assert_rel_error(self, Jr[0][0], -1.00011, 1.0e-5)

        stream = cStringIO()
        prob.check_partial_derivatives(out_stream=stream)

        abs_errors = findall('Absolute Error \(.+\) : (.+)', stream.getvalue())
        self.assertTrue(len(abs_errors) > 0)
        for match in abs_errors:
            abs_error = float(match)
            self.assertTrue(abs_error < 1e-6)
开发者ID:briantomko,项目名称:OpenMDAO,代码行数:32,代码来源:test_meta_model.py

示例2: test_derivatives

# 需要导入模块: from openmdao.core import Problem [as 别名]
# 或者: from openmdao.core.Problem import check_partial_derivatives [as 别名]
    def test_derivatives(self):
        meta = MetaModel()
        meta.add_param("x", 0.0)
        meta.add_output("f", 0.0)
        meta.default_surrogate = FloatKrigingSurrogate()

        prob = Problem(Group())
        prob.root.add("meta", meta, promotes=["x"])
        prob.root.add("p", ParamComp("x", 0.0), promotes=["x"])
        prob.setup(check=False)

        prob["meta.train:x"] = [0.0, 0.25, 0.5, 0.75, 1.0]
        prob["meta.train:f"] = [1.0, 0.75, 0.5, 0.25, 0.0]
        prob["x"] = 0.125
        prob.run()

        stream = cStringIO()
        prob.check_partial_derivatives(out_stream=stream)

        abs_errors = findall("Absolute Error \(.+\) : (.+)", stream.getvalue())
        self.assertTrue(len(abs_errors) > 0)
        for match in abs_errors:
            abs_error = float(match)
            self.assertTrue(abs_error < 1e-6)
开发者ID:kishenr12,项目名称:OpenMDAO,代码行数:26,代码来源:test_meta_model.py

示例3: test_derivatives

# 需要导入模块: from openmdao.core import Problem [as 别名]
# 或者: from openmdao.core.Problem import check_partial_derivatives [as 别名]
    def test_derivatives(self):
        meta = MetaModel()
        meta.add_param('x', 0.)
        meta.add_output('f', 0.)
        meta.default_surrogate = FloatKrigingSurrogate()

        prob = Problem(Group())
        prob.root.add('meta', meta, promotes=['x'])
        prob.root.add('p', ParamComp('x', 0.), promotes=['x'])
        prob.setup(check=False)

        prob['meta.train:x'] = [0., .25, .5, .75, 1.]
        prob['meta.train:f'] = [1., .75, .5, .25, 0.]
        prob['x'] = 0.125
        prob.run()

        stream = cStringIO()
        prob.check_partial_derivatives(out_stream=stream)

        abs_errors = findall('Absolute Error \(.+\) : (.+)', stream.getvalue())
        self.assertTrue(len(abs_errors) > 0)
        for match in abs_errors:
            abs_error = float(match)
            self.assertTrue(abs_error < 1e-6)
开发者ID:jcchin,项目名称:project_clippy,代码行数:26,代码来源:test_meta_model.py

示例4: test_simple_array_model2

# 需要导入模块: from openmdao.core import Problem [as 别名]
# 或者: from openmdao.core.Problem import check_partial_derivatives [as 别名]
    def test_simple_array_model2(self):
        prob = Problem()
        prob.root = Group()
        comp = prob.root.add('comp', ExecComp('y = mat.dot(x)',
                                              x=np.zeros((2,)), y=np.zeros((2,)),
                                              mat=np.array([[2.,7.],[5.,-3.]])))

        p1 = prob.root.add('p1', ParamComp('x', np.ones([2])))

        prob.root.connect('p1.x', 'comp.x')

        prob.setup(check=False)
        prob.run()

        data = prob.check_partial_derivatives(out_stream=None)

        assert_rel_error(self, data['comp'][('y','x')]['abs error'][0], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['abs error'][1], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['abs error'][2], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['rel error'][0], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['rel error'][1], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['rel error'][2], 0.0, 1e-5)
开发者ID:kishenr12,项目名称:OpenMDAO,代码行数:24,代码来源:test_exec_comp.py

示例5: test_simple_array_model

# 需要导入模块: from openmdao.core import Problem [as 别名]
# 或者: from openmdao.core.Problem import check_partial_derivatives [as 别名]
    def test_simple_array_model(self):
        prob = Problem()
        prob.root = Group()
        prob.root.add('comp', ExecComp(['y[0]=2.0*x[0]+7.0*x[1]',
                                        'y[1]=5.0*x[0]-3.0*x[1]'],
                                       x=np.zeros([2]), y=np.zeros([2])))

        prob.root.add('p1', ParamComp('x', np.ones([2])))

        prob.root.connect('p1.x', 'comp.x')

        prob.setup(check=False)
        prob.run()

        data = prob.check_partial_derivatives(out_stream=None)

        assert_rel_error(self, data['comp'][('y','x')]['abs error'][0], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['abs error'][1], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['abs error'][2], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['rel error'][0], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['rel error'][1], 0.0, 1e-5)
        assert_rel_error(self, data['comp'][('y','x')]['rel error'][2], 0.0, 1e-5)
开发者ID:kishenr12,项目名称:OpenMDAO,代码行数:24,代码来源:test_exec_comp.py


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