Covariance matrix adaptation evolutionary strategy
The CMA-ES algorithm has been implemented based on [Han23] with basic Riemannian adaptations, related to transport of the covariance matrix and its update vectors. Other attempts at adapting CMA-ES to Riemannian optimization include [CFFS10]. The algorithm is suitable for global optimization.
Covariance matrix transport between consecutive mean points is handled by the eigenvector_transport! function, which is based on the idea of transport of matrix eigenvectors.
Manopt.cma_es — Function
cma_es(M, f, p=rand(M); σ::Real=1.0, kwargs...)
cma_es(M, mco::AbstractManifoldCostObjective, p=rand(M); σ::Real=1.0, kwargs...)
cma_es!(M, f, p_m; σ::Real=1.0, kwargs...)
cma_es!(M, mco::AbstractManifoldCostObjective, p_m; σ::Real=1.0, kwargs...)Perform covariance matrix adaptation evolutionary strategy search for global gradient-free randomized optimization. It is suitable for complicated non-convex functions. It can be reasonably expected to find global minimum within 3σ distance from p_m.
Implementation is based on [Han23] with basic adaptations to the Riemannian setting.
Input
M::AbstractManifold: a Riemannian manifold $\mathcal{M}$f: a cost function $f: \mathcal{M}→ ℝ$ implemented as(M, p) -> vp::P: a point on the manifold $\mathcal{M}$
Keyword arguments
σ=1.0: initial standard deviationλ=4 + Int(floor(3 * log(manifold_dimension(M)))): population size (can be increased for a more thorough global search but decreasing is not recommended)tol_fun=1e-12: tolerance for theStopWhenPopulationCostConcentrated, similar to absolute difference between function values at subsequent pointstol_x=1e-12: tolerance for theStopWhenPopulationStronglyConcentrated, similar to absolute difference between subsequent point but actually computed from distribution parameters.stopping_criterion::StoppingCriterion= default_cma_es_stopping_criterion(M, λ; tol_fun=tol_fun, tol_x=tol_x): a functor indicating that the stopping criterion is fulfilledcallbacks::D = Dict{Symbol,Function}(): provided callback functions given as a dictionary with symbols as keysretraction_method::AbstractRetractionMethod=default_retraction_method(M, typeof(p)): a retraction $\operatorname{retr}$ to use, see the section on retractionsvector_transport_method::AbstractVectorTransportMethod=default_vector_transport_method(M, typeof(p)): a vector transport $\mathcal T_{⋅←⋅}$ to use, see the section on vector transportsbasis=default_basis(M, typeof(p)): a basis used to represent the covariance matrix in coordinatesrng=default_rng(): random number generator for generating new points onM
All other keyword arguments are passed to decorate_state! for state decorators or decorate_objective! for objective decorators, respectively.
Output
The obtained approximate minimizer $p^*$. To obtain the whole final state of the solver, see get_solver_return for details, especially the return_state= keyword.
Manopt.cma_es! — Function
cma_es(M, f, p=rand(M); σ::Real=1.0, kwargs...)
cma_es(M, mco::AbstractManifoldCostObjective, p=rand(M); σ::Real=1.0, kwargs...)
cma_es!(M, f, p_m; σ::Real=1.0, kwargs...)
cma_es!(M, mco::AbstractManifoldCostObjective, p_m; σ::Real=1.0, kwargs...)Perform covariance matrix adaptation evolutionary strategy search for global gradient-free randomized optimization. It is suitable for complicated non-convex functions. It can be reasonably expected to find global minimum within 3σ distance from p_m.
Implementation is based on [Han23] with basic adaptations to the Riemannian setting.
Input
M::AbstractManifold: a Riemannian manifold $\mathcal{M}$f: a cost function $f: \mathcal{M}→ ℝ$ implemented as(M, p) -> vp::P: a point on the manifold $\mathcal{M}$
Keyword arguments
σ=1.0: initial standard deviationλ=4 + Int(floor(3 * log(manifold_dimension(M)))): population size (can be increased for a more thorough global search but decreasing is not recommended)tol_fun=1e-12: tolerance for theStopWhenPopulationCostConcentrated, similar to absolute difference between function values at subsequent pointstol_x=1e-12: tolerance for theStopWhenPopulationStronglyConcentrated, similar to absolute difference between subsequent point but actually computed from distribution parameters.stopping_criterion::StoppingCriterion= default_cma_es_stopping_criterion(M, λ; tol_fun=tol_fun, tol_x=tol_x): a functor indicating that the stopping criterion is fulfilledcallbacks::D = Dict{Symbol,Function}(): provided callback functions given as a dictionary with symbols as keysretraction_method::AbstractRetractionMethod=default_retraction_method(M, typeof(p)): a retraction $\operatorname{retr}$ to use, see the section on retractionsvector_transport_method::AbstractVectorTransportMethod=default_vector_transport_method(M, typeof(p)): a vector transport $\mathcal T_{⋅←⋅}$ to use, see the section on vector transportsbasis=default_basis(M, typeof(p)): a basis used to represent the covariance matrix in coordinatesrng=default_rng(): random number generator for generating new points onM
All other keyword arguments are passed to decorate_state! for state decorators or decorate_objective! for objective decorators, respectively.
Output
The obtained approximate minimizer $p^*$. To obtain the whole final state of the solver, see get_solver_return for details, especially the return_state= keyword.
State
Manopt.CMAESState — Type
CMAESState{P,T} <: AbstractManoptSolverStateState of covariance matrix adaptation evolution strategy.
Fields
p::P: a point on the manifold $\mathcal{M}$ storing the best point found so farcallbacks::D: provided callback functions given as a dictionary with symbols as keysp_objobjective value atpμparent numberλpopulation sizeμ_effvariance effective selection mass for the meanc_1learning rate for the rank-one updatec_cdecay rate for cumulation path for the rank-one updatec_μlearning rate for the rank-μ updatec_σdecay rate for the cumulation path for the step-size controlc_mlearning rate for the meand_σdamping parameter for step-size updatepopulationpopulation of the current generationys_ccoordinates of random vectors for the current generationcovariance_matrixcoordinates of the covariance matrixlast_varianceseigenvalues ofcovariance_matrixfrom the previous iteration, used to replace nonpositive eigenvaluescovariance_matrix_eigeneigen decomposition ofcovariance_matrixcovariance_matrix_condcondition number ofcovariance_matrix, updated after eigen decompositionbest_fitness_current_genbest fitness value of individuals in the current generationmedian_fitness_current_genmedian fitness value of individuals in the current generationworst_fitness_current_genworst fitness value of individuals in the current generationp_mpoint around which the search for new candidates is doneσstep sizep_σcoordinates of a vector in $T_{p_m}\mathcal{M}$p_ccoordinates of a vector in $T_{p_m}\mathcal{M}$deviationsstandard deviations of coordinate RNGbufferbuffer of lengthn_coordsfor random number generation and for the weighted mean $⟨y⟩_w$ of the selected stepse_mv_normexpected value of norm of then_coords-variable standard normal distributionrecombination_weightsrecombination weights used for updating covariance matrixretraction_method::AbstractRetractionMethod: a retraction $\operatorname{retr}$ to use, see the section on retractionsstop::StoppingCriterion: a functor indicating that the stopping criterion is fulfilledvector_transport_method::AbstractVectorTransportMethod: a vector transport $\mathcal T_{⋅←⋅}$ to use, see the section on vector transportsbasisa real coefficient basis for covariance matrixrngRNG for generating new points
Constructor
CMAESState( M::AbstractManifold, p_m::P, μ::Int, λ::Int, μ_eff::TParams, c_1::TParams, c_c::TParams, c_μ::TParams, c_σ::TParams, c_m::TParams, d_σ::TParams, stop::TStopping, covariance_matrix::Matrix{TParams}, σ::TParams, recombination_weights::Vector{TParams}; callbacks=Dict{Symbol, Function}(), retraction_method::TRetraction=default_retraction_method(M, typeof(p_m)), vector_transport_method::TVTM=default_vector_transport_method(M, typeof(p_m)), basis::TB=default_basis(M, typeof(p_m)), rng::TRng=default_rng(),) where { P, TParams<:Real, TStopping<:StoppingCriterion, TRetraction<:AbstractRetractionMethod, TVTM<:AbstractVectorTransportMethod, TB<:AbstractBasis, TRng<:AbstractRNG,}See also
Stopping criteria
Manopt.StopWhenBestCostInGenerationConstant — Type
StopWhenBestCostInGenerationConstant <: StoppingCriterionStop if the range of the best objective function values of the last iteration_range generations is zero. This corresponds to EqualFunValues condition from [Han23].
See also StopWhenPopulationCostConcentrated.
Manopt.StopWhenCovarianceIllConditioned — Type
StopWhenCovarianceIllConditioned <: StoppingCriterionStop CMA-ES if condition number of covariance matrix exceeds threshold. This corresponds to ConditionCov condition from [Han23].
Manopt.StopWhenEvolutionStagnates — Type
StopWhenEvolutionStagnates{TParam<:Real} <: StoppingCriterionThe best and median fitness in each iteration is tracked over the last (at most) max_size iterations, and the criterion is evaluated once at least min_size values have been recorded. Solver is stopped if in both histories the median of the most recent fraction of values is not better than the median of the oldest fraction.
Manopt.StopWhenPopulationCostConcentrated — Type
StopWhenPopulationCostConcentrated{TParam<:Real} <: StoppingCriterionStop if the range of the best objective function value in the last max_size generations and all function values in the current generation is below tol. This corresponds to TolFun condition from [Han23].
Constructor
StopWhenPopulationCostConcentrated(tol::Real, max_size::Int)Manopt.StopWhenPopulationDiverges — Type
StopWhenPopulationDiverges{TParam<:Real} <: StoppingCriterionStop if σ times the maximum deviation has grown by a factor larger than tol compared to its value at the start of the run. This usually indicates a far too small σ, or divergent behavior. This corresponds to TolXUp condition from [Han23].
Manopt.StopWhenPopulationStronglyConcentrated — Type
StopWhenPopulationStronglyConcentrated{TParam<:Real} <: StoppingCriterionStop if the standard deviation in all coordinates is smaller than tol and norm of σ * p_c is smaller than tol. This corresponds to TolX condition from [Han23].
Fields
tolthe tolerance to verify againstat_iterationan internal field to indicate at which iteration $k ≥ 0$ the tolerance was met.
Constructor
StopWhenPopulationStronglyConcentrated(tol::Real)Technical details
The cma_es solver requires the following functions of a manifold to be available
- A
retract!(M, q, p, X); it is recommended to set thedefault_retraction_methodto a favorite retraction. If this default is set, aretraction_method=does not have to be specified. - A
vector_transport_to!(M, Y, p, X, q); it is recommended to set thedefault_vector_transport_methodto a favorite vector transport. If this default is set, avector_transport_method=does not have to be specified. - A
copyto!(M, q, p)andcopy(M,p)for points and similarlycopy(M, p, X)for tangent vectors. get_coordinates!(M, c, p, X, b)andget_vector!(M, X, p, c, b)with respect to theAbstractBasisbprovided, which isdefault_basis(M, typeof(p))by default from thebasis=keyword.- An
is_flat(M). - A
manifold_dimension(M), which determines the default population sizeλ=and the default stopping criterion. - Within the default initialization
rand(M)is used to generate the initial point, and the tangent vector buffers are initialized callingzero_vector(M,p).
Internal helpers
You may add new methods to eigenvector_transport! if you know a more optimized implementation for your manifold.
Manopt.eigenvector_transport! — Function
eigenvector_transport!(
M::AbstractManifold, matrix_eigen::Eigen, p, q,
basis::AbstractBasis, vtm::AbstractVectorTransportMethod,
)Transport the matrix with matrix_eigen eigen decomposition when expanded in basis from point p to point q on M. Update matrix_eigen in-place.
(p, matrix_eigen) belongs to the fiber bundle of $B = \mathcal{M} × \mathrm{SPD}(n)$, where n is the (real) dimension of M. The function corresponds to the Ehresmann connection defined by vector transport vtm of eigenvectors of matrix_eigen.
Literature
- [CFFS10]
- S. Colutto, F. Fruhauf, M. Fuchs and O. Scherzer. The CMA-ES on Riemannian Manifolds to Reconstruct Shapes in 3-D Voxel Images. IEEE Transactions on Evolutionary Computation 14, 227–245 (2010).
- [Han23]
- N. Hansen. The CMA Evolution Strategy: A Tutorial. ArXiv Preprint (2023).