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


Python LBFGS.get_state方法代码示例

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


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

示例1: TestLBFGS_State

# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import get_state [as 别名]
class TestLBFGS_State(unittest.TestCase):
    def setUp(self):
        self.system = LJCluster(13)
        self.x = self.system.get_random_configuration()
        self.pot = self.system.get_potential()
        self.minimizer = LBFGS(self.x, self.pot)
    
    def test_state(self):
        # do several minimization iterations
        for i in xrange(10):
            self.minimizer.one_iteration()
        
        # get the state and save it
        ret = self.minimizer.get_result()
        state = self.minimizer.get_state()
        x1 = ret.coords.copy()
        
        # do several more iteration steps
        for i in xrange(10):
            self.minimizer.one_iteration()
        
        # now make a new minimizer and do several iterations
        minimizer2 = LBFGS(x1, self.pot)
        minimizer2.set_state(state)
        for i in xrange(10):
            minimizer2.one_iteration()
        
        # test that the two minimizers are in the same state
        ret1 = self.minimizer.get_result()
        ret2 = minimizer2.get_result()
        self.assertEqual(ret1.energy, ret2.energy)
        self.assertTrue((ret1.coords == ret2.coords).all())
        
        state1 = self.minimizer.get_state()
        state2 = minimizer2.get_state()
        
        self.assertTrue((state1.y == state2.y).all())
        self.assertTrue((state1.s == state2.s).all())
        self.assertTrue((state1.rho == state2.rho).all())
        self.assertTrue((state1.dXold == state2.dXold).all())
        self.assertTrue((state1.dGold == state2.dGold).all())
        self.assertEqual(state1.H0, state2.H0)
        self.assertEqual(state1.k, state2.k)
开发者ID:borislavujo,项目名称:pele,代码行数:45,代码来源:_test_lbfgs.py

示例2: test_state

# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import get_state [as 别名]
    def test_state(self):
        # do several minimization iterations
        for i in xrange(10):
            self.minimizer.one_iteration()

        # get the state and save it
        ret = self.minimizer.get_result()
        state = self.minimizer.get_state()
        x1 = ret.coords.copy()

        # do several more iteration steps
        for i in xrange(10):
            self.minimizer.one_iteration()

        # now make a new minimizer and do several iterations
        minimizer2 = LBFGS(x1, self.pot)
        minimizer2.set_state(state)
        for i in xrange(10):
            minimizer2.one_iteration()

        # test that the two minimizers are in the same state
        ret1 = self.minimizer.get_result()
        ret2 = minimizer2.get_result()
        self.assertEqual(ret1.energy, ret2.energy)
        self.assertTrue((ret1.coords == ret2.coords).all())

        state1 = self.minimizer.get_state()
        state2 = minimizer2.get_state()

        self.assertTrue((state1.y == state2.y).all())
        self.assertTrue((state1.s == state2.s).all())
        self.assertTrue((state1.rho == state2.rho).all())
        self.assertTrue((state1.dXold == state2.dXold).all())
        self.assertTrue((state1.dGold == state2.dGold).all())
        self.assertEqual(state1.H0, state2.H0)
        self.assertEqual(state1.k, state2.k)
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:38,代码来源:test_lbfgs.py

示例3: TestLBFGS_State

# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import get_state [as 别名]
class TestLBFGS_State(unittest.TestCase):
    def setUp(self):
        self.system = LJCluster(13)
        self.x = self.system.get_random_configuration()
        self.pot = self.system.get_potential()
        self.minimizer = LBFGS(self.x, self.pot)

    def test_state(self):
        # do several minimization iterations
        for i in xrange(10):
            self.minimizer.one_iteration()

        # get the state and save it
        ret = self.minimizer.get_result()
        state = self.minimizer.get_state()
        x1 = ret.coords.copy()

        # do several more iteration steps
        for i in xrange(10):
            self.minimizer.one_iteration()

        # now make a new minimizer and do several iterations
        minimizer2 = LBFGS(x1, self.pot)
        minimizer2.set_state(state)
        for i in xrange(10):
            minimizer2.one_iteration()

        # test that the two minimizers are in the same state
        ret1 = self.minimizer.get_result()
        ret2 = minimizer2.get_result()
        self.assertEqual(ret1.energy, ret2.energy)
        self.assertTrue((ret1.coords == ret2.coords).all())

        state1 = self.minimizer.get_state()
        state2 = minimizer2.get_state()

        self.assertTrue((state1.y == state2.y).all())
        self.assertTrue((state1.s == state2.s).all())
        self.assertTrue((state1.rho == state2.rho).all())
        self.assertTrue((state1.dXold == state2.dXold).all())
        self.assertTrue((state1.dGold == state2.dGold).all())
        self.assertEqual(state1.H0, state2.H0)
        self.assertEqual(state1.k, state2.k)

    def test_reset(self):
        # do several minimization iterations
        m1 = LBFGS(self.x, self.pot)
        for i in xrange(10):
            m1.one_iteration()

        # reset the minimizer and do it again
        m1.reset()
        e, g = self.pot.getEnergyGradient(self.x)
        m1.update_coords(self.x, e, g)
        for i in xrange(10):
            m1.one_iteration()

        # do the same number of steps of a new minimizer
        m2 = LBFGS(self.x, self.pot)
        for i in xrange(10):
            m2.one_iteration()

        # they should be the same (more or less)
        n = min(m1.k, m1.M)
        self.assertAlmostEqual(m1.H0, m2.H0, 5)
        self.assertEqual(m1.k, m2.k)
        arrays_nearly_equal(self, m1.y[:n, :], m2.y[:n, :])
        arrays_nearly_equal(self, m1.s[:n, :], m2.s[:n, :])
        arrays_nearly_equal(self, m1.rho[:n], m2.rho[:n])

        res1 = m1.get_result()
        res2 = m2.get_result()
        self.assertNotEqual(res1.nfev, res2.nfev)
        self.assertNotEqual(res1.nsteps, res2.nsteps)
        self.assertAlmostEqual(res1.energy, res2.energy)
        arrays_nearly_equal(self, res1.coords, res2.coords)
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:78,代码来源:test_lbfgs.py


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