# Week 3 assignment: bug in the test

Hi, Suleman.

Sorry that the grader can’t tell you which function is the one with the problem here. Apparently this is some kind of limitation of the underlying grading platform.

I helped another student recently who had this exact symptom: 88/100 and a message about a hidden test failing. In that case, it turned out to be that they had used `A2.shape` in the `compute_cost` function to substitute for the m value (the number of samples) in the cost code. That’s at least one thing to check. If that doesn’t help, let us know!

Regards,
Paul

Hi, @paulinpaloalto, thank you for reply.
I think there is some other problem because I used `Y.shape[1]` in `compute_cost`.

regards,
Suleman

1 Like

Meaning you used the value of m that they already defined for you in the template code? Or that you used `Y.shape[1]` directly in the cost code?

1 Like

Yes, I used the value of m that they already defined in the template code.

1 Like

Ok, that probably means there is something else wrong with your code then. Please check your DMs for a message from me.

1 Like

Hi @Mubsi ,
Facing the similar issue.
My file id is nbpypdhd. Please suggest

### Exercise 3 - initialize_parameters

1 Like

You have the dimensions backward on both the W values, right? The number of rows is the number of output neurons and the number of columns is the number of input neurons (or features in layer 1).

If n_x = 2 and n_h = 4, then W1 should be 4 x 2, not 2 x 4, right?

1 Like

Hi @paulinpaloalto
Z is calculated by taking transpose of W1 (Z=W1`T` . X +b) . So, in that case W1 should be of shape (n_x, n_h). Isn’t it?

1 Like

Hi Soumak,

Have a look at the shape of the weight matrix for W1 again and what parameters will you return?
Paul sir is right

1 Like

There is no transpose in the Week 3 forward propagation formula. Look again at the instructions or at the lectures. That is only in the Week 2 Logistic Regression case.

Here is a recent thread which goes through the derivation of the shape of the W matrices in Week 3.

1 Like

Got it… thanks @Rashmi

1 Like

Thanks @paulinpaloalto … understood the issue of my code.

1 Like

Now I have changed the code

`````` W1 = np.random.rand(n_h, n_x)*0.01
b1 = (np.zeros((n_h,1)))
where n_h = n[1] and n_x = n[0]
``````

So, the initialization has the following values for W1 when called for the test method

``````[[0.00435995 0.00025926 0.00549662]
[0.00435322 0.00420368 0.00330335]
[0.00204649 0.00619271 0.00299655]
[0.00266827 0.00621134 0.00529142]
[0.0013458  0.00513578 0.0018444 ]]
``````

with
n_x → 3
n_h – > 5
n_y —> 2
But the expected value is

``````W1 = [[-0.00416758 -0.00056267]
[-0.02136196  0.01640271]
[-0.01793436 -0.00841747]
[ 0.00502881 -0.01245288]]
``````

which is 2X4 array
I am getting the below error now

``````~/work/release/W3A1/public_tests.py in initialize_parameters_test(target)
57     assert parameters["b2"].shape == expected_output["b2"].shape, f"Wrong shape for b2."
58
---> 59     assert np.allclose(parameters["W1"], expected_output["W1"]), "Wrong values for W1"
60     assert np.allclose(parameters["b1"], expected_output["b1"]), "Wrong values for b1"
61     assert np.allclose(parameters["W2"], expected_output["W2"]), "Wrong values for W2"

AssertionError: Wrong values for W1
``````

The expected value in the test cases are

``````expected_output = {'W1': np.array(
[[-0.00416758, -0.00056267, -0.02136196],
[ 0.01640271, -0.01793436, -0.00841747],
[ 0.00502881, -0.01245288, -0.01057952],
[-0.00909008,  0.00551454,  0.02292208],
[ 0.00041539, -0.01117925,  0.00539058]]),
'b1': np.array([[0.], [0.], [0.], [0.], [0.]]),
'W2': np.array([[-5.96159700e-03, -1.91304965e-04,  1.17500122e-02,
-7.47870949e-03,  9.02525097e-05],
[-8.78107893e-03, -1.56434170e-03,  2.56570452e-03,
-9.88779049e-03, -3.38821966e-03]]),
'b2': np.array([[0.], [0.]])}
``````

But the value created by the method, does not match. Value created by the method
are

``````W1 = [[0.00435995 0.00025926 0.00549662]
[0.00435322 0.00420368 0.00330335]
[0.00204649 0.00619271 0.00299655]
[0.00266827 0.00621134 0.00529142]
[0.0013458  0.00513578 0.0018444 ]]
b1 = [[0.]
[0.]
[0.]
[0.]
[0.]]
W2 = [[0.00785335 0.00853975 0.00494237 0.00846561 0.00079645]
[0.00505246 0.00065287 0.00428122 0.00096531 0.0012716 ]]
b2 = [[0.]
[0.]]
``````

Can you please check if I am doing something wrong?

1 Like

Hi Soumak,

Are you applying this formula correctly?

. Have a look and modify the changes.

Also, if you want to learn more on the why do we use this formula, here is a clear picture available on this thread.

1 Like

OMG…
Used below
W1 = np.random.rand(n_h, n_x)*0.01

Corrected the code and now working.

Thanks a lot @Rashmi and @paulinpaloalto

1 Like

If it’s any comfort, you are not the first person to make this mistake. That little “n” on the end there makes a big difference. The key clue is that all your values are positive, whereas the “normal” or Gaussian distribution gives both negative and positive values.

2 Likes

I double checked everything I could not find my code problem
in week 3 assignment all cells passed tests except nn_model cell
It has the same error mentioned in this topic(“wrong W1 shape”)
I do not know what else to check?(except hard code/randn/… which mentioned above)

when a cell fails and all its previous cells pass the test , I just have to modify the current cell? or in some cases some changes in previous cells might be needed too?

This is my lab ID : zcmteuhg

1 Like

Hi Sahar,

Welcome to the community.

Please share the traceback and the error you are receiving.

1 Like

You can think of a graded cell passing unit tests as ‘necessary but not sufficient’ for both passing subsequent local unit tests and the overall grader. Unit tests do not, and cannot, prove code is completely correct for all inputs. Rather, they prove that the code is not incorrect for one specific set of inputs passed to or embedded in that unit test. If you fail a unit test due to shape, you need to work backwards through the code to where that shape was created. You can rule out statements that impact values only, but not shape (eg the difference between `rand()` and `randn()`)

BTW, if you haven’t ever read it, I highly recommend the book Aspects of Scientific Explanation to deeply understand the limits of provability. Something I think all programmers and scientists should have in their mental toolbox. Cheers.

1 Like

Interesting! Haven’t looked at the actual book yet, but here’s the Wikipedia page about the Raven Paradox. Thinking is hard work. I need another cup of coffee

2 Likes