Course 1 Week 4 programming assignment #2 error


In the week 4 programming assignment “Building_your_Deep_Neural_Network_Step_by_Step” and in the section 6.3 - L-Model Backward, the formula for dAL provided is not correct

Given :
dAL = - (np.divide(Y, AL) - np.divide(1 - Y, 1 - AL)) # derivative of cost with respect to AL
Correct formula:
dAL = - (np.divide(Y, AL) + np.divide(1 - Y, 1 - AL)) # derivative of cost with respect to AL

I have used the given formula instead of the correct one because if I use the correct one then test doesn’t pass.
Please update the material.
Thank you

The formula you show as “Correct” is actually not correct. It is the first one (Given) that is correct, which is why using that one works. Look at how the parentheses work in that expression. The signs of the two terms are opposite because of the Chain Rule: you get an extra factor of -1 in the second term, because of the derivative of (1 - AL). There is nothing wrong with the material.

Thanks for your reply. But, please note the following:

According the video tutorial in Course 1 Week3 “Backpropagation Intuition (Optional)” at time 1.18 the formula for Loss function L(a,y) = -yloga - (1-y)log(1-a) and thus dL(a,y) = (-y/a) + ((1-y)/(1-a)) according to chain rule.

And Course 1 Week 4 " Forward and Backward Propagation" at time 7.05 it says da = (y/a)+((1-y)/(1-a))

It is all consistent with the “Given” formula you showed above. You apparently transcribed it incorrectly:

The minus sign on the first term is pretty clear.

1 Like

Its not about minus in 1st term. It about minus sign in second term. Please refer to my first comment and observe the difference in sign in “second term”.

The formula shown in your screenshot and my screenshot doesnt match

Please have a more careful look at the parentheses in the line of python code that you circled in red there. It is the same if you apply the distributive law. The point is that parentheses matter.

Oops, I didn’t notice the common braces. Thank you for your patience in answering my question.

Notice that those same parentheses were also there in the code samples in your original post on this thread. Also notice that my comment about the sign of the first term is that you wrote that incorrectly in the quote I showed above. Programming is a game of details, right?

My bad ! In my original post , I copied the formula from the material, thus didn’t notice the common braces. And in my comment where I talk about the video timings, I missed the minus sign in my last line. Sorry for the confusion. Definitely, I missed that detail. Thank you again

Hats off to Paul sir, he has been so patient with you Thendral! I have been chasing your comments since the beginning and wanted to intervene, but I refrained just because I wanted Paul sir to make you understand the right :slight_smile: