nelder_mead¶
Simplex method for derivative-free optimization. Explores using a simplex (triangle in 2D) that reflects, expands, contracts around the optimum.
Signature¶
def nelder_mead(
objective_fn: Callable[[Sequence[float]], float],
x0: Sequence[float],
*,
max_iter: int = 10_000,
tol: float = 1e-8,
on_progress: Callable[[Progress], bool | None] | None = None,
progress_interval: int = 0,
) -> Result[list[float]]
Example¶
from solvor import nelder_mead
def objective(x):
return (x[0] - 2)**2 + (x[1] + 1)**2
result = nelder_mead(objective, x0=[0.0, 0.0])
print(result.solution) # Close to [2, -1]
When to Use¶
- No gradients available
- Noisy or non-smooth objectives
- "I have no idea what this function looks like"
How It Works¶
- Start with simplex of n+1 points
- Order by objective value
- Reflect worst point through centroid
- If better, try expanding further
- If worse, try contracting
- Repeat until convergence
Tips¶
- Works in low dimensions. Performance degrades above ~20D.
- No gradients needed. Pure function evaluation.
- Can escape local minima. But not guaranteed.
See Also¶
- Powell - Another derivative-free method
- Bayesian Optimization - When evaluations are expensive