Class CMAES
- All Implemented Interfaces:
Algorithm,Extensible,Configurable,Named,Stateful
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
ConstructorsConstructorDescriptionConstructs 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 TypeMethodDescriptionvoidapplyConfiguration(TypedProperties properties) Applies the properties to this instance.Returns the non-dominated archive of the best solutions found.doublegetCc()Returns the cumulation parameter.doublegetCcov()Returns the learning rate.doubleReturns the learning rate when diagonal mode is active.Gets the current configuration of this instance.doublegetCs()Returns the step size of the cumulation parameter.doublegetDamps()Returns the damping for step size.intReturns 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, ornullif no initial search point was specified.intReturns the number of offspring generated each iteration.getName()Returns the name of this algorithm.Returns the current best-known result.doublegetSigma()Returns the overall standard deviation.voidPerforms any initialization that is required by this algorithm.protected voidInitializes the internal state of the algorithm.booleanReturnstrueif consistency checks are enabled;falseotherwise.protected voiditerate()Performs one iteration of the algorithm.voidloadState(ObjectInputStream stream) Loads the state of this object from the stream.voidsaveState(ObjectOutputStream stream) Writes the state of this object to the stream.voidsetArchive(NondominatedPopulation archive) Sets the non-dominated archive of the best solutions found.voidsetCc(double cc) Sets the cumulation parameter.voidsetCcov(double ccov) Sets the learning rate.voidsetCcovsep(double ccovsep) Sets the learning rate when diagonal mode is active.voidsetCheckConsistency(boolean checkConsistency) Enables or disables consistency checks to ensure CMA-ES remains numerically stable.voidsetCs(double cs) Sets the step size of the cumulation parameter.voidsetDamps(double damps) Sets the damping for step size.voidsetDiagonalIterations(int diagonalIterations) Sets the number of iterations in which only the covariance diagonal is used.voidsetFitnessEvaluator(IndicatorFitnessEvaluator fitnessEvaluator) Sets the indicator-based fitness evaluator used as a secondary comparison criteria for comparing population individuals with the same rank, ornullto use the default crowding distance metricvoidsetLambda(int lambda) Sets the number of offspring generated each iteration.voidsetSigma(double sigma) Sets the overall standard deviation.Methods inherited from class org.moeaframework.algorithm.AbstractAlgorithm
assertNotInitialized, evaluate, getExtensions, getNumberOfEvaluations, getProblem, isInitialized, isTerminated, step, terminateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.moeaframework.algorithm.Algorithm
evaluateAll, evaluateAll, run, runMethods 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, ornullto 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, anddiagonalIterationsare 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, ornullto use the default crowding distance metricarchive- the nondominated archive for storing the elite individualsinitialSearchPoint- an initial search point, ornullif 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
-
getName
Description copied from interface:AlgorithmReturns the name of this algorithm. Whenever possible, this name should match the name recognized byAlgorithmFactory. -
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, ornullif no initial search point was specified.- Returns:
- the initial search point to start searching from, or
nullif 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, ornullto use the default crowding distance metric- Parameters:
fitnessEvaluator- the indicator-based fitness evaluator
-
isCheckConsistency
public boolean isCheckConsistency()Returnstrueif consistency checks are enabled;falseotherwise.- Returns:
trueif consistency checks are enabled;falseotherwise
-
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-trueif consistency checks are enabled;falseotherwise
-
applyConfiguration
Description copied from interface:ConfigurableApplies 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 call
TypedProperties.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 any
Configurableobjects inside this object, they should be updated before callingsuper.applyConfiguration(properties).- Specified by:
applyConfigurationin interfaceConfigurable- Parameters:
properties- the user-defined properties
-
getConfiguration
Description copied from interface:ConfigurableGets 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:
getConfigurationin interfaceConfigurable- Returns:
- the properties defining this instance
-
initializeState
protected void initializeState()Initializes the internal state of the algorithm. -
initialize
public void initialize()Description copied from interface:AlgorithmPerforms 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 throwAlgorithmInitializationExceptionif called multiple times.Implementations should always call
super.initialize()to ensure the algorithm is initialized correctly.- Specified by:
initializein interfaceAlgorithm- Overrides:
initializein classAbstractAlgorithm
-
iterate
protected void iterate()Description copied from class:AbstractAlgorithmPerforms one iteration of the algorithm. This method should be overridden by implementations to perform each logical iteration of the algorithm.- Specified by:
iteratein classAbstractAlgorithm
-
getResult
Description copied from interface:AlgorithmReturns the current best-known result. -
saveState
Description copied from interface:StatefulWrites 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:
saveStatein interfaceStateful- Overrides:
saveStatein classAbstractAlgorithm- Parameters:
stream- the stream- Throws:
IOException- if an I/O error occurred
-
loadState
Description copied from interface:StatefulLoads 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:
loadStatein interfaceStateful- Overrides:
loadStatein classAbstractAlgorithm- Parameters:
stream- the stream- Throws:
IOException- if an I/O error occurredClassNotFoundException- if the stream referenced a class that is not defined
-