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 (random::rng_type &rng=random::globalRng)
 Default c'tor. More...
 
std::string name () const
 From INameable: return the class name. More...
 
SHARK_EXPORT_SYMBOL void read (InArchive &archive)
 Read the component from the supplied archive. More...
 
SHARK_EXPORT_SYMBOL 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. More...
 
SHARK_EXPORT_SYMBOL void init (ObjectiveFunctionType const &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...
 
void setInitialSigma (double initSigma)
 sets the initial step length sigma More...
 
double sigma () const
 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 to the lower bound on sigma times smalles eigenvalue. More...
 
void setLowerBound (double lowerBound)
 Set the lower bound on sigma times smalles eigenvalue. More...
 
std::size_t mu () const
 Returns the size of the parent population \(\mu\). More...
 
void setMu (std::size_t mu)
 Sets the number of selected samples. More...
 
void setLambda (std::size_t lambda)
 Sets the number of sampled points. More...
 
std::size_t lambda () const
 Returns a immutable 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...
 
std::size_t numberOfEvaluations () const
 Returns how often a point is evaluated. 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 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 Types

typedef Individual< RealVector, double, RealVector > IndividualType
 The type of individual used for the CMA. More...
 

Protected Member Functions

SHARK_EXPORT_SYMBOL std::vector< IndividualTypegenerateOffspring () const
 Samples lambda individuals from the search distribution. More...
 
SHARK_EXPORT_SYMBOL void updatePopulation (std::vector< IndividualType > const &offspring)
 Updates the strategy parameters based on the supplied offspring population. More...
 
SHARK_EXPORT_SYMBOL void doInit (std::vector< SearchPointType > const &points, std::vector< ResultType > const &functionValues, std::size_t lambda, std::size_t mu, double initialSigma)
 
- 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...
 

Additional Inherited Members

- 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

For noisy function, noise handling is supported using the noise level detection algorithm described in Hansen, N., et al. "A method for handling uncertainty in evolutionary optimization with an application to feedback control of combustion." IEEE Transactions on Evolutionary Computation 13.1 (2009): 180-197. Our implementation varies in small details, e.g. instead of the average rank the rank of the average function value is used for updating the strategy parameters which ensures asymptotic unbiasedness. We further do not have an upper bound on the number of reevaluations for the same reason.

Definition at line 65 of file CMA.h.

Member Typedef Documentation

◆ IndividualType

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

The type of individual used for the CMA.

Definition at line 210 of file CMA.h.

Member Enumeration Documentation

◆ RecombinationType

Models the recombination type.

Enumerator
EQUAL 
LINEAR 
SUPERLINEAR 

Definition at line 69 of file CMA.h.

Constructor & Destructor Documentation

◆ CMA()

SHARK_EXPORT_SYMBOL shark::CMA::CMA ( random::rng_type &  rng = random::globalRng)

Default c'tor.

Member Function Documentation

◆ condition()

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

Returns condition of covariance matrix.

Definition at line 197 of file CMA.h.

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

Referenced by main().

◆ covarianceMatrix()

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

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

Definition at line 141 of file CMA.h.

References shark::MultiVariateNormalDistribution::covarianceMatrix().

◆ doInit()

SHARK_EXPORT_SYMBOL void shark::CMA::doInit ( std::vector< SearchPointType > const &  points,
std::vector< ResultType > const &  functionValues,
std::size_t  lambda,
std::size_t  mu,
double  initialSigma 
)
protected

◆ eigenValues()

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

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

Definition at line 192 of file CMA.h.

References shark::MultiVariateNormalDistribution::eigenValues().

Referenced by condition(), and main().

◆ eigenVectors()

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

Returns eigenvectors of covariance matrix (not considering step size)

Definition at line 187 of file CMA.h.

References shark::MultiVariateNormalDistribution::eigenVectors().

Referenced by main().

◆ evolutionPath()

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

Accesses the evolution path for the covariance matrix update.

Definition at line 131 of file CMA.h.

◆ evolutionPathSigma()

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

Accesses the evolution path for the step size update.

Definition at line 136 of file CMA.h.

◆ generateOffspring()

SHARK_EXPORT_SYMBOL std::vector<IndividualType> shark::CMA::generateOffspring ( ) const
protected

Samples lambda individuals from the search distribution.

◆ init() [1/2]

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

Initializes the algorithm for the supplied objective function.

Implements shark::AbstractSingleObjectiveOptimizer< RealVector >.

Referenced by main(), and name().

◆ init() [2/2]

SHARK_EXPORT_SYMBOL void shark::CMA::init ( ObjectiveFunctionType const &  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.

◆ lambda()

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

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

Definition at line 182 of file CMA.h.

Referenced by name(), and setLambda().

◆ lowerBound()

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

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

Definition at line 156 of file CMA.h.

Referenced by setLowerBound().

◆ mean()

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

Accesses the current population mean.

Definition at line 121 of file CMA.h.

Referenced by main().

◆ mu()

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

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

Definition at line 166 of file CMA.h.

Referenced by name(), and setMu().

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 79 of file CMA.h.

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

◆ numberOfEvaluations()

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

Returns how often a point is evaluated.

Definition at line 203 of file CMA.h.

◆ read()

SHARK_EXPORT_SYMBOL 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 name().

◆ recombinationType() [1/2]

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

Accesses the recombination type.

Definition at line 146 of file CMA.h.

◆ recombinationType() [2/2]

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

Returns a mutable reference to the recombination type.

Definition at line 151 of file CMA.h.

◆ setInitialSigma()

void shark::CMA::setInitialSigma ( double  initSigma)
inline

sets the initial step length sigma

It is by default <=0 which means that sigma =1/sqrt(numVariables)

Definition at line 111 of file CMA.h.

Referenced by main().

◆ setLambda()

void shark::CMA::setLambda ( std::size_t  lambda)
inline

Sets the number of sampled points.

Definition at line 176 of file CMA.h.

References lambda().

◆ setLowerBound()

void shark::CMA::setLowerBound ( double  lowerBound)
inline

Set the lower bound on sigma times smalles eigenvalue.

Definition at line 161 of file CMA.h.

References lowerBound().

◆ setMu()

void shark::CMA::setMu ( std::size_t  mu)
inline

Sets the number of selected samples.

Definition at line 171 of file CMA.h.

References mu().

◆ sigma()

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

Accesses the current step size.

Definition at line 116 of file CMA.h.

Referenced by main().

◆ step()

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 name().

◆ suggestLambda()

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

Calculates lambda for the supplied dimensionality n.

Referenced by name().

◆ suggestMu()

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 name().

◆ updatePopulation()

SHARK_EXPORT_SYMBOL void shark::CMA::updatePopulation ( std::vector< IndividualType > const &  offspring)
protected

Updates the strategy parameters based on the supplied offspring population.

◆ weights()

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

Accesses the current weighting vector.

Definition at line 126 of file CMA.h.

◆ write()

SHARK_EXPORT_SYMBOL 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 name().


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