Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Trust-Region Newton

Synopsis
#include <boost/math/optimization/trust_region_newton.hpp>

namespace boost {
namespace math {
namespace optimization {

template<typename ArgumentContainer,
         typename RealType,
         class Objective,
         class InitializationPolicy,
         class ObjectiveEvalPolicy,
         class GradEvalPolicy,
         class HessianVectorPolicy>
class trust_region_newton
{
public:
  void step();
  RealType radius() const;
};

/* x holds rdiff::rvar<RealType, 2> for the default policies */
template<class Objective,
         typename ArgumentContainer,
         class InitializationPolicy = tape_initializer_rvar<RealType, 2>,
         class FunctionEvalPolicy = reverse_mode_function_eval_policy<RealType, 2>,
         class GradientEvalPolicy = reverse_mode_gradient_evaluation_policy<RealType, 2>,
         class HessianVectorPolicy = reverse_mode_hessian_vector_product_policy<RealType>>
auto make_trust_region_newton(Objective&& obj,
                              ArgumentContainer& x,
                              RealType initial_radius = 1,
                              InitializationPolicy&& ip = InitializationPolicy{},
                              FunctionEvalPolicy&& fep = FunctionEvalPolicy{},
                              GradientEvalPolicy&& gep = GradientEvalPolicy{},
                              HessianVectorPolicy&& hvp = HessianVectorPolicy{});

} // namespace optimization
} // namespace math
} // namespace boost

The trust-region Newton method minimizes the quadratic model m(p) = f + g.p + p.Hp/2 built from the exact Hessian H, over a ball |p| <= radius, then moves only if the objective agrees with the model. Near a minimum it converges quadratically, and unlike a line search it needs no positive definite Hessian: on negative curvature, at a saddle or a maximum, the step goes to the boundary of the ball along a descent direction.

The variables are rvar<RealType, 2>, and the objective is evaluated on them. The Hessian is never formed: each Hessian-vector product is one reverse sweep through the tape that records the gradient, so the memory is that of the tape, and the method suits large n.

Algorithm

At each step:

If a constraint policy of minimize moves x, the next step evaluates there.

A step costs one objective-and-gradient evaluation, two after a rejected step, and one Hessian-vector product per conjugate gradient iteration, at most n. Use the default gradient_norm_convergence_policy with minimize: since a rejected step leaves the objective unchanged, a convergence policy on the change in objective would stop there.

Parameters
Example
#include <boost/math/differentiation/autodiff_reverse.hpp>
#include <boost/math/optimization/minimizer.hpp>
#include <boost/math/optimization/trust_region_newton.hpp>
#include <iostream>
#include <vector>
namespace rdiff = boost::math::differentiation::reverse_mode;
namespace bopt  = boost::math::optimization;

template<class Real>
Real rosenbrock(std::vector<Real> const& x)
{
    Real f = Real(0);
    for (size_t i = 0; i + 1 < x.size(); ++i) {
        f += 100 * (x[i + 1] - x[i] * x[i]) * (x[i + 1] - x[i] * x[i]) + (1 - x[i]) * (1 - x[i]);
    }
    return f;
}

int main()
{
    using rvar = rdiff::rvar<double, 2>;
    std::vector<double> x0(10, -1.2);
    std::vector<rvar> x(x0.begin(), x0.end()); // each element its own variable
    auto opt = bopt::make_trust_region_newton(&rosenbrock<rvar>, x);
    auto result = bopt::minimize(opt, bopt::unconstrained_policy<std::vector<rvar>>{},
                                 bopt::gradient_norm_convergence_policy<double>(1e-10));
    std::cout << result.num_iter << " steps, f = " << result.objective_value << "\n";
}
Complexity

Per step, one gradient evaluation on rvar<RealType, 2>, whose tape is many times that of rvar<RealType, 1>, and up to n Hessian-vector products, each a sweep of that tape. It takes fewer steps than L-BFGS, and converges quadratically at the end, but each step costs more: minimizing the Rosenbrock function from (-1.2, 1, ...), L-BFGS is 3 to 20 times faster in wall time for n from 2 to 100 (reporting/performance/trust_region_newton_performance.cpp). Prefer it where the Hessian is indefinite, or where steps, not evaluations, are what cost.

References

PrevUpHomeNext