shark::CrossEntropyMethod Class Reference

Implements the Cross Entropy Method. More...

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

+ Inheritance diagram for shark::CrossEntropyMethod:

Classes

class  ConstantNoise
 Constant noise term z_t = noise. More...
 
class  INoiseType
 Interface class for noise type. More...
 
class  LinearNoise
 Linear noise term z_t = a + t / b. More...
 

Public Types

typedef boost::shared_ptr< INoiseTypeStrongNoisePtr
 Smart pointer for noise type. More...
 
- 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
 

Public Member Functions

SHARK_EXPORT_SYMBOL CrossEntropyMethod ()
 Default c'tor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
void read (InArchive &archive)
 Read the component from the supplied archive. More...
 
void write (OutArchive &archive) const
 Write the component to the supplied archive. More...
 
SHARK_EXPORT_SYMBOL void init (ObjectiveFunctionType const &function, SearchPointType const &p)
 Initializes the algorithm for the supplied objective function and the initial mean p. More...
 
SHARK_EXPORT_SYMBOL void init (ObjectiveFunctionType const &function, SearchPointType const &initialSearchPoint, unsigned int populationSize, unsigned int selectionSize, RealVector initialSigma)
 Initializes the algorithm for the supplied objective function. More...
 
SHARK_EXPORT_SYMBOL void step (ObjectiveFunctionType const &function)
 Executes one iteration of the algorithm. More...
 
RealVector const & variance () const
 Access the current variance. More...
 
void setVariance (RealVector variance)
 Set the variance to a vector. More...
 
void setVariance (double variance)
 Set all variance values. More...
 
RealVector const & mean () const
 Access the current population mean. More...
 
unsigned int selectionSize () const
 Returns the size of the parent population. More...
 
unsigned int & selectionSize ()
 Returns a mutable reference to the size of the parent population. More...
 
unsigned int populationSize () const
 Returns a immutable reference to the size of the population. More...
 
unsigned int & populationSize ()
 Returns a mutable reference to the size of the population. More...
 
void setNoiseType (INoiseType *noiseType)
 Set the noise type from a raw pointer. More...
 
const INoiseTypegetNoiseType () const
 Get an immutable reference to Noise Type. More...
 
- Public Member Functions inherited from shark::AbstractSingleObjectiveOptimizer< RealVector >
std::size_t numInitPoints () const
 By default most single objective optimizers only require a single point. More...
 
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. More...
 
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 ()
 
virtual void init (ObjectiveFunctionType const &function)
 Initialize the optimizer for the supplied objective function. 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 ()
 

Static Public Member Functions

static SHARK_EXPORT_SYMBOL unsigned suggestPopulationSize ()
 Sets default value for Population size. More...
 
static SHARK_EXPORT_SYMBOL unsigned suggestSelectionSize (unsigned int populationSize)
 Calculates selection size for the supplied population size. More...
 

Protected Types

typedef Individual< RealVector, double, RealVector > IndividualType
 

Protected Member Functions

SHARK_EXPORT_SYMBOL void updateStrategyParameters (std::vector< IndividualType > const &parents)
 Updates the strategy parameters based on the supplied parent population. More...
 
- 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...
 

Protected Attributes

std::size_t m_numberOfVariables
 Stores the dimensionality of the search space. More...
 
unsigned int m_selectionSize
 Number of vectors chosen when updating distribution parameters. More...
 
unsigned int m_populationSize
 Number of vectors sampled in a generation. More...
 
RealVector m_variance
 Variance for sample parameters. More...
 
RealVector m_mean
 The mean of the population. More...
 
unsigned m_counter
 Counter for generations. More...
 
StrongNoisePtr m_noise
 Noise type to apply in the update of distribution parameters. More...
 
- 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
 

Detailed Description

Implements the Cross Entropy Method.

This class implements the noisy cross entropy method as descibed in the following article.

Christophe Thiery, Bruno Scherrer. Improvements on Learning Tetris with Cross Entropy. International Computer Games Association Journal, ICGA, 2009, 32. <inria-00418930>

The algorithm aims to minimize an objective function through stochastic search. It works iteratively until a certain stopping criteria is met. At each iteration, it samples a number of vectors from a Gaussian distribution and evaluates each of these against the supplied objective function. Based on the return value from the objective function, a subset of the the best ranked vectors are chosen to update the search parameters of the next generation.

The mean of the Gaussian distribution is set to the centroid of the best ranked vectors, and the variance is set to the variance of the best ranked vectors in each individual dimension.

Definition at line 70 of file CrossEntropyMethod.h.

Member Typedef Documentation

◆ IndividualType

typedef Individual<RealVector, double, RealVector> shark::CrossEntropyMethod::IndividualType
protected

Definition at line 232 of file CrossEntropyMethod.h.

◆ StrongNoisePtr

Smart pointer for noise type.

Definition at line 86 of file CrossEntropyMethod.h.

Constructor & Destructor Documentation

◆ CrossEntropyMethod()

SHARK_EXPORT_SYMBOL shark::CrossEntropyMethod::CrossEntropyMethod ( )

Default c'tor.

Referenced by shark::CrossEntropyMethod::LinearNoise::name().

Member Function Documentation

◆ getNoiseType()

const INoiseType& shark::CrossEntropyMethod::getNoiseType ( ) const
inline

Get an immutable reference to Noise Type.

Definition at line 226 of file CrossEntropyMethod.h.

References m_noise.

◆ init() [1/2]

SHARK_EXPORT_SYMBOL void shark::CrossEntropyMethod::init ( ObjectiveFunctionType const &  function,
SearchPointType const &  p 
)
virtual

Initializes the algorithm for the supplied objective function and the initial mean p.

Implements shark::AbstractSingleObjectiveOptimizer< RealVector >.

