Nelder-Mead Simplex (NM)¶
NelderMead ¶
NelderMead(*, reflection=1.0, expansion=2.0, contraction=0.5, shrink=0.5, initial_step=0.1, restart_tol=1e-10, pop_size=None, **kwargs)
Nelder-Mead simplex method with restarts (Nelder and Mead 1965, Lagarias et al. 1998).
A local method for smooth problems with few variables. The simplex has d + 1 vertices,
where d is the number of codes, so pop_size is not used. It starts at a random
point x0, and vertex i is x0 with code i - 1 moved by initial_step (downward when
the move would pass 1).
Each iteration sorts the simplex. With x1 the best vertex, xn the second worst, x the worst and c the centroid of all vertices but x:
- Reflect: r = c + reflection * (c - x).
- If r is better than x1, expand: e = c + expansion * reflection * (c - x). Keep the better of e and r.
- Else if r is better than xn, keep r.
- Else if r is better than x, contract outside: o = c + contraction * reflection * (c - x). Keep o if it is at least as good as r, otherwise shrink.
- Else contract inside: i = c - contraction * (c - x). Keep i if it is better than x, otherwise shrink.
- Shrink: every vertex but x1 moves to x1 + shrink * (v - x1).
Trial points are clipped to [0, 1]. Comparisons follow the problem's rules, so
maximization and constraints work as usual. When the largest distance from x1 to
another vertex falls below restart_tol, the method restarts from a new random
point. The best solution is kept across restarts, so the whole budget is used.
Parameters
reflection,expansion,contraction,shrink: the coefficients rho, chi, gamma and sigma of Lagarias et al. (default 1, 2, 0.5, 0.5)initial_step: size of the initial simplex in code units (default 0.1)restart_tol: simplex size below which the method restarts (default 1e-10)
References: J. A. Nelder and R. Mead, "A simplex method for function minimization", The Computer Journal 7(4), 1965, 308 to 313. J. C. Lagarias, J. A. Reeds, M. H. Wright and P. E. Wright, "Convergence properties of the Nelder-Mead simplex method in low dimensions", SIAM Journal on Optimization 9(1), 1998, 112 to 147.
Example¶
import ypea
problem = ypea.Problem(
ypea.Real("x", shape=20, lb=-10, ub=10),
lambda sol: ypea.benchmarks.sphere(sol.x),
vectorized=True,
name="sphere",
)
alg = ypea.NelderMead(max_nfe=20_000)
result = alg.solve(problem, seed=1)
print(result.summary())
NM on sphere
best objective value: 1.92627e-17
feasible: True (violation 0)
evaluations: 20000, iterations: 15821, time: 5.96 s, stopped by: max_nfe
Differs from Python: MATLAB draws its own random numbers, so the best value differs from Python's.
problem = ypea.Problem( ...
vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
vectorized=true, ...
name="sphere");
alg = ypea.NelderMead(max_nfe=20000);
result = alg.solve(problem, seed=1);
disp(result.summary())
NM on sphere
best objective value: 3.38126e-17
feasible: true (violation 0)
evaluations: 20000, iterations: 15781, time: 4.49 s, stopped by: max_nfe
Search on Rastrigin¶