The Nelder-Mead Algorithm in Two Dimensions

本文介绍了Nelder-Mead算法的一个迭代步骤。首先对顶点进行排序,然后反射最差的点并通过比较成本来确定是否扩展或收缩。该算法适用于不需要导数的优化问题。

http://people.duke.edu/~hpgavin/cee201/Nelder-Mead-2D.pdf




Steps for one iteration of the Nelder-Mead Algorithm


1. Sort the vertices such that f(u) < f(v) < f(w). Point u is the best point, point v is the  next-to-worst point, and point w is the worst point.


2. Reflect the worst point, w, through the centroid of the remaining points (u and v) to obtain  the reflected point, r, and evaluate f(r).


If the cost at the reflected point, f(r), is between the best and next-to-worst cost (f(u) <f(r) < f(v)) then replace the worst point, w, with the reflected point, r, and go to step 5


3. If the cost at the reflected point, f(r), is better than f(u) (f(r) < f(u)) then extend the  reflected point, r, further past the average of u and v, to point e, and evaluate f(e).


(a) If the cost at the extended point, f(e), is better than the reflected point cost, f(r), then  replace the worst point, w, with the extended point, e, and go to step 5.


(b) Otherwise replace the worst point, w with the reflected point, r, and go to step 5.


4. If the inequalities of steps 2 and 3 are not satisfied, then it is certain that the reflected point, r, is worse than the next-to-worst point, v, (f(r) > f(v)) and, a smaller value of f might be  found between points w and r. So try to contract the worst point, w, to a point c between  w and r, and evaluate f(w). The best distance along the line from w to r can be hard to  

determine, and, in general, it is not worth trying too hard to find this minimum. Typicalvalues of c are one-quarter and three-quarters of the way from w to r. These are called insideand outside contraction points, ci and co.

    


### Nelder-Mead 单纯形算法解释 Nelder-Mead 方法是一种用于多维无约束优化的技术,尤其适用于那些导数难以计算的情况。该方法通过迭代调整一组点构成的几何图形——单纯形来寻找函数极小值[^1]。 #### 算法基本流程 在一个 n 维空间中,单纯形由 \(n+1\) 个顶点组成。对于每个新的迭代周期: - 计算当前单纯形各顶点处的目标函数值 - 找到目标函数值最大 (最差) 的顶点以及最小(最优) 和次优者 - 对最差点执行反射操作;如果反射成功,则可能进一步尝试扩展;反之则考虑收缩或缩小整个单纯形规模 此过程不断重复直到满足收敛条件为止。 ```python import numpy as np def nelder_mead(f, initial_simplex, alpha=1., gamma=2., rho=-0.5, sigma=0.5, tol=1e-8, maxiter=None): n = len(initial_simplex[0]) if not maxiter: maxiter = 200 * n for k in range(maxiter): # Order according to the values at vertices of the simplex. x = sorted(initial_simplex, key=lambda xi: f(xi)) x_0 = x[0] x_n = x[-1] # Compute centroid excluding worst point x_bar = sum([xi for xi in x[:-1]]) / n # Reflection step xr = x_bar + alpha*(x_bar - x_n) if f(xr) >= f(x[0]) and f(xr) < f(x[-2]): xt = xr.copy() elif f(xr) < f(x[0]): xe = x_bar + gamma*(xr - x_bar) if f(xe) < f(xr): xt = xe.copy() else: xt = xr.copy() else: xc = x_bar + rho*(x_n-x_bar) if f(xc) < f(x_n): xt = xc.copy() else: shrinkage_points = [] for i in range(len(x)): xs = x[i][0]+sigma*(np.array(x[i])-x[i][0]) shrinkage_points.append(xs.tolist()) x = shrinkage_points[:] continue # Replace the worst vertex with a better one found during this iteration x[-1] = xt[:] # Check convergence based on function value differences between points if all(abs(f(xi)-f(xj))<tol for xi in x for xj in x): break return min((fi := [f(vi) for vi in v]), key=abs), fi.index(min(fi)), x[min_index] initial_simplex = [[0], [1]] result = nelder_mead(lambda x: pow(x[0]-3, 2)+pow(x[0]-2, 4), initial_simplex) print(result) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值