Week 2, Assignment, Exercise 5 - Propagate

Hello, Could someone help me figure out what is missing in my code.
To implement the propagate function, I started with writing the activation followed by the cost, but I have one issue when writing dw. it tells me invalid syntax.
Even when I set dw = 1, it tells me the same issue: invalid syntax at dw

Moderator edit: code removed.

Welcome to the community.

This types of error occurs when a previous code has some errors in pairs of parenthesis, quotation, and so on.

I think your cost function does not have an equal number of open/close parenthesis.
That’s the first step to fix.

Then, you may be better to look at the cost calculation itself. We may need to transpose “A” for dot product.

Hope this helps.

Thank you very much. It was a parenthesis. But for the seconnd advice, I tried to transpose A but This time the error I got is : wrong value 8.168547875217449 != 2.0424567983978403

If you just add the closing parenthesis, and transpose A, then, it does not work.
Please look at the given equation closely.

J = -\frac{1}{m}\sum_{i=1}^m(y^{(i)}log(a^{(i)})+(1-y^{(i)})log(1-a^{(i)}))

The strategy is either to go with an element-wise multiplication or matrix operation (like dot product). Your previous implementation is mixture of two strategies.

You can see two terms that you need to tackle, i.e., y^{(i)}log(a^{(i)}) and (1-y^{(i)})log(1-a^{(i)})
If you go with a matrix operation like dot product, then, you will not need a summation.
If you go with an element-wise multiplication, then, you will need a summation.

With looking at your implementation, you use a dot product for the 2nd term. I think that’s the right way to implement (with transposing A). But you need to be consistent to both two terms above. (of course, it is possible to use a summation and dot product separately,… but, it may be a problem from a code readability.) Then, you can eliminate a summation, and get a right answer.

In any cases, you need to revisit your implementation of cost calculation.

Great ! Thank you for letting me know.

But, one thing… Posting a code is not recommended in here. (And, yours is the answer to this exercise :slight_smile: ) So, please remove it…

Hi @codewith_africa. I have removed the code from your original post. @anon57530071 is indeed correct about posting code, and in fact, it is against the Specialization’s honor code. Thanks for your future compliance! :grinning: