File:Nelder-Mead Simionescu.gif
来自Wikimedia Commons
跳转到导航
跳转到搜索
本预览的尺寸:600 × 600像素。 其他分辨率:240 × 240像素 | 480 × 480像素 | 1,000 × 1,000像素。
原始文件 (1,000 × 1,000像素,文件大小:1.31 MB,MIME类型:image/gif、循环、25帧、13秒)
文件信息
结构化数据
说明
摘要
[编辑]描述Nelder-Mead Simionescu.gif |
English: Animated Nelder-Mead minimum search of Simionescu's function. |
日期 | |
来源 | 自己的作品 |
作者 | nicoguaro |
GIF开发 InfoField | 本GIF 位图使用Matplotlib创作。 |
原始码 InfoField | Python codefrom numpy import cos, arctan2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
plt.rcParams["font.size"] = 10
plt.rcParams["mathtext.fontset"] = "cm"
# Minimization
def nelder_mead_step(fun, verts, alpha=1, gamma=2, rho=0.5,
sigma=0.5, beta=1.0):
"""Nelder-Mead iteration according to Wikipedia _[1]
References
----------
.. [1] Wikipedia contributors. "Nelder–Mead method." Wikipedia,
The Free Encyclopedia. Wikipedia, The Free Encyclopedia,
1 Sep. 2016. Web. 20 Sep. 2016.
"""
nverts, _ = verts.shape
f = np.apply_along_axis(fun, 1, verts, beta=beta)
# 1. Order
order = np.argsort(f)
verts = verts[order, :]
f = f[order]
# 2. Calculate xo, the centroid"
xo = verts[:-1, :].mean(axis=0)
# 3. Reflection
xr = xo + alpha*(xo - verts[-1, :])
fr = fun(xr, beta)
if f[0]<=fr and fr<f[-2]:
new_verts = np.vstack((verts[:-1, :], xr))
# 4. Expansion
elif fr<f[0]:
xe = xo + gamma*(xr - xo)
fe = fun(xe, beta)
if fe < fr:
new_verts = np.vstack((verts[:-1, :], xe))
else:
new_verts = np.vstack((verts[:-1, :], xe))
# 5. Contraction
else:
xc = xo + rho*(verts[-1, :] - xo)
fc = fun(xc, beta)
if fc < f[-1]:
new_verts = np.vstack((verts[:-1, :], xc))
# 6. Shrink
else:
new_verts = np.zeros_like(verts)
new_verts[0, :] = verts[0, :]
for k in range(1, nverts):
new_verts[k, :] = sigma*(verts[k,:] - verts[0,:])
return new_verts
def fun(x, beta=1.0):
"""Simionescu function using log-barrier method"""
x1, x2 = x
if x1**2 + x2**2 < (1 + 0.2*cos(8*arctan2(x1, x2)))**2:
barrier = -beta*np.log((1 + 0.2*cos(8*arctan2(x1, x2)))**2 - x1**2 - x2**2)
else:
barrier = np.inf
return x1*x2 + barrier
# Animation
def data_gen(num):
plt.gca().cla
x0 = np.array([0.4, -0.6])
x1 = np.array([-0.3, -0.6])
x2 = np.array([0.7, 0.6])
verts = np.vstack((x0, x1, x2))
beta = 1.0
for cont in range(num):
verts = nelder_mead_step(fun, verts, beta=beta)
beta /=2
# Plots
plt.cla()
poly = plt.Polygon(verts, facecolor="none", edgecolor="k",
linewidth=0.5, zorder=4)
plt.gca().add_patch(poly)
x1, x2 = np.mgrid[-1.25:1.25:101j, -1.25:1.25:101j]
z = x1*x2
cons = x1**2 + x2**2 - (1 + 0.2*cos(8*arctan2(x1, x2)))**2
z[cons > 0.02] = np.nan
levels = np.linspace(-1, 1, 30)
plt.contour(x1, x2, z, levels, cmap="seismic", linewidths=1)
plt.contour(x1, x2, cons, [0], colors="black", linewidths=1)
plt.axis("image")
plt.xlabel(r"$x$", fontsize=14)
plt.ylabel(r"$y$", fontsize=14)
fig = plt.figure(figsize=(5, 5))
ani = animation.FuncAnimation(fig, data_gen, range(25))
ani.save("Nelder-Mead_Simionescu.gif", writer='imagemagick', fps=2,
dpi=200)
plt.show()
|
许可协议
[编辑]我,本作品著作权人,特此采用以下许可协议发表本作品:
本文件采用知识共享署名-相同方式共享 4.0 国际许可协议授权。
- 您可以自由地:
- 共享 – 复制、发行并传播本作品
- 修改 – 改编作品
- 惟须遵守下列条件:
- 署名 – 您必须对作品进行署名,提供授权条款的链接,并说明是否对原始内容进行了更改。您可以用任何合理的方式来署名,但不得以任何方式表明许可人认可您或您的使用。
- 相同方式共享 – 如果您再混合、转换或者基于本作品进行创作,您必须以与原先许可协议相同或相兼容的许可协议分发您贡献的作品。
文件历史
点击某个日期/时间查看对应时刻的文件。
日期/时间 | 缩略图 | 大小 | 用户 | 备注 | |
---|---|---|---|---|---|
当前 | 2018年6月26日 (二) 19:47 | 1,000 × 1,000(1.31 MB) | Nicoguaro(留言 | 贡献) | Improve line widths | |
2016年11月22日 (二) 17:36 | 750 × 698(30 KB) | Pasimi(留言 | 贡献) | User created page with UploadWizard |
您不可以覆盖此文件。
文件用途
没有页面使用本文件。
全域文件用途
以下其他wiki使用此文件:
- ba.wikipedia.org上的用途
- el.wikipedia.org上的用途
- en.wikipedia.org上的用途
- fa.wikipedia.org上的用途
- id.wikipedia.org上的用途
- mk.wikipedia.org上的用途
- pt.wikipedia.org上的用途
- ru.wikipedia.org上的用途
- sr.wikipedia.org上的用途
- uk.wikipedia.org上的用途
- zh.wikipedia.org上的用途