Skip to content

Commit

Permalink
poorly conditioned test case and some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Mar 31, 2024
1 parent bd800bb commit 236be24
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
7 changes: 5 additions & 2 deletions docs/src/solvers/cma_es.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Particle swarm optimization
# Covariance matrix adaptation evolutionary strategy

```@meta
CurrentModule = Manopt
Expand All @@ -19,11 +19,14 @@ CMAESState

```@docs
CMAESConditionCov
StagnationCondition
TolXCondition
TolXUpCondition
```

## Literature

```@bibliography
Pages = ["particle_swarm.md"]
Pages = ["cma_es.md"]
Canonical=false
```
36 changes: 24 additions & 12 deletions src/solvers/cma_es.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,18 @@ function cma_es(M::AbstractManifold, f, p_m=rand(M); kwargs...)
return cma_es(M, mco, p_m; kwargs...)
end

function default_cma_es_stopping_criterion(M::AbstractManifold, λ::Int)
function default_cma_es_stopping_criterion(
M::AbstractManifold, λ::Int; tol_fun::TParam=1e-12, tol_x::TParam=1e-12
) where {TParam<:Real}
return StopAfterIteration(50000) |
CMAESConditionCov() |
EqualFunValuesCondition{Float64}(
Int(10 + ceil(30 * manifold_dimension(M) / λ))
) |
EqualFunValuesCondition{TParam}(Int(10 + ceil(30 * manifold_dimension(M) / λ))) |
StagnationCondition(
Int(120 + 30 * ceil(30 * manifold_dimension(M) / λ)), 20000, 0.3
) |
TolXUpCondition(1e4) |
TolFunCondition(1e-12, Int(10 + ceil(30 * manifold_dimension(M) / λ))) |
TolXCondition(1e-12)
TolFunCondition(tol_fun, Int(10 + ceil(30 * manifold_dimension(M) / λ))) |
TolXCondition(tol_x)
end

@doc raw"""
Expand All @@ -208,11 +208,19 @@ setting.
# Input
* `M` a manifold ``\mathcal M``
* `f` a cost function ``f: \mathcal M→ℝ`` to find a minimizer ``p^*`` for
* `p_m` an initial point `p`
* `σ` initial standard deviation
* `λ` population size (can be increased for a more thorough search)
* `M`: a manifold ``\mathcal M``
* `f`: a cost function ``f: \mathcal M→ℝ`` to find a minimizer ``p^*`` for
# Optional
* `p_m`: (`rand(M)`) an initial point `p`
* `σ` (`1.0`) initial standard deviation
* `λ` (`4 + Int(floor(3 * log(manifold_dimension(M))))`population size (can be
increased for a more thorough search)
* `tol_fun` (`1e-12`) tolerance for the `TolFunCondition`, similar to absolute difference
between function values at subsequent points
* `tol_x` (`1e-12`) tolerance for the `TolXCondition`, similar to absolute difference
between subsequent point but actually computed from distribution parameters.
# Output
Expand All @@ -225,7 +233,11 @@ function cma_es(
p_m=rand(M);
σ::Real=1.0,
λ::Int=4 + Int(floor(3 * log(manifold_dimension(M)))), # Eq. (48)
stopping_criterion::StoppingCriterion=default_cma_es_stopping_criterion(M, λ),
tol_fun::Real=1e-12,
tol_x::Real=1e-12,
stopping_criterion::StoppingCriterion=default_cma_es_stopping_criterion(
M, λ; tol_fun=tol_fun, tol_x=tol_x
),
retraction_method::AbstractRetractionMethod=default_retraction_method(M, typeof(p_m)),
vector_transport_method::AbstractVectorTransportMethod=default_vector_transport_method(
M, typeof(p_m)
Expand Down
17 changes: 17 additions & 0 deletions test/solvers/test_cma_es.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function divergent_example(::AbstractManifold, p)
return -norm(p)
end

function poorly_conditioned_example(::AbstractManifold, p)
return p' * [1e12 0; 0 -1e-6] * p
end

@testset "CMA-ES" begin
@testset "Euclidean CMA-ES" begin
M = Euclidean(2)
Expand All @@ -42,6 +46,19 @@ end
return_state=true,
)
@test only(get_active_stopping_criteria(o_d.stop)) isa Manopt.TolXUpCondition

o_d = cma_es(
M,
poorly_conditioned_example,
[10.0, 10.0];
σ=10.0,
rng=MersenneTwister(123),
return_state=true,
)
condcov_sc = only(get_active_stopping_criteria(o_d.stop))
@test condcov_sc isa Manopt.CMAESConditionCov
@test !Manopt.indicates_convergence(condcov_sc)
@test startswith(repr(condcov_sc), "CMAESConditionCov(")
end
@testset "Spherical CMA-ES" begin
M = Sphere(2)
Expand Down

0 comments on commit 236be24

Please sign in to comment.