Gradient checking Week 1, Wrong result on gradient_check_n()

Hi, I’m trying to pass the gradien checking assignment, but I’m stuck on this perticular function, as I’m not getting the desired result and an assertion error occurs.

The result I get is:

There is a mistake in the backward propagation! difference = 0.5177906384974295
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-16-c57ee5e9e05a> in <module>
      6 expected_values = [0.2850931567761623, 1.1890913024229996e-07]
      7 assert not(type(difference) == np.ndarray), "You are not using np.linalg.norm for numerator or denominator"
----> 8 assert np.any(np.isclose(difference, expected_values)), "Wrong value. It is not one of the expected values"

AssertionError: Wrong value. It is not one of the expected values

Hi @Mowh3n , welcome to the Discourse community! Thanks for your question. First of all, it is policy not to post any solutions on the platform so make sure to remove your code snipit.

If I quickly scan through it, first of all make sure theta_minus is not based on theta_plus, so make sure to correct that. Not sure whether that solves your assertion error immediately but suggest to check after that.

3 Likes

Sorry, didn’t know about the policy. Also that solved it, thank you for your help. I never thought it was something this simple! Thanks a bunch!!!

Thanks @Mowh3n , great to hear it is solved!

Hi, teacher, for the last assignment, i past, but the assert error is always there:
I don’t understand, I have used the np.linalg.norm() , and the result is right, why?

X, Y, parameters = gradient_check_n_test_case()

cost, cache = forward_propagation_n(X, Y, parameters)
gradients = backward_propagation_n(X, Y, cache)
difference = gradient_check_n(parameters, gradients, X, Y, 1e-7, True)
expected_values = [0.2850931567761623, 1.1890913024229996e-07]
assert not(type(difference) == np.ndarray), “You are not using np.linalg.norm for numerator or denominator”
assert np.any(np.isclose(difference, expected_values)), “Wrong value. It is not one of the expected values”

Hi @Lostfinger, you might have the correct answer but basically there is a check that your solution uses np.linalg.norm in the calculation of the numerator and the denominator. Did you do that?

yes, I used np.linalg.norm to calculate numerator and denominator, shouldn’t I ??

Yep, you should use it. Can you DM me with the complete code snipit, then I will try to have a look at it later.