Skip to content

Commit

Permalink
Deprecate NelderMead better.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkofod committed Aug 13, 2016
1 parent 32d6b37 commit 276c98d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/deprecate.jl
Original file line number Diff line number Diff line change
@@ -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))
19 changes: 18 additions & 1 deletion src/nelder_mead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/nelder_mead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 276c98d

Please sign in to comment.