Summarize Timeline Top Qs Fact Check
f
(
x
)
{\displaystyle f({\textbf {x}})}
の最小化を行う。
x
{\displaystyle {\textbf {x}}}
は n 次元のベクトル 。関数の引数は探索開始点。定数は一般的には
α
=
1
,
γ
=
2
,
ρ
=
1
/
2
,
σ
=
1
/
2
{\displaystyle \alpha =1,\gamma =2,\rho =1/2,\sigma =1/2}
を使用する。
e
i
{\displaystyle {\textbf {e}}_{i}}
は単位ベクトル。
function nelderMead(
x
1
{\displaystyle {\textbf {x}}_{1}}
) {
x
i
+
1
=
x
1
+
λ
e
i
for all i
∈
{
1
,
…
,
n
}
{\displaystyle {\textbf {x}}_{i+1}={\textbf {x}}_{1}+\lambda {\textbf {e}}_{i}{\text{ for all i }}\in \{1,\dots ,n\}}
while (所定のループ回数 や 値の改善が小さくなった) {
f
(
x
1
)
≤
f
(
x
2
)
≤
⋯
≤
f
(
x
n
+
1
)
{\displaystyle f({\textbf {x}}_{1})\leq f({\textbf {x}}_{2})\leq \cdots \leq f({\textbf {x}}_{n+1})}
となるようにソートする。
// 重心(
x
n
+
1
{\displaystyle {\textbf {x}}_{n+1}}
は除外)
x
0
=
1
n
∑
i
=
1
n
x
i
{\displaystyle {\textbf {x}}_{0}={\frac {1}{n}}\sum _{i=1}^{n}{\textbf {x}}_{i}}
x
r
=
x
o
+
α
(
x
o
−
x
n
+
1
)
{\displaystyle {\textbf {x}}_{r}={\textbf {x}}_{o}+\alpha ({\textbf {x}}_{o}-{\textbf {x}}_{n+1})}
if
(
f
(
x
1
)
≤
f
(
x
r
)
<
f
(
x
n
)
)
{\displaystyle (f({\textbf {x}}_{1})\leq f({\textbf {x}}_{r})<f({\textbf {x}}_{n}))}
{
// 反射
x
n
+
1
=
x
r
{\displaystyle {\textbf {x}}_{n+1}={\textbf {x}}_{r}}
} else if
(
f
(
x
r
)
<
f
(
x
1
)
)
{\displaystyle (f({\textbf {x}}_{r})<f({\textbf {x}}_{1}))}
{
// 膨張
x
e
=
x
o
+
γ
(
x
r
−
x
o
)
{\displaystyle {\textbf {x}}_{e}={\textbf {x}}_{o}+\gamma ({\textbf {x}}_{r}-{\textbf {x}}_{o})}
if
(
f
(
x
e
)
<
f
(
x
r
)
)
{\displaystyle (f({\textbf {x}}_{e})<f({\textbf {x}}_{r}))}
{
x
n
+
1
=
x
e
{\displaystyle {\textbf {x}}_{n+1}={\textbf {x}}_{e}}
} else {
x
n
+
1
=
x
r
{\displaystyle {\textbf {x}}_{n+1}={\textbf {x}}_{r}}
}
} else {
// 収縮
x
c
=
x
o
+
ρ
(
x
n
+
1
−
x
o
)
{\displaystyle {\textbf {x}}_{c}={\textbf {x}}_{o}+\rho ({\textbf {x}}_{n+1}-{\textbf {x}}_{o})}
if
(
f
(
x
c
)
<
f
(
x
n
+
1
)
)
{\displaystyle (f({\textbf {x}}_{c})<f({\textbf {x}}_{n+1}))}
{
x
n
+
1
=
x
c
{\displaystyle {\textbf {x}}_{n+1}={\textbf {x}}_{c}}
} else {
x
i
=
x
1
+
σ
(
x
i
−
x
1
)
for all i
∈
{
2
,
…
,
n
+
1
}
{\displaystyle {\textbf {x}}_{i}={\textbf {x}}_{1}+\sigma ({\textbf {x}}_{i}-{\textbf {x}}_{1}){\text{ for all i }}\in \{2,\dots ,n+1\}}
}
}
}
}