2.1 求解梯度的兩種方法
以$f(x,y)={{x}^{2}}+{{y}^{3}}$為例,很容易得到:
$\nabla f=\left[ \begin{aligned}& \frac{\partial f}{\partial x} \\& \frac{\partial f}{\partial y} \\\end{aligned} \right]=\left[ \begin{aligned}& 2x \\& 3{{y}^{2}} \\\end{aligned} \right]$
這樣就很容易求得某一點的梯度。
但是如果梯度的表達式很難寫出來,或者根本就寫不出來的時候,尤其定義去求梯度可是可以的:
$\nabla f=\left[ \begin{aligned}& \frac{\partial f}{\partial x} \\& \frac{\partial f}{\partial y} \\\end{aligned} \right]=\left[ \begin{aligned}& \frac{f(x+\Delta x,y)-f(x,y)}{\Delta x} \\& \frac{f(x,y+\Delta y)-f(x,y)}{\Delta y} \\\end{aligned} \right]$
在實際算的過程中這里的$\Delta x$,$\Delta y$也不用取太小一般$1\times {{10}^{-7}}$左右就可以了。
2.2 某些有約束優化問題可以轉化為無約束優化問題:
\[\begin{aligned}& \operatorname{minimize}\text{ }f({{x}_{1}},{{x}_{2}})\text{ }\operatorname{minimize}\text{ }f({{x}_{1}},{{x}_{2}}) \\& \text{ }{{x}_{1}}>0\text{ }\Rightarrow \text{ }{{x}_{1}}={{{\hat{x}}}^{2}}_{1} \\& \text{ }{{x}_{2}}\le -30\text{ }-\text{30}-{{x}_{2}}\text{=}{{{\hat{x}}}^{2}}_{2}\text{ }\Rightarrow -\text{30}-{{{\hat{x}}}^{2}}_{2}\text{=}{{x}_{2}} \\\end{aligned}\]
把上式中左邊的不等式優化,轉化為右邊的等式優化,再把等式代入目標函數中,形成了式(24)這樣的無約束優化問題:
\[\operatorname{minimize}\text{ }f({{\hat{x}}_{1}},{{\hat{x}}_{2}})\]
通過優化求解得到滿足上式的次優解$\left( {{{{\hat{x}}'}}_{1}},{{{{\hat{x}}'}}_{2}} \right)$,則原優化問題的解可以寫為:
\[\begin{aligned}& \text{ }{{x}_{1}}={{\left( {{{{\hat{x}}'}}_{\text{1}}} \right)}^{\text{2}}} \\& {{x}_{2}}\text{=}-\text{30}-{{\left( {{{{\hat{x}}'}}_{2}} \right)}^{\text{2}}} \\\end{aligned}\]
這樣的做法會增加目標函數的非線性度,但是很好的把有約束問題轉變為無約束問題。下面這個帶約束的優化問題同樣可以用上述方式處理:
\[\begin{aligned}& \operatorname{minimize}\text{ }f({{x}_{1}},{{x}_{2}})\text{ }\operatorname{minimize}\text{ }f({{x}_{1}},{{x}_{2}}) \\ & \text{ 3}\le {{x}_{1}}\le 12\text{ }\Rightarrow \text{ } \\\end{aligned}\]
這里的轉化,我想着用Sigmoid函數(logistic函數):
$f\left( x \right)=\frac{1}{1+{{e}^{-x}}}$
它的圖像如下:
這樣就可以用下面這個式子代替上述對${{x}_{1}}$的約束:
${{x}_{1}}=\frac{9}{1+{{e}^{-\hat{x}}}}+3$
它的圖像如下