shark::CMA Class Reference

Implements the CMA-ES. More...

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

+ Inheritance diagram for shark::CMA:

Public Types

enum  RecombinationType { EQUAL = 0, LINEAR = 1, SUPERLINEAR = 2 }
 Models the recombination 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 CMA ()
 Default c'tor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
template<typename Container , typename Extractor >
RealVector weightedSum (const Container &container, const RealVector &weights, const Extractor &e)
 Calculates the center of gravity of the given population \( \in \mathbb{R}^d\). 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. More...
 
SHARK_EXPORT_SYMBOL void init (ObjectiveFunctionType &function, SearchPointType const &initialSearchPoint, std::size_t lambda, std::size_t mu, double initialSigma, const boost::optional< RealMatrix > &initialCovarianceMatrix=boost::optional< RealMatrix >())
 Initializes the algorithm for the supplied objective function. More...
 
SHARK_EXPORT_SYMBOL void step (ObjectiveFunctionType const &function)
 Executes one iteration of the algorithm. More...
 
double sigma () const
 Accesses the current step size. More...
 
void setSigma (double sigma)
 Accesses the current step size. More...
 
RealVector const & mean () const
 Accesses the current population mean. More...
 
RealVector const & weights () const
 Accesses the current weighting vector. More...
 
RealVector const & evolutionPath () const
 Accesses the evolution path for the covariance matrix update. More...
 
RealVector const & evolutionPathSigma () const
 Accesses the evolution path for the step size update. More...
 
RealMatrix const & covarianceMatrix () const
 Accesses the covariance matrix of the normal distribution used for generating offspring individuals. More...
 
RecombinationType recombinationType () const
 Accesses the recombination type. More...
 
RecombinationTyperecombinationType ()
 Returns a mutable reference to the recombination type. More...
 
const double & lowerBound () const
 Returns a const reference tothe lower bound on sigma times smalles eigenvalue. More...
 
double & lowerBound ()
 Returns a mutable reference to the lower bound on sigma times smalles eigenvalue. More...
 
std::size_t mu () const
 Returns the size of the parent population \(\mu\). More...
 
std::size_t & mu ()
 Returns a mutabl rference to the size of the parent population \(\mu\). More...
 
std::size_t lambda () const
 Returns a immutable reference to the size of the offspring population \(\mu\). More...
 
std::size_t & lambda ()
 Returns a mutable reference to the size of the offspring population \(\mu\). More...
 
RealMatrix const & eigenVectors () const
 Returns eigenvectors of covariance matrix (not considering step size) More...
 
RealVector const & eigenValues () const
 Returns a eigenvectors of covariance matrix (not considering step size) More...
 
double condition () const
 Returns condition of covariance matrix. More...
 
- 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 ()
 

Static Public Member Functions

static SHARK_EXPORT_SYMBOL std::size_t suggestLambda (std::size_t dimension)
 Calculates lambda for the supplied dimensionality n. More...
 
static SHARK_EXPORT_SYMBOL std::size_t suggestMu (std::size_t lambda, RecombinationType recomb=SUPERLINEAR)
 Calculates mu for the supplied lambda and the recombination strategy. More...
 

Protected Member Functions

SHARK_EXPORT_SYMBOL void updateStrategyParameters (const std::vector< Individual< RealVector, double, RealVector > > &offspring)
 Updates the strategy parameters based on the supplied offspring 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...
 
std::size_t m_mu
 The size of the parent population. More...
 
std::size_t m_lambda
 The size of the offspring population, needs to be larger than mu. More...
 
RecombinationType m_recombinationType
 Stores the recombination type. More...
 
double m_sigma
 
double m_cC
 
double m_c1
 
double m_cMu
 
double m_cSigma
 
double m_dSigma
 
double m_muEff
 
double m_lowerBound
 
RealVector m_mean
 
RealVector m_weights
 
RealVector m_evolutionPathC
 
RealVector m_evolutionPathSigma
 
std::size_t m_counter
 counter for generations More...
 
MultiVariateNormalDistribution m_mutationDistribution
 
- 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 CMA-ES.

The algorithm is described in

