Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-240

Cosine Schedule Mean Value

Problem

Compute the mean learning rate of a cosine annealing schedule over discrete steps.

For step = 0 through total inclusive evaluate lr(step) = min_lr + 0.5 * (base_lr - min_lr) * (1 + cos(pi * step / total)) and return the arithmetic mean of those total + 1 values. If total is not positive, return min_lr.

Hint

The discrete average of the cosine curve sits near the midpoint of the range.

Test cases

case 1
in: [0.1,0,4]
expected: 0.05
case 2
in: [0.1,0.01,10]
expected: 0.05500000000000001
case 3
in: [1,0,100]
expected: 0.49999999999999983
case 4
in: [0.1,0,0]
expected: 0
Starter codePython
def cosine_schedule_mean(base_lr, min_lr, total):
    # Your code here
    pass

4 test cases · run your code against them in the editor