Commit ad2cd090 authored by Martin Reinecke's avatar Martin Reinecke

cleanup

parent fbb298cf
......@@ -32,9 +32,6 @@ class ConjugateGradient(Minimizer):
----------
controller : IterationController
Object that decides when to terminate the minimization.
reset_count : integer *optional*
Number of iterations after which to restart; i.e., forget previous
conjugated directions (default: None).
preconditioner : Operator *optional*
This operator can be provided which transforms the variables of the
system to improve the conditioning (default: None).
......@@ -46,9 +43,7 @@ class ConjugateGradient(Minimizer):
"""
def __init__(self, controller, reset_count=None, preconditioner=None):
self._reset_count = None if reset_count is None else int(reset_count)
def __init__(self, controller, preconditioner=None):
self._preconditioner = preconditioner
self._controller = controller
......@@ -92,19 +87,12 @@ class ConjugateGradient(Minimizer):
return energy, controller.ERROR
alpha = previous_gamma/ddotq
reset = False
if alpha < 0:
self.logger.warn("Positive definiteness of A violated!")
reset = True
if self._reset_count is not None:
reset += (iteration_number % self._reset_count == 0)
if reset:
self.logger.info("Resetting conjugate directions.")
energy = energy.at(energy.position+d*alpha)
r = -energy.gradient
else:
r -= q * alpha
energy = energy.at_with_grad(energy.position+d*alpha,-r)
return energy, controller.ERROR
r -= q * alpha
energy = energy.at_with_grad(energy.position+d*alpha,-r)
status = self._controller.check(energy)
if status != controller.CONTINUE:
......
......@@ -31,7 +31,8 @@ class DefaultIterationController(IterationController):
self._itcount = -1
self._ccount = 0
if self._tol_rel_gradnorm is not None:
self._tol_rel_gradnorm *= energy.gradient_norm
self._tol_rel_gradnorm_now = self._tol_rel_gradnorm \
* energy.gradient_norm
return self.check(energy)
def check(self, energy):
......@@ -44,7 +45,7 @@ class DefaultIterationController(IterationController):
if energy.gradient_norm <= self._tol_gradnorm:
self._ccount += 1
if self._tol_rel_gradnorm is not None:
if energy.gradient_norm <= self._tol_rel_gradnorm:
if energy.gradient_norm <= self._tol_rel_gradnorm_now:
self._ccount += 1
if self._ccount >= self._convergence_level:
return self.CONVERGED
......
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