The Nelder-Mead Algorithm

Learn to implement the Nelder-Mead algorithm, which is a heuristic-based optimization algorithm.

What is the Nelder-Mead algorithm?

Different from random and grid search, the Nelder-Mead algorithm is a heuristic-based optimization that uses several heuristics to minimize the number of iterations required to reach the optimal solution. The algorithm has several names, like the downhill simplex method, amoeba method, and polytope. It is based on a simplex, which is a shape with n+1n+1 vertices in an nn-dimensional space—for example, a triangle represents a simplex in 2D space and a tetrahedron represents a simplex in 3D space.

At any point in time, the Nelder-Mead algorithm maintains a set of n+1n+1 points in an nn-dimensional space, i.e., a simplex. It then evaluates the objective on each of the vertices of the simplex (polytope) and updates the worst vertex with a newer one, resulting in a shrunk simplex. This process is repeated until some desired bound is obtained.

Let’s take searching for a house as an example, where the objective function f(x)f(x) returns the price of a candidate house xx in a town. The task is to find the most competitive house (in terms of pricing) in the whole town. The Nelder-Mead algorithm will start with the three initial points (or house candidates) uu, vv, and ww, forming a simplex in a 2D space. Here are the steps to complete this process:

  1. Ordering the points: We order uu, vv, and ww according to their objective values (house prices). For example, if f(u)f(v)f(w)f(u) \leq f(v) \leq f(w), we will call uu as the best point, vv as the second-best point, and ww as the worst point. In other words, the method evaluates the cost function at each house and orders them from the lowest to the highest cost. The house with the lowest cost is called the best point, and the house with the highest cost is called the worst point.

Get hands-on with 1400+ tech skills courses.