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
3a8d202d
Commit
3a8d202d
authored
May 19, 2020
by
Philipp Arras
Browse files
Add some testing
parent
6d5b914b
Pipeline
#75220
passed with stages
in 8 minutes and 27 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty6/minimization/iteration_controllers.py
View file @
3a8d202d
...
...
@@ -108,7 +108,7 @@ class EnergyHistory(object):
self
.
_lst
=
[]
@
property
def
timestamps
(
self
):
def
time
_
stamps
(
self
):
return
[
x
for
x
,
_
in
self
.
_lst
]
@
property
...
...
@@ -128,6 +128,9 @@ class EnergyHistory(object):
self
.
_lst
+=
other
.
_lst
return
self
def
__len__
(
self
):
return
len
(
self
.
_lst
)
def
append_history
(
func
):
@
functools
.
wraps
(
func
)
...
...
nifty6/plot.py
View file @
3a8d202d
...
...
@@ -288,7 +288,7 @@ def _plot_history(f, ax, **kwargs):
plt
.
yscale
(
kwargs
.
pop
(
"yscale"
,
"linear"
))
mi
,
ma
=
np
.
inf
,
-
np
.
inf
for
i
,
fld
in
enumerate
(
f
):
xcoord
=
date2num
([
dt
.
fromtimestamp
(
ts
)
for
ts
in
fld
.
timestamps
])
xcoord
=
date2num
([
dt
.
fromtimestamp
(
ts
)
for
ts
in
fld
.
time
_
stamps
])
ycoord
=
fld
.
energy_values
ax
.
scatter
(
xcoord
,
ycoord
,
label
=
label
[
i
],
alpha
=
alpha
[
i
],
color
=
color
[
i
],
s
=
size
[
i
])
...
...
test/test_kl.py
View file @
3a8d202d
...
...
@@ -39,7 +39,7 @@ def test_kl(constants, point_estimates, mirror_samples, mf):
import
numpy
as
np
lh
=
ift
.
GaussianEnergy
(
domain
=
op
.
target
,
sampling_dtype
=
np
.
float64
)
@
op
ic
=
ift
.
GradientNormController
(
iteration_limit
=
5
)
ic
.
activate_and_reset
_logging
()
ic
.
enable
_logging
()
h
=
ift
.
StandardHamiltonian
(
lh
,
ic_samp
=
ic
)
mean0
=
ift
.
from_random
(
'normal'
,
h
.
domain
)
...
...
@@ -51,7 +51,14 @@ def test_kl(constants, point_estimates, mirror_samples, mf):
point_estimates
=
point_estimates
,
mirror_samples
=
mirror_samples
,
napprox
=
0
)
ic
.
pop_history
()
assert_
(
len
(
ic
.
history
)
>
0
)
assert_
(
len
(
ic
.
history
)
==
len
(
ic
.
history
.
time_stamps
))
assert_
(
len
(
ic
.
history
)
==
len
(
ic
.
history
.
energy_values
))
ic
.
history
.
reset
()
assert_
(
len
(
ic
.
history
)
==
0
)
assert_
(
len
(
ic
.
history
)
==
len
(
ic
.
history
.
time_stamps
))
assert_
(
len
(
ic
.
history
)
==
len
(
ic
.
history
.
energy_values
))
locsamp
=
kl
.
_local_samples
klpure
=
ift
.
MetricGaussianKL
(
mean0
,
h
,
...
...
@@ -87,8 +94,10 @@ def test_kl(constants, point_estimates, mirror_samples, mf):
# Test constants (after some minimization)
cg
=
ift
.
GradientNormController
(
iteration_limit
=
5
)
minimizer
=
ift
.
NewtonCG
(
cg
)
minimizer
=
ift
.
NewtonCG
(
cg
,
activate_logging
=
True
)
kl
,
_
=
minimizer
(
kl
)
if
len
(
constants
)
!=
2
:
assert_
(
len
(
minimizer
.
inversion_history
)
>
0
)
diff
=
(
mean0
-
kl
.
position
).
to_dict
()
for
kk
in
constants
:
assert_allclose
(
diff
[
kk
].
val
,
0
*
diff
[
kk
].
val
)
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