Week 3 updating parameters 1 test failed

here is the result for updating parameters : 2 test passed and 1 failed
however the same function expected results matches and all the following tests and functions works well giving expected results but i still get only 88% as assignment grades
“”"
W1 = [[-0.00643025 0.01936718]
[-0.02410458 0.03978052]
[-0.01653973 -0.02096177]
[ 0.01046864 -0.05990141]]
b1 = [[-1.02420756e-06]
[ 1.27373948e-05]
[ 8.32996807e-07]
[-3.20136836e-06]]
W2 = [[-0.01041081 -0.04463285 0.01758031 0.04747113]]
b2 = [[0.00010457]]
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)
in
7 print("b2 = " + str(parameters[“b2”]))
8
----> 9 update_parameters_test(update_parameters)

~/work/release/W3A1/public_tests.py in update_parameters_test(target)
263 ]
264
→ 265 multiple_test(test_cases, target)
266
267 def nn_model_test(target):

~/work/release/W3A1/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.00643025 0.01936718]
[-0.02410458 0.03978052]
[-0.01653973 -0.02096177]
[ 0.01046864 -0.05990141]]
b1 = [[-1.02420756e-06]
[ 1.27373948e-05]
[ 8.32996807e-07]
[-3.20136836e-06]]
W2 = [[-0.01041081 -0.04463285 0.01758031 0.04747113]]
b2 = [[0.00010457]]
“”"

My guess is that the problem is that you are using the “in place” style operators for your update. That means:

W -= <... update formula ...>

As opposed to:

W = W - <... update formula ...>

The in place form only works if you first break the connection to the global variables that are the test inputs. Here’s a thread which goes into the details of why this is required.

1 Like

Thank you so much , that’s true I used " W - = "
and when I used " W = W - " , issue was resolved
But should be both are same, even the expected result is same

Yes, they give the same local answer, but apparently you didn’t read the thread that I linked. That explains why the -= method has a side effect that causes the tests to fail. Although it is also a valid point that they could have written the tests in a different way such that the side effect of modifying the global data would not have caused the tests to fail.

I did the same thing (used ‘in place’ style ‘-=’). This thread helped me out. Thank you!

2 Likes