Hansen, N., S. Kern (2004). Evaluating the CMA Evolution Strategy on Multimodal Test Functions. In Proceedings of the Eighth International Conference on Parallel Problem Solving from Nature (PPSN VIII), pp. 282-291, LNCS, Springer-Verlag

Definition at line 57 of file CMA.h.

Member Enumeration Documentation

Models the recombination type.

Enumerator
EQUAL 
LINEAR 
SUPERLINEAR 

Definition at line 63 of file CMA.h.

Constructor & Destructor Documentation

SHARK_EXPORT_SYMBOL shark::CMA::CMA ( )

Default c'tor.

Member Function Documentation

double shark::CMA::condition ( ) const
inline
RealMatrix const& shark::CMA::covarianceMatrix ( ) const
inline

Accesses the covariance matrix of the normal distribution used for generating offspring individuals.

Definition at line 162 of file CMA.h.

References shark::MultiVariateNormalDistribution::covarianceMatrix(), and m_mutationDistribution.

RealVector const& shark::CMA::eigenValues ( ) const
inline

Returns a eigenvectors of covariance matrix (not considering step size)

Definition at line 232 of file CMA.h.

References shark::MultiVariateNormalDistribution::eigenValues(), and m_mutationDistribution.

Referenced by condition(), and main().

RealMatrix const& shark::CMA::eigenVectors ( ) const
inline

Returns eigenvectors of covariance matrix (not considering step size)

Definition at line 225 of file CMA.h.

References shark::MultiVariateNormalDistribution::eigenVectors(), and m_mutationDistribution.

Referenced by main().

RealVector const& shark::CMA::evolutionPath ( ) const
inline

Accesses the evolution path for the covariance matrix update.

Definition at line 152 of file CMA.h.

References m_evolutionPathC.

RealVector const& shark::CMA::evolutionPathSigma ( ) const
inline

Accesses the evolution path for the step size update.

Definition at line 157 of file CMA.h.

References m_evolutionPathSigma.

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

Initializes the algorithm for the supplied objective function.

Implements shark::AbstractSingleObjectiveOptimizer< RealVector >.

Referenced by main(), and weightedSum().

SHARK_EXPORT_SYMBOL void shark::CMA::init ( ObjectiveFunctionType function,
SearchPointType const &  initialSearchPoint,
std::size_t  lambda,
std::size_t  mu,
double  initialSigma,
const boost::optional< RealMatrix > &  initialCovarianceMatrix = boost::optional< RealMatrix >() 
)

Initializes the algorithm for the supplied objective function.

std::size_t shark::CMA::lambda ( ) const
inline

Returns a immutable reference to the size of the offspring population \(\mu\).

Definition at line 211 of file CMA.h.

References m_lambda.

Referenced by weightedSum().

std::size_t& shark::CMA::lambda ( )
inline

Returns a mutable reference to the size of the offspring population \(\mu\).

Definition at line 218 of file CMA.h.

References m_lambda.

const double& shark::CMA::lowerBound ( ) const
inline

Returns a const reference tothe lower bound on sigma times smalles eigenvalue.

Definition at line 183 of file CMA.h.

References m_lowerBound.

double& shark::CMA::lowerBound ( )
inline

Returns a mutable reference to the lower bound on sigma times smalles eigenvalue.

Definition at line 190 of file CMA.h.

References m_lowerBound.

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

Accesses the current population mean.

Definition at line 142 of file CMA.h.

References m_mean.

Referenced by main().

std::size_t shark::CMA::mu ( ) const
inline

Returns the size of the parent population \(\mu\).

Definition at line 197 of file CMA.h.

References m_mu.

Referenced by weightedSum().

std::size_t& shark::CMA::mu ( )
inline

Returns a mutabl rference to the size of the parent population \(\mu\).

Definition at line 204 of file CMA.h.

References m_mu.

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 75 of file CMA.h.

void shark::CMA::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 weightedSum().

RecombinationType shark::CMA::recombinationType ( ) const
inline

Accesses the recombination type.

Definition at line 169 of file CMA.h.

References m_recombinationType.

RecombinationType& shark::CMA::recombinationType ( )
inline

Returns a mutable reference to the recombination type.

Definition at line 176 of file CMA.h.

References m_recombinationType.

