Skip to content
GitLab
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
addf0517
Commit
addf0517
authored
Jun 21, 2017
by
Theo Steininger
Browse files
Merge branch 'master' of gitlab.mpcdf.mpg.de:ift/NIFTy
parents
7f18a1cc
b509b860
Pipeline
#13885
failed with stages
in 5 minutes and 27 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
demos/wiener_filter_hamiltonian.py
View file @
addf0517
...
@@ -24,7 +24,7 @@ class WienerFilterEnergy(Energy):
...
@@ -24,7 +24,7 @@ class WienerFilterEnergy(Energy):
@
property
@
property
def
value
(
self
):
def
value
(
self
):
D_inv_x
=
self
.
D_inverse_x
()
D_inv_x
=
self
.
D_inverse_x
()
H
=
0.5
*
D_inv_x
.
dot
(
self
.
position
)
-
self
.
j
.
dot
(
self
.
position
)
H
=
0.5
*
D_inv_x
.
v
dot
(
self
.
position
)
-
self
.
j
.
dot
(
self
.
position
)
return
H
.
real
return
H
.
real
@
property
@
property
...
...
nifty/energies/line_energy.py
View file @
addf0517
...
@@ -109,7 +109,7 @@ class LineEnergy(Energy):
...
@@ -109,7 +109,7 @@ class LineEnergy(Energy):
@
property
@
property
def
gradient
(
self
):
def
gradient
(
self
):
return
self
.
energy
.
gradient
.
dot
(
self
.
line_direction
)
return
self
.
energy
.
gradient
.
v
dot
(
self
.
line_direction
)
@
property
@
property
def
curvature
(
self
):
def
curvature
(
self
):
...
...
nifty/field.py
View file @
addf0517
...
@@ -1040,7 +1040,7 @@ class Field(Loggable, Versionable, object):
...
@@ -1040,7 +1040,7 @@ class Field(Loggable, Versionable, object):
new_field
.
set_val
(
new_val
=
new_val
,
copy
=
False
)
new_field
.
set_val
(
new_val
=
new_val
,
copy
=
False
)
return
new_field
return
new_field
def
dot
(
self
,
x
=
None
,
spaces
=
None
,
bare
=
False
):
def
v
dot
(
self
,
x
=
None
,
spaces
=
None
,
bare
=
False
):
""" Computes the volume-factor-aware dot product of 'self' with x.
""" Computes the volume-factor-aware dot product of 'self' with x.
Parameters
Parameters
...
...
nifty/minimization/conjugate_gradient.py
View file @
addf0517
...
@@ -121,12 +121,12 @@ class ConjugateGradient(Loggable, object):
...
@@ -121,12 +121,12 @@ class ConjugateGradient(Loggable, object):
r
=
b
-
A
(
x0
)
r
=
b
-
A
(
x0
)
d
=
self
.
preconditioner
(
r
)
d
=
self
.
preconditioner
(
r
)
previous_gamma
=
r
.
dot
(
d
)
previous_gamma
=
r
.
v
dot
(
d
)
if
previous_gamma
==
0
:
if
previous_gamma
==
0
:
self
.
logger
.
info
(
"The starting guess is already perfect solution "
self
.
logger
.
info
(
"The starting guess is already perfect solution "
"for the inverse problem."
)
"for the inverse problem."
)
return
x0
,
self
.
convergence_level
+
1
return
x0
,
self
.
convergence_level
+
1
norm_b
=
np
.
sqrt
(
b
.
dot
(
b
))
norm_b
=
np
.
sqrt
(
b
.
v
dot
(
b
))
x
=
x0
x
=
x0
convergence
=
0
convergence
=
0
iteration_number
=
1
iteration_number
=
1
...
@@ -137,7 +137,7 @@ class ConjugateGradient(Loggable, object):
...
@@ -137,7 +137,7 @@ class ConjugateGradient(Loggable, object):
self
.
callback
(
x
,
iteration_number
)
self
.
callback
(
x
,
iteration_number
)
q
=
A
(
d
)
q
=
A
(
d
)
alpha
=
previous_gamma
/
d
.
dot
(
q
)
alpha
=
previous_gamma
/
d
.
v
dot
(
q
)
if
not
np
.
isfinite
(
alpha
):
if
not
np
.
isfinite
(
alpha
):
self
.
logger
.
error
(
"Alpha became infinite! Stopping."
)
self
.
logger
.
error
(
"Alpha became infinite! Stopping."
)
...
@@ -158,7 +158,7 @@ class ConjugateGradient(Loggable, object):
...
@@ -158,7 +158,7 @@ class ConjugateGradient(Loggable, object):
r
-=
q
*
alpha
r
-=
q
*
alpha
s
=
self
.
preconditioner
(
r
)
s
=
self
.
preconditioner
(
r
)
gamma
=
r
.
dot
(
s
)
gamma
=
r
.
v
dot
(
s
)
if
gamma
.
real
<
0
:
if
gamma
.
real
<
0
:
self
.
logger
.
warn
(
"Positive definitness of preconditioner "
self
.
logger
.
warn
(
"Positive definitness of preconditioner "
...
...
nifty/minimization/descent_minimizer.py
View file @
addf0517
...
@@ -137,7 +137,7 @@ class DescentMinimizer(Loggable, object):
...
@@ -137,7 +137,7 @@ class DescentMinimizer(Loggable, object):
# compute the the gradient for the current location
# compute the the gradient for the current location
gradient
=
energy
.
gradient
gradient
=
energy
.
gradient
gradient_norm
=
gradient
.
dot
(
gradient
)
gradient_norm
=
gradient
.
v
dot
(
gradient
)
# check if position is at a flat point
# check if position is at a flat point
if
gradient_norm
==
0
:
if
gradient_norm
==
0
:
...
...
nifty/minimization/vl_bfgs.py
View file @
addf0517
...
@@ -261,7 +261,7 @@ class InformationStore(object):
...
@@ -261,7 +261,7 @@ class InformationStore(object):
"""
"""
key
=
tuple
(
sorted
((
i
,
j
)))
key
=
tuple
(
sorted
((
i
,
j
)))
if
key
not
in
self
.
_ss_store
:
if
key
not
in
self
.
_ss_store
:
self
.
_ss_store
[
key
]
=
self
.
s
[
i
].
dot
(
self
.
s
[
j
])
self
.
_ss_store
[
key
]
=
self
.
s
[
i
].
v
dot
(
self
.
s
[
j
])
return
self
.
_ss_store
[
key
]
return
self
.
_ss_store
[
key
]
def
sy_store
(
self
,
i
,
j
):
def
sy_store
(
self
,
i
,
j
):
...
@@ -284,7 +284,7 @@ class InformationStore(object):
...
@@ -284,7 +284,7 @@ class InformationStore(object):
"""
"""
key
=
(
i
,
j
)
key
=
(
i
,
j
)
if
key
not
in
self
.
_sy_store
:
if
key
not
in
self
.
_sy_store
:
self
.
_sy_store
[
key
]
=
self
.
s
[
i
].
dot
(
self
.
y
[
j
])
self
.
_sy_store
[
key
]
=
self
.
s
[
i
].
v
dot
(
self
.
y
[
j
])
return
self
.
_sy_store
[
key
]
return
self
.
_sy_store
[
key
]
def
yy_store
(
self
,
i
,
j
):
def
yy_store
(
self
,
i
,
j
):
...
@@ -307,7 +307,7 @@ class InformationStore(object):
...
@@ -307,7 +307,7 @@ class InformationStore(object):
"""
"""
key
=
tuple
(
sorted
((
i
,
j
)))
key
=
tuple
(
sorted
((
i
,
j
)))
if
key
not
in
self
.
_yy_store
:
if
key
not
in
self
.
_yy_store
:
self
.
_yy_store
[
key
]
=
self
.
y
[
i
].
dot
(
self
.
y
[
j
])
self
.
_yy_store
[
key
]
=
self
.
y
[
i
].
v
dot
(
self
.
y
[
j
])
return
self
.
_yy_store
[
key
]
return
self
.
_yy_store
[
key
]
def
sgrad_store
(
self
,
i
):
def
sgrad_store
(
self
,
i
):
...
@@ -319,7 +319,7 @@ class InformationStore(object):
...
@@ -319,7 +319,7 @@ class InformationStore(object):
Scalar product.
Scalar product.
"""
"""
return
self
.
s
[
i
].
dot
(
self
.
last_gradient
)
return
self
.
s
[
i
].
v
dot
(
self
.
last_gradient
)
def
ygrad_store
(
self
,
i
):
def
ygrad_store
(
self
,
i
):
"""Returns scalar product between y_i and gradient on initial position.
"""Returns scalar product between y_i and gradient on initial position.
...
@@ -330,7 +330,7 @@ class InformationStore(object):
...
@@ -330,7 +330,7 @@ class InformationStore(object):
Scalar product.
Scalar product.
"""
"""
return
self
.
y
[
i
].
dot
(
self
.
last_gradient
)
return
self
.
y
[
i
].
v
dot
(
self
.
last_gradient
)
def
gradgrad_store
(
self
):
def
gradgrad_store
(
self
):
"""Returns scalar product of gradient on initial position with itself.
"""Returns scalar product of gradient on initial position with itself.
...
@@ -341,7 +341,7 @@ class InformationStore(object):
...
@@ -341,7 +341,7 @@ class InformationStore(object):
Scalar product.
Scalar product.
"""
"""
return
self
.
last_gradient
.
dot
(
self
.
last_gradient
)
return
self
.
last_gradient
.
v
dot
(
self
.
last_gradient
)
def
add_new_point
(
self
,
x
,
gradient
):
def
add_new_point
(
self
,
x
,
gradient
):
"""Updates the s list and y list.
"""Updates the s list and y list.
...
...
nifty/operators/composed_operator/composed_operator.py
View file @
addf0517
...
@@ -51,7 +51,7 @@ class ComposedOperator(LinearOperator):
...
@@ -51,7 +51,7 @@ class ComposedOperator(LinearOperator):
Notes
Notes
-----
-----
Very useful
l
in case one has to transform a Field living over a product
Very useful in case one has to transform a Field living over a product
space (see example below).
space (see example below).
Examples
Examples
...
...
nifty/probing/mixin_classes/trace_prober_mixin.py
View file @
addf0517
...
@@ -30,7 +30,7 @@ class TraceProberMixin(object):
...
@@ -30,7 +30,7 @@ class TraceProberMixin(object):
super
(
TraceProberMixin
,
self
).
reset
()
super
(
TraceProberMixin
,
self
).
reset
()
def
finish_probe
(
self
,
probe
,
pre_result
):
def
finish_probe
(
self
,
probe
,
pre_result
):
result
=
probe
[
1
].
dot
(
pre_result
,
bare
=
True
)
result
=
probe
[
1
].
v
dot
(
pre_result
,
bare
=
True
)
self
.
__sum_of_probings
+=
result
self
.
__sum_of_probings
+=
result
if
self
.
compute_variance
:
if
self
.
compute_variance
:
self
.
__sum_of_squares
+=
result
.
conjugate
()
*
result
self
.
__sum_of_squares
+=
result
.
conjugate
()
*
result
...
...
test/test_operators/test_composed_operator.py
View file @
addf0517
...
@@ -40,8 +40,8 @@ class ComposedOperator_Tests(unittest.TestCase):
...
@@ -40,8 +40,8 @@ class ComposedOperator_Tests(unittest.TestCase):
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
(
space1
,
space2
))
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
(
space1
,
space2
))
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
(
space1
,
space2
))
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
(
space1
,
space2
))
tt1
=
rand2
.
dot
(
op
.
times
(
rand1
))
tt1
=
rand2
.
v
dot
(
op
.
times
(
rand1
))
tt2
=
rand1
.
dot
(
op
.
adjoint_times
(
rand2
))
tt2
=
rand1
.
v
dot
(
op
.
adjoint_times
(
rand2
))
assert_approx_equal
(
tt1
,
tt2
)
assert_approx_equal
(
tt1
,
tt2
)
@
expand
(
product
(
spaces
,
spaces
))
@
expand
(
product
(
spaces
,
spaces
))
...
...
test/test_operators/test_diagonal_operator.py
View file @
addf0517
...
@@ -33,8 +33,8 @@ class DiagonalOperator_Tests(unittest.TestCase):
...
@@ -33,8 +33,8 @@ class DiagonalOperator_Tests(unittest.TestCase):
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
diag
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
D
=
DiagonalOperator
(
space
,
diagonal
=
diag
,
bare
=
bare
,
copy
=
copy
)
tt1
=
rand1
.
dot
(
D
.
times
(
rand2
))
tt1
=
rand1
.
v
dot
(
D
.
times
(
rand2
))
tt2
=
rand2
.
dot
(
D
.
times
(
rand1
))
tt2
=
rand2
.
v
dot
(
D
.
times
(
rand1
))
assert_approx_equal
(
tt1
,
tt2
)
assert_approx_equal
(
tt1
,
tt2
)
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
@
expand
(
product
(
spaces
,
[
True
,
False
],
[
True
,
False
]))
...
...
test/test_operators/test_fft_operator.py
View file @
addf0517
...
@@ -143,8 +143,8 @@ class FFTOperatorTests(unittest.TestCase):
...
@@ -143,8 +143,8 @@ class FFTOperatorTests(unittest.TestCase):
inp
=
Field
.
from_random
(
domain
=
a
,
random_type
=
'normal'
,
std
=
1
,
mean
=
0
,
inp
=
Field
.
from_random
(
domain
=
a
,
random_type
=
'normal'
,
std
=
1
,
mean
=
0
,
dtype
=
tp
)
dtype
=
tp
)
out
=
fft
.
times
(
inp
)
out
=
fft
.
times
(
inp
)
v1
=
np
.
sqrt
(
out
.
dot
(
out
))
v1
=
np
.
sqrt
(
out
.
v
dot
(
out
))
v2
=
np
.
sqrt
(
inp
.
dot
(
fft
.
adjoint_times
(
out
)))
v2
=
np
.
sqrt
(
inp
.
v
dot
(
fft
.
adjoint_times
(
out
)))
assert_allclose
(
v1
,
v2
,
rtol
=
tol
,
atol
=
tol
)
assert_allclose
(
v1
,
v2
,
rtol
=
tol
,
atol
=
tol
)
@
expand
(
product
([
128
,
256
],
@
expand
(
product
([
128
,
256
],
...
@@ -159,6 +159,6 @@ class FFTOperatorTests(unittest.TestCase):
...
@@ -159,6 +159,6 @@ class FFTOperatorTests(unittest.TestCase):
inp
=
Field
.
from_random
(
domain
=
a
,
random_type
=
'normal'
,
std
=
1
,
mean
=
0
,
inp
=
Field
.
from_random
(
domain
=
a
,
random_type
=
'normal'
,
std
=
1
,
mean
=
0
,
dtype
=
tp
)
dtype
=
tp
)
out
=
fft
.
times
(
inp
)
out
=
fft
.
times
(
inp
)
v1
=
np
.
sqrt
(
out
.
dot
(
out
))
v1
=
np
.
sqrt
(
out
.
v
dot
(
out
))
v2
=
np
.
sqrt
(
inp
.
dot
(
fft
.
adjoint_times
(
out
)))
v2
=
np
.
sqrt
(
inp
.
v
dot
(
fft
.
adjoint_times
(
out
)))
assert_allclose
(
v1
,
v2
,
rtol
=
tol
,
atol
=
tol
)
assert_allclose
(
v1
,
v2
,
rtol
=
tol
,
atol
=
tol
)
test/test_operators/test_response_operator.py
View file @
addf0517
...
@@ -27,6 +27,6 @@ class ResponseOperator_Tests(unittest.TestCase):
...
@@ -27,6 +27,6 @@ class ResponseOperator_Tests(unittest.TestCase):
exposure
=
[
exposure
])
exposure
=
[
exposure
])
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
op
.
target
[
0
])
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
op
.
target
[
0
])
tt1
=
rand2
.
dot
(
op
.
times
(
rand1
))
tt1
=
rand2
.
v
dot
(
op
.
times
(
rand1
))
tt2
=
rand1
.
dot
(
op
.
adjoint_times
(
rand2
))
tt2
=
rand1
.
v
dot
(
op
.
adjoint_times
(
rand2
))
assert_approx_equal
(
tt1
,
tt2
)
assert_approx_equal
(
tt1
,
tt2
)
test/test_operators/test_smoothing_operator.py
View file @
addf0517
...
@@ -60,8 +60,8 @@ class SmoothingOperator_Tests(unittest.TestCase):
...
@@ -60,8 +60,8 @@ class SmoothingOperator_Tests(unittest.TestCase):
log_distances
=
log_distances
)
log_distances
=
log_distances
)
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
tt1
=
rand1
.
dot
(
op
.
times
(
rand2
))
tt1
=
rand1
.
v
dot
(
op
.
times
(
rand2
))
tt2
=
rand2
.
dot
(
op
.
adjoint_times
(
rand1
))
tt2
=
rand2
.
v
dot
(
op
.
adjoint_times
(
rand1
))
assert_approx_equal
(
tt1
,
tt2
)
assert_approx_equal
(
tt1
,
tt2
)
@
expand
(
product
(
spaces
,
[
0.
,
.
5
,
5.
],
[
False
]))
@
expand
(
product
(
spaces
,
[
0.
,
.
5
,
5.
],
[
False
]))
...
@@ -79,8 +79,8 @@ class SmoothingOperator_Tests(unittest.TestCase):
...
@@ -79,8 +79,8 @@ class SmoothingOperator_Tests(unittest.TestCase):
log_distances
=
log_distances
)
log_distances
=
log_distances
)
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand1
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
rand2
=
Field
.
from_random
(
'normal'
,
domain
=
space
)
tt1
=
rand1
.
dot
(
op
.
inverse_times
(
rand2
))
tt1
=
rand1
.
v
dot
(
op
.
inverse_times
(
rand2
))
tt2
=
rand2
.
dot
(
op
.
inverse_adjoint_times
(
rand1
))
tt2
=
rand2
.
v
dot
(
op
.
inverse_adjoint_times
(
rand1
))
assert_approx_equal
(
tt1
,
tt2
)
assert_approx_equal
(
tt1
,
tt2
)
@
expand
(
product
([
100
,
200
],
[
1
,
0.4
],
[
0.
,
1.
,
3.7
],
@
expand
(
product
([
100
,
200
],
[
1
,
0.4
],
[
0.
,
1.
,
3.7
],
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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