Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Optimist::LineSearch Namespace Reference

Namespace for the one-dimensional line searches used by the descent optimizers. More...

Classes

struct  Settings
 Line search parameters and result. More...

Typedefs

using Method
 Available line search strategies.

Functions

std::string name (const Method method)
 Get the name of a line search strategy.
template<typename Scalar>
Scalar armijo_bound (const Scalar phi_0, const Scalar dphi_0, const Scalar alpha, const Settings< Scalar > &s, const Scalar c)
template<typename Scalar>
Scalar cubic_minimizer (const Scalar a, const Scalar phi_a, const Scalar dphi_a, const Scalar b, const Scalar phi_b, const Scalar dphi_b)
template<typename Scalar, typename Phi>
bool armijo (Phi &&phi, const Scalar phi_0, const Scalar dphi_0, Scalar &alpha, Scalar &phi_alpha, const Settings< Scalar > &s=Settings< Scalar >())
 Backtracking line search enforcing the Armijo condition \( \phi(\alpha) \leq \phi(0) + c_1\alpha\phi'(0) \), with safeguarded quadratic interpolation of the trial steps.
template<typename Scalar, typename Phi>
bool goldstein (Phi &&phi, const Scalar phi_0, const Scalar dphi_0, Scalar &alpha, Scalar &phi_alpha, const Settings< Scalar > &s=Settings< Scalar >())
 Line search enforcing the Goldstein conditions \( \phi(0) + (1-c)\alpha\phi'(0) \leq \phi(\alpha) \leq \phi(0) + c\alpha\phi'(0) \), by expansion and bisection. Only function values are used.
template<typename Scalar, typename Phi>
bool strong_wolfe (Phi &&phi, const Scalar phi_0, const Scalar dphi_0, Scalar &alpha, Scalar &phi_alpha, Scalar &dphi_alpha, const Settings< Scalar > &s=Settings< Scalar >())
 Line search enforcing the strong Wolfe conditions \( \phi(\alpha) \leq \phi(0) + c_1\alpha\phi'(0) \) and \( |\phi'(\alpha)| \leq c_2|\phi'(0)| \) (Nocedal and Wright, Algorithms 3.5 and 3.6), with cubic interpolation in the zoom phase.
template<typename Scalar>
void more_thuente_step (Scalar &stx, Scalar &fx, Scalar &dx, Scalar &sty, Scalar &fy, Scalar &dy, Scalar &stp, const Scalar fp, const Scalar dp, bool &brackt, const Scalar stpmin, const Scalar stpmax, const Scalar noise=0)
 Safeguarded step of the Moré-Thuente line search (MINPACK-2 dcstep). Computes a new trial step from the interval endpoints \((s_x, f_x, d_x) \), \( (s_y, f_y, d_y) \) and the current trial \((s_p, f_p, d_p) \), and updates the interval that contains a step satisfying the strong Wolfe conditions.
template<typename Scalar, typename Phi>
bool more_thuente (Phi &&phi, const Scalar phi_0, const Scalar dphi_0, Scalar &alpha, Scalar &phi_alpha, Scalar &dphi_alpha, const Settings< Scalar > &s=Settings< Scalar >())
 Line search of Moré and Thuente (1994), as implemented in MINPACK-2 (dcsrch). It finds a step satisfying the strong Wolfe conditions by safeguarded cubic and quadratic interpolation, working on the auxiliary function \( \psi(\alpha) = \phi(\alpha) - \phi(0) - c_1\alpha\phi'(0) \) until an interval with a suitable step is found.
template<typename Scalar, typename Phi>
bool search (const Method method, Phi &&phi, const Scalar phi_0, const Scalar dphi_0, Scalar &alpha, Scalar &phi_alpha, Scalar &dphi_alpha, const Settings< Scalar > &s)
 Run the selected line search.

Detailed Description

Line searches

Descent optimizers update the iterate as \(\mathbf{x}_{k+1} = \mathbf{x}_k + \alpha_k \mathbf{d}_k\), where \(\mathbf{d}_k\) is a descent direction, \(\nabla f(\mathbf{x}_k)^\top \mathbf{d}_k < 0\). The step \(\alpha_k\) is chosen by a line search on \(\phi(\alpha) = f(\mathbf{x}_k + \alpha\mathbf{d}_k)\). Four strategies are available in the Optimist::LineSearch namespace:

  • Armijo backtracking enforces the sufficient decrease condition

    \[ \phi(\alpha) \leq \phi(0) + c_1 \alpha \phi'(0) \text{,} \]

    shrinking the trial step by safeguarded quadratic interpolation. It needs function values only.
  • Goldstein enforces \(\phi(0) + (1-c)\alpha\phi'(0) \leq \phi(\alpha) \leq \phi(0) + c\alpha\phi'(0)\) with \(0 < c < 1/2\), by expansion and bisection, which also rules out steps that are too short.
  • Strong Wolfe enforces sufficient decrease together with the curvature condition \(|\phi'(\alpha)| \leq c_2|\phi'(0)|\) (Nocedal and Wright, Algorithms 3.5 and 3.6), with a bracketing phase followed by a zoom phase based on safeguarded cubic interpolation. It guarantees \(\mathbf{s}_k^\top\mathbf{y}_k > 0\), which keeps quasi-Newton updates positive definite, and it is the default choice of the BFGS solver.
  • Moré-Thuente (1994) enforces the same strong Wolfe conditions with the safeguarded cubic and quadratic interpolation steps of MINPACK-2 (dcsrch/dcstep), working on the auxiliary function \(\psi(\alpha) = \phi(\alpha) - \phi(0) - c_1\alpha\phi'(0)\) until a suitable bracket is found.

Close to a minimizer the decrease of \(\phi\) falls below its rounding error, so that a literal sufficient decrease test would reject every step. All searches therefore accept \(\phi(\alpha) \leq \phi(0) + c_1\alpha\phi'(0) + \epsilon_f|\phi(0)|\), and compare function values inside the bracket only above that level (below it, the derivative decides), in the spirit of the approximate Wolfe conditions of Hager and Zhang. The default \(\epsilon_f = 100\,\epsilon\) can be raised for cost functions evaluated with heavy cancellation.

The parameters ( \(c_1 = 10^{-4}\), \(c_2 = 0.9\), \(c = 0.25\), \(\epsilon_f\), maximum step and number of trials) are collected in LineSearch::Settings.

All line searches work on the restriction of the objective to the search direction, \( \phi(\alpha) = f(\mathbf{x} + \alpha\mathbf{d}) \), and are therefore independent of the vector type. The restriction is provided as a callable with signature

bool phi(Scalar alpha, Scalar &value, Scalar *derivative);

where derivative is nullptr when \( \phi'(\alpha) \) is not needed.

Typedef Documentation

◆ Method

Initial value:
enum class Method : Integer {
ARMIJO = 0,
GOLDSTEIN = 1,
STRONG_WOLFE = 2,
MORE_THUENTE = 3
}
enum class Method :Integer { ARMIJO=0, GOLDSTEIN=1, STRONG_WOLFE=2, MORE_THUENTE=3 } Method
Available line search strategies.
Definition LineSearch.hh:41
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:98

Function Documentation

◆ armijo()

template<typename Scalar, typename Phi>
bool Optimist::LineSearch::armijo ( Phi && phi,
const Scalar phi_0,
const Scalar dphi_0,
Scalar & alpha,
Scalar & phi_alpha,
const Settings< Scalar > & s = Settings<Scalar>() )
Parameters
[in]phiRestricted objective.
[in]phi_0Value \( \phi(0) \).
[in]dphi_0Slope \( \phi'(0) < 0 \).
[in,out]alphaInitial trial step on input, accepted step on output.
[out]phi_alphaValue at the accepted step.
[in]sLine search settings.
Returns
True if an acceptable step was found.

◆ armijo_bound()

template<typename Scalar>
Scalar Optimist::LineSearch::armijo_bound ( const Scalar phi_0,
const Scalar dphi_0,
const Scalar alpha,
const Settings< Scalar > & s,
const Scalar c )

Right-hand side of the (relaxed) sufficient decrease condition.

◆ cubic_minimizer()

template<typename Scalar>
Scalar Optimist::LineSearch::cubic_minimizer ( const Scalar a,
const Scalar phi_a,
const Scalar dphi_a,
const Scalar b,
const Scalar phi_b,
const Scalar dphi_b )

Minimizer of the cubic interpolating \( (a, \phi_a, \phi'_a) \) and \( (b, \phi_b, \phi'_b) \), safeguarded to the inner part of the interval. Falls back to bisection when the cubic has no minimizer.

◆ goldstein()

template<typename Scalar, typename Phi>
bool Optimist::LineSearch::goldstein ( Phi && phi,
const Scalar phi_0,
const Scalar dphi_0,
Scalar & alpha,
Scalar & phi_alpha,
const Settings< Scalar > & s = Settings<Scalar>() )
Parameters
[in]phiRestricted objective.
[in]phi_0Value \( \phi(0) \).
[in]dphi_0Slope \( \phi'(0) < 0 \).
[in,out]alphaInitial trial step on input, accepted step on output.
[out]phi_alphaValue at the accepted step.
[in]sLine search settings.
Returns
True if an acceptable step was found.

◆ more_thuente()

template<typename Scalar, typename Phi>
bool Optimist::LineSearch::more_thuente ( Phi && phi,
const Scalar phi_0,
const Scalar dphi_0,
Scalar & alpha,
Scalar & phi_alpha,
Scalar & dphi_alpha,
const Settings< Scalar > & s = Settings<Scalar>() )
Parameters
[in]phiRestricted objective (with derivative).
[in]phi_0Value \( \phi(0) \).
[in]dphi_0Slope \( \phi'(0) < 0 \).
[in,out]alphaInitial trial step on input, accepted step on output.
[out]phi_alphaValue at the accepted step.
[out]dphi_alphaSlope at the accepted step.
[in]sLine search settings.
Returns
True if an acceptable step was found.

◆ more_thuente_step()

template<typename Scalar>
void Optimist::LineSearch::more_thuente_step ( Scalar & stx,
Scalar & fx,
Scalar & dx,
Scalar & sty,
Scalar & fy,
Scalar & dy,
Scalar & stp,
const Scalar fp,
const Scalar dp,
bool & brackt,
const Scalar stpmin,
const Scalar stpmax,
const Scalar noise = 0 )

◆ name()

std::string Optimist::LineSearch::name ( const Method method)
inline

◆ search()

template<typename Scalar, typename Phi>
bool Optimist::LineSearch::search ( const Method method,
Phi && phi,
const Scalar phi_0,
const Scalar dphi_0,
Scalar & alpha,
Scalar & phi_alpha,
Scalar & dphi_alpha,
const Settings< Scalar > & s )

The derivative at the accepted step is returned only by the searches that compute it (strong Wolfe and Moré-Thuente); dphi_alpha is left untouched by Armijo and Goldstein.

Parameters
[in]methodLine search strategy.
[in]phiRestricted objective.
[in]phi_0Value \( \phi(0) \).
[in]dphi_0Slope \( \phi'(0) < 0 \).
[in,out]alphaInitial trial step on input, accepted step on output.
[out]phi_alphaValue at the accepted step.
[out]dphi_alphaSlope at the accepted step (see above).
[in]sLine search settings.
Returns
True if an acceptable step was found.

◆ strong_wolfe()

template<typename Scalar, typename Phi>
bool Optimist::LineSearch::strong_wolfe ( Phi && phi,
const Scalar phi_0,
const Scalar dphi_0,
Scalar & alpha,
Scalar & phi_alpha,
Scalar & dphi_alpha,
const Settings< Scalar > & s = Settings<Scalar>() )
Parameters
[in]phiRestricted objective (with derivative).
[in]phi_0Value \( \phi(0) \).
[in]dphi_0Slope \( \phi'(0) < 0 \).
[in,out]alphaInitial trial step on input, accepted step on output.
[out]phi_alphaValue at the accepted step.
[out]dphi_alphaSlope at the accepted step.
[in]sLine search settings.
Returns
True if an acceptable step was found.