Learning Rate Decay

~10 mincode completion

Implement decay_lr(initial_lr, decay_rate, epoch) that returns the decayed learning rate.

Examples

Epoch 0: no decay

Input
decay_lr(0.1, 0.9, 0)
Output
0.1

Epoch 1: single decay step

Input
decay_lr(0.1, 0.9, 1)
Output
0.09

Halving decay after 4 epochs

Input
decay_lr(1, 0.5, 4)
Output
0.0625

Hints

Hint 1

Work directly with the arguments initial_lr, decay_rate, epoch and return the result rather than printing it.

Hint 2

A common slip here: multiplied by epoch instead of power.

Requirements

  • initial_lr: Starting learning rate (alpha_0)

  • decay_rate: Decay factor gamma, in (0, 1)

  • epoch: Current epoch index (0-based)

  • Return Decayed learning rate: initial_lr decay_rate * epoch

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

3 employers weight this skill

1 big tech firm, 1 frontier lab, 1 quant fund. Top match scores 80.

Python
import numpy as np

def decay_lr(initial_lr: float, decay_rate: float, epoch: int) -> float:
    """
    Compute the decayed learning rate at a given epoch.

    Args:
        initial_lr:  Starting learning rate (alpha_0)
        decay_rate:  Decay factor gamma, in (0, 1)
        epoch:       Current epoch index (0-based)

    Returns:
        Decayed learning rate: initial_lr * decay_rate ** epoch
    """
    # 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.