DLS 1 - Week 3 Assigment Exercise 3 & 8 bug in assert [SOLVED]

I think there is a bug in the assertment of the ex3, because my output seems to match the matrices sizes of the expected values. The values may vary due to the random initialization.

W1 = [[0.00435995 0.00025926]
 [0.00549662 0.00435322]
 [0.00420368 0.00330335]
 [0.00204649 0.00619271]]
b1 = [[0.]
 [0.]
 [0.]
 [0.]]
W2 = [[0.00299655 0.00266827 0.00621134 0.00529142]]
b2 = [[0.]]

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-10-0eb4c3a6d62e> in <module>
      8 print("b2 = " + str(parameters["b2"]))
      9 
---> 10 initialize_parameters_test(initialize_parameters)

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

AssertionError: Wrong values for W1

----------------------------------------------------

Expected output

W1 = [[-0.00416758 -0.00056267]
 [-0.02136196  0.01640271]
 [-0.01793436 -0.00841747]
 [ 0.00502881 -0.01245288]]
b1 = [[0.]
 [0.]
 [0.]
 [0.]]
W2 = [[-0.01057952 -0.00909008  0.00551454  0.02292208]]
b2 = [[0.]]

Because the function from Ex3 initialize_parameters is also used in the ex8, I think that may also be the reason why that test (ex 8) is also failing. The cost reduces as expected and the regions (red and blue) are detected correctly in the inference.

Cost after iteration 0: 0.693167
Cost after iteration 1000: 0.000218
Cost after iteration 2000: 0.000108
Cost after iteration 3000: 0.000071
Cost after iteration 4000: 0.000053
Cost after iteration 5000: 0.000043
Cost after iteration 6000: 0.000035
Cost after iteration 7000: 0.000030
Cost after iteration 8000: 0.000026
Cost after iteration 9000: 0.000024
W1 = [[-0.73252981  1.35783783]
 [ 0.57390147 -1.06958822]
 [-0.74554827  1.38385349]
 [ 0.71679558 -1.32173584]]
b1 = [[ 0.35010915]
 [-0.23773822]
 [ 0.35947588]
 [-0.33653067]]
W2 = [[-3.07471162  1.91194267 -3.20198642  2.90926871]]
b2 = [[0.22069583]]

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-20-6d3d4c22ad68> in <module>
      7 print("b2 = " + str(parameters["b2"]))
      8 
----> 9 nn_model_test(nn_model)

~/work/release/W3A1/public_tests.py in nn_model_test(target)
    273     assert output["b2"].shape == expected_output["b2"].shape, f"Wrong shape for b2."
    274 
--> 275     assert np.allclose(output["W1"], expected_output["W1"]), "Wrong values for W1"
    276     assert np.allclose(output["b1"], expected_output["b1"]), "Wrong values for b1"
    277     assert np.allclose(output["W2"], expected_output["W2"]), "Wrong values for W2"

AssertionError: Wrong values for W1

image

I think the default tolerances in np.allclose are too small for this test 3 or 8. Or perhaps the seed used was different for the test cases?

I don’t think there is an issue with my actual code, else the other tests would fail and the inference of the regions would not be correct. This is why I’m a bit more inclined to say that the unit tests may have an issue.

Cheers

lab_id: unsffvpp

If the test fails, why would you conclude that the test is broken? More likely it is your code that is broken. Notice that all your W1 and W2 values are positive. That probably means you used the incorrect “random” function. They literally wrote out the code for you in the instructions. Please compare the instructions to the code you actually wrote.

Hello Paulin,

Yes, you are right. I confused np.random.rand with np.random.randn .
Thanks for pointing it out.

Issue solved

Best regards,