There seems to be an oversight in the evaluation of Exercise 2 in the first notebook of Week 4.
Although the size of my matrices Wi is correct, their initialization values are quite different when using np.random.rand() (as specified in the cell above the code).
However, I found that if I replace the random generation for np.random.normal() it works, so it seems the test cases where calculated with this function in mind.
Therefore, I think this section,
Use random initialization for the weight matrices. Use np.random.randn() * 0.01
Should be changed to,
Use random normal initialization for the weight matrices. Use np.random.normal() * 0.01
Sorry I mistyped, it should say np.random.randn(). However, it only works with np.random.normal(), so I don’t know if I have an outdated version of the notebook.
It will work fine with np.random.randn. I built the code that way and it worked for me. Note that if you type new code and just call the function from the test cell again, it runs the old code. You actually have to click “Shift-Enter” on the modified function cell in order to get the new code added to the runtime image.
Thanks. I did call the function again, so I guess this could be an issue with my environment. I had to restart the whole kernel for it to work correctly with randn. Thanks for the help!
Glad to hear you got it to work, but the evidence you report suggests that you are misinterpreting what I said. The point is that if you just call the function again after typing new code, it just runs the old code. You can easily prove this to yourself:
Take a function that you know works and purposely break it by multiplying the return value by 2. Now run the test that calls the function again. It still works, right? Even though you broke it.
Now click on the function cell and type “Shift-Enter”. Now run the test again: “Kaboom!”, right?
The point is that “Kernel → Restart” reruns everything from the beginning, so that picks up the new code.