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
508800eb
Commit
508800eb
authored
Aug 22, 2017
by
Martin Reinecke
Browse files
merge master
parents
8acbab72
1297585d
Pipeline
#17041
passed with stage
in 18 minutes and 40 seconds
Changes
124
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty/library/critical_filter/__init__.py
View file @
508800eb
# -*- coding: utf-8 -*-
from
critical_power_curvature
import
CriticalPowerCurvature
from
critical_power_energy
import
CriticalPowerEnergy
from
.
critical_power_curvature
import
CriticalPowerCurvature
from
.
critical_power_energy
import
CriticalPowerEnergy
nifty/library/log_normal_wiener_filter/__init__.py
View file @
508800eb
# -*- coding: utf-8 -*-
from
log_normal_wiener_filter_curvature
import
LogNormalWienerFilterCurvature
from
log_normal_wiener_filter_energy
import
LogNormalWienerFilterEnergy
from
.
log_normal_wiener_filter_curvature
import
LogNormalWienerFilterCurvature
from
.
log_normal_wiener_filter_energy
import
LogNormalWienerFilterEnergy
nifty/library/wiener_filter/__init__.py
View file @
508800eb
# -*- coding: utf-8 -*-
from
wiener_filter_curvature
import
WienerFilterCurvature
from
wiener_filter_energy
import
WienerFilterEnergy
from
.
wiener_filter_curvature
import
WienerFilterCurvature
from
.
wiener_filter_energy
import
WienerFilterEnergy
nifty/minimization/__init__.py
View file @
508800eb
...
...
@@ -16,13 +16,13 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
line_searching
import
*
from
iteration_controller
import
IterationController
from
default_iteration_controller
import
DefaultIterationController
from
minimizer
import
Minimizer
from
conjugate_gradient
import
ConjugateGradient
from
nonlinear_cg
import
NonlinearCG
from
descent_minimizer
import
DescentMinimizer
from
steepest_descent
import
SteepestDescent
from
vl_bfgs
import
VL_BFGS
from
relaxed_newton
import
RelaxedNewton
from
.
line_searching
import
*
from
.
iteration_controller
import
IterationController
from
.
default_iteration_controller
import
DefaultIterationController
from
.
minimizer
import
Minimizer
from
.
conjugate_gradient
import
ConjugateGradient
from
.
nonlinear_cg
import
NonlinearCG
from
.
descent_minimizer
import
DescentMinimizer
from
.
steepest_descent
import
SteepestDescent
from
.
vl_bfgs
import
VL_BFGS
from
.
relaxed_newton
import
RelaxedNewton
nifty/minimization/default_iteration_controller.py
View file @
508800eb
...
...
@@ -16,6 +16,7 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
print_function
from
.iteration_controller
import
IterationController
class
DefaultIterationController
(
IterationController
):
...
...
@@ -37,7 +38,7 @@ class DefaultIterationController(IterationController):
def
check
(
self
,
energy
):
self
.
_itcount
+=
1
print
"iteration"
,
self
.
_itcount
,
"gradnorm"
,
energy
.
gradient_norm
,
"level"
,
self
.
_ccount
,
energy
.
value
print
(
"iteration"
,
self
.
_itcount
,
"gradnorm"
,
energy
.
gradient_norm
,
"level"
,
self
.
_ccount
,
energy
.
value
)
if
self
.
_iteration_limit
is
not
None
:
if
self
.
_itcount
>=
self
.
_iteration_limit
:
return
self
.
CONVERGED
...
...
nifty/minimization/descent_minimizer.py
View file @
508800eb
...
...
@@ -16,11 +16,13 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
import
abc
import
numpy
as
np
from
.minimizer
import
Minimizer
from
.line_searching
import
LineSearchStrongWolfe
from
future.utils
import
with_metaclass
class
DescentMinimizer
(
Minimizer
):
...
...
nifty/minimization/iteration_controller.py
View file @
508800eb
...
...
@@ -16,14 +16,16 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
builtins
import
range
import
abc
from
nifty.nifty_meta
import
NiftyMeta
import
numpy
as
np
from
keepers
import
Loggable
from
future.utils
import
with_metaclass
class
IterationController
(
Loggable
,
object
):
class
IterationController
(
with_metaclass
(
NiftyMeta
,
type
(
'NewBase'
,
(
Loggable
,
object
)
,
{})))
:
"""The abstract base class for all iteration controllers.
An iteration controller is an object that monitors the progress of a
minimization iteration. At the begin of the minimization, its start()
...
...
@@ -41,9 +43,7 @@ class IterationController(Loggable, object):
the information passed to the controller during the iteration process.
"""
__metaclass__
=
NiftyMeta
CONVERGED
,
CONTINUE
,
ERROR
=
range
(
3
)
CONVERGED
,
CONTINUE
,
ERROR
=
list
(
range
(
3
))
@
abc
.
abstractmethod
def
start
(
self
,
energy
):
...
...
nifty/minimization/line_searching/__init__.py
View file @
508800eb
...
...
@@ -16,5 +16,5 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
line_search
import
LineSearch
from
line_search_strong_wolfe
import
LineSearchStrongWolfe
from
.
line_search
import
LineSearch
from
.
line_search_strong_wolfe
import
LineSearchStrongWolfe
nifty/minimization/line_searching/line_search.py
View file @
508800eb
...
...
@@ -21,9 +21,10 @@ import abc
from
keepers
import
Loggable
from
nifty
import
LineEnergy
from
future.utils
import
with_metaclass
class
LineSearch
(
Loggable
,
object
):
class
LineSearch
(
with_metaclass
(
abc
.
ABCMeta
,
with_metaclass
(
abc
.
ABCMeta
,
type
(
'NewBase'
,
(
Loggable
,
object
)
,
{}))))
:
"""Class for determining the optimal step size along some descent direction.
Initialize the line search procedure which can be used by a specific line
...
...
@@ -39,8 +40,6 @@ class LineSearch(Loggable, object):
"""
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
):
self
.
preferred_initial_step_size
=
None
...
...
nifty/minimization/line_searching/line_search_strong_wolfe.py
View file @
508800eb
...
...
@@ -16,6 +16,9 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
print_function
from
__future__
import
division
from
builtins
import
range
import
numpy
as
np
from
.line_search
import
LineSearch
...
...
@@ -124,7 +127,7 @@ class LineSearchStrongWolfe(LineSearch):
alpha1
=
1.0
/
pk
.
norm
()
# start the minimization loop
for
i
in
x
range
(
self
.
max_iterations
):
for
i
in
range
(
self
.
max_iterations
):
if
alpha1
==
0
:
self
.
logger
.
warn
(
"Increment size became 0."
)
return
le_0
.
energy
...
...
@@ -152,7 +155,7 @@ class LineSearchStrongWolfe(LineSearch):
# update alphas
alpha0
,
alpha1
=
alpha1
,
min
(
2
*
alpha1
,
self
.
max_step_size
)
if
alpha1
==
self
.
max_step_size
:
print
"reached max step size, bailing out"
print
(
"reached max step size, bailing out"
)
return
le_alpha1
.
energy
phi_alpha0
=
phi_alpha1
...
...
@@ -208,7 +211,7 @@ class LineSearchStrongWolfe(LineSearch):
assert
phi_lo
<=
phi_0
+
self
.
c1
*
alpha_lo
*
phiprime_0
assert
phiprime_lo
*
(
alpha_hi
-
alpha_lo
)
<
0.
for
i
in
x
range
(
self
.
max_zoom_iterations
):
for
i
in
range
(
self
.
max_zoom_iterations
):
# assert phi_lo <= phi_0 + self.c1*alpha_lo*phiprime_0
# assert phiprime_lo*(alpha_hi-alpha_lo)<0.
delta_alpha
=
alpha_hi
-
alpha_lo
...
...
nifty/minimization/minimizer.py
View file @
508800eb
...
...
@@ -22,11 +22,11 @@ from nifty.nifty_meta import NiftyMeta
import
numpy
as
np
from
keepers
import
Loggable
from
future.utils
import
with_metaclass
class
Minimizer
(
Loggable
,
object
):
class
Minimizer
(
with_metaclass
(
NiftyMeta
,
type
(
'NewBase'
,
(
Loggable
,
object
)
,
{})))
:
""" A base class used by all minimizers.
"""
__metaclass__
=
NiftyMeta
@
abc
.
abstractmethod
def
__call__
(
self
,
energy
):
...
...
nifty/minimization/steepest_descent.py
View file @
508800eb
from
__future__
import
division
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
...
...
@@ -16,6 +17,7 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
from
.descent_minimizer
import
DescentMinimizer
...
...
nifty/minimization/vl_bfgs.py
View file @
508800eb
...
...
@@ -16,6 +16,9 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
from
builtins
import
range
from
builtins
import
object
import
numpy
as
np
from
.descent_minimizer
import
DescentMinimizer
...
...
@@ -76,7 +79,7 @@ class VL_BFGS(DescentMinimizer):
delta
=
self
.
_information_store
.
delta
descent_direction
=
delta
[
0
]
*
b
[
0
]
for
i
in
x
range
(
1
,
len
(
delta
)):
for
i
in
range
(
1
,
len
(
delta
)):
descent_direction
+=
delta
[
i
]
*
b
[
i
]
return
descent_direction
...
...
@@ -149,14 +152,15 @@ class InformationStore(object):
result
=
[]
m
=
self
.
history_length
mmax
=
self
.
max_history_length
k
=
self
.
k
k
=
self
.
k
s
=
self
.
s
for
i
in
xrange
(
m
):
for
i
in
range
(
m
):
result
.
append
(
s
[(
k
-
m
+
i
)
%
mmax
])
y
=
self
.
y
for
i
in
x
range
(
m
):
for
i
in
range
(
m
):
result
.
append
(
y
[(
k
-
m
+
i
)
%
mmax
])
result
.
append
(
self
.
last_gradient
)
...
...
@@ -183,18 +187,18 @@ class InformationStore(object):
# update the stores
k1
=
(
k
-
1
)
%
mmax
for
i
in
x
range
(
m
):
for
i
in
range
(
m
):
kmi
=
(
k
-
m
+
i
)
%
mmax
self
.
ss
[
kmi
,
k1
]
=
self
.
ss
[
k1
,
kmi
]
=
self
.
s
[
kmi
].
vdot
(
self
.
s
[
k1
])
self
.
yy
[
kmi
,
k1
]
=
self
.
yy
[
k1
,
kmi
]
=
self
.
y
[
kmi
].
vdot
(
self
.
y
[
k1
])
self
.
sy
[
kmi
,
k1
]
=
self
.
s
[
kmi
].
vdot
(
self
.
y
[
k1
])
for
j
in
x
range
(
m
-
1
):
for
j
in
range
(
m
-
1
):
kmj
=
(
k
-
m
+
j
)
%
mmax
self
.
sy
[
k1
,
kmj
]
=
self
.
s
[
k1
].
vdot
(
self
.
y
[
kmj
])
for
i
in
x
range
(
m
):
for
i
in
range
(
m
):
kmi
=
(
k
-
m
+
i
)
%
mmax
for
j
in
x
range
(
m
):
for
j
in
range
(
m
):
kmj
=
(
k
-
m
+
j
)
%
mmax
result
[
i
,
j
]
=
self
.
ss
[
kmi
,
kmj
]
result
[
i
,
m
+
j
]
=
result
[
m
+
j
,
i
]
=
self
.
sy
[
kmi
,
kmj
]
...
...
@@ -228,16 +232,16 @@ class InformationStore(object):
alpha
=
np
.
empty
(
m
,
dtype
=
np
.
float
)
for
j
in
x
range
(
m
-
1
,
-
1
,
-
1
):
delta_b_b
=
sum
([
delta
[
l
]
*
b_dot_b
[
l
,
j
]
for
l
in
x
range
(
2
*
m
+
1
)])
for
j
in
range
(
m
-
1
,
-
1
,
-
1
):
delta_b_b
=
sum
([
delta
[
l
]
*
b_dot_b
[
l
,
j
]
for
l
in
range
(
2
*
m
+
1
)])
alpha
[
j
]
=
delta_b_b
/
b_dot_b
[
j
,
m
+
j
]
delta
[
m
+
j
]
-=
alpha
[
j
]
for
i
in
x
range
(
2
*
m
+
1
):
for
i
in
range
(
2
*
m
+
1
):
delta
[
i
]
*=
b_dot_b
[
m
-
1
,
2
*
m
-
1
]
/
b_dot_b
[
2
*
m
-
1
,
2
*
m
-
1
]
for
j
in
x
range
(
m
):
delta_b_b
=
sum
([
delta
[
l
]
*
b_dot_b
[
m
+
j
,
l
]
for
l
in
x
range
(
2
*
m
+
1
)])
for
j
in
range
(
m
):
delta_b_b
=
sum
([
delta
[
l
]
*
b_dot_b
[
m
+
j
,
l
]
for
l
in
range
(
2
*
m
+
1
)])
beta
=
delta_b_b
/
b_dot_b
[
j
,
m
+
j
]
delta
[
j
]
+=
(
alpha
[
j
]
-
beta
)
...
...
nifty/nifty_meta.py
View file @
508800eb
...
...
@@ -17,7 +17,7 @@ class DocStringInheritor(type):
if
doc
:
clsdict
[
'__doc__'
]
=
doc
break
for
attr
,
attribute
in
clsdict
.
items
():
for
attr
,
attribute
in
list
(
clsdict
.
items
()
)
:
if
not
attribute
.
__doc__
:
for
mro_cls
in
(
mro_cls
for
base
in
bases
for
mro_cls
in
base
.
mro
()
...
...
nifty/nifty_utilities.py
View file @
508800eb
...
...
@@ -16,6 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
builtins
import
next
from
builtins
import
range
import
numpy
as
np
from
itertools
import
product
...
...
@@ -53,7 +55,7 @@ def get_slice_list(shape, axes):
raise
ValueError
(
"axes(axis) does not match shape."
)
axes_select
=
[
0
if
x
in
axes
else
1
for
x
,
y
in
enumerate
(
shape
)]
axes_iterables
=
\
[
range
(
y
)
for
x
,
y
in
enumerate
(
shape
)
if
x
not
in
axes
]
[
list
(
range
(
y
)
)
for
x
,
y
in
enumerate
(
shape
)
if
x
not
in
axes
]
for
index
in
product
(
*
axes_iterables
):
it_iter
=
iter
(
index
)
slice_list
=
[
...
...
nifty/operators/__init__.py
View file @
508800eb
...
...
@@ -18,24 +18,24 @@
from
__future__
import
division
from
linear_operator
import
LinearOperator
from
.
linear_operator
import
LinearOperator
from
diagonal_operator
import
DiagonalOperator
from
.
diagonal_operator
import
DiagonalOperator
from
endomorphic_operator
import
EndomorphicOperator
from
.
endomorphic_operator
import
EndomorphicOperator
from
smoothing_operator
import
*
from
.
smoothing_operator
import
*
from
fft_operator
import
*
from
.
fft_operator
import
*
from
invertible_operator_mixin
import
InvertibleOperatorMixin
from
.
invertible_operator_mixin
import
InvertibleOperatorMixin
from
projection_operator
import
ProjectionOperator
from
.
projection_operator
import
ProjectionOperator
from
composed_operator
import
ComposedOperator
from
.
composed_operator
import
ComposedOperator
from
response_operator
import
ResponseOperator
from
.
response_operator
import
ResponseOperator
from
laplace_operator
import
LaplaceOperator
from
.
laplace_operator
import
LaplaceOperator
from
smoothness_operator
import
SmoothnessOperator
from
.
smoothness_operator
import
SmoothnessOperator
nifty/operators/composed_operator/__init__.py
View file @
508800eb
...
...
@@ -16,4 +16,4 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
composed_operator
import
ComposedOperator
from
.
composed_operator
import
ComposedOperator
nifty/operators/composed_operator/composed_operator.py
View file @
508800eb
...
...
@@ -16,7 +16,8 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
nifty.operators.linear_operator
import
LinearOperator
from
builtins
import
range
from
..linear_operator
import
LinearOperator
class
ComposedOperator
(
LinearOperator
):
...
...
@@ -136,7 +137,7 @@ class ComposedOperator(LinearOperator):
def
_times_helper
(
self
,
x
,
spaces
,
func
):
space_index
=
0
if
spaces
is
None
:
spaces
=
range
(
len
(
self
.
domain
))
spaces
=
list
(
range
(
len
(
self
.
domain
))
)
for
op
in
self
.
_operator_store
:
active_spaces
=
spaces
[
space_index
:
space_index
+
len
(
op
.
domain
)]
space_index
+=
len
(
op
.
domain
)
...
...
@@ -147,7 +148,7 @@ class ComposedOperator(LinearOperator):
def
_inverse_times_helper
(
self
,
x
,
spaces
,
func
):
space_index
=
0
if
spaces
is
None
:
spaces
=
range
(
len
(
self
.
target
))
spaces
=
list
(
range
(
len
(
self
.
target
))
)
rev_spaces
=
spaces
[::
-
1
]
for
op
in
reversed
(
self
.
_operator_store
):
active_spaces
=
rev_spaces
[
space_index
:
space_index
+
len
(
op
.
target
)]
...
...
nifty/operators/diagonal_operator/__init__.py
View file @
508800eb
...
...
@@ -16,4 +16,4 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
diagonal_operator
import
DiagonalOperator
from
.
diagonal_operator
import
DiagonalOperator
nifty/operators/diagonal_operator/diagonal_operator.py
View file @
508800eb
...
...
@@ -16,14 +16,16 @@
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from
__future__
import
division
from
builtins
import
range
import
numpy
as
np
from
d2o
import
distributed_data_object
,
\
STRATEGIES
as
DISTRIBUTION_STRATEGIES
from
nifty
.config
import
nifty_configuration
as
gc
from
nifty
.field
import
Field
from
nifty.operators
.endomorphic_operator
import
EndomorphicOperator
from
..
.config
import
nifty_configuration
as
gc
from
..
.field
import
Field
from
.
.endomorphic_operator
import
EndomorphicOperator
class
DiagonalOperator
(
EndomorphicOperator
):
...
...
@@ -125,11 +127,11 @@ class DiagonalOperator(EndomorphicOperator):
operation
=
lambda
z
:
z
.
adjoint
().
__mul__
)
def
_inverse_times
(
self
,
x
,
spaces
):
return
self
.
_times_helper
(
x
,
spaces
,
operation
=
lambda
z
:
z
.
__rdiv__
)
return
self
.
_times_helper
(
x
,
spaces
,
operation
=
lambda
z
:
z
.
__r
true
div__
)
def
_adjoint_inverse_times
(
self
,
x
,
spaces
):
return
self
.
_times_helper
(
x
,
spaces
,
operation
=
lambda
z
:
z
.
adjoint
().
__rdiv__
)
operation
=
lambda
z
:
z
.
adjoint
().
__r
true
div__
)
def
diagonal
(
self
,
bare
=
False
,
copy
=
True
):
""" Returns the diagonal of the Operator.
...
...
@@ -269,7 +271,7 @@ class DiagonalOperator(EndomorphicOperator):
# the one of x, reshape the local data of self and apply it directly
active_axes
=
[]
if
spaces
is
None
:
active_axes
=
range
(
len
(
x
.
shape
))
active_axes
=
list
(
range
(
len
(
x
.
shape
))
)
else
:
for
space_index
in
spaces
:
active_axes
+=
x
.
domain_axes
[
space_index
]
...
...
@@ -287,7 +289,7 @@ class DiagonalOperator(EndomorphicOperator):
local_diagonal
=
redistr_diagonal_val
.
get_local_data
(
copy
=
False
)
reshaper
=
[
x
.
val
.
data
.
shape
[
i
]
if
i
in
active_axes
else
1
for
i
in
x
range
(
len
(
x
.
shape
))]
for
i
in
range
(
len
(
x
.
shape
))]
reshaped_local_diagonal
=
np
.
reshape
(
local_diagonal
,
reshaper
)
# here the actual multiplication takes place
...
...
Prev
1
2
3
4
5
6
7
Next
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