Commit 5104854f authored by Philipp Arras's avatar Philipp Arras
Browse files

Add preconditioner to NewtonCG

parent 36209276
Pipeline #52271 passed with stages
in 8 minutes and 26 seconds
...@@ -160,14 +160,14 @@ class NewtonCG(DescentMinimizer): ...@@ -160,14 +160,14 @@ class NewtonCG(DescentMinimizer):
super(NewtonCG, self).__init__(controller=controller, super(NewtonCG, self).__init__(controller=controller,
line_searcher=line_searcher) line_searcher=line_searcher)
def get_descent_direction(self, energy): def get_descent_direction(self, energy, preconditioner=None):
float64eps = np.finfo(np.float64).eps float64eps = np.finfo(np.float64).eps
r = energy.gradient r = energy.gradient
maggrad = abs(r).sum() maggrad = abs(r).sum()
termcond = np.min([0.5, np.sqrt(maggrad)]) * maggrad termcond = np.min([0.5, np.sqrt(maggrad)]) * maggrad
pos = energy.position*0 pos = energy.position*0
d = r d = r if preconditioner is None else preconditioner(r)
previous_gamma = r.vdot(r) previous_gamma = r.vdot(d)
ii = 0 ii = 0
while True: while True:
if abs(r).sum() <= termcond: if abs(r).sum() <= termcond:
...@@ -182,7 +182,8 @@ class NewtonCG(DescentMinimizer): ...@@ -182,7 +182,8 @@ class NewtonCG(DescentMinimizer):
alpha = previous_gamma/curv alpha = previous_gamma/curv
pos = pos - alpha*d pos = pos - alpha*d
r = r - alpha*q r = r - alpha*q
gamma = r.vdot(r) s = r if preconditioner is None else preconditioner(r)
gamma = r.vdot(s)
d = d*(gamma/previous_gamma)+r d = d*(gamma/previous_gamma)+r
previous_gamma = gamma previous_gamma = gamma
......
Supports Markdown
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