Conjugate-gradient method for unconstrained optimization. More...

#include <shark/Algorithms/GradientDescent/CG.h>

+ Inheritance diagram for shark::CG< SearchPointType >:

Public Types

typedef AbstractLineSearchOptimizer< SearchPointType >::ObjectiveFunctionType ObjectiveFunctionType
 
- Public Types inherited from shark::AbstractLineSearchOptimizer< SearchPointType >
typedef AbstractSingleObjectiveOptimizer< SearchPointType >::ObjectiveFunctionType ObjectiveFunctionType
 
- Public Types inherited from shark::AbstractSingleObjectiveOptimizer< SearchPointType >
typedef base_type::SearchPointType SearchPointType
 
typedef base_type::SolutionType SolutionType
 
typedef base_type::ResultType ResultType
 
typedef base_type::ObjectiveFunctionType ObjectiveFunctionType
 
- Public Types inherited from shark::AbstractOptimizer< PointType, ResultT, SolutionTypeT >
enum  Feature {
  REQUIRES_VALUE = 1 , REQUIRES_FIRST_DERIVATIVE = 2 , REQUIRES_SECOND_DERIVATIVE = 4 , CAN_SOLVE_CONSTRAINED = 8 ,
  REQUIRES_CLOSEST_FEASIBLE = 16
}
 Models features that the optimizer requires from the objective function. More...
 
typedef PointType SearchPointType
 
typedef ResultT ResultType
 
typedef SolutionTypeT SolutionType
 
typedef AbstractObjectiveFunction< PointType, ResultTypeObjectiveFunctionType
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

Public Member Functions

std::string name () const
 returns the name of the object
 
void read (InArchive &archive)
 Read the component from the supplied archive.
 
void write (OutArchive &archive) const
 Write the component to the supplied archive.
 
- Public Member Functions inherited from shark::AbstractLineSearchOptimizer< SearchPointType >
 AbstractLineSearchOptimizer ()
 
void init (ObjectiveFunctionType const &objectiveFunction, SearchPointType const &startingPoint)
 
void step (ObjectiveFunctionType const &objectiveFunction)
 
LineSearch< SearchPointType > const & lineSearch () const
 
LineSearch< SearchPointType > & lineSearch ()
 
SearchPointType const & derivative () const
 Returns the derivative at the current point. Can be used for stopping criteria.
 
- Public Member Functions inherited from shark::AbstractSingleObjectiveOptimizer< SearchPointType >
std::size_t numInitPoints () const
 By default most single objective optimizers only require a single point.
 
virtual void init (ObjectiveFunctionType const &function, std::vector< SearchPointType > const &initPoints)
 Initialize the optimizer for the supplied objective function using a set of initialisation points.
 
virtual void init (ObjectiveFunctionType const &function, SearchPointType const &startingPoint)=0
 initializes the optimizer using a predefined starting point
 
virtual const SolutionTypesolution () const
 returns the current solution of the optimizer
 
- Public Member Functions inherited from shark::AbstractOptimizer< PointType, ResultT, SolutionTypeT >
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool requiresValue () const
 
bool requiresFirstDerivative () const
 
bool requiresSecondDerivative () const
 
bool canSolveConstrained () const
 
bool requiresClosestFeasible () const
 
virtual ~AbstractOptimizer ()
 
virtual void init (ObjectiveFunctionType const &function)
 Initialize the optimizer for the supplied objective function.
 
virtual void init (ObjectiveFunctionType const &function, std::vector< SearchPointType > const &initPoints)=0
 Initialize the optimizer for the supplied objective function using a set of initialisation points.
 
virtual void step (ObjectiveFunctionType const &function)=0
 Carry out one step of the optimizer for the supplied objective function.
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor.
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...).
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...).
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Protected Member Functions

void initModel ()
 Initializes the internal model.
 
void computeSearchDirection (ObjectiveFunctionType const &objectiveFunction)
 Updates the Model and computes the next search direction.
 
