4#ifndef LBFGSPP_LINE_SEARCH_BACKTRACKING_H
5#define LBFGSPP_LINE_SEARCH_BACKTRACKING_H
15template <
typename Scalar>
19 using Vector = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
43 template <
typename Foo>
45 const Vector& xp,
const Vector& drt,
const Scalar& step_max,
46 Scalar& step, Scalar& fx, Vector& grad, Scalar& dg, Vector& x)
49 const Scalar dec = 0.5;
50 const Scalar inc = 2.1;
53 if (step <= Scalar(0))
54 throw std::invalid_argument(
"'step' must be positive");
57 const Scalar fx_init = fx;
59 const Scalar dg_init = grad.dot(drt);
62 throw std::logic_error(
"the moving direction increases the objective function value");
64 const Scalar test_decr = param.
ftol * dg_init;
71 x.noalias() = xp + step * drt;
75 if (fx > fx_init + step * test_decr || (fx != fx))
87 if (dg < param.
wolfe * dg_init)
97 if (dg > -param.
wolfe * dg_init)
110 throw std::runtime_error(
"the line search step became smaller than the minimum value allowed");
113 throw std::runtime_error(
"the line search step became larger than the maximum value allowed");
119 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