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
d0a8f4d8
Commit
d0a8f4d8
authored
Jul 29, 2018
by
Martin Reinecke
Browse files
enable more tests
parent
1e157696
Changes
3
Hide whitespace changes
Inline
Side-by-side
nifty5/sugar.py
View file @
d0a8f4d8
...
...
@@ -38,8 +38,8 @@ from .operators.power_distributor import PowerDistributor
__all__
=
[
'PS_field'
,
'power_analyze'
,
'create_power_operator'
,
'create_harmonic_smoothing_operator'
,
'from_random'
,
'full'
,
'from_global_data'
,
'from_local_data'
,
'makeDomain'
,
'sqrt'
,
'exp'
,
'log'
,
'tanh'
,
'
conjugate
'
,
'get_signal_variance'
,
'makeOp'
,
'domain_union'
]
'makeDomain'
,
'sqrt'
,
'exp'
,
'log'
,
'tanh'
,
'
positive_tanh
'
,
'conjugate'
,
'get_signal_variance'
,
'makeOp'
,
'domain_union'
]
def
PS_field
(
pspace
,
func
):
...
...
@@ -257,7 +257,7 @@ def domain_union(domains):
_current_module
=
sys
.
modules
[
__name__
]
for
f
in
[
"sqrt"
,
"exp"
,
"log"
,
"tanh"
,
"conjugate"
]:
for
f
in
[
"sqrt"
,
"exp"
,
"log"
,
"tanh"
,
"positive_tanh"
,
"conjugate"
]:
def
func
(
f
):
def
func2
(
x
):
from
.linearization
import
Linearization
...
...
test/test_energies/consistency
_check
.py
→
test/test_energies/
test_
consistency.py
View file @
d0a8f4d8
...
...
@@ -25,100 +25,81 @@ import numpy as np
class
Energy_Tests
(
unittest
.
TestCase
):
def
make_model
(
self
,
type
,
**
kwargs
):
if
type
==
'Constant'
:
np
.
random
.
seed
(
kwargs
[
'seed'
])
S
=
ift
.
ScalingOperator
(
1.
,
kwargs
[
'space'
])
s
=
S
.
draw_sample
()
return
ift
.
Constant
(
ift
.
MultiField
.
from_dict
({
kwargs
[
'space_key'
]:
s
}),
ift
.
MultiField
.
from_dict
({
kwargs
[
'space_key'
]:
s
}))
elif
type
==
'Variable'
:
np
.
random
.
seed
(
kwargs
[
'seed'
])
S
=
ift
.
ScalingOperator
(
1.
,
kwargs
[
'space'
])
s
=
S
.
draw_sample
()
return
ift
.
Variable
(
ift
.
MultiField
.
from_dict
({
kwargs
[
'space_key'
]:
s
}))
elif
type
==
'LinearModel'
:
return
ift
.
LinearModel
(
inp
=
kwargs
[
'model'
],
lin_op
=
kwargs
[
'lin_op'
])
else
:
raise
ValueError
(
'unknown type passed'
)
def
make_model
(
self
,
**
kwargs
):
np
.
random
.
seed
(
kwargs
[
'seed'
])
S
=
ift
.
ScalingOperator
(
1.
,
kwargs
[
'space'
])
s
=
S
.
draw_sample
()
return
ift
.
MultiField
.
from_dict
({
kwargs
[
'space_key'
]:
s
})
@
expand
(
product
(
[
'Variable'
],
[
ift
.
GLSpace
(
15
),
ift
.
RGSpace
(
64
,
distances
=
.
789
),
ift
.
RGSpace
([
32
,
32
],
distances
=
.
789
)],
[
4
,
78
,
23
]
))
def
testGaussian
(
self
,
type1
,
space
,
seed
):
def
testGaussian
(
self
,
space
,
seed
):
model
=
self
.
make_model
(
type1
,
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
energy
=
ift
.
GaussianEnergy
(
model
)
ift
.
extra
.
check_value_gradient_consistency
(
energy
)
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
energy
=
ift
.
GaussianEnergy
()
ift
.
extra
.
check_value_gradient_consistency
(
energy
,
model
)
@
expand
(
product
(
[
'Variable'
],
[
ift
.
GLSpace
(
15
),
ift
.
RGSpace
(
64
,
distances
=
.
789
),
ift
.
RGSpace
([
32
,
32
],
distances
=
.
789
)],
[
4
,
78
,
23
]
))
def
testQuadratic
(
self
,
type1
,
space
,
seed
):
np
.
random
.
seed
(
seed
)
S
=
ift
.
ScalingOperator
(
1.
,
space
)
s
=
[
S
.
draw_sample
()
for
_
in
range
(
3
)]
energy
=
ift
.
QuadraticEnergy
(
s
[
0
],
ift
.
makeOp
(
s
[
1
]),
s
[
2
])
ift
.
extra
.
check_value_gradient_consistency
(
energy
)
# @expand(product(
# [ift.GLSpace(15),
# ift.RGSpace(64, distances=.789),
# ift.RGSpace([32, 32], distances=.789)],
# [4, 78, 23]
# ))
# def testQuadratic(self, type1, space, seed):
# np.random.seed(seed)
# S = ift.ScalingOperator(1., space)
# s = [S.draw_sample() for _ in range(3)]
# energy = ift.QuadraticEnergy(s[0], ift.makeOp(s[1]), s[2])
# ift.extra.check_value_gradient_consistency(energy)
@
expand
(
product
(
[
'Variable'
],
[
ift
.
GLSpace
(
15
),
ift
.
RGSpace
(
64
,
distances
=
.
789
),
ift
.
RGSpace
([
32
,
32
],
distances
=
.
789
)],
[
4
,
78
,
23
]
))
def
testPoissonian
(
self
,
type1
,
space
,
seed
):
def
testPoissonian
(
self
,
space
,
seed
):
model
=
self
.
make_model
(
type1
,
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
model
=
ift
.
PointwiseExponential
(
model
)
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
model
=
ift
.
exp
(
model
)
d
=
np
.
random
.
poisson
(
120
,
size
=
space
.
shape
)
d
=
ift
.
Field
.
from_global_data
(
space
,
d
)
energy
=
ift
.
PoissonianEnergy
(
model
,
d
)
ift
.
extra
.
check_value_gradient_consistency
(
energy
)
energy
=
ift
.
PoissonianEnergy
(
ift
.
exp
,
d
)
ift
.
extra
.
check_value_gradient_consistency
(
energy
,
model
,
tol
=
1e-7
)
@
expand
(
product
(
[
'Variable'
],
[
ift
.
GLSpace
(
15
),
ift
.
RGSpace
(
64
,
distances
=
.
789
),
ift
.
RGSpace
([
32
,
32
],
distances
=
.
789
)],
[
4
,
78
,
23
]
))
def
testHamiltonian_and_KL
(
self
,
type1
,
space
,
seed
):
def
testHamiltonian_and_KL
(
self
,
space
,
seed
):
model
=
self
.
make_model
(
type1
,
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
model
=
ift
.
PointwiseExponential
(
model
)
lh
=
ift
.
GaussianEnergy
(
model
)
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
model
=
model
.
exp
(
)
lh
=
ift
.
GaussianEnergy
()
hamiltonian
=
ift
.
Hamiltonian
(
lh
)
ift
.
extra
.
check_value_gradient_consistency
(
hamiltonian
)
ift
.
extra
.
check_value_gradient_consistency
(
hamiltonian
,
model
)
S
=
ift
.
ScalingOperator
(
1.
,
space
)
samps
=
[
S
.
draw_sample
()
for
i
in
range
(
3
)]
kl
=
ift
.
SampledKullbachLeiblerDivergence
(
hamiltonian
,
samps
)
ift
.
extra
.
check_value_gradient_consistency
(
kl
)
ift
.
extra
.
check_value_gradient_consistency
(
kl
,
model
)
@
expand
(
product
(
[
'Variable'
],
[
ift
.
GLSpace
(
15
),
ift
.
RGSpace
(
64
,
distances
=
.
789
),
ift
.
RGSpace
([
32
,
32
],
distances
=
.
789
)],
[
4
,
78
,
23
]
))
def
testBernoulli
(
self
,
type1
,
space
,
seed
):
def
testBernoulli
(
self
,
space
,
seed
):
model
=
self
.
make_model
(
type1
,
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
model
=
ift
.
PointwiseP
ositive
T
anh
(
model
)
space_key
=
's1'
,
space
=
space
,
seed
=
seed
)[
's1'
]
model
=
model
.
p
ositive
_t
anh
()
d
=
np
.
random
.
binomial
(
1
,
0.1
,
size
=
space
.
shape
)
d
=
ift
.
Field
.
from_global_data
(
space
,
d
)
energy
=
ift
.
BernoulliEnergy
(
model
,
d
)
ift
.
extra
.
check_value_gradient_consistency
(
energy
)
energy
=
ift
.
BernoulliEnergy
(
ift
.
positive_tanh
,
d
)
ift
.
extra
.
check_value_gradient_consistency
(
energy
,
model
,
tol
=
1e-7
)
test/test_energies/test_map.py
View file @
d0a8f4d8
...
...
@@ -53,6 +53,7 @@ class Energy_Tests(unittest.TestCase):
n
=
N
.
draw_sample
()
s
=
ht
(
ift
.
makeOp
(
A
)(
xi0_var
))
R
=
ift
.
ScalingOperator
(
10.
,
space
)
def
d_model
(
inp
):
if
nonlinearity
==
""
:
return
R
(
ht
(
ift
.
makeOp
(
A
)(
inp
)))
...
...
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