本文整理汇总了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)
示例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)
示例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)