void shark::CMA::setSigma ( double  sigma)
inline

Accesses the current step size.

Definition at line 136 of file CMA.h.

References m_sigma, and sigma().

Referenced by main().

double shark::CMA::sigma ( ) const
inline

Accesses the current step size.

Definition at line 131 of file CMA.h.

References m_sigma.

Referenced by main(), and setSigma().

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

Executes one iteration of the algorithm.

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

Referenced by main(), and weightedSum().

static SHARK_EXPORT_SYMBOL std::size_t shark::CMA::suggestLambda ( std::size_t  dimension)
static

Calculates lambda for the supplied dimensionality n.

Referenced by weightedSum().

static SHARK_EXPORT_SYMBOL std::size_t shark::CMA::suggestMu ( std::size_t  lambda,
RecombinationType  recomb = SUPERLINEAR 
)
static

Calculates mu for the supplied lambda and the recombination strategy.

Referenced by weightedSum().

SHARK_EXPORT_SYMBOL void shark::CMA::updateStrategyParameters ( const std::vector< Individual< RealVector, double, RealVector > > &  offspring)
protected

Updates the strategy parameters based on the supplied offspring population.

Referenced by condition().

template<typename Container , typename Extractor >
RealVector shark::CMA::weightedSum ( const Container &  container,
const RealVector &  weights,
const Extractor &  e 
)
inline

Calculates the center of gravity of the given population \( \in \mathbb{R}^d\).

Definition at line 84 of file CMA.h.

References init(), lambda(), m_numberOfVariables, mu(), read(), SHARK_EXPORT_SYMBOL, step(), suggestLambda(), suggestMu(), SUPERLINEAR, weights(), and write().

RealVector const& shark::CMA::weights ( ) const
inline

Accesses the current weighting vector.

Definition at line 147 of file CMA.h.

References m_weights.

Referenced by weightedSum().

void shark::CMA::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 weightedSum().

Member Data Documentation

double shark::CMA::m_c1
protected

Definition at line 259 of file CMA.h.

double shark::CMA::m_cC
protected

Definition at line 258 of file CMA.h.

double shark::CMA::m_cMu
protected

Definition at line 260 of file CMA.h.

std::size_t shark::CMA::m_counter
protected

counter for generations

Definition at line 273 of file CMA.h.

double shark::CMA::m_cSigma
protected

Definition at line 261 of file CMA.h.

double shark::CMA::m_dSigma
protected

Definition at line 262 of file CMA.h.

RealVector shark::CMA::m_evolutionPathC
protected

Definition at line 270 of file CMA.h.

Referenced by evolutionPath().

RealVector shark::CMA::m_evolutionPathSigma
protected

Definition at line 271 of file CMA.h.

Referenced by evolutionPathSigma().

std::size_t shark::CMA::m_lambda
protected

The size of the offspring population, needs to be larger than mu.

Definition at line 253 of file CMA.h.

Referenced by lambda().

double shark::CMA::m_lowerBound
protected

Definition at line 265 of file CMA.h.

Referenced by lowerBound().

RealVector shark::CMA::m_mean
protected

Definition at line 267 of file CMA.h.

Referenced by mean().

std::size_t shark::CMA::m_mu
protected

The size of the parent population.

Definition at line 252 of file CMA.h.

Referenced by mu().

double shark::CMA::m_muEff
protected

Definition at line 263 of file CMA.h.

MultiVariateNormalDistribution shark::CMA::m_mutationDistribution
protected

Definition at line 275 of file CMA.h.

Referenced by condition(), covarianceMatrix(), eigenValues(), and eigenVectors().

std::size_t shark::CMA::m_numberOfVariables
protected

Stores the dimensionality of the search space.

Definition at line 251 of file CMA.h.

Referenced by weightedSum().

RecombinationType shark::CMA::m_recombinationType
protected

Stores the recombination type.

Definition at line 255 of file CMA.h.

Referenced by recombinationType().

double shark::CMA::m_sigma
protected

Definition at line 257 of file CMA.h.

Referenced by setSigma(), and sigma().

RealVector shark::CMA::m_weights
protected

Definition at line 268 of file CMA.h.

Referenced by weights().


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