Compare Scheduler Curves
Problem Statement
Compare three different schedulers side by side over the same number of epochs.
Background
Different schedulers produce different decay curves. StepLR gives discrete drops, ExponentialLR gives smooth decay, CosineAnnealingLR gives a cosine-shaped curve.
Your Task
The starter code provides a run_scheduler helper function. Use it to generate LR curves for StepLR (step_size=5, gamma=0.5), ExponentialLR (gamma=0.9), and CosineAnnealingLR (T_max=15, eta_min=0.001).
Output Format
Returns a dictionary with "step_lrs", "exp_lrs", "cosine_lrs", and "final_comparison".
Example
None
{'step_lrs': [0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.025, 0.025, 0.025, 0.025, 0.025], 'exp_lrs': [0.1, 0.09, 0.081, 0.0729, 0.0656, 0.059, 0.0531, 0.0478, 0.043, 0.0387, 0.0349, 0.0314, 0.0282, 0.0254, 0.0229], 'cosine_lrs': [0.1, 0.0966, 0.0868, 0.0714, 0.0517, 0.0505, 0.0302, 0.0302, 0.0143, 0.0143, 0.001, 0.001, 0.001, 0.001, 0.001], 'final_comparison': {'step': 0.025, 'exponential': 0.0229, 'cosine': 0.001}}- We initialize three schedulers: StepLR with , , and ; ExponentialLR with and ; and CosineAnnealingLR with , , and .
- For each of the 15 epochs, we update the learning rate for each scheduler: StepLR reduces the rate by a factor of every epochs, ExponentialLR reduces the rate by a factor of every epoch, and CosineAnnealingLR reduces the rate according to a cosine schedule.
- We record the learning rate values for each scheduler at each epoch, rounding to 4 decimals, resulting in the
'step_lrs','exp_lrs', and'cosine_lrs'lists in the output. - Finally, we create the
'final_comparison'dictionary with the final learning rate of each scheduler, giving the output{'step': 0.025, 'exponential': 0.0229, 'cosine': 0.001}.
Constraints
- Same initial LR for all three
- 15 epochs each
- Compare final values