Referenced by name().

◆ init() [2/2]

SHARK_EXPORT_SYMBOL void shark::CrossEntropyMethod::init ( ObjectiveFunctionType const &  function,
SearchPointType const &  initialSearchPoint,
unsigned int  populationSize,
unsigned int  selectionSize,
RealVector  initialSigma 
)

Initializes the algorithm for the supplied objective function.

◆ mean()

RealVector const& shark::CrossEntropyMethod::mean ( ) const
inline

Access the current population mean.

Definition at line 183 of file CrossEntropyMethod.h.

References m_mean.

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 128 of file CrossEntropyMethod.h.

References init(), populationSize(), read(), selectionSize(), SHARK_EXPORT_SYMBOL, step(), suggestPopulationSize(), suggestSelectionSize(), and write().

◆ populationSize() [1/2]

unsigned int shark::CrossEntropyMethod::populationSize ( ) const
inline

Returns a immutable reference to the size of the population.

Definition at line 204 of file CrossEntropyMethod.h.

References m_populationSize.

Referenced by name().

◆ populationSize() [2/2]

unsigned int& shark::CrossEntropyMethod::populationSize ( )
inline

Returns a mutable reference to the size of the population.

Definition at line 211 of file CrossEntropyMethod.h.

References m_populationSize.

◆ read()

void shark::CrossEntropyMethod::read ( InArchive archive)
virtual

Read the component from the supplied archive.

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

Reimplemented from shark::ISerializable.

Referenced by name().

◆ selectionSize() [1/2]

unsigned int shark::CrossEntropyMethod::selectionSize ( ) const
inline

Returns the size of the parent population.

Definition at line 190 of file CrossEntropyMethod.h.

References m_selectionSize.

Referenced by name().

◆ selectionSize() [2/2]

unsigned int& shark::CrossEntropyMethod::selectionSize ( )
inline

Returns a mutable reference to the size of the parent population.

Definition at line 197 of file CrossEntropyMethod.h.

References m_selectionSize.

◆ setNoiseType()

void shark::CrossEntropyMethod::setNoiseType ( INoiseType noiseType)
inline

Set the noise type from a raw pointer.

Definition at line 218 of file CrossEntropyMethod.h.

References m_noise.

◆ setVariance() [1/2]

void shark::CrossEntropyMethod::setVariance ( RealVector  variance)
inline

Set the variance to a vector.

Definition at line 172 of file CrossEntropyMethod.h.

References m_variance, and variance().

◆ setVariance() [2/2]

void shark::CrossEntropyMethod::setVariance ( double  variance)
inline

Set all variance values.

Definition at line 178 of file CrossEntropyMethod.h.

References m_variance.

◆ step()

SHARK_EXPORT_SYMBOL void shark::CrossEntropyMethod::step ( ObjectiveFunctionType const &  function)
virtual

Executes one iteration of the algorithm.

Implements shark::AbstractOptimizer< RealVector, double, SingleObjectiveResultSet< RealVector > >.

Referenced by name().

◆ suggestPopulationSize()

static SHARK_EXPORT_SYMBOL unsigned shark::CrossEntropyMethod::suggestPopulationSize ( )
static

Sets default value for Population size.

Referenced by name().

◆ suggestSelectionSize()

static SHARK_EXPORT_SYMBOL unsigned shark::CrossEntropyMethod::suggestSelectionSize ( unsigned int  populationSize)
static

Calculates selection size for the supplied population size.

Referenced by name().

◆ updateStrategyParameters()

SHARK_EXPORT_SYMBOL void shark::CrossEntropyMethod::updateStrategyParameters ( std::vector< IndividualType > const &  parents)
protected

Updates the strategy parameters based on the supplied parent population.

◆ variance()

RealVector const& shark::CrossEntropyMethod::variance ( ) const
inline

Access the current variance.

Definition at line 167 of file CrossEntropyMethod.h.

References m_variance.

Referenced by setVariance().

◆ write()

void shark::CrossEntropyMethod::write ( OutArchive archive) const
virtual

Write the component to the supplied archive.

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

Reimplemented from shark::ISerializable.

Referenced by name().

Member Data Documentation

◆ m_counter

unsigned shark::CrossEntropyMethod::m_counter
protected

Counter for generations.

Definition at line 247 of file CrossEntropyMethod.h.

◆ m_mean

RealVector shark::CrossEntropyMethod::m_mean
protected

The mean of the population.

Definition at line 245 of file CrossEntropyMethod.h.

Referenced by mean().

◆ m_noise

StrongNoisePtr shark::CrossEntropyMethod::m_noise
protected

Noise type to apply in the update of distribution parameters.

Definition at line 249 of file CrossEntropyMethod.h.

Referenced by shark::CrossEntropyMethod::ConstantNoise::ConstantNoise(), getNoiseType(), shark::CrossEntropyMethod::ConstantNoise::name(), and setNoiseType().

◆ m_numberOfVariables

std::size_t shark::CrossEntropyMethod::m_numberOfVariables
protected

Stores the dimensionality of the search space.

Definition at line 238 of file CrossEntropyMethod.h.

◆ m_populationSize

unsigned int shark::CrossEntropyMethod::m_populationSize
protected

Number of vectors sampled in a generation.

Definition at line 240 of file CrossEntropyMethod.h.

Referenced by populationSize().

◆ m_selectionSize

unsigned int shark::CrossEntropyMethod::m_selectionSize
protected

Number of vectors chosen when updating distribution parameters.

Definition at line 239 of file CrossEntropyMethod.h.

Referenced by selectionSize().

◆ m_variance

RealVector shark::CrossEntropyMethod::m_variance
protected

Variance for sample parameters.

Definition at line 242 of file CrossEntropyMethod.h.

Referenced by setVariance(), and variance().


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