本文整理汇总了Python中pele.optimize.LBFGS.run方法的典型用法代码示例。如果您正苦于以下问题:Python LBFGS.run方法的具体用法?Python LBFGS.run怎么用?Python LBFGS.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pele.optimize.LBFGS
的用法示例。
在下文中一共展示了LBFGS.run方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def test(self):
minimizer = LBFGS(self.x.copy(), self.pot, fortran=True, debug=True)
ret = minimizer.run()
m2 = LBFGS(self.x.copy(), self.pot, fortran=False, debug=True)
ret2 = m2.run()
print "fortran", ret.nfev, ret2.nfev
# self.assertEqual(ret.nfev, ret2.nfev)
self.assertAlmostEqual(ret.energy, ret2.energy, 5)
示例2: test
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def test(self):
minimizer = LBFGS(self.x.copy(), self.pot, armijo=True, debug=True)
ret = minimizer.run()
self.assertTrue(ret.success)
print "\n\n"
minimizer = LBFGS(self.x.copy(), self.pot, armijo=False, debug=True)
ret_nowolfe = minimizer.run()
self.assertTrue(ret_nowolfe.success)
print "nfev armijo, noarmijo", ret.nfev, ret_nowolfe.nfev, ret.energy, ret_nowolfe.energy
示例3: lbfgs_py
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def lbfgs_py(coords, pot, **kwargs):
if not hasattr(pot, "getEnergyGradient"):
# for compatibility with old quenchers.
# assume pot is a getEnergyGradient function
pot = _getEnergyGradientWrapper(pot)
lbfgs = LBFGS(coords, pot, **kwargs)
return lbfgs.run()
示例4: runtest
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def runtest(X, pot, natoms = 100, iprint=-1):
from _lbfgs_py import PrintEvent
tol = 1e-5
maxstep = 0.005
Xinit = np.copy(X)
e, g = pot.getEnergyGradient(X)
print "energy", e
lbfgs = LBFGS(X, pot, maxstep = 0.1, nsteps=10000, tol=tol,
iprint=iprint, H0=2.)
printevent = PrintEvent( "debugout.xyz")
lbfgs.attachEvent(printevent)
ret = lbfgs.run()
print ret
print ""
print "now do the same with scipy lbfgs"
from pele.optimize import lbfgs_scipy as quench
ret = quench(Xinit, pot, tol = tol)
print ret
#print ret[1], ret[2], ret[3]
if False:
print "now do the same with scipy bfgs"
from pele.optimize import bfgs as oldbfgs
ret = oldbfgs(Xinit, pot, tol = tol)
print ret
if False:
print "now do the same with gradient + linesearch"
import _bfgs
gpl = _bfgs.GradientPlusLinesearch(Xinit, pot, maxstep = 0.1)
ret = gpl.run(1000, tol = 1e-6)
print ret
if False:
print "calling from wrapper function"
from pele.optimize import lbfgs_py
ret = lbfgs_py(Xinit, pot, tol = tol)
print ret
if True:
print ""
print "now do the same with lbfgs_py"
from pele.optimize import lbfgs_py
ret = lbfgs_py(Xinit, pot, tol = tol)
print ret
try:
import pele.utils.pymolwrapper as pym
pym.start()
for n, coords in enumerate(printevent.coordslist):
coords=coords.reshape(natoms, 3)
pym.draw_spheres(coords, "A", n)
except ImportError:
print "error loading pymol"
示例5: _lbfgs_py
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def _lbfgs_py(coords, pot, **kwargs):
lbfgs = LBFGS(coords, pot, **kwargs)
ret = lbfgs.run()
coords = ret.coords
e = ret.energy
rms = ret.rms
funcalls = ret.nfev
return coords, e, rms, funcalls, ret
示例6: run
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def run(X_train):
# fit a Gaussian Mixture Model with two components
clf = mixture.GMM(n_components=2, covariance_type='full')
pot = GMMPotential(clf, X_train)
params = pot.get_random_coords()
print params
e, g = pot.getEnergyGradient(params)
print "energy", e
print "grad", g
opt = LBFGS(params, pot, tol=1e-5, maxstep=1., iprint=1)#, events=[print_event])
res = opt.run()
print "finished"
e, g = pot.getEnergyGradient(res.coords)
print "energy", e
print "grad"
print "grad", g
# raise Exception("exiting early")
# clf.fit(X_train)
print "weights"
print clf.covars_
print "\nmeans"
print clf.means_
print "\ncovariances"
print clf.covars_
# display predicted scores by the model as a contour plot
x = np.linspace(-20.0, 30.0)
y = np.linspace(-20.0, 40.0)
X, Y = np.meshgrid(x, y)
XX = np.array([X.ravel(), Y.ravel()]).T
Z = -clf.score_samples(XX)[0]
Z = Z.reshape(X.shape)
CS = plt.contour(X, Y, Z, norm=LogNorm(vmin=1.0, vmax=1000.0),
levels=np.logspace(0, 3, 10))
CB = plt.colorbar(CS, shrink=0.8, extend='both')
plt.scatter(X_train[:, 0], X_train[:, 1], .8)
plt.title('Negative log-likelihood predicted by a GMM')
plt.axis('tight')
make_ellipses(clf, plt.gca())
plt.show()
示例7: test1
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def test1(self):
pot = DiscontinuousHarmonic()
x0 = np.array([-10, 1])
opt = LBFGS(x0, pot, debug=True)
res = opt.run()
self.assertFalse(res.success)
示例8: lbfgs_py
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
def lbfgs_py(coords, pot, **kwargs):
lbfgs = LBFGS(coords, pot, **kwargs)
return lbfgs.run()
示例9: TestMYLBFGS_LBFGS
# 需要导入模块: from pele.optimize import LBFGS [as 别名]
# 或者: from pele.optimize.LBFGS import run [as 别名]
class TestMYLBFGS_LBFGS(unittest.TestCase):
def setUp(self):
self.setUp1(verbose=False)
def setUp1(self, verbose=False, **kwargs):
np.random.seed(0)
natoms = 18
self.system = LJCluster(natoms)
self.pot = self.system.get_potential()
x = self.system.get_random_configuration()
ret = lbfgs_py(x, self.pot, tol=10)
self.x = ret.coords
self.kwargs = kwargs
self.verbose = verbose
self.M = 4
if self.verbose: iprint=1
else: iprint = -1
self.myo = MYLBFGS(self.x, self.pot, iprint=iprint, debug=True, M=self.M)
self.o = LBFGS(self.x, self.pot, iprint=iprint, debug=True, M=self.M, **self.kwargs)
def test(self):
N = self.x.size
M = self.M
myo = self.myo
o = self.o
# do one iteration
for i in xrange(3 * self.M):
myo.one_iteration()
o.one_iteration()
if self.verbose:
print ""
print "H0", myo.H0, o.H0
print "rho ", o.rho[:]
print "myrho", myo.W[N:N+M]
myret = myo.get_result()
ret = o.get_result()
self.assertAlmostEqual(ret.energy, myret.energy, 4)
self.assertLess(np.max(np.abs(myret.coords - ret.coords)), 1e-6)
# do a second iteration
for i in xrange(1):
myo.one_iteration()
o.one_iteration()
myret = myo.get_result()
ret = o.get_result()
if self.verbose:
print "H0", myret.H0, ret.H0
print "rho ", o.rho[:]
print "myrho", myo.W[N:N+M]
self.assertAlmostEqual(ret.energy, myret.energy, 4)
self.assertLess(np.max(np.abs(myret.coords - ret.coords)), 1e-6)
def test_complete(self):
myret = self.myo.run()
ret = self.o.run()
self.assertEqual(ret.nfev, myret.nfev)
self.assertEqual(ret.nsteps, myret.nsteps)
self.assertAlmostEqual(ret.energy, myret.energy, 4)
self.assertLess(np.max(np.abs(myret.coords - ret.coords)), 1e-6)