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
Open sidebar
ift
NIFTy
Commits
be972356
Commit
be972356
authored
Oct 15, 2019
by
Philipp Arras
Browse files
Delete everything related to iteration controller logging
parent
c59be760
Pipeline
#61917
passed with stages
in 8 minutes and 12 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
demos/getting_started_3.py
View file @
be972356
...
...
@@ -103,15 +103,11 @@ if __name__ == '__main__':
data
=
signal_response
(
mock_position
)
+
N
.
draw_sample
()
# Minimization parameters
fo
=
'energy0.txt'
fs
=
'energy1.txt'
fi
=
'energy2.txt'
ic_sampling
=
ift
.
AbsDeltaEnergyController
(
0.5
,
convergence_level
=
5
,
iteration_limit
=
100
,
file_name
=
fs
)
ic_newton
=
ift
.
GradInfNormController
(
name
=
'Newton'
,
tol
=
1e-7
,
iteration_limit
=
35
,
file_name
=
fo
)
minimizer
=
ift
.
NewtonCG
(
ic_newton
,
file_name
=
fi
)
iteration_limit
=
100
)
ic_newton
=
ift
.
GradInfNormController
(
name
=
'Newton'
,
tol
=
1e-7
,
iteration_limit
=
35
)
minimizer
=
ift
.
NewtonCG
(
ic_newton
)
# Set up likelihood and information Hamiltonian
likelihood
=
ift
.
GaussianEnergy
(
mean
=
data
,
...
...
@@ -164,5 +160,3 @@ if __name__ == '__main__':
linewidth
=
[
1.
]
*
len
(
powers
)
+
[
3.
,
3.
])
plot
.
output
(
ny
=
1
,
nx
=
3
,
xsize
=
24
,
ysize
=
6
,
name
=
filename_res
)
print
(
"Saved results as '{}'."
.
format
(
filename_res
))
ift
.
energy_history_analysis
(
fo
,
fi
,
fs
,
fname
=
'energy_history.png'
)
nifty5/__init__.py
View file @
be972356
...
...
@@ -74,7 +74,7 @@ from .minimization.energy_adapter import EnergyAdapter
from
.minimization.metric_gaussian_kl
import
MetricGaussianKL
from
.sugar
import
*
from
.plot
import
Plot
,
energy_history_analysis
from
.plot
import
Plot
from
.library.smooth_linear_amplitude
import
(
SLAmplitude
,
LinearSLAmplitude
,
CepstrumOperator
)
...
...
nifty5/minimization/descent_minimizers.py
View file @
be972356
...
...
@@ -166,8 +166,7 @@ class NewtonCG(DescentMinimizer):
"""
def
__init__
(
self
,
controller
,
napprox
=
0
,
line_searcher
=
None
,
name
=
None
,
nreset
=
20
,
max_cg_iterations
=
200
,
energy_reduction_factor
=
0.1
,
file_name
=
None
):
nreset
=
20
,
max_cg_iterations
=
200
,
energy_reduction_factor
=
0.1
):
if
line_searcher
is
None
:
line_searcher
=
LineSearch
(
preferred_initial_step_size
=
1.
)
super
(
NewtonCG
,
self
).
__init__
(
controller
=
controller
,
...
...
@@ -175,7 +174,6 @@ class NewtonCG(DescentMinimizer):
self
.
_napprox
=
napprox
self
.
_name
=
name
self
.
_nreset
=
nreset
self
.
_file_name
=
file_name
self
.
_max_cg_iterations
=
max_cg_iterations
self
.
_alpha
=
energy_reduction_factor
...
...
@@ -185,8 +183,7 @@ class NewtonCG(DescentMinimizer):
else
:
ediff
=
self
.
_alpha
*
(
old_value
-
energy
.
value
)
ic
=
AbsDeltaEnergyController
(
ediff
,
iteration_limit
=
self
.
_max_cg_iterations
,
name
=
self
.
_name
,
file_name
=
self
.
_file_name
)
ediff
,
iteration_limit
=
self
.
_max_cg_iterations
,
name
=
self
.
_name
)
e
=
QuadraticEnergy
(
0
*
energy
.
position
,
energy
.
metric
,
energy
.
gradient
)
p
=
None
if
self
.
_napprox
>
1
:
...
...
nifty5/minimization/iteration_controllers.py
View file @
be972356
...
...
@@ -15,8 +15,6 @@
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
from
time
import
time
import
numpy
as
np
from
..logger
import
logger
...
...
@@ -97,15 +95,13 @@ class GradientNormController(IterationController):
"""
def
__init__
(
self
,
tol_abs_gradnorm
=
None
,
tol_rel_gradnorm
=
None
,
convergence_level
=
1
,
iteration_limit
=
None
,
name
=
None
,
p
=
2
,
file_name
=
None
):
convergence_level
=
1
,
iteration_limit
=
None
,
name
=
None
,
p
=
2
):
self
.
_tol_abs_gradnorm
=
tol_abs_gradnorm
self
.
_tol_rel_gradnorm
=
tol_rel_gradnorm
self
.
_convergence_level
=
convergence_level
self
.
_iteration_limit
=
iteration_limit
self
.
_name
=
name
self
.
_p
=
p
self
.
_file_name
=
file_name
def
start
(
self
,
energy
):
self
.
_itcount
=
-
1
...
...
@@ -152,12 +148,6 @@ class GradientNormController(IterationController):
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
,
self
.
_norm
(
energy
)))
return
self
.
CONTINUE
...
...
@@ -180,12 +170,11 @@ class GradInfNormController(IterationController):
"""
def
__init__
(
self
,
tol
,
convergence_level
=
1
,
iteration_limit
=
None
,
name
=
None
,
file_
name
=
None
):
name
=
None
):
self
.
_tol
=
tol
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
...
...
@@ -218,12 +207,6 @@ class GradInfNormController(IterationController):
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
,
crit
))
return
self
.
CONTINUE
...
...
@@ -314,12 +297,11 @@ class AbsDeltaEnergyController(IterationController):
"""
def
__init__
(
self
,
deltaE
,
convergence_level
=
1
,
iteration_limit
=
None
,
name
=
None
,
file_
name
=
None
):
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
...
...
@@ -359,9 +341,4 @@ class AbsDeltaEnergyController(IterationController):
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
nifty5/plot.py
View file @
be972356
...
...
@@ -17,7 +17,6 @@
import
os
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
.
import
dobj
...
...
@@ -539,56 +538,3 @@ class Plot(object):
_plot
(
self
.
_plots
[
i
],
ax
,
**
self
.
_kwargs
[
i
])
fig
.
tight_layout
()
_makeplot
(
kwargs
.
pop
(
"name"
,
None
))
def
energy_history_analysis
(
fname_outer
,
fname_inner
,
fname_sampling
,
fname
=
None
,
figsize
=
[
30
,
10
]):
"""Visualizes the behaviour of the various minimizers during a
minimization procedure.
Parameters
----------
fname_outer : string
File name of file which was written by an :class:`IterationController`
and contains the energy history of the Newton minimizer.
fname_inner : string
File name of file which was written by an :class:`IterationController`
and contains the energy history of the inverter inside of the Newton
minimizer.
fname_sampling : string
File name of file which was written by an :class:`IterationController`
and contains the energy history of the inverter which controls the
sampling.
fname : string
File name of the output plot. None lets matplotlib open an interactive
window and no file is written. Default is None.
figsize : tuple of float
figsize of output plot (see `matplotlib.pyplot.subplots`). Default is
[30, 10].
"""
# FIXME Visualize convergence criteria as well
tsa
,
esa
,
_
=
np
.
loadtxt
(
fname_sampling
,
delimiter
=
' '
).
T
tou
,
eou
,
_
=
np
.
loadtxt
(
fname_outer
,
delimiter
=
' '
).
T
tin
,
ein
,
_
=
np
.
loadtxt
(
fname_inner
,
delimiter
=
' '
).
T
t0
=
np
.
min
([
*
tsa
,
*
tou
,
*
tin
])
tsa
=
(
tsa
-
t0
)
/
3600
tou
=
(
tou
-
t0
)
/
3600
tin
=
(
tin
-
t0
)
/
3600
fig
,
(
ax0
,
ax1
)
=
plt
.
subplots
(
nrows
=
2
,
sharex
=
True
,
figsize
=
figsize
)
p1
=
ax0
.
scatter
(
tin
,
ein
,
marker
=
'x'
,
c
=
'r'
,
label
=
'Newton inverter'
,
alpha
=
.
3
)
p2
=
ax0
.
scatter
(
tsa
,
esa
,
marker
=
'x'
,
label
=
'Sampling inverter'
,
alpha
=
.
3
)
ax0
.
set_ylim
([
1.5
*
np
.
min
(
esa
),
np
.
max
(
esa
)
-
0.1
*
np
.
min
(
esa
)])
ax0
.
set_ylabel
(
'Conjugate gradient energy'
)
ax0
.
legend
([
p1
,
p2
],
[
p1
.
get_label
(),
p2
.
get_label
()])
ax1
.
scatter
(
tou
,
eou
,
marker
=
'>'
,
c
=
'g'
)
ax1
.
set_ylabel
(
'Newton energy'
)
# ax1.set_yscale('log')
ax1
.
set_xlabel
(
"Time [h]"
)
plt
.
tight_layout
()
if
fname
is
None
:
plt
.
show
()
else
:
plt
.
savefig
(
fname
)
plt
.
close
()
Write
Preview
Supports
Markdown
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