W4 A1 | Ex-10 | Not all tests were passed for update_parameters

I have seen other posts that talk about using ‘-=’ as their assignment, but I am not using that.

My code is more in the form of
param[W(i+1)] = param[W(i+1)] - learning_rate * grads[dW(i+1)]

I seem to not fully understand the supposed order in these steps.

The output I receive is:

W1 = [[-0.41675785 -0.05626683 -2.1361961   1.64027081]
 [-1.79343559 -0.84174737  0.50288142 -1.24528809]
 [-1.05795222 -0.90900761  0.55145404  2.29220801]]
b1 = [[ 0.04153939]
 [-1.11792545]
 [ 0.53905832]]
W2 = [[-0.5961597  -0.0191305   1.17500122]]
b2 = [[-0.74787095]]
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
 2  Tests passed
 1  Tests failed
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-124-e0da3f3aab9d> in <module>
      7 print ("b2 = "+ str(t_parameters["b2"]))
      8 
----> 9 update_parameters_test(update_parameters)

~/work/release/W4A1/public_tests.py in update_parameters_test(target)
    501     ]
    502     #print(target(*test_cases[2]["input"]))
--> 503     multiple_test(test_cases, target)
    504 
    505 

~/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 update_parameters. Check your equations and avoid using global variables inside the function.

Expected output:

W1 = [[-0.59562069 -0.09991781 -2.14584584  1.82662008]
 [-1.76569676 -0.80627147  0.51115557 -1.18258802]
 [-1.0535704  -0.86128581  0.68284052  2.20374577]]
b1 = [[-0.04659241]
 [-1.28888275]
 [ 0.53405496]]
W2 = [[-0.55569196  0.0354055   1.32964895]]
b2 = [[-0.84610769]]

It is fine to use the syntax you describe. But if the results are not correct, there must be something wrong. E.g. perhaps you are not applying the correct gradient to the relevant parameter. Note that in this test case the gradients are just given to you, so it’s not a problem with how you compute gradients. Here’s the output I get for that test case:

W1 = [[-0.59562069 -0.09991781 -2.14584584  1.82662008]
 [-1.76569676 -0.80627147  0.51115557 -1.18258802]
 [-1.0535704  -0.86128581  0.68284052  2.20374577]]
b1 = [[-0.04659241]
 [-1.28888275]
 [ 0.53405496]]
W2 = [[-0.55569196  0.0354055   1.32964895]]
b2 = [[-0.84610769]]
 All tests passed.

You’ll notice that a) it is different than yours and b) it agrees with the “Expected Output” shown in the notebook. The shapes of your values are all correct. There really aren’t very many “moving parts” here, so some careful proofreading should turn up an answer.

Update: I tried one obvious mistake: using + instead of - to apply the gradients. That fails, of course, but the outputs are not the same as yours.

1 Like