From b80883255aac200ee0451550af6a6f3d087166f4 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 24 Jul 2010 19:49:12 +0000 Subject: [PATCH] Added a simple newton search strategy. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403773 --- .../optimization_search_strategies.h | 38 +++++++++ .../optimization_search_strategies_abstract.h | 85 +++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/dlib/optimization/optimization_search_strategies.h b/dlib/optimization/optimization_search_strategies.h index d2ac571b5..aab8cb870 100644 --- a/dlib/optimization/optimization_search_strategies.h +++ b/dlib/optimization/optimization_search_strategies.h @@ -278,6 +278,44 @@ namespace dlib data_helper dh_temp; }; +// ---------------------------------------------------------------------------------------- + + template + class newton_search_strategy_obj + { + public: + newton_search_strategy_obj( + const hessian_funct& hess + ) : hessian(hess) {} + + double get_wolfe_rho ( + ) const { return 0.01; } + + double get_wolfe_sigma ( + ) const { return 0.9; } + + unsigned long get_max_line_search_iterations ( + ) const { return 100; } + + template + const matrix get_next_direction ( + const T& x, + const double , + const T& funct_derivative + ) + { + return -inv(hessian(x))*funct_derivative; + } + + private: + hessian_funct hessian; + }; + + template + newton_search_strategy_obj newton_search_strategy ( + const hessian_funct& hessian + ) { return newton_search_strategy_obj(hessian); } + // ---------------------------------------------------------------------------------------- } diff --git a/dlib/optimization/optimization_search_strategies_abstract.h b/dlib/optimization/optimization_search_strategies_abstract.h index 8ada13fcb..c81d20860 100644 --- a/dlib/optimization/optimization_search_strategies_abstract.h +++ b/dlib/optimization/optimization_search_strategies_abstract.h @@ -230,6 +230,91 @@ namespace dlib !*/ }; +// ---------------------------------------------------------------------------------------- + + template + class newton_search_strategy_obj + { + /*! + REQUIREMENTS ON hessian_funct + Lets denote the function being optimized as f(x). Then the + hessian_funct must be a function object that takes in an x + and returns the hessian matrix at x. hessian_funct must also + be copy constructable. + + WHAT THIS OBJECT REPRESENTS + This object represents a strategy for determining which direction + a line search should be carried out along. This particular object + is an implementation of the newton method for determining this + direction. That is, it uses the following formula to determine + the direction: + search_direction = -inv(hessian(x))*derivative + !*/ + public: + newton_search_strategy_obj( + const hessian_funct& hess + ); + /*! + ensures + - This object is properly initialized and ready to generate + search directions. + !*/ + + double get_wolfe_rho ( + ) const; + /*! + ensures + - returns the value of the Wolfe rho parameter that should be used when + this search strategy is used with the line_search() function. + !*/ + + double get_wolfe_sigma ( + ) const; + /*! + ensures + - returns the value of the Wolfe sigma parameter that should be used when + this search strategy is used with the line_search() function. + !*/ + + unsigned long get_max_line_search_iterations ( + ) const; + /*! + ensures + - returns the value of the max iterations parameter that should be used when + this search strategy is used with the line_search() function. + !*/ + + template + const matrix get_next_direction ( + const T& x, + const double funct_value, + const T& funct_derivative + ); + /*! + requires + - for some objective function f(): + - x == the search point for the current iteration + - funct_value == f(x) + - funct_derivative == derivative(f)(x) + ensures + - Assuming that a line search is going to be conducted starting from the + point x, this function returns the direction in which the search should + proceed. + !*/ + + }; + + template + newton_search_strategy_obj newton_search_strategy ( + const hessian_funct& hessian + ) { return newton_search_strategy_obj(hessian); } + /*! + ensures + - constructs and returns a newton_search_strategy_obj. + This function is just a helper to make the syntax for creating + these objects a little simpler. + !*/ + // ---------------------------------------------------------------------------------------- }