shark::GridSearch Class Reference

Optimize by trying out a grid of configurations. More...

#include <shark/Algorithms/DirectSearch/GridSearch.h>

+ Inheritance diagram for shark::GridSearch:

Public Member Functions

 GridSearch ()
 
std::string name () const
 From INameable: return the class name. More...
 
void configure (size_t params, double min, double max, size_t numSections)
 
void configure (const std::vector< double > &min, const std::vector< double > &max, const std::vector< size_t > &sections)
 
void configure (double min1, double max1, size_t sections1, double min2, double max2, size_t sections2)
 
void configure (double min1, double max1, size_t sections1)
 
void configure (size_t params, const std::vector< double > &values)
 
void configure (const std::vector< std::vector< double > > &values)
 
virtual void read (InArchive &archive)
 Read the component from the supplied archive. More...
 
virtual void write (OutArchive &archive) const
 Write the component to the supplied archive. More...
 
virtual void init (ObjectiveFunctionType &objectiveFunction, SearchPointType const &startingPoint)
 
void assignLinearRange (size_t index, size_t noOfSections, double min, double max)
 
void assignExponentialRange (size_t index, double factor, double exp_base, int min, int max)
 
void step (ObjectiveFunctionType const &objectiveFunction)
 
- Public Member Functions inherited from shark::AbstractSingleObjectiveOptimizer< RealVector >
virtual void init (ObjectiveFunctionType &function)
 
virtual const SolutionTypesolution () const
 returns the current solution of the optimizer More...
 
- Public Member Functions inherited from shark::AbstractOptimizer< RealVector, double, SingleObjectiveResultSet< RealVector > >
const Featuresfeatures () const
 
virtual void updateFeatures ()
 
bool requiresValue () const
 
bool requiresFirstDerivative () const
 
bool requiresSecondDerivative () const
 
bool canSolveConstrained () const
 
bool requiresClosestFeasible () const
 
virtual ~AbstractOptimizer ()
 Empty virtual d'tor. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Protected Attributes

std::vector< std::vector< double > > m_nodeValues
 The array columns contain the grid values for the corresponding parameter axis. More...
 
bool m_configured
 
- Protected Attributes inherited from shark::AbstractSingleObjectiveOptimizer< RealVector >
SolutionType m_best
 current solution of the optimizer More...
 
- Protected Attributes inherited from shark::AbstractOptimizer< RealVector, double, SingleObjectiveResultSet< RealVector > >
Features m_features
 

Additional Inherited Members

- Public Types inherited from shark::AbstractSingleObjectiveOptimizer< RealVector >
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< RealVector, double, SingleObjectiveResultSet< RealVector > >
enum  Feature
 Models features that the optimizer requires from the objective function. More...
 
typedef RealVector SearchPointType
 
typedef double ResultType
 
typedef SingleObjectiveResultSet< RealVector > SolutionType
 
typedef AbstractObjectiveFunction< RealVector, ResultTypeObjectiveFunctionType
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 
- Protected Member Functions inherited from shark::AbstractOptimizer< RealVector, double, SingleObjectiveResultSet< RealVector > >
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. More...
 

Detailed Description

Optimize by trying out a grid of configurations.

The GridSearch class allows for the definition of a grid in parameter space. It does a simple one-step optimization over the grid by trying out every possible parameter combination. Please note that the computation effort grows exponentially with the number of parameters.
If you only want to try a subset of the grid, consider using the PointSearch class instead. A more sophisticated (less exhaustive) grid search variant is available with the NestedGridSearch class.

Definition at line 64 of file GridSearch.h.

Constructor & Destructor Documentation

§ GridSearch()

shark::GridSearch::GridSearch ( )
inline

Definition at line 67 of file GridSearch.h.

References m_configured.

Member Function Documentation

§ assignExponentialRange()

void shark::GridSearch::assignExponentialRange ( size_t  index,
double  factor,
double  exp_base,
int  min,
int  max 
)
inline

Set exponentially progressing grid values for one certain parameter only. This is especially useful if one parameter needs special treatment. The grid points will be filled with values \( factor \cdot expbase ^i \), where i does integer steps between min and max.

Parameters
indexthe index of the parameter that gets new grid values
factorthe value that the exponential base grid should be multiplied by
exp_basethe exponential grid will progress on this base (e.g. 2, 10)
minthe smallest exponent for exp_base
maxthe largest exponent for exp_base

Definition at line 265 of file GridSearch.h.

References m_nodeValues, shark::blas::min(), RANGE_CHECK, and SIZE_CHECK.

§ assignLinearRange()

void shark::GridSearch::assignLinearRange ( size_t  index,
size_t  noOfSections,
double  min,
double  max 
)
inline

Assign linearly progressing grid values to one certain parameter only. This is especially useful if one parameter needs special treatment

Parameters
indexthe index of the parameter to which grid values are assigned
noOfSectionshow many grid points should be assigned to that parameter
minsmallest value for that parameter
maxlargest value for that parameter

Definition at line 239 of file GridSearch.h.

References m_nodeValues, RANGE_CHECK, and SIZE_CHECK.

