Author: Akash Ajagekar (SYSEN 6800 Fall 2021)

## Theory

Adam is a combination of two gradient descent methods which are explained below,

### Momentum:

This is a optimization algorithm which takes into consideration the 'exponentially weighted average' and accelerates the gradient descent. It is an extension of gradient descent optimization algorithm.

The Momentum algorithm is solved in two parts. First is to calculate the change to position and second one is to update the old position with the updated position. The change in position is given by,

update = α * m_t

The new position or weights at time t is given by,

w_t+1 = w_t - update

Here in the above equation α(Step Size) is the Hyperparameter which controls the movement in the search space which is also called as learning rate. And, f'(x) is the derivative function or aggregate of gradients at time t.

where,

m_t = β * m_t - 1 + (1 - β) * (∂L / ∂w_t)

In the above equations m_t and m_t-1 are aggregate of gradients at time t and aggregate of gradient at time t-1.

According to [2] Momentum has the effect of dampening down the change in the gradient and, in turn, the step size with each new point in the search space.

### Root Mean Square Propagation (RMSP):

It s given by,

w_t+1 = w_t - (αt / (vt + e) ^ 1/2) * (∂L / ∂w_t)

where,

vt = βvt - 1 + (1 - β) * (∂L / ∂w_t) ^ 2

Here,

Aggregate of gradient at t = m_t

Aggregate of gradient at t - 1 = m_t - 1

Weights at time t = w_t

Weights at time t + 1 = w_t + 1

αt = learning rate(Hyperparameter)

∂L = derivative of loss function

∂w_t = derivative of weights at t

β = Average parameter

e = constant

But as we know these two optimizers explained below have some problems such as generalizing performance. The article [3] tells us that Adam takes over the attributes of the above two optimizers and build upon them to give more optimized gradient descent.

## Algorithm

Taking the equations used in the above two optimizers

m_t = β1 * m_t - 1 + (1 - β1) * (∂L / ∂w_t) and vt = β2vt - 1 + (1 - β2) * (∂L / ∂w_t) ^ 2

Initially both mt and vt are set to 0. Both tend to be more biased towards ) as β1 and β2 are equal to 1. By computing bias corrected m_t and vt, this problem is corrected by the Adam optimizer. The equations are as follows,

m'_t = m_t / (1 - β1 ^ t)

v't = vt / (1 - β2 ^ t)

Now as we are getting used to gradient descent after every iteration and hence it remains controlled and unbiased. Now substitute the new parameters in place of the old ones. We get,

w_t+1 = w_t - m'_t ( α / v't^1/2 + e)

## Performance

Adam optimizer gives much more higher performance results than the other optimizers and outperforms by a big margin for a better optimized gradient. The diagram below is one example of performance comparison of all the optimizers.

Comparison of training a multilayer neural network on MNIST images for different gradient descent algorithms published in the original Adam paper (Kingma, 2015)[4].

## Numerical Example

Let's see an example of Adam optimizer. A sample dataset is shown below which as weight and height of couple of people. We have to predict the height of a person based on the given weight.

 Hours Studying 60 76 85 76 50 55 100 105 45 78 57 91 69 74 112 Exam Grad 76 72.3 88 60 79 47 67 66 65 61 68 56 75 57 76

The hypothesis function is,

${\displaystyle f_{\theta }(x)=\theta _{0}+\theta _{1}x.}$

The cost function is,

${\displaystyle J({\theta })={\frac {1}{2}}\sum _{i}^{n}{\big (}f_{\theta }(x_{i})-y_{i}{\big )}^{2},}$

The optimization problem is defined as, we have to find the values of theta which help to minimize the objective function mentioned below,

${\displaystyle \mathrm {argmin} _{\theta }\quad {\frac {1}{n}}\sum _{i}^{n}{\big (}f_{\theta }(x_{i})-y_{i}{\big )}^{2}}$

The cost function with respect to the weights ${\displaystyle \theta _{0}}$ and ${\displaystyle \theta _{1}}$ are,

${\displaystyle {\frac {\partial J(\theta )}{\partial \theta _{0}}}={\big (}f_{\theta }(x)-y{\big )}}$
${\displaystyle {\frac {\partial J(\theta )}{\partial \theta _{1}}}={\big (}f_{\theta }(x)-y{\big )}x}$

