CosineAnnealingLR Learning Rate Scheduler
Calculus & Optimization DS practice problem on Onlearn.
Difficulty: medium.
Topics: Understanding CosineAnnealingLR Learning Rate Scheduler, Cosine Annealing Function, Hyperparameter Decay, Epoch-based State Management, Modular Class Design, Precision Rounding, Mathematical Foundations, Optimization Theory, Numerical Analysis, Software Engineering, Deep Learning Infrastructure, Calculus and Trigonometry, Learning Rate Scheduling, Iterative Optimization Algorithms, Object-Oriented Programming, Floating Point Arithmetic.
Problem Write a Python class CosineAnnealingLRScheduler to implement a learning rate scheduler based on the Cosine Annealing LR strategy. Your class should have an init method to initialize with an initial lr (float), T max (int, the maximum number of iterations/epochs), and min lr (float, the minimum learning rate) parameters. It should also have a get lr(self, epoch) method that returns the current learning rate for a given epoch (int). The learning rate should follow a cosine annealing schedule. The returned learning rate should be rounded to 4 decimal places. Only use standard Python and the math module for trigonometric functions.