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 graphic使用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()
|
授權條款
[編輯]我,本作品的著作權持有者,決定用以下授權條款發佈本作品:
此檔案採用創用CC 姓名標示-相同方式分享 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 的使用狀況