Optimization method with schedule_lr_decay 2 Week in the second Course

Hi, I would like to know how can be solved the problem to calculate 0.5 instead of 0.4545…

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

The following cell failed:

learning_rate = 0.5
print("Original learning rate: ", learning_rate)

epoch_num_1 = 10
epoch_num_2 = 100
decay_rate = 0.3
time_interval = 100
learning_rate_1 = schedule_lr_decay(learning_rate, epoch_num_1, decay_rate, time_in...
learning_rate_2 = schedule_lr_decay(learning_rate, epoch_num_2, decay_rate, time_in...
print("Updated learning rate after {} epochs: ".format(epoch_num_1), learning_rate_...
print("Updated learning rate after {} epochs: ".format(epoch_num_2), learning_rate_...

schedule_lr_decay_test(schedule_lr_decay)

The error was:

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

~/work/submitted/courseraLearner/W2A1/public_tests.py in schedule_lr_decay_test(tar...
    314 
    315     assert np.isclose(output_1, expected_output_1),f"output: {output_1} exp...
--> 316     assert np.isclose(output_2, expected_output_2),f"output: {output_2} exp...
    317 
    318     learning_rate = 0.3

AssertionError: output: 0.45454545454545453 expected: 0.5

thank you,
MY

Hi @Minyoung_Hong,

This is incorrect.

Please take a look at the equation provided for this exercise and try again.

By paying close attention to the equation and the hint provided, you’ll notice there’s something missing in your implementation.

Best,
Mubsi

Yes, those funny looking brackets in the denominator are more than just fancy parentheses! :smile: And they actually point that out in the instructions, as Mubsi says.

Hello Paul, I could calculate the learning rate but when I am trying to calculate schedule learning decay I am having the same issues.
so I checked the hint section which took me to numpy floor.

still not able to understand. can you please guide where I am going wrong?

the error I am getting is this

AssertionError Traceback (most recent call last)
in
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)
314
315 assert np.isclose(output_1, expected_output_1),f"output: {output_1} expected: {expected_output_1}"
→ 316 assert np.isclose(output_2, expected_output_2),f"output: {output_2} expected: {expected_output_2}"
317
318 learning_rate = 0.3

AssertionError: output: 0.025 expected: 0.5

I got the answer Paul.