Commit 89e27a11 authored by Theo Steininger's avatar Theo Steininger

Merge branch 'vl_bfgs' into 'master'

Vl bfgs

See merge request !159
parents 841b7ecb 026e670e
Pipeline #14548 passed with stages
in 14 minutes and 1 second
......@@ -1087,17 +1087,12 @@ class Field(Loggable, Versionable, object):
return dotted.sum(spaces=spaces)
def norm(self):
""" Computes the Lq-norm of the field values.
Parameters
----------
q : scalar
Parameter q of the Lq-norm (default: 2).
""" Computes the L2-norm of the field values.
Returns
-------
norm : scalar
The Lq-norm of the field values.
The L2-norm of the field values.
"""
return np.sqrt(np.abs(self.vdot(x=self)))
......
......@@ -146,14 +146,14 @@ class DescentMinimizer(Loggable, object):
break
# current position is encoded in energy object
descend_direction = self.get_descend_direction(energy)
descent_direction = self.get_descent_direction(energy)
# compute the step length, which minimizes energy.value along the
# search direction
step_length, f_k, new_energy = \
self.line_searcher.perform_line_search(
energy=energy,
pk=descend_direction,
pk=descent_direction,
f_k_minus_1=f_k_minus_1)
f_k_minus_1 = energy.value
......@@ -195,5 +195,5 @@ class DescentMinimizer(Loggable, object):
return energy, convergence
@abc.abstractmethod
def get_descend_direction(self, energy):
def get_descent_direction(self, energy):
raise NotImplementedError
......@@ -25,31 +25,31 @@ from nifty import LineEnergy
class LineSearch(Loggable, object):
"""Class for determining the optimal step size along some descent direction.
Initialize the line search procedure which can be used by a specific line
search method. Its finds the step size in a specific direction in the
minimization process.
Attributes
----------
line_energy : LineEnergy Object
LineEnergy object from which we can extract energy at a specific point.
f_k_minus_1 : Field
Value of the field at the k-1 iteration of the line search procedure.
prefered_initial_step_size : float
preferred_initial_step_size : float
Initial guess for the step length.
"""
__metaclass__ = abc.ABCMeta
def __init__(self):
self.line_energy = None
self.f_k_minus_1 = None
self.prefered_initial_step_size = None
self.preferred_initial_step_size = None
def _set_line_energy(self, energy, pk, f_k_minus_1=None):
"""Set the coordinates for a new line search.
......@@ -58,13 +58,13 @@ class LineSearch(Loggable, object):
----------
energy : Energy object
Energy object from which we can calculate the energy, gradient and
curvature at a specific point.
curvature at a specific point.
pk : Field
Unit vector pointing into the search direction.
f_k_minus_1 : float
Value of the fuction (energy) which will be minimized at the k-1
Value of the fuction (energy) which will be minimized at the k-1
iteration of the line search procedure. (Default: None)
"""
self.line_energy = LineEnergy(position=0.,
energy=energy,
......
......@@ -24,9 +24,9 @@ from .line_search import LineSearch
class LineSearchStrongWolfe(LineSearch):
"""Class for finding a step size that satisfies the strong Wolfe conditions.
Algorithm contains two stages. It begins whit a trial step length and it
keeps increasing the it until it finds an acceptable step length or an
interval. If it does not satisfy the Wolfe conditions it performs the Zoom
Algorithm contains two stages. It begins whit a trial step length and
keeps increasing it until it finds an acceptable step length or an
interval. If it does not satisfy the Wolfe conditions, it performs the Zoom
algorithm (second stage). By interpolating it decreases the size of the
interval until an acceptable step length is found.
......@@ -120,8 +120,8 @@ class LineSearchStrongWolfe(LineSearch):
# set alphas
alpha0 = 0.
if self.prefered_initial_step_size is not None:
alpha1 = self.prefered_initial_step_size
if self.preferred_initial_step_size is not None:
alpha1 = self.preferred_initial_step_size
elif old_phi_0 is not None and phiprime_0 != 0:
alpha1 = min(1.0, 1.01*2*(phi_0 - old_phi_0)/phiprime_0)
if alpha1 < 0:
......
......@@ -32,9 +32,9 @@ class RelaxedNewton(DescentMinimizer):
convergence_level=convergence_level,
iteration_limit=iteration_limit)
self.line_searcher.prefered_initial_step_size = 1.
self.line_searcher.preferred_initial_step_size = 1.
def get_descend_direction(self, energy):
def get_descent_direction(self, energy):
""" Calculates the descent direction according to a Newton scheme.
The descent direction is determined by weighting the gradient at the
......@@ -50,12 +50,9 @@ class RelaxedNewton(DescentMinimizer):
Returns
-------
descend_direction : Field
descent_direction : Field
Returns the descent direction with proposed step length. In a
quadratic potential this corresponds to the optimal step.
"""
gradient = energy.gradient
curvature = energy.curvature
descend_direction = curvature.inverse_times(gradient)
return descend_direction * -1
return -energy.curvature.inverse_times(energy.gradient)
......@@ -20,7 +20,7 @@ from .descent_minimizer import DescentMinimizer
class SteepestDescent(DescentMinimizer):
def get_descend_direction(self, energy):
def get_descent_direction(self, energy):
""" Implementation of the steepest descent minimization scheme.
Also known as 'gradient descent'. This algorithm simply follows the
......@@ -34,10 +34,9 @@ class SteepestDescent(DescentMinimizer):
Returns
-------
descend_direction : Field
descent_direction : Field
Returns the descent direction.
"""
descend_direction = energy.gradient
return descend_direction * -1
return -energy.gradient
This diff is collapsed.
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