I added a print statement in my propagate code to show the A and m values. Here’s what I see on the test cell for propagate:
m = 3
A = [[0.99979657 0.62245933 0.00273196]]
dw = [[ 0.25071532]
[-0.06604096]]
db = -0.1250040450043965
cost = 0.15900537707692405
m = 4
A = [[0.99849882 0.99979657 0.15446527 0.99966465]]
All tests passed!
There must be some problem with your code. Notice that all your values have much smaller absolute values than my results and all of them include the factor of \frac {1}{m}. Are your A and m values the same as what I show above?
Dear @paulinpaloalto, thank you very much for your answer. As you mentioned there was an error in my code. Fortunately, I was able to figure it out. Thank you for your help!
Hi @paulinpaloalto , I am having a problem with the propagate function as well and I have also been getting the same outputs those being:
dw = [[-0.00154399]
[-0.00492761]]
db = 0.0014555781367842193
cost = 0.0015453193941501516
The thing that has been confusing me is that my A and m do not match. For the A values before applying sigmoid I have a 1x3 , I have [[ 9. 12. -5.4]] and after A = [[0.99987661 0.99999386 0.00449627]]. Is there something I am misunderstanding here with the operations. I thought I was taking the dot product of w.T, a 1x2 (w is a 2x1) with X which is a 2x3 to get 1x3. After getting the dot product, I broadcast the bias which was 2f in the tests. And I can call the sigmoid function or rewrite the sigmoid function, and apply the sigmoid to that vector to get A.
As for m which is provided as m = X.shape[1]. I thought m is the number of examples, is that correct? m is given by the prompt and when I print m, I get the 3. But I noticed, your m increases from 3 to 4.
That just means you have the old version of the notebook. I added the logic to also print out my Z values
Z = w^T \cdot X + b
before computing A and here’s what I get for the propagate test cell:
m = 3
Z = [[ 8.5 0.5 -5.9]]
A = [[0.99979657 0.62245933 0.00273196]]
dw = [[ 0.25071532]
[-0.06604096]]
db = -0.1250040450043965
cost = 0.15900537707692405
m = 4
Z = [[ 6.5 8.5 -1.7 8. ]]
A = [[0.99849882 0.99979657 0.15446527 0.99966465]]
All tests passed!
The point is that second test (the one from public_tests.py) has also changed in the latest version of the notebook. It has m = 4 and some different input values. You need to use the “get a clean copy” procedure from the FAQ Thread to get the latest version. Note that you need to delete the file public_tests.py before you do the “Get Latest Version”, so that you pick up the new version of that file which has the fix in addition to the notebook file itself. You need to move the notebook file aside (as described in the instructions) and then “copy/paste” over your work to the new copy.
The instructions are pretty clear that the “Get Latest Version” procedure will never overwrite an existing file, so you need to move your version of the notebook aside and also delete all the utility files (the dot py files) you see when you click “File → Open” in order to get the updates.
The other big topic here is how “updates” work when the course staff publishes a new or fixed version of something. They can publish any given update either as a “forced update” or not. I think they usually used “forced” updates, so you get it without any action on your part. Then you need to recover any of your work from the saved copy of the notebook that they moved aside (the date will be interpolated into the name) and saved for you. So it looks like they must have published the latest fix as a “self paced” fix that you have to ask for. Well, either that or there is something about your situation that I don’t understand.
If you are going to use the dot product to compute the cost, it requires that you transpose the second operand. Here’s a thread which shows some examples of the techniques that can be used.
The value you show does look like it is a 64 bit floating point value. Please print the type you are actually getting and see what it is. E.g. try adding this print statement to your code in propagate:
print(f"type(db) = {type(db)}")
When I run the test case for propagate with that statement in place, here’s what I get:
@paulinpaloalto@andres.castillo I am getting this same assertion error due to the public_tests.py checking against the wrong inputs.
What do you mean by you need to “forceRefresh” to get the fix working? I have tried refreshing the page, restarting the Kernel, and typing in “forceRefresh()” and “forceRefresh” into a cell, but I am still getting this assertion error on the side of the developer. What can I do to get this working?
Your cost calculation is wrong. You are dotting a 1 x m array with a scalar, which will give you a 1 x m array as the output if I am reading the code correctly. Also db should be a scalar. You need an np.sum there.
@paulinpaloalto , could you tell how can I get the newer version of this notebook , this problem has wasted a lot of my time and I am not sure how this would be configured
Just an insight. I don’t want to spoil. I held ValueError: shapes (1,3) and (1,3) not aligned for some time.
np.dot is element-wise multiplication (or np.multiply) followed by np.sum. Sometimes it is better to do it explicitly.
Error corrected, test passed.