The initial values of ${\displaystyle {\theta }}$ will be set to [10, 1] and the learning rate ${\displaystyle \alpha }$, is set to 0.01 and setting the parameters ${\displaystyle \beta _{1}}$, ${\displaystyle \beta _{2}}$, and e as 0.94, 0.9878 and 10^-8 respectively. Starting from the first data sample the gradients are,

${\displaystyle {\frac {\partial J(\theta )}{\partial \theta _{0}}}={\big (}(10+1\cdot 60-76{\big )}=-6}$
${\displaystyle {\frac {\partial J(\theta )}{\partial \theta _{1}}}={\big (}(10+1\cdot 60-76{\big )}\cdot 60=-360}$

Here ${\displaystyle m_{0}}$ and ${\displaystyle v_{0}}$ are zero, ${\displaystyle m_{1}}$ and ${\displaystyle v_{1}}$ are calculated as

${\displaystyle m_{1}=0.94\cdot 0+(1-0.94)\cdot {\begin{bmatrix}-6\\-360\end{bmatrix}}={\begin{bmatrix}-0.36\\-21.6\end{bmatrix}}}$
${\displaystyle v_{1}=0.9878\cdot 0+(1-0.9878)\cdot {\begin{bmatrix}-6^{2}\\-360^{2}\end{bmatrix}}={\begin{bmatrix}0.4392\\1581.12\end{bmatrix}},}$

The new bias-corrected values of ${\displaystyle m_{1}}$ and ${\displaystyle v_{1}}$ are,

${\displaystyle {\hat {m}}_{1}={\begin{bmatrix}-0.36\\-21.6\end{bmatrix}}{\frac {1}{(1-0.94^{1})}}={\begin{bmatrix}-6\\-360\end{bmatrix}}}$
${\displaystyle {\hat {v}}_{1}={\begin{bmatrix}0.4392\\1581.12\end{bmatrix}}{\frac {1}{(1-0.9878^{1})}}={\begin{bmatrix}36\\129600\end{bmatrix}}.}$

Finally, the weight update is,

${\displaystyle \theta _{0}=10-0.01\cdot -6/({\sqrt {36}}+10^{-8})=10.01}$
${\displaystyle \theta _{1}=1-0.01\cdot -360/({\sqrt {129600}}+10^{-8})=1.01}$

The procedure is repeated until the values of the weights are converged.

## Applications

The Adam optimization algorithm is the replacement optimization algorithm for SGD for training DNN. According to Adam combines the best properties of the AdaGrad and RMSP algorithms to provide an optimization algorithm that can handle sparse gradients on noisy problems. Adam is proved to be the best optimizer amongst all the other optimizers such as AdaGrad, SGD, RMSP etc. Further research is going on Adaptive optimizers for Federated Learning and their performances are being compared. Federated Learning is a privacy preserving technique which is an alternative for Machine Learning where data training is done on the device itself without sharing it with the cloud server.

AdaMax[4] is a variant of the Adam algorithm proposed in the original Adam paper that uses an exponentially weighted infinity norm instead of the second-order moment estimate. The weighted infinity norm updated ${\displaystyle u_{t}}$, is computed as

${\displaystyle u_{t}=\max(\beta _{2}\cdot u_{t-1},|g_{t}|).}$

The parameter update then becomes

${\displaystyle \theta _{t}=\theta _{t-1}-(\alpha /(1-\beta _{1}^{t}))\cdot m_{t}/u_{t}.}$

The Nadam algorithm[5] was proposed in 2016 and incorporates the Nesterov Accelerate Gradient (NAG)[6], a popular momentum like SGD variation, into the first-order moment term.

## Conclusion

Adam is a variant of the gradient descent algorithm that has been widely adopted in the machine learning community. Adam can be seen as the combination of two other variants of gradient descent, SGD with momentum and RMSProp. Adam uses estimations of the first and second-order moments of the gradient to adapt the parameter update. These moment estimations are computed via moving averages,${\displaystyle m_{t}}$ and ${\displaystyle v_{t}}$, of the gradient and the squared gradient respectfully. In a variety of neural network training applications, Adam has shown increased convergence and robustness over other gradient descent algorithms and is often recommended as the default optimizer for training.[7]

## References

1. https://arxiv.org/pdf/1412.6980.pdf ADAM: A METHOD FOR STOCHASTIC OPTIMIZATION
2. Deep Learning (Adaptive Computation and Machine Learning series)
4. Cite error: Invalid <ref> tag; no text was provided for refs named adam