The Adam optimizer provides a combination of momentum and adaptive scaling based on the second moment of gradients. Researchers have proposed several variants aiming for further improvements or addressing specific behaviors. Two notable variants are Adamax and Nadam. These methods modify Adam's core components, specifically how it scales the learning rate or incorporates momentum, offering alternative approaches for certain optimization scenarios.
Adamax: Adaptive Learning Rates with Infinity Norm
Adam scales the learning rate for each parameter based on a decaying average of the squared past gradients (vt), which effectively uses the L2 norm. Adamax, introduced in the same paper as Adam by Kingma and Ba, uses the L∞ norm (infinity norm, or maximum norm) for scaling instead.
The motivation stems from generalizing Adam's update rule. Adam's per-parameter update involves dividing the first moment estimate m^t by v^t. The term vt is roughly proportional to the L2 norm of the current and past gradients. What happens if we generalize this to an Lp norm? The update component vt would involve the p-th power of gradients:
vt=β2vt−1+(1−β2)∣gt∣p
The parameter update would then involve division by vt1/p. Adam corresponds to p=2. Adamax examines the case where p→∞. As p→∞, the Lp norm converges to the L∞ norm (the maximum absolute value). This leads to a remarkably simple update for the scaling term, often denoted as ut to distinguish it from Adam's vt:
ut=max(β2ut−1,∣gt∣)
Notice that this update doesn't require element-wise squaring or square roots. It relies on the max operation. Because ut relies on a max operation, it can be more stable than Adam's vt when dealing with very large but sparse gradients, as the max is less affected by infrequent large values compared to the sum of squares.
The full Adamax parameter update rule becomes:
θt+1=θt−utηm^t
Here, m^t is the bias-corrected first moment estimate, calculated exactly as in Adam:
mt=β1mt−1+(1−β1)gtm^t=1−β1tmt
Important Points about Adamax:
Scaling: Uses the L∞ norm (maximum) for scaling, derived as the limit of the Lp norm.
Update Rule (ut): Simpler calculation (ut=max(β2ut−1,∣gt∣)) compared to Adam's vt.
Stability: Potentially more stable than Adam, especially with sparse gradients or sudden large gradients, due to the max operation being less sensitive than summing squares.
Hyperparameters: Uses the same hyperparameters as Adam (η, β1, β2), with similar typical default values (β1≈0.9, β2≈0.999).
Adamax provides a computationally slightly simpler variant of Adam that might offer better stability in certain situations.
Nadam: Incorporating Nesterov Momentum into Adam
Nesterov Accelerated Gradient (NAG) is known to often improve the convergence speed of standard momentum methods by calculating the gradient after applying a preliminary momentum step (looking ahead). The Nadam (Nesterov-accelerated Adaptive Moment Estimation) optimizer, proposed by Dozat, aims to integrate this Nesterov momentum principle into the Adam framework.
Recall that Adam updates parameters using bias-corrected estimates of the first moment (mt) and second moment (vt) of the gradients. Nadam modifies how the first moment estimate influences the update step to incorporate the "lookahead" aspect of NAG.
The core idea in NAG is to compute the gradient at θt+μmt−1 (where μ is the momentum coefficient) instead of at θt. Nadam applies a similar correction within Adam's update. Instead of using only the previous momentum term β1m^t−1 to anticipate the next position, Nadam effectively incorporates the current gradient information more directly into the momentum part of the update.
Let's look at the update steps for Nadam:
Compute gradient: gt=∇f(θt−1)
Update biased first moment estimate: mt=β1mt−1+(1−β1)gt
Update biased second moment estimate: vt=β2vt−1+(1−β2)gt2
Compute bias-corrected first moment: m^t=1−β1tmt
Compute bias-corrected second moment: v^t=1−β2tvt
Compute the Nadam parameter update:
θt=θt−1−v^t+ϵη(β1m^t+1−β1t(1−β1)gt)
Compare the Nadam update (Step 6) to the standard Adam update:
Adam Update: θt=θt−1−v^t+ϵηm^t=θt−1−v^t+ϵη(1−β1tβ1mt−1+1−β1t(1−β1)gt)
The main difference lies in how the momentum term is applied. Nadam uses β1m^t which includes the influence of the current gradient gt via mt, combined with another term involving the current gradient 1−β1t(1−β1)gt. This structure effectively applies the momentum step using the updated momentum mt and incorporates the gradient correction in a way that mimics NAG's lookahead behavior.
Important Points about Nadam:
Momentum: Integrates Nesterov momentum with Adam's adaptive learning rates.
Update Rule: Modifies the Adam update to use a Nesterov-style momentum calculation.
Convergence: Often converges faster than Adam, especially on problems where NAG outperforms standard momentum. It can be particularly effective for training complex models like recurrent neural networks or deep CNNs.
Hyperparameters: Uses the same hyperparameters as Adam (η, β1, β2), often with similar default values.
Nadam is frequently a strong choice when faster convergence is desired and the overhead of the slightly more complex update calculation is acceptable.
Practical Notes
Both Adamax and Nadam are readily available in popular machine learning libraries like TensorFlow (tf.keras.optimizers.Adamax, tf.keras.optimizers.Nadam) and PyTorch (torch.optim.Adamax, torch.optim.Nadam).
When to Choose: While Adam remains a very popular and often effective default, try Nadam if faster convergence is a priority. Adamax might be worth exploring if you observe instability possibly related to large or sparse gradients when using Adam.
Hyperparameter Tuning: Although defaults often work well, tuning the learning rate η and momentum decay parameters β1,β2 can still yield performance improvements, just as with Adam. β1 typically influences the momentum aspect, while β2 controls the adaptivity based on past gradient magnitudes.
Empirical Evaluation: As with all optimization algorithms, the best choice often depends on the specific problem, dataset, and model architecture. It's recommended to empirically compare the performance of Adam, Adamax, and Nadam (along with potentially other optimizers like RMSprop or SGD with momentum) on your specific task.
By understanding the subtle but significant modifications introduced by Adamax and Nadam, you gain more tools for navigating optimization, potentially achieving more stable or faster training for your machine learning models. They represent valuable refinements built upon the foundational Adam algorithm.
Adam: A Method for Stochastic Optimization, Diederik P. Kingma, Jimmy Ba, 2015International Conference on Learning Representations (ICLR 2015)DOI: 10.48550/arXiv.1412.6980 - Original paper introducing the Adam optimizer and its variant Adamax, detailing their derivation and properties.
Incorporating Nesterov Momentum into Adam, Timothy Dozat, 2016Proceedings of the 4th International Conference on Learning Representations - Report introducing the Nadam optimizer, which integrates Nesterov momentum with Adam's adaptive learning rate mechanism.
tf.keras.optimizers.Adamax, TensorFlow Developers, 2024 (TensorFlow) - Official TensorFlow Keras documentation for the Adamax optimizer, providing usage examples and implementation details.
tf.keras.optimizers.Nadam, TensorFlow Developers, 2024 (TensorFlow) - Official TensorFlow Keras documentation for the Nadam optimizer, outlining its parameters and usage in practice.