Week 3 Exercise 4 - forward_propagation

I’m getting the error “AssertionError: Wrong values for A2”

My output for A2 is “A2 = [[0.22590804 0.22501596 0.22528938]]”
The test case expects “A2 = [[0.21292656 0.21274673 0.21295976]]”

I’m wondering if the test case is off since they’re so close?

Hi, @Glenn_Cameron_Jr and welcome!

Very unlikely that the test case if foul–not unprecedented, but rare. When posting an issue its very helpful (quite necessary, actually) to insert a snapshot of the “Traceback”, i.e. the error log, produced by your execution. NOT your code which is a violation of the Coursera honor code. Please do that and we’ll see you on the flip side.

Thanks for your response Ken. Here’s the traceback:
A2 = [[0.22590804 0.22501596 0.22528938]]

AssertionError Traceback (most recent call last)
in
3 print("A2 = " + str(A2))
4
----> 5 forward_propagation_test(forward_propagation)

~/work/release/W3A1/public_tests.py in forward_propagation_test(target)
108 assert output[1][“Z2”].shape == expected_Z2.shape, f"Wrong shape for cache[‘Z2’]."
109
→ 110 assert np.allclose(output[0], expected_A2), “Wrong values for A2”
111 assert np.allclose(output[1][“Z1”], expected_Z1), “Wrong values for cache[‘Z1’]”
112 assert np.allclose(output[1][“A1”], expected_A1), “Wrong values for cache[‘A1’]”

AssertionError: Wrong values for A2

Things to verify while you get that traceback posted:

  1. That your initialize_parameters(...) function passed its tests with matching output to the expected output. The notebook will not let you change the np.random.seed(2) statement so you are good there.
  2. If so, there are pretty much just two sources error left. First, you need to retrieve the arrays from the parameters dictionary properly. Second your expressions for forward propagation need to be correctly specified. The instructions offer guidance on both.

OK, not much help there, but good practice for future posts. Your forward prop expressions are likely off. In addition to the sigmoid() and np.tanh() functions mentioned in the instructions, you will also need np.dot(). Time to put in your eagle eyes! :nerd_face:

I had tan instead of tanh :man_facepalming:

Thanks Ken!

You caught your prey. Well done!

You need to adjust your notion of “close” here. :nerd_face: Just for future reference note that an error in the second decimal place is not a rounding error: it’s a real error. We are doing 64 bit floating point here, so rounding errors are typically of order 10^{-16} or smaller. Here’s a thread which shows some examples of different ways to express a simple computation that can result in different values, but the errors are of the aforementioned small scale.

1 Like