Adam Optimizer Update

~25 mincode completion

Implement adam_update(weights, m, v, gradient, learning_rate, beta1, beta2, epsilon, t). Return (weights_new, m_new, v_new).

Examples

First step, cold start: weights decrease (accessor [0])

Input
adam_update([0], [0], [0], [1], 0.001, 0.9, 0.99, 1e-8, 1)
[0] of result
[-0.001]

Zero gradient: weights unchanged (accessor [0])

Input
adam_update([1, -1], [0, 0], [0, 0], [0, 0], 0.01, 0.9, 0.99, 1e-8, 1)
[0] of result
[1, -1]

m_new correct (accessor [1])

Input
adam_update([0], [0], [0], [1], 0.001, 0.9, 0.99, 1e-8, 1)
[1] of result
[0.1]

Hints

Hint 1

Take the square root at the end, not inside the sum.

Hint 2

Do not forget to the bias correction. That step is easy to skip.

Requirements

  • weights: Current weight vector

  • m: First moment estimate (same shape as weights)

  • v: Second moment estimate (same shape as weights)

  • : Current gradient

  • learning_rate: Step size (alpha)

  • beta1: First moment decay (typically 0.9)

  • beta2: Second moment decay (typically 0.999)

  • epsilon: Numerical stability constant

  • : Current time step (1-indexed)

  • Return Tuple (weights_new, m_new, v_new).

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~25 min

8 employers weight this skill

4 big tech firms, 2 quant funds, 1 frontier lab, 1 autonomy company. Top match scores 91.

Python
import numpy as np

def adam_update(weights: np.ndarray, m: np.ndarray, v: np.ndarray, gradient: np.ndarray,
               learning_rate: float, beta1: float, beta2: float, epsilon: float, t: int):
    """
    Perform one Adam optimizer update.

    Args:
        weights:       Current weight vector
        m:             First moment estimate (same shape as weights)
        v:             Second moment estimate (same shape as weights)
        gradient:      Current gradient
        learning_rate: Step size (alpha)
        beta1:         First moment decay (typically 0.9)
        beta2:         Second moment decay (typically 0.999)
        epsilon:       Numerical stability constant
        t:             Current time step (1-indexed)

    Returns:
        Tuple (weights_new, m_new, v_new).
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.