Implements the Cross Entropy Method. More...
#include <shark/Algorithms/DirectSearch/CrossEntropyMethod.h>
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< INoiseType > | StrongNoisePtr |
Smart pointer for noise type. More... | |
![]() | |
typedef base_type::SearchPointType | SearchPointType |
typedef base_type::SolutionType | SolutionType |
typedef base_type::ResultType | ResultType |
typedef base_type::ObjectiveFunctionType | ObjectiveFunctionType |
![]() | |
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, ResultType > | ObjectiveFunctionType |
typedef TypedFlags< Feature > | Features |
typedef TypedFeatureNotAvailableException< Feature > | FeatureNotAvailableException |
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 &function, SearchPointType const &p) |
Initializes the algorithm for the supplied objective function and the initial mean p. More... | |
SHARK_EXPORT_SYMBOL void | init (ObjectiveFunctionType &function) |
Inits the Cross Entropy, only with the objective function. More... | |
SHARK_EXPORT_SYMBOL void | init (ObjectiveFunctionType &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 INoiseType & | getNoiseType () const |
Get an immutable reference to Noise Type. More... | |
![]() | |
virtual const SolutionType & | solution () const |
returns the current solution of the optimizer More... | |
![]() | |
const Features & | features () 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... | |
![]() | |
virtual | ~INameable () |
![]() | |
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 Member Functions | |
SHARK_EXPORT_SYMBOL void | updateStrategyParameters (const std::vector< Individual< RealVector, double, RealVector > > &parents) |
Updates the strategy parameters based on the supplied parent population. More... | |
![]() | |
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... | |
Normal< Rng::rng_type > | m_distribution |
Normal distribution. More... | |
StrongNoisePtr | m_noise |
Noise type to apply in the update of distribution parameters. More... | |
![]() | |
SolutionType | m_best |
current solution of the optimizer More... | |
![]() | |
Features | m_features |
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.
typedef boost::shared_ptr<INoiseType> shark::CrossEntropyMethod::StrongNoisePtr |
Smart pointer for noise type.
Definition at line 86 of file CrossEntropyMethod.h.
SHARK_EXPORT_SYMBOL shark::CrossEntropyMethod::CrossEntropyMethod | ( | ) |
Default c'tor.
Referenced by shark::CrossEntropyMethod::LinearNoise::name().
|
inline |
Get an immutable reference to Noise Type.
Definition at line 231 of file CrossEntropyMethod.h.
References m_noise, SHARK_EXPORT_SYMBOL, and updateStrategyParameters().
|
virtual |
Initializes the algorithm for the supplied objective function and the initial mean p.
Implements shark::AbstractSingleObjectiveOptimizer< RealVector >.
Referenced by name().
|
virtual |
Inits the Cross Entropy, only with the objective function.
Reimplemented from shark::AbstractSingleObjectiveOptimizer< RealVector >.
SHARK_EXPORT_SYMBOL void shark::CrossEntropyMethod::init | ( | ObjectiveFunctionType & | function, |
SearchPointType const & | initialSearchPoint, | ||
unsigned int | populationSize, | ||
unsigned int | selectionSize, | ||
RealVector | initialSigma | ||
) |
Initializes the algorithm for the supplied objective function.
|
inline |
Access the current population mean.
Definition at line 188 of file CrossEntropyMethod.h.
References m_mean.
|
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().
|
inline |
Returns a immutable reference to the size of the population.
Definition at line 209 of file CrossEntropyMethod.h.
References m_populationSize.
Referenced by name().
|
inline |
Returns a mutable reference to the size of the population.
Definition at line 216 of file CrossEntropyMethod.h.
References m_populationSize.
|
virtual |
Read the component from the supplied archive.
[in,out] | archive | The archive to read from. |
Reimplemented from shark::ISerializable.
Referenced by name().
|
inline |
Returns the size of the parent population.
Definition at line 195 of file CrossEntropyMethod.h.
References m_selectionSize.
Referenced by name().
|
inline |
Returns a mutable reference to the size of the parent population.
Definition at line 202 of file CrossEntropyMethod.h.
References m_selectionSize.
|
inline |
Set the noise type from a raw pointer.
Definition at line 223 of file CrossEntropyMethod.h.
References m_noise.
|
inline |
Set the variance to a vector.
Definition at line 177 of file CrossEntropyMethod.h.
References m_variance, and variance().
|
inline |
Set all variance values.
Definition at line 183 of file CrossEntropyMethod.h.
References m_variance, and shark::blas::repeat().
|
virtual |
Executes one iteration of the algorithm.
Implements shark::AbstractOptimizer< RealVector, double, SingleObjectiveResultSet< RealVector > >.
Referenced by name().
|
static |
Sets default value for Population size.
Referenced by name().
|
static |
Calculates selection size for the supplied population size.
Referenced by name().
|
protected |
Updates the strategy parameters based on the supplied parent population.
Referenced by getNoiseType().
|
inline |
Access the current variance.
Definition at line 172 of file CrossEntropyMethod.h.
References m_variance.
Referenced by setVariance().
|
virtual |
Write the component to the supplied archive.
[in,out] | archive | The archive to write to. |
Reimplemented from shark::ISerializable.
Referenced by name().
|
protected |
Counter for generations.
Definition at line 251 of file CrossEntropyMethod.h.
|
protected |
Normal distribution.
Definition at line 253 of file CrossEntropyMethod.h.
|
protected |
The mean of the population.
Definition at line 249 of file CrossEntropyMethod.h.
Referenced by mean().
|
protected |
Noise type to apply in the update of distribution parameters.
Definition at line 254 of file CrossEntropyMethod.h.
Referenced by shark::CrossEntropyMethod::ConstantNoise::ConstantNoise(), getNoiseType(), shark::CrossEntropyMethod::ConstantNoise::name(), shark::CrossEntropyMethod::ConstantNoise::noiseValue(), and setNoiseType().
|
protected |
Stores the dimensionality of the search space.
Definition at line 242 of file CrossEntropyMethod.h.
|
protected |
Number of vectors sampled in a generation.
Definition at line 244 of file CrossEntropyMethod.h.
Referenced by populationSize().
|
protected |
Number of vectors chosen when updating distribution parameters.
Definition at line 243 of file CrossEntropyMethod.h.
Referenced by selectionSize().
|
protected |
Variance for sample parameters.
Definition at line 246 of file CrossEntropyMethod.h.
Referenced by setVariance(), and variance().