Week 2 Exercise 5 propagate function

Hi!

I have the same problem with the results of exercise 5. I’m getting these results even after updating to the latest version:

dw = [[-0.00154399]
[-0.00492761]]
db = 0.0014555781367842193
cost = 0.0015453193941501516
All tests passed!

These results don’t match the expected values.

1 Like

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?

1 Like

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!

1 Like

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.

1 Like

Hi, Ryan.

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.

1 Like

Thank you very much for the assistance, you were correct, it was just a matter of updating the public_tests.

I get a traceback error: ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0). I would appreciate any insights. Thank you.

3 Likes

I am getting this error, how to fix it ???

1 Like

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.

Thank you! I understand it better now.

1 Like

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:

type(db) = <class 'numpy.float64'>
dw = [[ 0.25071532]
[-0.06604096]]
db = -0.1250040450043965
cost = 0.15900537707692405


Of course that passes the assertion as written. What do you see for the type?

1 Like

@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?

2 Likes

There is a topic on the FAQ Thread that explains how to get a clean copy of the notebook and the associated files.

2 Likes

I am getting the same Assertion Error and for the type I am getting :
type(db) = <class ‘numpy.ndarray’>

Attaching the SS of my code

{moderator edit - solution code removed}

1 Like

I tried using np.float64 too , but it doesn’t change the type.
I also tried using np.dot()

I can’t figure out where the error is occuring

1 Like

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.

3 Likes

@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

please respond as soon as possible

1 Like