@Deprecated public class CMAESOptimizer extends BaseAbstractMultivariateSimpleBoundsOptimizer<MultivariateFunction> implements MultivariateOptimizer
An implementation of the active Covariance Matrix Adaptation Evolution Strategy (CMA-ES) for non-linear, non-convex, non-smooth, global function minimization. The CMA-Evolution Strategy (CMA-ES) is a reliable stochastic optimization method which should be applied if derivative-based methods, e.g. quasi-Newton BFGS or conjugate gradient, fail due to a rugged search landscape (e.g. noise, local optima, outlier, etc.) of the objective function. Like a quasi-Newton method, the CMA-ES learns and applies a variable metric on the underlying search space. Unlike a quasi-Newton method, the CMA-ES neither estimates nor uses gradients, making it considerably more reliable in terms of finding a good, or even close to optimal, solution.
In general, on smooth objective functions the CMA-ES is roughly ten times slower than BFGS (counting objective function evaluations, no gradients provided). For up to variables also the derivative-free simplex direct search method (Nelder and Mead) can be faster, but it is far less reliable than CMA-ES.
The CMA-ES is particularly well suited for non-separable and/or badly conditioned problems. To observe the advantage of CMA compared to a conventional evolution strategy, it will usually take about function evaluations. On difficult problems the complete optimization (a single run) is expected to take roughly between and function evaluations.
This implementation is translated and adapted from the Matlab version
of the CMA-ES algorithm as implemented in module cmaes.m
version 3.51.
Modifier and Type | Class and Description |
---|---|
private static class |
CMAESOptimizer.DoubleIndex
Deprecated.
Used to sort fitness values.
|
private class |
CMAESOptimizer.FitnessFunction
Deprecated.
Normalizes fitness values to the range [0,1].
|
static class |
CMAESOptimizer.PopulationSize
Deprecated.
Population size.
|
static class |
CMAESOptimizer.Sigma
Deprecated.
Input sigma values.
|
Modifier and Type | Field and Description |
---|---|
private RealMatrix |
B
Deprecated.
Coordinate system.
|
private RealMatrix |
BD
Deprecated.
B*D, stored for efficiency.
|
private RealMatrix |
C
Deprecated.
Covariance matrix.
|
private double |
cc
Deprecated.
Cumulation constant.
|
private double |
ccov1
Deprecated.
Learning rate for rank-one update.
|
private double |
ccov1Sep
Deprecated.
Learning rate for rank-one update - diagonalOnly
|
private double |
ccovmu
Deprecated.
Learning rate for rank-mu update'
|
private double |
ccovmuSep
Deprecated.
Learning rate for rank-mu update - diagonalOnly
|
private int |
checkFeasableCount
Deprecated.
Determines how often a new random offspring is generated in case it is
not feasible / beyond the defined limits, default is 0.
|
private double |
chiN
Deprecated.
Expectation of ||N(0,I)|| == norm(randn(N,1)).
|
private double |
cs
Deprecated.
Cumulation constant for step-size.
|
private RealMatrix |
D
Deprecated.
Scaling.
|
private double |
damps
Deprecated.
Damping for step-size.
|
static int |
DEFAULT_CHECKFEASABLECOUNT
Deprecated.
Default value for
checkFeasableCount : 0. |
static int |
DEFAULT_DIAGONALONLY
Deprecated.
Default value for
diagonalOnly : 0. |
static boolean |
DEFAULT_ISACTIVECMA
Deprecated.
Default value for
isActiveCMA : true. |
static int |
DEFAULT_MAXITERATIONS
Deprecated.
Default value for
maxIterations : 30000. |
static RandomGenerator |
DEFAULT_RANDOMGENERATOR
Deprecated.
Default value for
random . |
static double |
DEFAULT_STOPFITNESS
Deprecated.
Default value for
stopFitness : 0.0. |
private RealMatrix |
diagC
Deprecated.
Diagonal of C, used for diagonalOnly.
|
private RealMatrix |
diagD
Deprecated.
Diagonal of sqrt(D), stored for efficiency.
|
private int |
diagonalOnly
Deprecated.
Defines the number of initial iterations, where the covariance matrix
remains diagonal and the algorithm has internally linear time complexity.
|
private int |
dimension
Deprecated.
Number of objective variables/problem dimension
|
private double[] |
fitnessHistory
Deprecated.
History queue of best values.
|
private boolean |
generateStatistics
Deprecated.
Indicates whether statistic data is collected.
|
private int |
historySize
Deprecated.
Size of history queue of best values.
|
private double[] |
inputSigma
Deprecated.
|
private boolean |
isActiveCMA
Deprecated.
Covariance update mechanism, default is active CMA.
|
private boolean |
isMinimize
Deprecated.
Number of objective variables/problem dimension
|
private int |
iterations
Deprecated.
Number of iterations already performed.
|
private int |
lambda
Deprecated.
Population size, offspring number.
|
private double |
logMu2
Deprecated.
log(mu + 0.5), stored for efficiency.
|
private int |
maxIterations
Deprecated.
Maximal number of iterations allowed.
|
private int |
mu
Deprecated.
Number of parents/points for recombination.
|
private double |
mueff
Deprecated.
Variance-effectiveness of sum w_i x_i.
|
private double |
normps
Deprecated.
Norm of ps, stored for efficiency.
|
private RealMatrix |
pc
Deprecated.
Evolution path.
|
private RealMatrix |
ps
Deprecated.
Evolution path for sigma.
|
private RandomGenerator |
random
Deprecated.
Random generator.
|
private double |
sigma
Deprecated.
Overall standard deviation - search volume.
|
private java.util.List<RealMatrix> |
statisticsDHistory
Deprecated.
History of D matrix.
|
private java.util.List<java.lang.Double> |
statisticsFitnessHistory
Deprecated.
History of fitness values.
|
private java.util.List<RealMatrix> |
statisticsMeanHistory
Deprecated.
History of mean matrix.
|
private java.util.List<java.lang.Double> |
statisticsSigmaHistory
Deprecated.
History of sigma values.
|
private double |
stopFitness
Deprecated.
Limit for fitness value.
|
private double |
stopTolFun
Deprecated.
Stop if fun-changes smaller stopTolFun.
|
private double |
stopTolHistFun
Deprecated.
Stop if back fun-changes smaller stopTolHistFun.
|
private double |
stopTolUpX
Deprecated.
Stop if x-changes larger stopTolUpX.
|
private double |
stopTolX
Deprecated.
Stop if x-change smaller stopTolX.
|
private RealMatrix |
weights
Deprecated.
Array for weighted recombination.
|
private RealMatrix |
xmean
Deprecated.
Objective variables.
|
evaluations
Constructor and Description |
---|
CMAESOptimizer()
Deprecated.
As of version 3.1: Parameter
lambda must be
passed with the call to optimize (whereas in the current code it is set to an undocumented value). |
CMAESOptimizer(int lambda)
Deprecated.
As of version 3.1: Parameter
lambda must be
passed with the call to optimize (whereas in the current code it is set to an undocumented value).. |
CMAESOptimizer(int lambda,
double[] inputSigma)
Deprecated.
|
CMAESOptimizer(int lambda,
double[] inputSigma,
int maxIterations,
double stopFitness,
boolean isActiveCMA,
int diagonalOnly,
int checkFeasableCount,
RandomGenerator random,
boolean generateStatistics)
Deprecated.
|
CMAESOptimizer(int lambda,
double[] inputSigma,
int maxIterations,
double stopFitness,
boolean isActiveCMA,
int diagonalOnly,
int checkFeasableCount,
RandomGenerator random,
boolean generateStatistics,
ConvergenceChecker<PointValuePair> checker)
Deprecated.
|
CMAESOptimizer(int maxIterations,
double stopFitness,
boolean isActiveCMA,
int diagonalOnly,
int checkFeasableCount,
RandomGenerator random,
boolean generateStatistics,
ConvergenceChecker<PointValuePair> checker)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
private void |
checkParameters()
Deprecated.
Checks dimensions and values of boundaries and inputSigma if defined.
|
private static void |
copyColumn(RealMatrix m1,
int col1,
RealMatrix m2,
int col2)
Deprecated.
Copies a column from m1 to m2.
|
private static RealMatrix |
diag(RealMatrix m)
Deprecated.
|
private static RealMatrix |
divide(RealMatrix m,
RealMatrix n)
Deprecated.
|
protected PointValuePair |
doOptimize()
Deprecated.
Perform the bulk of the optimization algorithm.
|
private static RealMatrix |
eye(int n,
int m)
Deprecated.
|
java.util.List<RealMatrix> |
getStatisticsDHistory()
Deprecated.
|
java.util.List<java.lang.Double> |
getStatisticsFitnessHistory()
Deprecated.
|
java.util.List<RealMatrix> |
getStatisticsMeanHistory()
Deprecated.
|
java.util.List<java.lang.Double> |
getStatisticsSigmaHistory()
Deprecated.
|
private void |
initializeCMA(double[] guess)
Deprecated.
Initialization of the dynamic search parameters
|
private static int[] |
inverse(int[] indices)
Deprecated.
|
private static RealMatrix |
log(RealMatrix m)
Deprecated.
|
private static double |
max(double[] m)
Deprecated.
|
private static double |
max(RealMatrix m)
Deprecated.
|
private static double |
min(double[] m)
Deprecated.
|
private static double |
min(RealMatrix m)
Deprecated.
|
private static RealMatrix |
ones(int n,
int m)
Deprecated.
|
protected PointValuePair |
optimizeInternal(int maxEval,
MultivariateFunction f,
GoalType goalType,
OptimizationData... optData)
Deprecated.
Optimize an objective function.
|
private void |
parseOptimizationData(OptimizationData... optData)
Deprecated.
Scans the list of (required and optional) optimization data that
characterize the problem.
|
private static void |
push(double[] vals,
double val)
Deprecated.
Pushes the current best fitness value in a history queue.
|
private double[] |
randn(int size)
Deprecated.
|
private RealMatrix |
randn1(int size,
int popSize)
Deprecated.
|
private static RealMatrix |
repmat(RealMatrix mat,
int n,
int m)
Deprecated.
|
private static int[] |
reverse(int[] indices)
Deprecated.
|
private static RealMatrix |
selectColumns(RealMatrix m,
int[] cols)
Deprecated.
|
private static RealMatrix |
sequence(double start,
double end,
double step)
Deprecated.
|
private int[] |
sortedIndices(double[] doubles)
Deprecated.
Sorts fitness values.
|
private static RealMatrix |
sqrt(RealMatrix m)
Deprecated.
|
private static RealMatrix |
square(RealMatrix m)
Deprecated.
|
private static RealMatrix |
sumRows(RealMatrix m)
Deprecated.
|
private static RealMatrix |
times(RealMatrix m,
RealMatrix n)
Deprecated.
|
private static RealMatrix |
triu(RealMatrix m,
int k)
Deprecated.
|
private void |
updateBD(double negccov)
Deprecated.
Update B and D from C.
|
private void |
updateCovariance(boolean hsig,
RealMatrix bestArx,
RealMatrix arz,
int[] arindex,
RealMatrix xold)
Deprecated.
Update of the covariance matrix C.
|
private void |
updateCovarianceDiagonalOnly(boolean hsig,
RealMatrix bestArz)
Deprecated.
Update of the covariance matrix C for diagonalOnly > 0
|
private boolean |
updateEvolutionPaths(RealMatrix zmean,
RealMatrix xold)
Deprecated.
Update of the evolution paths ps and pc.
|
private static RealMatrix |
zeros(int n,
int m)
Deprecated.
|
optimize, optimize
computeObjectiveValue, getConvergenceChecker, getEvaluations, getGoalType, getLowerBound, getMaxEvaluations, getStartPoint, getUpperBound, optimize, optimizeInternal
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
optimize
getConvergenceChecker, getEvaluations, getMaxEvaluations
public static final int DEFAULT_CHECKFEASABLECOUNT
checkFeasableCount
: 0.public static final double DEFAULT_STOPFITNESS
stopFitness
: 0.0.public static final boolean DEFAULT_ISACTIVECMA
isActiveCMA
: true.public static final int DEFAULT_MAXITERATIONS
maxIterations
: 30000.public static final int DEFAULT_DIAGONALONLY
diagonalOnly
: 0.public static final RandomGenerator DEFAULT_RANDOMGENERATOR
random
.private int lambda
private boolean isActiveCMA
private int checkFeasableCount
private double[] inputSigma
CMAESOptimizer.Sigma
private int dimension
private int diagonalOnly
private boolean isMinimize
private boolean generateStatistics
private int maxIterations
private double stopFitness
private double stopTolUpX
private double stopTolX
private double stopTolFun
private double stopTolHistFun
private int mu
private double logMu2
private RealMatrix weights
private double mueff
private double sigma
private double cc
private double cs
private double damps
private double ccov1
private double ccovmu
private double chiN
private double ccov1Sep
private double ccovmuSep
private RealMatrix xmean
private RealMatrix pc
private RealMatrix ps
private double normps
private RealMatrix B
private RealMatrix D
private RealMatrix BD
private RealMatrix diagD
private RealMatrix C
private RealMatrix diagC
private int iterations
private double[] fitnessHistory
private int historySize
private RandomGenerator random
private java.util.List<java.lang.Double> statisticsSigmaHistory
private java.util.List<RealMatrix> statisticsMeanHistory
private java.util.List<java.lang.Double> statisticsFitnessHistory
private java.util.List<RealMatrix> statisticsDHistory
@Deprecated public CMAESOptimizer()
lambda
must be
passed with the call to optimize
(whereas in the current code it is set to an undocumented value).@Deprecated public CMAESOptimizer(int lambda)
lambda
must be
passed with the call to optimize
(whereas in the current code it is set to an undocumented value)..lambda
- Population size.@Deprecated public CMAESOptimizer(int lambda, double[] inputSigma)
lambda
and inputSigma
must be
passed with the call to optimize
.lambda
- Population size.inputSigma
- Initial standard deviations to sample new points
around the initial guess.@Deprecated public CMAESOptimizer(int lambda, double[] inputSigma, int maxIterations, double stopFitness, boolean isActiveCMA, int diagonalOnly, int checkFeasableCount, RandomGenerator random, boolean generateStatistics)
SimpleValueChecker.SimpleValueChecker()
lambda
- Population size.inputSigma
- Initial standard deviations to sample new points
around the initial guess.maxIterations
- Maximal number of iterations.stopFitness
- Whether to stop if objective function value is smaller than
stopFitness
.isActiveCMA
- Chooses the covariance matrix update method.diagonalOnly
- Number of initial iterations, where the covariance matrix
remains diagonal.checkFeasableCount
- Determines how often new random objective variables are
generated in case they are out of bounds.random
- Random generator.generateStatistics
- Whether statistic data is collected.@Deprecated public CMAESOptimizer(int lambda, double[] inputSigma, int maxIterations, double stopFitness, boolean isActiveCMA, int diagonalOnly, int checkFeasableCount, RandomGenerator random, boolean generateStatistics, ConvergenceChecker<PointValuePair> checker)
lambda
and inputSigma
must be
passed with the call to optimize
.lambda
- Population size.inputSigma
- Initial standard deviations to sample new points
around the initial guess.maxIterations
- Maximal number of iterations.stopFitness
- Whether to stop if objective function value is smaller than
stopFitness
.isActiveCMA
- Chooses the covariance matrix update method.diagonalOnly
- Number of initial iterations, where the covariance matrix
remains diagonal.checkFeasableCount
- Determines how often new random objective variables are
generated in case they are out of bounds.random
- Random generator.generateStatistics
- Whether statistic data is collected.checker
- Convergence checker.public CMAESOptimizer(int maxIterations, double stopFitness, boolean isActiveCMA, int diagonalOnly, int checkFeasableCount, RandomGenerator random, boolean generateStatistics, ConvergenceChecker<PointValuePair> checker)
maxIterations
- Maximal number of iterations.stopFitness
- Whether to stop if objective function value is smaller than
stopFitness
.isActiveCMA
- Chooses the covariance matrix update method.diagonalOnly
- Number of initial iterations, where the covariance matrix
remains diagonal.checkFeasableCount
- Determines how often new random objective variables are
generated in case they are out of bounds.random
- Random generator.generateStatistics
- Whether statistic data is collected.checker
- Convergence checker.public java.util.List<java.lang.Double> getStatisticsSigmaHistory()
public java.util.List<RealMatrix> getStatisticsMeanHistory()
public java.util.List<java.lang.Double> getStatisticsFitnessHistory()
public java.util.List<RealMatrix> getStatisticsDHistory()
protected PointValuePair optimizeInternal(int maxEval, MultivariateFunction f, GoalType goalType, OptimizationData... optData)
optimizeInternal
in class BaseAbstractMultivariateOptimizer<MultivariateFunction>
maxEval
- Allowed number of evaluations of the objective function.f
- Objective function.goalType
- Optimization type.optData
- Optimization data. The following data will be looked for:
protected PointValuePair doOptimize()
doOptimize
in class BaseAbstractMultivariateOptimizer<MultivariateFunction>
private void parseOptimizationData(OptimizationData... optData)
optData
- Optimization data. The following data will be looked for:
private void checkParameters()
private void initializeCMA(double[] guess)
guess
- Initial guess for the arguments of the fitness function.private boolean updateEvolutionPaths(RealMatrix zmean, RealMatrix xold)
zmean
- Weighted row matrix of the gaussian random numbers generating
the current offspring.xold
- xmean matrix of the previous generation.private void updateCovarianceDiagonalOnly(boolean hsig, RealMatrix bestArz)
hsig
- Flag indicating a small correction.bestArz
- Fitness-sorted matrix of the gaussian random values of the
current offspring.private void updateCovariance(boolean hsig, RealMatrix bestArx, RealMatrix arz, int[] arindex, RealMatrix xold)
hsig
- Flag indicating a small correction.bestArx
- Fitness-sorted matrix of the argument vectors producing the
current offspring.arz
- Unsorted matrix containing the gaussian random values of the
current offspring.arindex
- Indices indicating the fitness-order of the current offspring.xold
- xmean matrix of the previous generation.private void updateBD(double negccov)
negccov
- Negative covariance factor.private static void push(double[] vals, double val)
vals
- History queue.val
- Current best fitness value.private int[] sortedIndices(double[] doubles)
doubles
- Array of values to be sorted.private static RealMatrix log(RealMatrix m)
m
- Input matrixprivate static RealMatrix sqrt(RealMatrix m)
m
- Input matrix.private static RealMatrix square(RealMatrix m)
m
- Input matrix.private static RealMatrix times(RealMatrix m, RealMatrix n)
m
- Input matrix 1.n
- Input matrix 2.private static RealMatrix divide(RealMatrix m, RealMatrix n)
m
- Input matrix 1.n
- Input matrix 2.private static RealMatrix selectColumns(RealMatrix m, int[] cols)
m
- Input matrix.cols
- Columns to select.private static RealMatrix triu(RealMatrix m, int k)
m
- Input matrix.k
- Diagonal position.private static RealMatrix sumRows(RealMatrix m)
m
- Input matrix.private static RealMatrix diag(RealMatrix m)
m
- Input matrix.private static void copyColumn(RealMatrix m1, int col1, RealMatrix m2, int col2)
m1
- Source matrix.col1
- Source column.m2
- Target matrix.col2
- Target column.private static RealMatrix ones(int n, int m)
n
- Number of rows.m
- Number of columns.private static RealMatrix eye(int n, int m)
n
- Number of rows.m
- Number of columns.private static RealMatrix zeros(int n, int m)
n
- Number of rows.m
- Number of columns.private static RealMatrix repmat(RealMatrix mat, int n, int m)
mat
- Input matrix.n
- Number of row replicates.m
- Number of column replicates.private static RealMatrix sequence(double start, double end, double step)
start
- Start value.end
- End value.step
- Step size.private static double max(RealMatrix m)
m
- Input matrix.private static double min(RealMatrix m)
m
- Input matrix.private static double max(double[] m)
m
- Input array.private static double min(double[] m)
m
- Input array.private static int[] inverse(int[] indices)
indices
- Input index array.private static int[] reverse(int[] indices)
indices
- Input index array.private double[] randn(int size)
size
- Length of random array.private RealMatrix randn1(int size, int popSize)
size
- Number of rows.popSize
- Population size.Copyright (c) 2003-2014 Apache Software Foundation