Commit b8088325 authored by Davis King's avatar Davis King

Added a simple newton search strategy.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403773
parent d286560e
...@@ -278,6 +278,44 @@ namespace dlib ...@@ -278,6 +278,44 @@ namespace dlib
data_helper dh_temp; data_helper dh_temp;
}; };
// ----------------------------------------------------------------------------------------
template <typename hessian_funct>
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 <typename T>
const matrix<double,0,1> get_next_direction (
const T& x,
const double ,
const T& funct_derivative
)
{
return -inv(hessian(x))*funct_derivative;
}
private:
hessian_funct hessian;
};
template <typename hessian_funct>
newton_search_strategy_obj<hessian_funct> newton_search_strategy (
const hessian_funct& hessian
) { return newton_search_strategy_obj<hessian_funct>(hessian); }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -230,6 +230,91 @@ namespace dlib ...@@ -230,6 +230,91 @@ namespace dlib
!*/ !*/
}; };
// ----------------------------------------------------------------------------------------
template <typename hessian_funct>
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 <typename T>
const matrix<double,0,1> 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 <typename hessian_funct>
newton_search_strategy_obj<hessian_funct> newton_search_strategy (
const hessian_funct& hessian
) { return newton_search_strategy_obj<hessian_funct>(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.
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment