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< PointType, ResultT, SolutionTypeT >
enum  Feature {
  REQUIRES_VALUE = 1 , REQUIRES_FIRST_DERIVATIVE = 2 , REQUIRES_SECOND_DERIVATIVE = 4 , CAN_SOLVE_CONSTRAINED = 8 ,
  REQUIRES_CLOSEST_FEASIBLE = 16
}
 Models features that the optimizer requires from the objective function. More...
 
typedef PointType SearchPointType
 
typedef ResultT ResultType
 
typedef SolutionTypeT SolutionType
 
typedef AbstractObjectiveFunction< PointType, ResultTypeObjectiveFunctionType
 
typedef TypedFlags< FeatureFeatures
 
typedef TypedFeatureNotAvailableException< FeatureFeatureNotAvailableException
 

Public Member Functions

SHARK_EXPORT_SYMBOL CMA (random::rng_type &rng=random::globalRng)
 Default c'tor.
 
std::string name () const
 From INameable: return the class name.
 
SHARK_EXPORT_SYMBOL void read (InArchive &archive)
 Read the component from the supplied archive.
 
SHARK_EXPORT_SYMBOL void write (OutArchive &archive) const
 Write the component to the supplied archive.
 
SHARK_EXPORT_SYMBOL void init (ObjectiveFunctionType const &function, SearchPointType const &p)
 Initializes the algorithm for the supplied objective function.
 
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.
 
SHARK_EXPORT_SYMBOL void step (ObjectiveFunctionType const &function)
 Executes one iteration of the algorithm.
 
void setInitialSigma (double initSigma)
 sets the initial step length sigma
 
double sigma () const
 Accesses the current step size.
 
RealVector const & mean () const
 Accesses the current population mean.
 
RealVector const & weights () const
 Accesses the current weighting vector.
 
RealVector const & evolutionPath () const
 Accesses the evolution path for the covariance matrix update.
 
RealVector const & evolutionPathSigma () const
 Accesses the evolution path for the step size update.
 
RealMatrix const & covarianceMatrix () const
 Accesses the covariance matrix of the normal distribution used for generating offspring individuals.
 
RecombinationType recombinationType () const
 Accesses the recombination type.
 
RecombinationTyperecombinationType ()
 Returns a mutable reference to the recombination type.
 
const double & lowerBound () const
 Returns a const reference to the lower bound on sigma times smalles eigenvalue.
 
void setLowerBound (double lowerBound)
 Set the lower bound on sigma times smalles eigenvalue.
 
std::size_t mu () const
 Returns the size of the parent population \(\mu\).
 
void setMu (std::size_t mu)
 Sets the number of selected samples.
 
void setLambda (std::size_t lambda)
 Sets the number of sampled points.
 
std::size_t lambda () const
 Returns a immutable reference to the size of the offspring population \(\mu\).
 
RealMatrix const & eigenVectors () const
 Returns eigenvectors of covariance matrix (not considering step size)
 
RealVector const & eigenValues () const
 Returns a eigenvectors of covariance matrix (not considering step size)
 
double condition () const
 Returns condition of covariance matrix.
 
std::size_t numberOfEvaluations () const
 Returns how often a point is evaluated.
 
- Public Member Functions inherited from shark::AbstractSingleObjectiveOptimizer< RealVector >
std::size_t numInitPoints () const
 By default most single objective optimizers only require a single point.
 
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.
 
virtual const SolutionTypesolution () const
 returns the current solution of the optimizer
 
- Public Member Functions inherited from shark::AbstractOptimizer< PointType, ResultT, SolutionTypeT >
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.
 
virtual void init (ObjectiveFunctionType const &function, std::vector< SearchPointType > const &initPoints)=0
 Initialize the optimizer for the supplied objective function using a set of initialisation points.
 
virtual void step (ObjectiveFunctionType const &function)=0
 Carry out one step of the optimizer for the supplied objective function.
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor.
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...).
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...).
 
 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.
 
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.
 

Protected Types

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

Protected Member Functions

SHARK_EXPORT_SYMBOL std::vector< IndividualTypegenerateOffspring () const
 Samples lambda individuals from the search distribution

 
SHARK_EXPORT_SYMBOL void updatePopulation (std::vector< IndividualType > const &offspring)
 Updates the strategy parameters based on the supplied offspring population.
 
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< PointType, ResultT, SolutionTypeT >
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.
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractSingleObjectiveOptimizer< RealVector >
SolutionType m_best
 Current solution of the optimizer.
 
- Protected Attributes inherited from shark::AbstractOptimizer< PointType, ResultT, SolutionTypeT >
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 66 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 211 of file CMA.h.

Member Enumeration Documentation

◆ RecombinationType

Models the recombination type.

Enumerator
EQUAL 
LINEAR 
SUPERLINEAR 

Definition at line 70 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 198 of file CMA.h.

References eigenValues(), and shark::MultiVariateNormalDistribution::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 142 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 193 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 188 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 132 of file CMA.h.

◆ evolutionPathSigma()

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

Accesses the evolution path for the step size update.

Definition at line 137 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 &  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.

◆ init() [2/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 main().

◆ lambda()

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

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

Definition at line 183 of file CMA.h.

Referenced by 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 157 of file CMA.h.

Referenced by setLowerBound().

◆ mean()

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

Accesses the current population mean.

Definition at line 122 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 167 of file CMA.h.

Referenced by setMu().

◆ name()

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

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 80 of file CMA.h.

◆ numberOfEvaluations()

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

Returns how often a point is evaluated.

Definition at line 204 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.

◆ recombinationType() [1/2]

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

Returns a mutable reference to the recombination type.

Definition at line 152 of file CMA.h.

◆ recombinationType() [2/2]

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

Accesses the recombination type.

Definition at line 147 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 112 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 177 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 162 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 172 of file CMA.h.

References mu().

◆ sigma()

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

Accesses the current step size.

Definition at line 117 of file CMA.h.

Referenced by main(), and main().

◆ step()

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

Executes one iteration of the algorithm.

Referenced by main(), and main().

◆ suggestLambda()

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

Calculates lambda for the supplied dimensionality n.

◆ 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.

◆ 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 127 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.


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