Deep-ML | Adam With and Without Bias Correction: A Sweep over beta2 and the StepsizeAdam With and Without Bias Correction: A Sweep over beta2 and the Stepsize
Adam With and Without Bias Correction: A Sweep over beta2 and the Stepsize
```python
import numpy as np
X = np.array([[1.0, 0.0], [0.0, 2.0], [1.0, 1.0]])
y = np.array([1.0, -1.0, 0.5])
print([round(x, 5) for x in adam_loss_curve(X, y, 0.1, 0.9, 0.999, 4)])
```
Output:
[0.28333, 0.2089, 0.15126, 0.10882]
Reasoning:
With bias correction the first step moves every weight by almost exactly alpha = 0.1 against the sign of its gradient, so the loss drops from its starting value of 0.375 in the first update and keeps falling as the steps continue.
The Adam paper tests its bias-correction terms by training the same model with and without them over a grid of β1, β2 and stepsizes, and reports that β2 close to 1 without the correction makes training unstable, most of all early on. Write the training loop that such a sweep needs, on a small least-squares problem, with the correction as a switch.
adam_loss_curve(X, y, alpha, beta1, beta2, steps, bias_correction=True, eps=1e-8) -> list
X: array of shape (n, d); y: array of shape (n,).
Minimise L(w)=2n1∥Xw−y∥2 starting from w0=0, with the full-batch gradient gt=n1X⊤(Xwt−1−y).
Update, element-wise, with m0=v0=0:
mt=β1mt−1+(1−β1)gt,vt=β2vt−1+(1−β2)gt2,wt=wt−1−αv^t+ϵm^t,
where m^t=mt/(1−β1t) and v^t=vt/(1−β2t) when bias_correction is true, and m^t=mt, v^t=vt when it is false.
Returns a list of steps floats: entry t−1 is L(wt), the loss after update t. steps = 0 returns [].