Added a simple newton search strategy.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403773
This commit is contained in:
Davis King 2010-07-24 19:49:12 +00:00
parent d286560e8e
commit b80883255a
2 changed files with 123 additions and 0 deletions

View File

@ -278,6 +278,44 @@ namespace dlib
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); }
// ----------------------------------------------------------------------------------------
}

View File

@ -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.
!*/
// ----------------------------------------------------------------------------------------
}