Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
On Thursday, 7th July from 1 to 3 pm there will be a maintenance with a short downtime of GitLab.
Open sidebar
ift
NIFTy
Commits
17dbecec
Commit
17dbecec
authored
Oct 17, 2018
by
Martin Reinecke
Browse files
introduce CG resetting
parent
0a0258b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
nifty5/minimization/conjugate_gradient.py
View file @
17dbecec
...
...
@@ -33,6 +33,9 @@ class ConjugateGradient(Minimizer):
----------
controller : :py:class:`nifty5.IterationController`
Object that decides when to terminate the minimization.
nreset : int
every `nreset` CG steps the residual will be recomputed accurately
by applying the operator instead of updating the old residual
References
----------
...
...
@@ -40,8 +43,9 @@ class ConjugateGradient(Minimizer):
2006, Springer-Verlag New York
"""
def
__init__
(
self
,
controller
):
def
__init__
(
self
,
controller
,
nreset
=
20
):
self
.
_controller
=
controller
self
.
_nreset
=
nreset
def
__call__
(
self
,
energy
,
preconditioner
=
None
):
""" Runs the conjugate gradient minimization.
...
...
@@ -74,6 +78,7 @@ class ConjugateGradient(Minimizer):
if
previous_gamma
==
0
:
return
energy
,
controller
.
CONVERGED
iter
=
0
while
True
:
q
=
energy
.
apply_metric
(
d
)
ddotq
=
d
.
vdot
(
q
).
real
...
...
@@ -86,9 +91,14 @@ class ConjugateGradient(Minimizer):
logger
.
error
(
"Error: ConjugateGradient: alpha<0."
)
return
energy
,
controller
.
ERROR
r
=
r
-
q
*
alpha
energy
=
energy
.
at_with_grad
(
energy
.
position
-
alpha
*
d
,
r
)
iter
+=
1
if
iter
<
self
.
_nreset
:
r
=
r
-
q
*
alpha
energy
=
energy
.
at_with_grad
(
energy
.
position
-
alpha
*
d
,
r
)
else
:
energy
=
energy
.
at
(
energy
.
position
-
alpha
*
d
)
r
=
energy
.
gradient
iter
=
0
s
=
r
if
preconditioner
is
None
else
preconditioner
(
r
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment