From 7b0207ced36123844791bb8dd905b5cb8671d60b Mon Sep 17 00:00:00 2001 From: Patrick Kofod Mogensen Date: Fri, 12 Aug 2016 15:46:07 +0200 Subject: [PATCH] Deprecate NelderMead better. --- src/deprecate.jl | 2 +- src/nelder_mead.jl | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/deprecate.jl b/src/deprecate.jl index 4d68717a0..6a0fd4efc 100644 --- a/src/deprecate.jl +++ b/src/deprecate.jl @@ -1 +1 @@ -@deprecate NelderMead(a::Real, g::Real, b::Real) NelderMead(parameters = FixedParameters(a, g, b, 0.5)) +@deprecate NelderMead(a::Real, g::Real, b::Real) NelderMead(initial_simplex = AffineSimplexer(), parameters = FixedParameters(a, g, b, 0.5)) diff --git a/src/nelder_mead.jl b/src/nelder_mead.jl index a7d6bc40c..147745409 100644 --- a/src/nelder_mead.jl +++ b/src/nelder_mead.jl @@ -43,7 +43,24 @@ immutable NelderMead{Ts <: Simplexer, Tp <: NMParameters} <: Optimizer parameters::Tp end -NelderMead(; initial_simplex = AffineSimplexer(), parameters = AdaptiveParameters()) = NelderMead(initial_simplex, parameters) + +function NelderMead(; kwargs...) + KW = Dict(kwargs) + if any(haskey(KW, k) for k in (:a,:g,:b)) + a, g, b = 1.0, 2.0, 0.5 + haskey(KW, :a) && (a = KW[:a]) + haskey(KW, :g) && (g = KW[:g]) + haskey(KW, :b) && (b = KW[:b]) + return NelderMead(a, g, b) + elseif any(haskey(KW, k) for k in (:initial_simplex, :parameters)) + initial_simplex, parameters = AffineSimplexer(), AdaptiveParameters() + haskey(KW, :initial_simplex) && (initial_simplex = KW[:initial_simplex]) + haskey(KW, :parameters) && (parameters = KW[:parameters]) + return NelderMead(initial_simplex, parameters) + else + return NelderMead(AffineSimplexer(), AdaptiveParameters()) + end +end # centroid except h-th vertex function centroid!{T}(c::Array{T}, simplex, h=0)