Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ift
NIFTy
Commits
7412dcc3
Commit
7412dcc3
authored
May 09, 2017
by
Matevz, Sraml (sraml)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
documentation Line search and Quasi Newton minimizer added
parent
ad3a7d38
Pipeline
#12185
passed with stage
in 4 minutes and 47 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
55 deletions
+102
-55
nifty/minimization/line_searching/line_search.py
nifty/minimization/line_searching/line_search.py
+26
-28
nifty/minimization/quasi_newton_minimizer.py
nifty/minimization/quasi_newton_minimizer.py
+76
-27
No files found.
nifty/minimization/line_searching/line_search.py
View file @
7412dcc3
...
@@ -24,50 +24,48 @@ from nifty import LineEnergy
...
@@ -24,50 +24,48 @@ from nifty import LineEnergy
class
LineSearch
(
Loggable
,
object
):
class
LineSearch
(
Loggable
,
object
):
"""Class for finding a step size.
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
Initial guess for the step length.
"""
"""
Class for finding a step size.
"""
__metaclass__
=
abc
.
ABCMeta
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
):
def
__init__
(
self
):
"""
Parameters
----------
f : callable f(x, *args)
Objective function.
fprime : callable f'(x, *args)
Objective functions gradient.
f_args : tuple (optional)
Additional arguments passed to objective function and its
derivation.
"""
self
.
line_energy
=
None
self
.
line_energy
=
None
self
.
f_k_minus_1
=
None
self
.
f_k_minus_1
=
None
self
.
prefered_initial_step_size
=
None
self
.
prefered_initial_step_size
=
None
def
_set_line_energy
(
self
,
energy
,
pk
,
f_k_minus_1
=
None
):
def
_set_line_energy
(
self
,
energy
,
pk
,
f_k_minus_1
=
None
):
"""
"""Set the coordinates for a new line search.
Set the coordinates for a new line search.
Parameters
Parameters
----------
----------
xk : ndarray, d2o, field
energy : Energy object
Starting point.
Energy object from which we can calculate the
energy, gradient and curvature at a specific point.
pk :
ndarray, d2o, f
ield
pk :
F
ield
Unit vector in search direction.
Unit vector in search direction.
f_k : float (optional)
f_k_minus_1 : float *optional*
Function value f(x_k).
Value of the field at the k-1 iteration of the line search
procedure.
fprime_k : ndarray, d2o, field (optional)
Function value fprime(xk).
"""
"""
self
.
line_energy
=
LineEnergy
(
position
=
0.
,
self
.
line_energy
=
LineEnergy
(
position
=
0.
,
energy
=
energy
,
energy
=
energy
,
...
...
nifty/minimization/quasi_newton_minimizer.py
View file @
7412dcc3
...
@@ -26,6 +26,54 @@ from .line_searching import LineSearchStrongWolfe
...
@@ -26,6 +26,54 @@ from .line_searching import LineSearchStrongWolfe
class
QuasiNewtonMinimizer
(
Loggable
,
object
):
class
QuasiNewtonMinimizer
(
Loggable
,
object
):
"""A Class used by other minimization methods to find local minimum.
Quasi-Newton methods are used to find local minima or maxima of a function
by approximating the Jacobian or Hessian matrix at every iteration. The
class performs general steps(gets the gradient, descend direction, step
size and checks the conergence) which can be used then by a specific
minimization method.
Parameters
----------
line_searcher : callable
Function which finds the step size into the descent direction. (default:
LineSearchStrongWolfe())
callback : function, *optional*
Function f(energy, iteration_number) specified by the user to print
iteration number and energy value at every iteration step. It accepts
a function(energy) and integer(iteration_number). (default: None)
convergence_tolerance : scalar
Tolerance specifying convergence. (default: 1E-4)
convergence_level : integer
Number of times the tolerance should be undershot before
exiting. (default: 3)
iteration_limit : integer *optional*
Maximum number of iterations performed. (default: None)
Attributes
----------
convergence_tolerance : float
Tolerance specifying convergence.
convergence_level : float
Number of times the tolerance should be undershot before
exiting.
iteration_limit : integer
Maximum number of iterations performed.
line_searcher : callable
Function which finds the step size into the descent direction
callback : function
Function f(energy, iteration_number) specified by the user to print
iteration number and energy value at every iteration step. It accepts
a function(energy) and integer(iteration_number).
Raises
------
StopIteration
Raised if
*callback function does not match the specified form.
"""
__metaclass__
=
abc
.
ABCMeta
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
,
line_searcher
=
LineSearchStrongWolfe
(),
callback
=
None
,
def
__init__
(
self
,
line_searcher
=
LineSearchStrongWolfe
(),
callback
=
None
,
...
@@ -43,33 +91,34 @@ class QuasiNewtonMinimizer(Loggable, object):
...
@@ -43,33 +91,34 @@ class QuasiNewtonMinimizer(Loggable, object):
self
.
callback
=
callback
self
.
callback
=
callback
def
__call__
(
self
,
energy
):
def
__call__
(
self
,
energy
):
"""
"""Runs the minimization on the provided Energy class.
Runs the steepest descent minimization.
Accepts the NIFTY Energy class which describes our system and it runs
Parameters
the minimization to find the minimum/maximum of the system.
----------
x0 : field
Parameters
Starting guess for the minimization.
----------
alpha : scalar, *optional*
energy : Energy object
Starting step width to be multiplied with normalized gradient
Energy object provided by the user from which we can calculate the
(default: 1).
energy, gradient and curvature at a specific point.
tol : scalar, *optional*
Tolerance specifying convergence; measured by maximal change in
Returns
`x` (default: 1E-4).
-------
clevel : integer, *optional*
x : field
Number of times the tolerance should be undershot before
Latest `energy` of the minimization.
exiting (default: 8).
convergence : integer
self.iteration_limit : integer, *optional*
Latest convergence level indicating whether the minimization
Maximum number of iterations performed (default: 100,000).
has converged or not.
Returns
Note
-------
----
x : field
It stops the minimization if:
Latest `x` of the minimization.
*callback function does not match the specified form.
convergence : integer
*a perfectly flat point is reached.
Latest convergence level indicating whether the minimization
*according to line-search the minimum is found.
has converged or not.
*target convergence level is reached.
*iteration limit is reached.
"""
"""
convergence
=
0
convergence
=
0
...
...
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