Optimization programming assignment - exercise 4 - AssertionError: Not all tests were passed for update_parameters_with_momentum

2 Tests passed
1 Tests failed

AssertionError Traceback (most recent call last)
in
11 print(“v["db2"] = v” + str(v[“db2”]))
12
—> 13 update_parameters_with_momentum_test(update_parameters_with_momentum)

~/work/release/W2A1/public_tests.py in update_parameters_with_momentum_test(target)
175 ]
176
→ 177 multiple_test(test_cases, target)
178
179

/opt/conda/lib/python3.7/site-packages/dlai_tools/testing_utils.py in multiple_test(test_cases, target)
162 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
163 raise AssertionError(
→ 164 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

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

I don’t believe I’m using any global variables.

I’m using beta, learning_rate, parameters[“W” + str(l)], parameters[“b” + str(l)], grads[‘dW’ + str(l)], grads[‘db’ + str(l)]

Can’t figure out what it’s complaining about…

You can go to the Files menu and open the “public_tests.py” file.
Then you can find the test cases for that function and perhaps figure out which one is failing.

multiple_test(test_cases, target)

is failing

/opt/conda/lib/python3.7/site-packages/dlai_tools/testing_utils.py in multiple_test(test_cases, target)
162 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
163 raise AssertionError(
→ 164 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

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

It seems to be happening in code I don’t control…

Your code is referenced by the function pointer “target”.

You don’t modify the tests - you modify your code, then the tests verify whether it works correctly.

Note that you shouldn’t put too much store in the fact that you passed 2 tests. If you looked at the tests, you’ll see that typically they first check the type of the output value, then the shape and only if the first two pass do they check the actual values. So you probably produced a numpy array of the correct dimensions, but the actual values are wrong.

So, as Tom says, the fact that the error is thrown in code you didn’t write doesn’t mean it’s not your problem. Now the question is figuring out where your code is incorrect. Most people have trouble in the Adam section, but that comes later. There the issue is typically “order of operations” on the \epsilon value.

For the Momentum logic, there are a lot fewer moving parts than in the Adam case. The first step would be to carefully compare your code to the math formulas. E.g. in the formula for u_{dW^{[l]}} there are two terms and they use different base values: the value multiplied by \beta is different than the one multiplied by (1 - \beta), right?

And continue that level of analysis through both the formulas …

ok, I got it, thank you

If my hints there are not enough to get you to the solution, let me know. There are more direct ways to help if required …

your hint was enough, I’m passing the tests now. Moving to Adam. Thank you

That’s great news! Onward! :nerd_face: