Week 4 assignment #1 identical result but failed test case

in week 4 assignment 1 in the last section of the assignment I get the 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]
[ 0.53405496]]
W2 = [[-0.55569196 0.0354055 1.32964895]]
b2 = [[-0.84610769]]

which is identical to the expected output but I get an error message that says :

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

does anyone know why is that?

thank you.

Hello. The expected output is the same but there are additional test cases that your code must pass. If you look closely at the last notebook cell that you ran, your code worked fine up until the last line of the cell. Those are the additional test cases.

I would take the advice of the error message to heart. Since you are generating the correct output in the first test, my guess is that your coded math is valid. So my first pass would to be sure that you are not using global variables anywhere in your functions. That is, any “helper function” applied in the body of another function, must inherit its arguments from the main function (i.e. the one applying the helper functions).

1 Like

Change the params.copy() to copy.deepcopy(params).

Reason: During test, they are calling update_parameters thrice with same parameters which we are updating in each function call.
Our function is working correctly on first call. But during the second and third call, we are computing gradient descent on top of the expected output.

By doing deepcopy, you will make sure that you are working on the fresh set every time.

Hope this helps.

1 Like