- Protected Member Functions inherited from shark::AbstractOptimizer< PointType, ResultT, SolutionTypeT >
void checkFeatures (ObjectiveFunctionType const &objectiveFunction)
 Convenience function that checks whether the features of the supplied objective function match with the required features of the optimizer.
 

Protected Attributes

unsigned m_count
 
- Protected Attributes inherited from shark::AbstractLineSearchOptimizer< SearchPointType >
LineSearch< SearchPointTypem_linesearch
 used line search method.
 
std::size_t m_dimension
 number of parameters
 
double m_initialStepLength
 Initial step length to begin with the line search.
 
SearchPointType m_derivative
 gradient of m_best.point
 
SearchPointType m_searchDirection
 search direction of next step
 
SearchPointType m_lastPoint
 previous point
 
SearchPointType m_lastDerivative
 gradient of the previous point
 
double m_lastValue
 value of the previous point
 
- Protected Attributes inherited from shark::AbstractSingleObjectiveOptimizer< SearchPointType >
SolutionType m_best
 Current solution of the optimizer.
 
- Protected Attributes inherited from shark::AbstractOptimizer< PointType, ResultT, SolutionTypeT >
Features m_features
 

Detailed Description

template<class SearchPointType = RealVector>
class shark::CG< SearchPointType >

Conjugate-gradient method for unconstrained optimization.

The next CG search Direction p_{k+1} is computed using the current gradient g_k by \( p_{k+1} = \beta p_k - g_k \) where beta can be computed using different formulas well known is the Fletcher - Reeves method: \( \beta = ||g_k||2/ ||g_{k-1}||^2 \) we use \( \beta = ||g_k||^2 /<p_k,g_k-g_{k-1}> \) which is formula 5.49 in Nocedal, Wright - Numerical Optimization. This formula has better numerical properties than Fletcher-Reeves for non-quadratic functions while ensuring a descent direction.

We implement restarting to ensure quadratic convergence near the optimum as well as numerical stability

Definition at line 59 of file CG.h.

Member Typedef Documentation

◆ ObjectiveFunctionType

template<class SearchPointType = RealVector>
typedef AbstractLineSearchOptimizer<SearchPointType>::ObjectiveFunctionType shark::CG< SearchPointType >::ObjectiveFunctionType

Definition at line 62 of file CG.h.

Member Function Documentation

◆ computeSearchDirection()

template<class SearchPointType = RealVector>
void shark::CG< SearchPointType >::computeSearchDirection ( ObjectiveFunctionType const &  objectiveFunction)
protectedvirtual

Updates the Model and computes the next search direction.

After a step was performed, this method is called to compute the next search direction. This usually involves updating the internal model using the new and old step information. Afterwards m_searchDirection should contain the next search direction.

Implements shark::AbstractLineSearchOptimizer< SearchPointType >.

◆ initModel()

template<class SearchPointType = RealVector>
void shark::CG< SearchPointType >::initModel ( )
protectedvirtual

Initializes the internal model.

Line Search Methods use a Model to search for the next search direction. The model is initialized during init()

Implements shark::AbstractLineSearchOptimizer< SearchPointType >.

◆ name()

template<class SearchPointType = RealVector>
std::string shark::CG< SearchPointType >::name ( ) const
inlinevirtual

returns the name of the object

Reimplemented from shark::INameable.

Definition at line 67 of file CG.h.

◆ read()

template<class SearchPointType = RealVector>
void shark::CG< SearchPointType >::read ( InArchive archive)
virtual

Read the component from the supplied archive.

Parameters
[in,out]archiveThe archive to read from.

Reimplemented from shark::AbstractLineSearchOptimizer< SearchPointType >.

◆ write()

template<class SearchPointType = RealVector>
void shark::CG< SearchPointType >::write ( OutArchive archive) const
virtual

Write the component to the supplied archive.

Parameters
[in,out]archiveThe archive to write to.

Reimplemented from shark::AbstractLineSearchOptimizer< SearchPointType >.

Member Data Documentation

◆ m_count

template<class SearchPointType = RealVector>
unsigned shark::CG< SearchPointType >::m_count
protected

Definition at line 74 of file CG.h.


The documentation for this class was generated from the following file: