5#ifndef LBFGSPP_LINE_SEARCH_BRACKETING_H
6#define LBFGSPP_LINE_SEARCH_BRACKETING_H
16template <
typename Scalar>
20 using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
46 template <
typename Foo>
48 const Vector& xp,
const Vector& drt,
const Scalar& step_max,
49 Scalar& step, Scalar& fx, Vector& grad, Scalar& dg, Vector& x)
52 if (step <= Scalar(0))
53 throw std::invalid_argument(
"'step' must be positive");
56 const Scalar fx_init = fx;
58 const Scalar dg_init = grad.dot(drt);
61 throw std::logic_error(
"the moving direction increases the objective function value");
63 const Scalar test_decr = param.
ftol * dg_init;
67 step_hi = std::numeric_limits<Scalar>::infinity();
73 x.noalias() = xp + step * drt;
77 if (fx > fx_init + step * test_decr || (fx != fx))
89 if (dg < param.
wolfe * dg_init)
99 if (dg > -param.
wolfe * dg_init)
111 assert(step_lo < step_hi);
114 throw std::runtime_error(
"the line search step became smaller than the minimum value allowed");
117 throw std::runtime_error(
"the line search step became larger than the maximum value allowed");
120 step = std::isinf(step_hi) ? 2 * step : step_lo / 2 + step_hi / 2;
124 throw std::runtime_error(
"the line search routine reached the maximum number of iterations");
static void LineSearch(Foo &f, const LBFGSParam< Scalar > ¶m, const Vector &xp, const Vector &drt, const Scalar &step_max, Scalar &step, Scalar &fx, Vector &grad, Scalar &dg, Vector &x)
@ LBFGS_LINESEARCH_BACKTRACKING_ARMIJO
@ LBFGS_LINESEARCH_BACKTRACKING_WOLFE