Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIFTy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
13
Merge Requests
13
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ift
NIFTy
Commits
9584a133
Commit
9584a133
authored
Sep 06, 2019
by
Philipp Arras
Committed by
Lukas Platz
Sep 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add AbsDeltaEnergyController
parent
5ded9f44
Pipeline
#60211
passed with stages
in 8 minutes and 25 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
1 deletion
+74
-1
nifty5/__init__.py
nifty5/__init__.py
+1
-1
nifty5/minimization/iteration_controllers.py
nifty5/minimization/iteration_controllers.py
+73
-0
No files found.
nifty5/__init__.py
View file @
9584a133
...
...
@@ -59,7 +59,7 @@ from .probing import probe_with_posterior_samples, probe_diagonal, \
from
.minimization.line_search
import
LineSearch
from
.minimization.iteration_controllers
import
(
IterationController
,
GradientNormController
,
DeltaEnergyController
,
GradInfNormController
)
GradInfNormController
,
AbsDeltaEnergyController
)
from
.minimization.minimizer
import
Minimizer
from
.minimization.conjugate_gradient
import
ConjugateGradient
from
.minimization.nonlinear_cg
import
NonlinearCG
...
...
nifty5/minimization/iteration_controllers.py
View file @
9584a133
...
...
@@ -18,6 +18,7 @@
from
..logger
import
logger
from
..utilities
import
NiftyMeta
import
numpy
as
np
from
time
import
time
class
IterationController
(
metaclass
=
NiftyMeta
):
...
...
@@ -266,3 +267,75 @@ class DeltaEnergyController(IterationController):
return
self
.
CONVERGED
return
self
.
CONTINUE
class
AbsDeltaEnergyController
(
IterationController
):
"""An iteration controller checking (mainly) the energy change from one
iteration to the next.
Parameters
----------
deltaE : float
If the difference between the last and current energies is below this
value, the convergence counter will be increased in this iteration.
convergence_level : int, default=1
The number which the convergence counter must reach before the
iteration is considered to be converged
iteration_limit : int, optional
The maximum number of iterations that will be carried out.
name : str, optional
if supplied, this string and some diagnostic information will be
printed after every iteration
"""
def
__init__
(
self
,
deltaE
,
convergence_level
=
1
,
iteration_limit
=
None
,
name
=
None
,
file_name
=
None
):
self
.
_deltaE
=
deltaE
self
.
_convergence_level
=
convergence_level
self
.
_iteration_limit
=
iteration_limit
self
.
_name
=
name
self
.
_file_name
=
file_name
def
start
(
self
,
energy
):
self
.
_itcount
=
-
1
self
.
_ccount
=
0
self
.
_Eold
=
0.
return
self
.
check
(
energy
)
def
check
(
self
,
energy
):
self
.
_itcount
+=
1
inclvl
=
False
Eval
=
energy
.
value
diff
=
abs
(
self
.
_Eold
-
Eval
)
if
self
.
_itcount
>
0
:
if
diff
<
self
.
_deltaE
:
inclvl
=
True
self
.
_Eold
=
Eval
if
inclvl
:
self
.
_ccount
+=
1
else
:
self
.
_ccount
=
max
(
0
,
self
.
_ccount
-
1
)
# report
if
self
.
_name
is
not
None
:
logger
.
info
(
"{}: Iteration #{} energy={:.6E} diff={:.6E} crit={:.6E}"
.
format
(
self
.
_name
,
self
.
_itcount
,
Eval
,
diff
,
self
.
_deltaE
))
# Are we done?
if
self
.
_iteration_limit
is
not
None
:
if
self
.
_itcount
>=
self
.
_iteration_limit
:
logger
.
warning
(
"{} Iteration limit reached. Assuming convergence"
.
format
(
""
if
self
.
_name
is
None
else
self
.
_name
+
": "
))
return
self
.
CONVERGED
if
self
.
_ccount
>=
self
.
_convergence_level
:
return
self
.
CONVERGED
# Write energy to file
if
self
.
_file_name
is
not
None
:
with
open
(
self
.
_file_name
,
'a+'
)
as
f
:
f
.
write
(
'{} {} {}
\n
'
.
format
(
time
(),
energy
.
value
,
diff
))
return
self
.
CONTINUE
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