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
026e670e
Commit
026e670e
authored
Jul 09, 2017
by
Martin Reinecke
Browse files
while we are at it: some orthography policing
parent
276ca31b
Pipeline
#14537
passed with stage
in 6 minutes and 44 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty/minimization/descent_minimizer.py
View file @
026e670e
...
...
@@ -146,14 +146,14 @@ class DescentMinimizer(Loggable, object):
break
# current position is encoded in energy object
descen
d
_direction
=
self
.
get_descen
d
_direction
(
energy
)
descen
t
_direction
=
self
.
get_descen
t
_direction
(
energy
)
# compute the step length, which minimizes energy.value along the
# search direction
step_length
,
f_k
,
new_energy
=
\
self
.
line_searcher
.
perform_line_search
(
energy
=
energy
,
pk
=
descen
d
_direction
,
pk
=
descen
t
_direction
,
f_k_minus_1
=
f_k_minus_1
)
f_k_minus_1
=
energy
.
value
...
...
@@ -195,5 +195,5 @@ class DescentMinimizer(Loggable, object):
return
energy
,
convergence
@
abc
.
abstractmethod
def
get_descen
d
_direction
(
self
,
energy
):
def
get_descen
t
_direction
(
self
,
energy
):
raise
NotImplementedError
nifty/minimization/line_searching/line_search.py
View file @
026e670e
...
...
@@ -25,31 +25,31 @@ from nifty import LineEnergy
class
LineSearch
(
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
search method. Its finds the step size in a specific direction in the
minimization process.
Attributes
----------
line_energy : LineEnergy Object
LineEnergy object from which we can extract energy at a specific point.
f_k_minus_1 : Field
Value of the field at the k-1 iteration of the line search procedure.
prefered_initial_step_size : float
prefer
r
ed_initial_step_size : float
Initial guess for the step length.
"""
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
):
self
.
line_energy
=
None
self
.
f_k_minus_1
=
None
self
.
prefered_initial_step_size
=
None
self
.
prefer
r
ed_initial_step_size
=
None
def
_set_line_energy
(
self
,
energy
,
pk
,
f_k_minus_1
=
None
):
"""Set the coordinates for a new line search.
...
...
@@ -58,13 +58,13 @@ class LineSearch(Loggable, object):
----------
energy : Energy object
Energy object from which we can calculate the energy, gradient and
curvature at a specific point.
curvature at a specific point.
pk : Field
Unit vector pointing into the search direction.
f_k_minus_1 : float
Value of the fuction (energy) which will be minimized at the k-1
Value of the fuction (energy) which will be minimized at the k-1
iteration of the line search procedure. (Default: None)
"""
self
.
line_energy
=
LineEnergy
(
position
=
0.
,
energy
=
energy
,
...
...
nifty/minimization/line_searching/line_search_strong_wolfe.py
View file @
026e670e
...
...
@@ -120,8 +120,8 @@ class LineSearchStrongWolfe(LineSearch):
# set alphas
alpha0
=
0.
if
self
.
prefered_initial_step_size
is
not
None
:
alpha1
=
self
.
prefered_initial_step_size
if
self
.
prefer
r
ed_initial_step_size
is
not
None
:
alpha1
=
self
.
prefer
r
ed_initial_step_size
elif
old_phi_0
is
not
None
and
phiprime_0
!=
0
:
alpha1
=
min
(
1.0
,
1.01
*
2
*
(
phi_0
-
old_phi_0
)
/
phiprime_0
)
if
alpha1
<
0
:
...
...
nifty/minimization/relaxed_newton.py
View file @
026e670e
...
...
@@ -32,9 +32,9 @@ class RelaxedNewton(DescentMinimizer):
convergence_level
=
convergence_level
,
iteration_limit
=
iteration_limit
)
self
.
line_searcher
.
prefered_initial_step_size
=
1.
self
.
line_searcher
.
prefer
r
ed_initial_step_size
=
1.
def
get_descen
d
_direction
(
self
,
energy
):
def
get_descen
t
_direction
(
self
,
energy
):
""" Calculates the descent direction according to a Newton scheme.
The descent direction is determined by weighting the gradient at the
...
...
@@ -50,12 +50,9 @@ class RelaxedNewton(DescentMinimizer):
Returns
-------
descen
d
_direction : Field
descen
t
_direction : Field
Returns the descent direction with proposed step length. In a
quadratic potential this corresponds to the optimal step.
"""
gradient
=
energy
.
gradient
curvature
=
energy
.
curvature
descend_direction
=
curvature
.
inverse_times
(
gradient
)
return
descend_direction
*
-
1
return
-
energy
.
curvature
.
inverse_times
(
energy
.
gradient
)
nifty/minimization/steepest_descent.py
View file @
026e670e
...
...
@@ -20,7 +20,7 @@ from .descent_minimizer import DescentMinimizer
class
SteepestDescent
(
DescentMinimizer
):
def
get_descen
d
_direction
(
self
,
energy
):
def
get_descen
t
_direction
(
self
,
energy
):
""" Implementation of the steepest descent minimization scheme.
Also known as 'gradient descent'. This algorithm simply follows the
...
...
@@ -34,10 +34,9 @@ class SteepestDescent(DescentMinimizer):
Returns
-------
descen
d
_direction : Field
descen
t
_direction : Field
Returns the descent direction.
"""
descend_direction
=
energy
.
gradient
return
descend_direction
*
-
1
return
-
energy
.
gradient
nifty/minimization/vl_bfgs.py
View file @
026e670e
...
...
@@ -40,7 +40,7 @@ class VL_BFGS(DescentMinimizer):
self
.
_information_store
=
None
return
super
(
VL_BFGS
,
self
).
__call__
(
energy
)
def
get_descen
d
_direction
(
self
,
energy
):
def
get_descen
t
_direction
(
self
,
energy
):
"""Implementation of the Vector-free L-BFGS minimization scheme.
Find the descent direction by using the inverse Hessian.
...
...
@@ -57,7 +57,7 @@ class VL_BFGS(DescentMinimizer):
Returns
-------
descen
d
_direction : Field
descen
t
_direction : Field
Returns the descent direction.
References
...
...
@@ -80,11 +80,11 @@ class VL_BFGS(DescentMinimizer):
b
=
self
.
_information_store
.
b
delta
=
self
.
_information_store
.
delta
descen
d
_direction
=
delta
[
0
]
*
b
[
0
]
descen
t
_direction
=
delta
[
0
]
*
b
[
0
]
for
i
in
xrange
(
1
,
len
(
delta
)):
descen
d
_direction
+=
delta
[
i
]
*
b
[
i
]
descen
t
_direction
+=
delta
[
i
]
*
b
[
i
]
return
descen
d
_direction
return
descen
t
_direction
class
InformationStore
(
object
):
...
...
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