Issue with forward propagation output mismatch despite correct initialization and parameter shapes in neural network model

Issue with Forward Propagation and Parameter Initialization in Week 3 Assignment

Hello everyone,

I’m currently working on the Week 3 programming assignment i.e. Planar Data Classification with One Hidden Layer, specifically on the forward propagation function part. I’m facing an issue where the values of A2 do not match the expected output provided by the grader.

Issue:

  • Shape Issue: The shape of A2 seems correct (1, 3), but the values do not match the expected output from the grader function.
  • Parameter Initialization: I’ve ensured that parameters are initialized with small random values.
  • Expected Results: The values of A2 should match exactly with the expected output in the grader, but I’m getting different results despite the shapes aligning.

What I’ve Tried:

  • Used np.random.seed(2) for consistent random initialization.
  • Verified the shapes of the parameter matrices (e.g., W1, W2, b1, b2) and the intermediate outputs (e.g., Z1, A1, Z2).
  • Added assertions to check for shape consistency, but the values of A2 still don’t match.

Has anyone else faced similar issues where the values of A2 don’t match the expected results even though the shapes are correct? If yes, what specific details should I focus on when trying to match the output values exactly?

Any help or suggestions would be greatly appreciated!

Could you send me by private message only those lines of code what you wrote to the code? (per function)

Sure, thank you

It is a mistake to add or change any settings of the random seeds: they take care of that for you in the various test cases. You can read the source for the test function that is used in that cell by clicking “File → Open” and then opening the file public_tests.py.

If your dimensions are correct, then I’d start by carefully checking the other details like the activation functions. Compare your code to the formulas shown in the descriptions. Did you use tanh for the hidden layer and sigmoid for the output layer?

2 Likes

The error is caused by the fact that we have to use a different activation function for A1 than for A2.

2 Likes

Thank you so much for pointing that out. It worked!!

1 Like

Thank you very much. It was so silly of me!

You are welcome! :wink:

1 Like