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..d52840609 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 haskey(KW, :a) || haskey(KW, :g) || haskey(KW, :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 haskey(KW, :initial_simplex) || haskey(KW, :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) diff --git a/test/nelder_mead.jl b/test/nelder_mead.jl index 02cf01b25..13dd86e68 100644 --- a/test/nelder_mead.jl +++ b/test/nelder_mead.jl @@ -11,3 +11,14 @@ let @assert norm(res.minimum - prob.solutions) < 1e-2 end end + + +# Test that deprecated syntax runs +let + dep_prob = Optim.UnconstrainedProblems.examples["Rosenbrock"] + optimize(dep_prob.f, dep_prob.initial_x, NelderMead(a = 1.0)) + optimize(dep_prob.f, dep_prob.initial_x, NelderMead(g = 2.0)) + optimize(dep_prob.f, dep_prob.initial_x, NelderMead(b = 0.5)) + optimize(dep_prob.f, dep_prob.initial_x, NelderMead(initial_simplex = Optim.AffineSimplexer())) + optimize(dep_prob.f, dep_prob.initial_x, NelderMead(parameters = Optim.AdaptiveParameters())) +end