Week 4, Assignment 1, Exercise 7

Hi, I’m getting the following output and error message. I checked if there’re global variables inside the function. Any tips for debugging? Thanks a lot!


dA_prev: [[ 1.171184   -2.25692836  2.88493634 -2.74652635]
 [ 0.08836827 -0.74323806  0.35001173  0.32130443]
 [-1.96938704  1.93676839 -0.71200498  1.57793738]
 [ 1.9909725  -2.22927794  1.66044295 -2.47022438]
 [-0.53006964  1.37719417 -1.18286322  0.65216967]]
dW: [[ 0.07313866 -0.0976715  -0.87585828  0.73763362  0.00785716]
 [ 0.85508818  0.37530413 -0.59912655  0.71278189 -0.58931808]
 [ 0.97913304 -0.24376494 -0.08839671  0.55151192 -0.10290907]]
db: [[0.52506378]
 [0.03003974]
 [0.15430078]]
Error: Wrong output for variable 0.
Error: Wrong output for variable 2.
 2  Tests passed
 1  Tests failed
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-19-3427f65cb756> in <module>
      6 print("db: " + str(t_db))
      7 
----> 8 linear_backward_test(linear_backward)

~/work/release/W4A1/public_tests.py in linear_backward_test(target)
    308     ]
    309 
--> 310     multiple_test(test_cases, target)
    311 
    312 def linear_activation_backward_test(target):

~/work/release/W4A1/test_utils.py in multiple_test(test_cases, target)
    140         print('\033[92m', success," Tests passed")
    141         print('\033[91m', len(test_cases) - success, " Tests failed")
--> 142         raise AssertionError("Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.".format(target.__name__))
    143 

AssertionError: Not all tests were passed for linear_backward. Check your equations and avoid using global variables inside the function.


Here are the answers I get on that test cell:

dA_prev: [[-1.15171336  0.06718465 -0.3204696   2.09812712]
 [ 0.60345879 -3.72508701  5.81700741 -3.84326836]
 [-0.4319552  -1.30987417  1.72354705  0.05070578]
 [-0.38981415  0.60811244 -1.25938424  1.47191593]
 [-2.52214926  2.67882552 -0.67947465  1.48119548]]
dW: [[ 0.07313866 -0.0976715  -0.87585828  0.73763362  0.00785716]
 [ 0.85508818  0.37530413 -0.59912655  0.71278189 -0.58931808]
 [ 0.97913304 -0.24376494 -0.08839671  0.55151192 -0.10290907]]
db: [[-0.14713786]
 [-0.11313155]
 [-0.13209101]]
 All tests passed.

That’s pretty interesting: notice that your dW values are correct, but the other two are wrong. And notice that in both the wrong cases, the signs of the terms are exactly opposite everywhere. So that’s a pretty good clue where to look for the problems: please carefully compare your code for dA_prev and db with the math formulas shown in the instructions.

Solved! Thank you very much!