Optimization
Table of Contents
%%html
<center><iframe src="https://www.youtube.com/embed/AjEGqE9UOvo?rel=0"
width="560" height="315" frameborder="0" allowfullscreen></iframe></center>
3 key components
Procedures
In mathematical expression
$$\begin{align*}
\min_{x} \quad &f(x) \\
\text{subject to} \quad &g_i(x) \leq 0, \qquad i=1,\cdots,m
\end{align*}
$$
$\;\;\; $where
Remarks) equivalent
Generalization for multivariate function $f:\mathbb{R}^n \rightarrow \ \mathbb{R}$
$$
x = \begin{bmatrix}
x_1 \\
x_2 \\
\vdots \\
x_n
\end{bmatrix} \quad \quad \quad \quad \nabla _x f(x) = \begin{bmatrix}
\partial f(x) \over \partial x_1 \\
\vdots\\
\partial f(x) \over \partial x_n
\end{bmatrix}
$$
Direct solution
$$
\begin{align*}
f(x) &= 2x_1^2+ x_2^2 + x_1 x_2 -6 x_1 -5 x_2\\\\
\Longrightarrow \nabla _x f(x) &= \begin{bmatrix}
4x_1+x_2-6\\
2x_2 + x_1 -5
\end{bmatrix} = \begin{bmatrix}0\\0 \end{bmatrix}\\\\
\therefore x^* &= \begin{bmatrix}
4 & 1\\
1 & 2
\end{bmatrix} ^{-1} \begin{bmatrix}
6 \\ 5\\
\end{bmatrix} = \begin{bmatrix}
1 \\ 2\\
\end{bmatrix}
\end{align*}
$$
Exampels
Note: Revisit Least-Square Solution of $J(x) = \lVert Ax - y \rVert ^2$
$$
\begin{align*}
J(x) &= (Ax-y)^T(Ax-y)\\
&=(x^TA^T - y^T)(Ax - y)\\
&=x^TA^TAx - x^TA^Ty - y^TAx + y^Ty\\\\
\frac{\partial J}{\partial x} &= A^TAx + (A^TA)^Tx - A^Ty - (y^TA)^T
\\
&=A^TAx - 2A^Ty = 0\\\\
&\Rightarrow (A^TA)x = A^Ty\\\\
\therefore x^* &= (A^TA)^{-1}A^Ty
\end{align*}
$$
Iterative methods
$$ x \leftarrow x - \alpha \nabla _x f(x) \quad \quad \text{for some step size } \alpha > 0$$
$\qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \quad \qquad \qquad \bullet \, \text{Random initialization}$
$\qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \quad \qquad \qquad \bullet \, \text{Multiple trials}$
Example
$$
\begin{align*}
\min& \quad (x_1-3)^{2} + (x_2-3)^{2}\\\\
=\min& \quad \frac{1}{2} \begin{bmatrix} x_1 & x_2 \end{bmatrix}
\begin{bmatrix} 2 & 0 \\ 0 & 2 \end{bmatrix}
\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} -
\begin{bmatrix} 6 & 6 \end{bmatrix}
\begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + 18
\end{align*}
$$
import numpy as np
x = np.zeros((2,1))
print(x)
H = np.matrix([[2, 0],[0, 2]])
g = -np.matrix([[6],[6]])
x = np.zeros((2,1))
alpha = 0.1
for i in range(10):
df = H*x + g
x = x - alpha*df
print(x)
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')