Package org.moeaframework.algorithm
Class CMAES
java.lang.Object
org.moeaframework.algorithm.AbstractAlgorithm
org.moeaframework.algorithm.CMAES
- All Implemented Interfaces:
Extensible
,Algorithm
,Configurable
,Stateful
The Covariance Matrix Adaption Evolution Strategy (CMA-ES) algorithm for single and multi-objective problems.
For multi-objective problems, individuals are compared using Pareto ranking and crowding distance to break
ties. An optional
fitnessEvaluator
parameter can be specified to replace the crowding distance calculation
with, for example, the hypervolume indicator.
This file is based on the Java implementation of CMA-ES by Nikolaus Hansen available at https://www.lri.fr/~hansen/cmaes_inmatlab.html#java, originally licensed under the GNU LGPLv3.
References:
- Hansen and 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, Berlin: Springer.
- Hansen, N. (2011). The CMA Evolution Strategy: A Tutorial. Available at https://www.lri.fr/~hansen/cmatutorial.pdf.
- Igel, C., N. Hansen, and S. Roth (2007). Covariance Matrix Adaptation for Multi-objective Optimization. Evolutionary Computation, 15(1):1-28.
-
Field Summary
Fields inherited from class org.moeaframework.algorithm.AbstractAlgorithm
initialized, numberOfEvaluations, problem, terminated
-
Constructor Summary
ConstructorDescriptionConstructs a new CMA-ES intance using default parameters.CMAES
(Problem problem, int lambda, IndicatorFitnessEvaluator fitnessEvaluator, NondominatedPopulation archive) Constructs a new CMA-ES instance using default parameters.CMAES
(Problem problem, int lambda, IndicatorFitnessEvaluator fitnessEvaluator, NondominatedPopulation archive, double[] initialSearchPoint, boolean checkConsistency, double cc, double cs, double damps, double ccov, double ccovsep, double sigma, int diagonalIterations) Constructs a new CMA-ES instance with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyConfiguration
(TypedProperties properties) Applies the properties to this instance.Returns the non-dominated archive of the best solutions found.double
getCc()
Returns the cumulation parameter.double
getCcov()
Returns the learning rate.double
Returns the learning rate when diagonal mode is active.Gets the current configuration of this instance.double
getCs()
Returns the step size of the cumulation parameter.double
getDamps()
Returns the damping for step size.int
Returns the number of iterations in which only the covariance diagonal is used.Returns the indicator-based fitness evaluator.double[]
Returns the initial search point to start searching from, ornull
if no initial search point was specified.int
Returns the number of offspring generated each iteration.Returns the current best-known result.double
getSigma()
Returns the overall standard deviation.void
Performs any initialization that is required by this algorithm.protected void
boolean
Returnstrue
if consistency checks are enabled;false
otherwise.protected void
iterate()
Performs one iteration of the algorithm.void
loadState
(ObjectInputStream stream) Loads the state of this object from the stream.void
saveState
(ObjectOutputStream stream) Writes the state of this object to the stream.void
setArchive
(NondominatedPopulation archive) Sets the non-dominated archive of the best solutions found.void
setCc
(double cc) Sets the cumulation parameter.void
setCcov
(double ccov) Sets the learning rate.void
setCcovsep
(double ccovsep) Sets the learning rate when diagonal mode is active.void
setCheckConsistency
(boolean checkConsistency) Enables or disables consistency checks to ensure CMA-ES remains numerically stable.void
setCs
(double cs) Sets the step size of the cumulation parameter.void
setDamps
(double damps) Sets the damping for step size.void
setDiagonalIterations
(int diagonalIterations) Sets the number of iterations in which only the covariance diagonal is used.void
setFitnessEvaluator
(IndicatorFitnessEvaluator fitnessEvaluator) Sets the indicator-based fitness evaluator used as a secondary comparison criteria for comparing population individuals with the same rank, ornull
to use the default crowding distance metricvoid
setLambda
(int lambda) Sets the number of offspring generated each iteration.void
setSigma
(double sigma) Sets the overall standard deviation.Methods inherited from class org.moeaframework.algorithm.AbstractAlgorithm
assertNotInitialized, evaluate, getExtensions, getNumberOfEvaluations, getProblem, isInitialized, isTerminated, step, terminate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.moeaframework.core.Algorithm
evaluateAll, evaluateAll, run, run
Methods inherited from interface org.moeaframework.algorithm.extension.Extensible
addExtension, removeExtension
-
Constructor Details
-
CMAES
Constructs a new CMA-ES intance using default parameters.- Parameters:
problem
- the problem to optimize
-
CMAES
public CMAES(Problem problem, int lambda, IndicatorFitnessEvaluator fitnessEvaluator, NondominatedPopulation archive) Constructs a new CMA-ES instance using default parameters.- Parameters:
problem
- the problem to optimizelambda
- the offspring population sizefitnessEvaluator
- secondary comparison criteria for comparing population individuals with the same rank, ornull
to use the default crowding distance metricarchive
- the nondominated archive for storing the elite individuals
-
CMAES
public CMAES(Problem problem, int lambda, IndicatorFitnessEvaluator fitnessEvaluator, NondominatedPopulation archive, double[] initialSearchPoint, boolean checkConsistency, double cc, double cs, double damps, double ccov, double ccovsep, double sigma, int diagonalIterations) Constructs a new CMA-ES instance with the given parameters.If the parameters
cc
,cs
,damps
,ccov
,ccovsep
,sigma
, anddiagonalIterations
are set to any negative number, then the default parameter will be used.- Parameters:
problem
- the problem to optimizelambda
- the offspring population sizefitnessEvaluator
- secondary comparison criteria for comparing population individuals with the same rank, ornull
to use the default crowding distance metricarchive
- the nondominated archive for storing the elite individualsinitialSearchPoint
- an initial search point, ornull
if no initial search point is specifiedcheckConsistency
- iftrue
, performs checks to ensure CMA-ES remains numerically stablecc
- the cumulation parametercs
- the step size of the cumulation parameterdamps
- the damping factor for the step sizeccov
- the learning rateccovsep
- the learning rate when in diagonal-only modesigma
- the initial standard deviationdiagonalIterations
- the number of iterations in which only the covariance diagonal is used
-
-
Method Details
-
getDiagonalIterations
public int getDiagonalIterations()Returns the number of iterations in which only the covariance diagonal is used.- Returns:
- the number of iterations in which only the covariance diagonal is used
-
setDiagonalIterations
public void setDiagonalIterations(int diagonalIterations) Sets the number of iterations in which only the covariance diagonal is used. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
diagonalIterations
- the number of iterations in which only the covariance diagonal is used
-
getLambda
public int getLambda()Returns the number of offspring generated each iteration.- Returns:
- the number of offspring generated each iteration
-
setLambda
public void setLambda(int lambda) Sets the number of offspring generated each iteration. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
lambda
- the number of offspring generated each iteration
-
getSigma
public double getSigma()Returns the overall standard deviation.- Returns:
- the overall standard deviation
-
setSigma
public void setSigma(double sigma) Sets the overall standard deviation. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
sigma
- the overall standard deviation
-
getCcov
public double getCcov()Returns the learning rate.- Returns:
- the learning rate
-
setCcov
public void setCcov(double ccov) Sets the learning rate. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
ccov
- the learning rate
-
getCcovsep
public double getCcovsep()Returns the learning rate when diagonal mode is active.- Returns:
- the learning rate when diagonal mode is active
-
setCcovsep
public void setCcovsep(double ccovsep) Sets the learning rate when diagonal mode is active. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
ccovsep
- the learning rate when diagonal mode is active
-
getCs
public double getCs()Returns the step size of the cumulation parameter.- Returns:
- the step size of the cumulation parameter
-
setCs
public void setCs(double cs) Sets the step size of the cumulation parameter. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
cs
- the step size of the cumulation parameter
-
getCc
public double getCc()Returns the cumulation parameter.- Returns:
- the cumulation parameter
-
setCc
public void setCc(double cc) Sets the cumulation parameter. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
cc
- the cumulation parameter
-
getDamps
public double getDamps()Returns the damping for step size.- Returns:
- the damping for step size
-
setDamps
public void setDamps(double damps) Sets the damping for step size. If set to-1
, a default value will be provided during initialization. This property can only be configured before initialization.- Parameters:
damps
- the damping for step size
-
getInitialSearchPoint
public double[] getInitialSearchPoint()Returns the initial search point to start searching from, ornull
if no initial search point was specified.- Returns:
- the initial search point to start searching from, or
null
if no initial search point was specified
-
getArchive
Returns the non-dominated archive of the best solutions found.- Returns:
- the non-dominated archive of the best solutions found
-
setArchive
Sets the non-dominated archive of the best solutions found. This property can only be configured before initialization.- Parameters:
archive
- the non-dominated archive of the best solutions found
-
getFitnessEvaluator
Returns the indicator-based fitness evaluator.- Returns:
- the indicator-based fitness evaluator
-
setFitnessEvaluator
Sets the indicator-based fitness evaluator used as a secondary comparison criteria for comparing population individuals with the same rank, ornull
to use the default crowding distance metric- Parameters:
fitnessEvaluator
- the indicator-based fitness evaluator
-
isCheckConsistency
public boolean isCheckConsistency()Returnstrue
if consistency checks are enabled;false
otherwise.- Returns:
true
if consistency checks are enabled;false
otherwise
-
setCheckConsistency
public void setCheckConsistency(boolean checkConsistency) Enables or disables consistency checks to ensure CMA-ES remains numerically stable. This property can only be configured before initialization.- Parameters:
checkConsistency
-true
if consistency checks are enabled;false
otherwise
-
applyConfiguration
Description copied from interface:Configurable
Applies the properties to this instance. It is strongly recommended to apply a configuration immediately after creating the instance, as some properties can not be changed after the class is used. Exceptions may be thrown if attempting to set such properties. After calling this method, we encourage users to callTypedProperties.warnIfUnaccessedProperties()
to verify all properties were processed. This can identify simple mistakes like typos. If overriding this method, properties should only be updated if a new value is provided. Additionally, if updating anyConfigurable
objects inside this object, they should be updated before callingsuper.applyConfiguration(properties)
.- Specified by:
applyConfiguration
in interfaceConfigurable
- Parameters:
properties
- the user-defined properties
-
getConfiguration
Description copied from interface:Configurable
Gets the current configuration of this instance. In theory, these properties should be able to create a duplicate instance. Note however, they are unlikely to behave identically due to random numbers and other transient fields.- Specified by:
getConfiguration
in interfaceConfigurable
- Returns:
- the properties defining this instance
-
initializeState
protected void initializeState() -
initialize
public void initialize()Description copied from interface:Algorithm
Performs any initialization that is required by this algorithm. This method should only be called once, though the specific implementation may choose to no-op or throwAlgorithmInitializationException
if called multiple times.Implementations should always call
super.initialize()
to ensure the algorithm is initialized correctly.- Specified by:
initialize
in interfaceAlgorithm
- Overrides:
initialize
in classAbstractAlgorithm
-
iterate
protected void iterate()Description copied from class:AbstractAlgorithm
Performs one iteration of the algorithm. This method should be overridden by implementations to perform each logical iteration of the algorithm.- Specified by:
iterate
in classAbstractAlgorithm
-
getResult
Description copied from interface:Algorithm
Returns the current best-known result. -
saveState
Description copied from interface:Stateful
Writes the state of this object to the stream. The order that objects are written to the stream is important. We recommend first callingsuper.saveState(stream)
followed by writing each field.- Specified by:
saveState
in interfaceStateful
- Overrides:
saveState
in classAbstractAlgorithm
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurred
-
loadState
Description copied from interface:Stateful
Loads the state of this object from the stream. The order for reading objects from the stream must match the order they are written to the stream inStateful.saveState(ObjectOutputStream)
.- Specified by:
loadState
in interfaceStateful
- Overrides:
loadState
in classAbstractAlgorithm
- Parameters:
stream
- the stream- Throws:
IOException
- if an I/O error occurredClassNotFoundException
- if the stream referenced a class that is not defined
-