Exercise 8 - schedule_lr_decay Course 2 / Week2

Hi everyone,

I was doing the programming exercise and now I am stuck as the output is correct but the test case is failing me. Here is my code

# YOUR CODE STARTS HERE
if epoch_num % time_interval == 0:
    learning_rate = (1 / (1 + decay_rate) * (epoch_num / time_interval)) * learning_rate

Original learning rate:  0.5
Updated learning rate after 10 epochs:  0.5
Updated learning rate after 100 epochs:  0.3846153846153846
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-25-1b8d727c069a> in <module>
     11 print("Updated learning rate after {} epochs: ".format(epoch_num_2), learning_rate_2)
     12 
---> 13 schedule_lr_decay_test(schedule_lr_decay)

~/work/release/W2A1/public_tests.py in schedule_lr_decay_test(target)
    301 
    302 
--> 303     assert np.isclose(output_1, expected_output_1),f"output: {output_1} expected: {expected_output_1}"
    304     assert np.isclose(output_2, expected_output_2),f"output: {output_2} expected: {expected_output_2}"
    305 

AssertionError: output: 2.4 expected: 0.085714285

Expected output

Original learning rate:  0.5
Updated learning rate after 10 epochs:  0.5
Updated learning rate after 100 epochs:  0.3846153846153846

Help is appreciated

Thanks

Hey @fadilparves,

I’m curious why the if in the first line of your code?

Hi @neurogeek

The if is for checking if the current epoch is the each 1000th epoch, and only then the learning rate is decayed, this is for the exercise, where for every 1000 epoch, I need to decay the learning rate

Hey @fadilparves,

Remove that if statement because you don’t need it. The decay of the learning rate already accounts for epoch and time intervals directly in the formula: See the component (epoch_num / time_interval).

1 Like

learning_rate = (1/(1+(decay_rate*np.floor(epoch_num/time_interval))))*learning_rate0

no need to use if just write this it works

2 Likes

Remove that if statement because you don’t need it.

1 Like

Hey can you tell the code for update_lr one once.