W4_A1_Ex2_Random values for W1 and W2

The outputs are wrong even though my code is right…I don’t know what to do cause next excercises are based on this excercise



Hi @Yash_Ingle ,

Why are you calling initialize_parameters() and then initialise parameters again in the ‘for’ loop?
Initialize_parameters() is for a 2 layers model, the way it works is different, noticed the
Argument:
n_x – size of the input layer
n_h – size of the hidden layer
n_y – size of the output layer
So when the layer_dims[0], layer_dim[1] and layer_dim[2] are passed to the function, they are treated as
n_x – size of the input layer
n_h – size of the hidden layer
n_y – size of the output layer
The shape of W is (n_h,n-x)
However, Initialize_parameters_deep(), the function you are implementing, is for any number of layers. The shape of W is (units_current_hidden_layer, units_previous_hidden _layer).
As the variable parameters is created by calling initialize_parameters(), so it contains values that are not as expected. If you create the variable parameters as an empty dictionary, it should work.

Oh God!!! That was really silly mistake on my part… :face_with_peeking_eye:

Note that it also looks like you changed the “seed” value in that code from 3 to 1. In the original template code for initialize_parameters_deep the seed value is 3. If you want to confirm that, you can get a clean copy of the assignment and compare. There is a topic about how to do that on the DLS FAQ Thread.

The only reason for setting the seed value here is so that you’ll get exactly the same answers from the random number generator, so that it’s easy for them to create the test case for functions like this. In a real system, you wouldn’t normally do that, because you want the values not to be predictable. Once you set the seed to a particular value, then the sequence you get is deterministic. But notice that means that you need to initialize the variables in exactly the right order. So W1 gets the first batch of “random” values and W2 gets the second batch and so forth. If you did it in the opposite order, you’d also get a different answer than the test case will check for.