§ configure() [1/6]

void shark::GridSearch::configure ( size_t  params,
double  min,
double  max,
size_t  numSections 
)
inline

uniform initialization for all parameters

Parameters
paramsnumber of model parameters to optimize
minsmallest parameter value
maxlargest parameter value
numSectionstotal number of values in the interval

Definition at line 82 of file GridSearch.h.

References m_configured, m_nodeValues, shark::blas::min(), RANGE_CHECK, and SIZE_CHECK.

Referenced by init(), shark::NestedGridSearch::init(), shark::PointSearch::init(), and main().

§ configure() [2/6]

void shark::GridSearch::configure ( const std::vector< double > &  min,
const std::vector< double > &  max,
const std::vector< size_t > &  sections 
)
inline

individual definition for every parameter

Parameters
minsmallest value for every parameter
maxlargest value for every parameter
sectionstotal number of values for every parameter

Definition at line 101 of file GridSearch.h.

References m_configured, m_nodeValues, RANGE_CHECK, and SIZE_CHECK.

§ configure() [3/6]

void shark::GridSearch::configure ( double  min1,
double  max1,
size_t  sections1,
double  min2,
double  max2,
size_t  sections2 
)
inline

special case for 2D grid, individual definition for every parameter

Parameters
min1smallest value for first parameter
max1largest value for first parameter
sections1total number of values for first parameter
min2smallest value for second parameter
max2largest value for second parameter
sections2total number of values for second parameter

Definition at line 135 of file GridSearch.h.

References m_nodeValues, and RANGE_CHECK.

§ configure() [4/6]

void shark::GridSearch::configure ( double  min1,
double  max1,
size_t  sections1 
)
inline

special case for line search

Parameters
min1smallest value for first parameter
max1largest value for first parameter
sections1total number of values for first parameter

Definition at line 163 of file GridSearch.h.

References m_nodeValues, and RANGE_CHECK.

§ configure() [5/6]

void shark::GridSearch::configure ( size_t  params,
const std::vector< double > &  values 
)
inline

uniform definition of the values to test for all parameters

Parameters
paramsnumber of model parameters to optimize
valuesvalues used for every coordinate

Definition at line 182 of file GridSearch.h.

References m_configured, m_nodeValues, and SIZE_CHECK.

§ configure() [6/6]

void shark::GridSearch::configure ( const std::vector< std::vector< double > > &  values)
inline

individual definition for every parameter

Parameters
valuesvalues used. The first dimension is the parameter, the second dimension is the node.

Definition at line 194 of file GridSearch.h.

References m_configured, m_nodeValues, and SIZE_CHECK.

§ init()

virtual void shark::GridSearch::init ( ObjectiveFunctionType objectiveFunction,
SearchPointType const &  startingPoint 
)
inlinevirtual

If Gridsearch wasn't configured before calling this method, it is default constructed as a net spanning the range [-1,1] in all dimensions with 5 searchpoints (-1,-0.5,0,0.5,1). so don't forget to scale the parameter-ranges of the objective function! The startingPoint can actually be anything, only its dimension has to be correct.

Implements shark::AbstractSingleObjectiveOptimizer< RealVector >.

Definition at line 223 of file GridSearch.h.

References shark::AbstractOptimizer< RealVector, double, SingleObjectiveResultSet< RealVector > >::checkFeatures(), configure(), shark::AbstractObjectiveFunction< PointType, ResultT >::init(), shark::AbstractSingleObjectiveOptimizer< RealVector >::m_best, m_configured, m_nodeValues, shark::ResultSet< SearchPointT, ResultT >::point, and SIZE_CHECK.

§ name()

std::string shark::GridSearch::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 72 of file GridSearch.h.

§ read()

virtual void shark::GridSearch::read ( InArchive archive)
inlinevirtual

Read the component from the supplied archive.

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

Reimplemented from shark::ISerializable.

Definition at line 202 of file GridSearch.h.

References shark::AbstractSingleObjectiveOptimizer< RealVector >::m_best, m_configured, m_nodeValues, shark::ResultSet< SearchPointT, ResultT >::point, and shark::ResultSet< SearchPointT, ResultT >::value.

§ step()

void shark::GridSearch::step ( ObjectiveFunctionType const &  objectiveFunction)
inlinevirtual

§ write()

virtual void shark::GridSearch::write ( OutArchive archive) const
inlinevirtual

Write the component to the supplied archive.

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

Reimplemented from shark::ISerializable.

Definition at line 210 of file GridSearch.h.

References shark::AbstractSingleObjectiveOptimizer< RealVector >::m_best, m_configured, m_nodeValues, shark::ResultSet< SearchPointT, ResultT >::point, and shark::ResultSet< SearchPointT, ResultT >::value.

Member Data Documentation

§ m_configured

§ m_nodeValues

std::vector<std::vector<double> > shark::GridSearch::m_nodeValues
protected

The array columns contain the grid values for the corresponding parameter axis.

Definition at line 328 of file GridSearch.h.

Referenced by assignExponentialRange(), assignLinearRange(), configure(), init(), read(), step(), and write().


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