### Poor conditioning

Conditioning measures how rapidly the output changed with tiny changes in input.

For example, in a linear equation, we can use the inverse matrix $A^{-1}$ to solve $x$.

Nevertheless it is not commonly done in machine learning because $A^{-1}$ is slow to compute, and worse, $A^{-1}$ may amplify input errors rapidly.

For the function:

Condition number is defined as:

Poorly conditioned matrix $A$ is a matrix with a high condition number. $A^{-1}$ amplifies input errors. Small errors in $x$ can change the output of $A^{-1} x$ rapidly .

Other methods including matrix factorization can replace the matrix inversion method to avoid the poor conditioning to improve the numerical stability.

### Underflow or overflow

Softmax functions:

$e^x$ can be very large or very small. To avoid overflow or underflow, we can transform $x_j$ with $\max(x)$:

Proof:

Example:

### Hessian matrix

The first derivative measures the gradient and the second derivative measures the curvature.

When $% $, $f(x)$ curves down and when $f''(x)>0$, $f(x)$ curves up.

The second derivative indicates whether a gradient step drops the cost as much as the gradient alone may imply. For example, at $x=1.0$ (the orange dot on the right below), the gradient is positive and the cost drops towards $x=0$ direction. Since the second derivative is positive, the function curves upwards towards zero. i.e. the cost drops less than one predicted by the gradient alone.

With the second derivative, we may take advantage of the curvature information to create a better gradient descent method to reduce overshoot. For example, instead of descending to a local minimum from $L_1$, we may overshoot to $L_2$ in the left diagram below. In some NLP problem, the gradient is so steep that we may bound upward to much higher cost.

Hessian matrix is defined as:

#### Eigenvalues for H

$H$ is symmetrical:

And it is real. Any real symmetrical matrices can be decomposed into eigenvalues and eigenvectors. One more observation for the later use: the maximum value of $g^T H g$ for vector $v$ happens when $v$ aligns with the eigenvector that has the maximum eigenvalue $\lambda_{\max}$, i.e.

#### Learning rate

With Taylor series in 2nd order:

If $g^T H g$ is negative or 0, $f(x)$ decreases as $ϵ$ increases. However, we cannot drop $ϵ$ too far as the accuracy of the Taylor series drops as $ϵ$ increases. If $g^T H g$ is positive, it may cause $f(x)$ to go up again. The optimal step for $\epsilon$ is (assume $\epsilon>0$):

$\lambda_{\max}$ is the maximum eigenvalue for $H$. Hence, Hessian matrix $H$ establishes a lower bound of the optimal learning rate.

If the Hessian matrix has a poor condition number, the gradient along the eigenvector with the largest eigenvalue $\lambda_{\max}$ is much smaller than the one with the smallest eigenvalue. Gradient descent methods work poorly if the gradients in different directions are in different order of magnitude. The gradient descent methods will either learn too slow in the low gradient direction and/or overshoot the solution in the high gradient direction. We may use Newton’s method to control the gradient descent better.

#### Newton’s Method

With Newton’s method:

To find the critical point, we set $\frac{ df(x)}{d\Delta{x}} =0$:

Apply:

Extend it to multiple variables with $H$:

Apply the gradient descent with Newton’s method:

$f'(x)=0$ alone cannot tell whether $x$ is a local optimal point or a saddle point. With the second derivative test, when $f'(x)=0$ and $f''(x)>0$, $x$ is a local minimum. When $f'(x)=0$ and $% $, $x$ is a local maximum. However, if $f''(x)=0$, it will be in-conclusive (saddle point or local optimal point).

For multiple dimension, when $H$ is positive definite (all the eigenvalues are positive), $x$ is a local minimum. If $H$ is negative definite, $x$ is a local maximum. If at least one eigenvalue is positive and at least one is negative, the point is a saddle point because one direction is a local minimum and the other direction is a local maximum. If at least one eigenvalue is zero and the rest have the same sign, it will be in-conclusive again.

### Constrained Optimization

In deep learning, we may want to find an optimal point under certain constraints. For example, we want to maximize $f(x, y)$ subject to $g(x, y) = 0$. We will construct a new Lagrangian function $\mathcal{L}(x, \lambda)$ from $f$ and $g$ which the original optimal solution is the same as the optimal solution for the Lagrangian function. i.e. $\mathcal{L}^{'}(x, \lambda) = 0$.

#### Lagrange multiplier

To maximize $f(x, y)$ subject to $g(x, y) = 0$, we plot the contour plot of $f(x, y) = d_i$ for different $d_i$ ($d_1 > d_2 > d_3$). The solution lies on the red line with the largest $d_i$.

(Source Wikipedia)

Geometrically, the optimal point lies where the gradient at $f(x, y)$, the blue arrow, aligned with the gradient at $g(x, y)$, the red arrow.

i.e.

where $\lambda$ is the Lagrange multiplier and it can be positive or negative. We can now solve a constrained optimization problem using unconstrained optimization of the generalized Lagrangian.

We can have multiple constraints ($g^1, g^2 \ldots g^i$). ie. we want to maximize $f(x,y)$ subject to $g^1(x,y)=0, \ldots, g^i(x,y)=0$. The Lagrangian is generalized as:

And the optimal solution is

#### Example

Maximize $f$ subject to $x^2 + y^2 = 32$

The Lagrangian is:

To optimize $\mathcal{L}$, we need to solve:

Therefore:

By simply plugin the values, we can determine which one is the max or min.

#### Karush–Kuhn–Tucker (KKT)

KKT expands the constraints in the Lagrange multiplier to inequality also:

The Lagrangian is generalized to:

or

#### KKT conditions

The required KKT conditions to solve the optimization problems are:

and the solution needs to be verified with the constraints again.

Let’s go through the meaning of each KKT conditions. Same as Lagrange multiplier, the optimal points happen when the derivative $\mathcal{L}^{'}=0$, i.e.

In the Lagrange multiplier, $\lambda$ can be positive, negative or zero. In KKT. $\alpha$ must be greater or equal to 0. This guarantees the in-equality such that the solution is within the constrained area.

For

it indicates either the KKT multiplier $\alpha_i=0$ or the $h(x^{∗})=0$. If $\alpha_i=0$, we do not care about the constraint. The in-equality constrain is not necessary like the diagram below because the optimal point is guarantee to be inside the constrained area. We can simply ignore the constraint.

Otherwise, the in-equality constrain becomes the equality constraint $h(x^{*})=0$.

### Terms

We sample the outputs of a few small $\epsilon$ values and select $x \rightarrow x - \epsilon \nabla_{x} f(x)$ that output the best optimal value.