Exponential LR schedulerEasyoptimizationlearning-rateschedulertraining
Exponential LR scheduler
Background
ExponentialLR decays the learning rate by a constant multiplicative factor at every epoch — a smooth geometric decay, in contrast to StepLR's discrete drops. It is a common, simple schedule when you want the rate to taper continuously over training.
Problem statement
Implement an ExponentialLRScheduler class with:
__init__(self, initial_lr, gamma)get_lr(self, epoch)returning the learning rate at a given (0-indexed) epoch:
Round the result to 4 decimals.
Input
initial_lr—float, the starting learning rate .gamma—float, the per-epoch decay factor (e.g. 0.9 reduces the rate 10% each epoch).epoch—int, the current epoch (0-indexed) passed toget_lr.
Output
get_lr(epoch) returns a float learning rate, rounded to 4 decimals.
Examples
Example 1
Input: ExponentialLRScheduler(initial_lr=0.1, gamma=0.9)
get_lr(0), get_lr(1), get_lr(2), get_lr(3)
Output: 0.1, 0.09, 0.081, 0.0729
Explanation: each epoch multiplies the previous rate by : .
Constraints
- The exponent is the epoch itself (decay applies every epoch, not in blocks).
- Round the returned learning rate to 4 decimals.
Notes
- ExponentialLR is StepLR with
step_size = 1: the rate drops by on every epoch. - Geometric decay means the rate approaches (but never reaches) zero — useful for a long, gentle annealing tail.
Python
Loading...
This problem ships 4 hidden tests. They run in your browser via Pyodide — no backend, no submission queue. Press ▶ Run tests to execute.
- •Reference example sequence
- •Epoch 0 returns the initial rate
- •Decays geometrically each epoch
- •gamma = 1 keeps the rate constant