Commit e38eae92 authored by Theo Steininger's avatar Theo Steininger
Browse files

Merge branch 'newton' into 'master'

Newton

See merge request !45
parents 8b7f9360 73dabd0b
Pipeline #9995 failed with stages
in 34 minutes and 14 seconds
from nifty import *
import plotly.offline as pl
import plotly.graph_objs as go
#import plotly.offline as pl
#import plotly.graph_objs as go
from mpi4py import MPI
comm = MPI.COMM_WORLD
......
......@@ -80,9 +80,8 @@ class QuasiNewtonMinimizer(Loggable, object):
convergence = self.convergence_level+2
break
current_position = energy.position
descend_direction = self._get_descend_direction(current_position,
gradient)
# current position is encoded in energy object
descend_direction = self._get_descend_direction(energy)
# compute the step length, which minimizes energy.value along the
# search direction
......@@ -124,5 +123,5 @@ class QuasiNewtonMinimizer(Loggable, object):
return energy, convergence
@abc.abstractmethod
def _get_descend_direction(self, gradient, gradient_norm):
def _get_descend_direction(self, energy):
raise NotImplementedError
# -*- coding: utf-8 -*-
from .quasi_newton_minimizer import QuasiNewtonMinimizer
class RelaxedNewton(QuasiNewtonMinimizer):
def _get_descend_direction(self, energy):
gradient = energy.gradient
curvature = energy.curvature
descend_direction = curvature.inverse_times(gradient)
norm = descend_direction.norm()
if norm != 1:
return descend_direction / -norm
else:
return descend_direction * -1
......@@ -4,8 +4,8 @@ from .quasi_newton_minimizer import QuasiNewtonMinimizer
class SteepestDescent(QuasiNewtonMinimizer):
def _get_descend_direction(self, x, gradient):
descend_direction = gradient
def _get_descend_direction(self, energy):
descend_direction = energy.gradient
norm = descend_direction.norm()
if norm != 1:
return descend_direction / -norm
......
......@@ -24,7 +24,9 @@ class VL_BFGS(QuasiNewtonMinimizer):
self._information_store = None
return super(VL_BFGS, self).__call__(energy)
def _get_descend_direction(self, x, gradient):
def _get_descend_direction(self, energy):
x = energy.position
gradient = energy.gradient
# initialize the information store if it doesn't already exist
try:
self._information_store.add_new_point(x, gradient)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment