Class CMAES

All Implemented Interfaces:
Extensible, Algorithm, Configurable, Stateful

public class CMAES extends AbstractAlgorithm implements Configurable
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:

  1. 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.
  2. Hansen, N. (2011). The CMA Evolution Strategy: A Tutorial. Available at https://www.lri.fr/~hansen/cmatutorial.pdf.
  3. Igel, C., N. Hansen, and S. Roth (2007). Covariance Matrix Adaptation for Multi-objective Optimization. Evolutionary Computation, 15(1):1-28.
  • Constructor Details

    • CMAES

      public CMAES(Problem problem)
      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 optimize
      lambda - the offspring population size
      fitnessEvaluator - secondary comparison criteria for comparing population individuals with the same rank, or null to use the default crowding distance metric
      archive - 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, and diagonalIterations are set to any negative number, then the default parameter will be used.

      Parameters:
      problem - the problem to optimize
      lambda - the offspring population size
      fitnessEvaluator - secondary comparison criteria for comparing population individuals with the same rank, or null to use the default crowding distance metric
      archive - the nondominated archive for storing the elite individuals
      initialSearchPoint - an initial search point, or null if no initial search point is specified
      checkConsistency - if true, performs checks to ensure CMA-ES remains numerically stable
      cc - the cumulation parameter
      cs - the step size of the cumulation parameter
      damps - the damping factor for the step size
      ccov - the learning rate
      ccovsep - the learning rate when in diagonal-only mode
      sigma - the initial standard deviation
      diagonalIterations - 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, or null 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

      public NondominatedPopulation getArchive()
      Returns the non-dominated archive of the best solutions found.
      Returns:
      the non-dominated archive of the best solutions found
    • setArchive

      public void setArchive(NondominatedPopulation archive)
      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

      public IndicatorFitnessEvaluator getFitnessEvaluator()
      Returns the indicator-based fitness evaluator.
      Returns:
      the indicator-based fitness evaluator
    • setFitnessEvaluator

      public void setFitnessEvaluator(IndicatorFitnessEvaluator fitnessEvaluator)
      Sets the indicator-based fitness evaluator used as a secondary comparison criteria for comparing population individuals with the same rank, or null to use the default crowding distance metric
      Parameters:
      fitnessEvaluator - the indicator-based fitness evaluator
    • isCheckConsistency

      public boolean isCheckConsistency()
      Returns true 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

      public void applyConfiguration(TypedProperties properties)
      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 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 Configurable objects inside this object, they should be updated before calling super.applyConfiguration(properties).
      Specified by:
      applyConfiguration in interface Configurable
      Parameters:
      properties - the user-defined properties
    • getConfiguration

      public TypedProperties 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 interface Configurable
      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 throw AlgorithmInitializationException if called multiple times.

      Implementations should always call super.initialize() to ensure the algorithm is initialized correctly.

      Specified by:
      initialize in interface Algorithm
      Overrides:
      initialize in class AbstractAlgorithm
    • 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 class AbstractAlgorithm
    • getResult

      public NondominatedPopulation getResult()
      Description copied from interface: Algorithm
      Returns the current best-known result.
      Specified by:
      getResult in interface Algorithm
      Returns:
      the current best-known result
    • saveState

      public void saveState(ObjectOutputStream stream) throws IOException
      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 calling super.saveState(stream) followed by writing each field.
      Specified by:
      saveState in interface Stateful
      Overrides:
      saveState in class AbstractAlgorithm
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
    • loadState

      public void loadState(ObjectInputStream stream) throws IOException, ClassNotFoundException
      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 in Stateful.saveState(ObjectOutputStream).
      Specified by:
      loadState in interface Stateful
      Overrides:
      loadState in class AbstractAlgorithm
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
      ClassNotFoundException - if the stream referenced a class that is not defined