I used index i (of the for loop) to bump both θ (as is suggested in commented parts of the code, one with plus and one with minus). The same for J and gradapprox.
I have the similar issue in the gradient checcking even after correcting the backward propagation function.
There is a mistake in the backward propagation! difference = 0.33333334789859204
AssertionError Traceback (most recent call last)
in
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
There were two “fake” errors in back propagation: did you fix both of them?
yes, I fixed the two errors. Before fixing the two error I got the message shown below
There is a mistake in the backward propagation! difference = 0.5177906384974295
Thank you for your corporation.
The correct answer in that case is:
There is a mistake in the backward propagation! difference = 0.2850931567761623
So there must be something wrong in your calculations. There are lots of possibilities. I can only suggest checking carefully against the math formulas.
TypeError Traceback (most recent call last)
in
1 x, theta = 2, 4
----> 2 difference = gradient_check(2,4, print_msg=True)
3
4 #gradient_check_test(gradient_check)
TypeError: gradient_check() got an unexpected keyword argument ‘print_msg’
I have this code appeared in my notebook , and can not be deleted. Therefore can not pass the test.
That must mean that you have modified the definition of the function gradient_check. Here is what it looks like in my notebook:
# GRADED FUNCTION: gradient_check
def gradient_check(x, theta, epsilon=1e-7, print_msg=False):
You can see that print_msg is declared as a keyword argument to the function, so that error should not have been thrown.
So what does that definition look like in your notebook? That is part of the “template” code and you should not need to change it.
many thanks! Fixed the error.
Exactly the same error. I found I had said theta_minus[i] = theta_minus[i] + epsilon, instead of theta_minus[i] = theta_minus[i] - epsilon… copy and paste error
I got the same error. after spending 2 hours, I realized I was using “theta_minus[i] = theta_plus[i] - epsilon” instead of “theta_minus[i] = theta_minus[i] - epsilon”. copy paste issue…
I added some instrumentation to my code to print some of the intermediate values (inspired by this other recent thread):
32: gradapprox[i] = [0.], grad[i] = [0.]
33: gradapprox[i] = [0.], grad[i] = [0.]
34: gradapprox[i] = [0.], grad[i] = [0.]
35: gradapprox[i] = [0.9158017], grad[i] = [0.91580165]
36: gradapprox[i] = [0.02451541], grad[i] = [0.02451548]
37: gradapprox[i] = [-0.10797954], grad[i] = [-0.10797954]
38: gradapprox[i] = [0.90281879], grad[i] = [0.90281891]
39: gradapprox[i] = [0.], grad[i] = [0.]
40: gradapprox[i] = [0.], grad[i] = [0.]
41: gradapprox[i] = [0.], grad[i] = [0.]
42: gradapprox[i] = [0.19763344], grad[i] = [0.19763343]
43: gradapprox[i] = [0.], grad[i] = [0.]
44: gradapprox[i] = [0.], grad[i] = [0.]
45: gradapprox[i] = [2.24404227], grad[i] = [2.24404238]
46: gradapprox[i] = [0.21225742], grad[i] = [0.21225753]
numerator = 8.050575492696896e-07
denominator = 6.770359413353977
Your backward propagation works perfectly fine! difference = 1.1890913024229996e-07
How do those compare with your values? Notice that your final difference value is roughly twice what I get.
my last gradapprox[i] and grad[i] are
[0.21225742]
[0.21225753]
this is my num and denom
numerator = np.linalg.norm(grad[i] - gradapprox[i])
demoninator = np.linalg.norm(grad[i]) + np.linalg.norm(gradapprox[i])
so my last i’th num and denom become:
1.0433351499417043e-07
0.424514949831951
Why are you computing that only for the last value of i? The point is that you are supposed to be taking the norms of the entire vectors, right?
Alright. I had the same error, but fixed now. Thanks alot.
ValueError Traceback (most recent call last)
in
3 cost, cache = forward_propagation_n(X, Y, parameters)
4 gradients = backward_propagation_n(X, Y, cache)
----> 5 difference = gradient_check_n(parameters, gradients, X, Y, 1e-7, True)
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”
in gradient_check_n(parameters, gradients, X, Y, epsilon, print_msg)
—> 39 forward_propagation_n(X, Y, vector_to_dictionary(theta_plus[i]))
40 # YOUR CODE ENDS HERE
41
~/work/release/W1A3/gc_utils.py in vector_to_dictionary(theta)
53 “”"
54 parameters = {}
—> 55 parameters[“W1”] = theta[: 20].reshape((5, 4))
56 parameters[“b1”] = theta[20: 25].reshape((5, 1))
57 parameters[“W2”] = theta[25: 40].reshape((3, 5))
ValueError: cannot reshape array of size 1 into shape (5,4)
Hi,
I’m facing the above error. After wasting a lot of time to figure out the mistake i need some advice as i could not resolve the issue.
Thanks

