W2_Assignment_Ex6 : Optimize function : broadcast error

Hi,

I got this error after running the Optimize function, yet when i run the propagate function there is no problem, all the tests are passed, so i don’t understand why when i call the propagate function in the optimize function it raises an error…

Thanks in advance for your help :slight_smile:

1 Like

@bousek.dorian the code I see looks okay. Does it give you this error on the very first attempt of the loop in the optimize function, or does it run a few times first ?

Perhaps, in optimize() in the:

        # update rule (≈ 2 lines of code)
        # w = ...
        # b = ...
        # YOUR CODE STARTS HERE

You are doing something that inadvertently alters the dimensions of w ?

Perhaps your code in propagate works for only one shape of dataset, but not for all shapes.

Thank you for your answer !

Well when i add a counter in the code it looks like it loops 2 times then it raises the error…So maybe It’s the way i computed propagate that causes the error?

Here’s my propagate function code tho, It might help you to understand better what i did.

(By the way i coded the “cost” with basic multiplications and not dot products coz it raised me another error of shape when i tried to)

{moderator edit - solution code removed}

Yeah that’s what I thought too but I can’t figure it out what I did wrong since I didn’t modify anything except adding the lines of code requested…

I’ll bet your error is in the “update parameters” code in optimize. Please check the logic there compared to the math formula. You are probably using dw to update b.

1 Like

Please note you are not supposed to openly post your code here – One of the moderators will edit your post.

Again, since it runs at least once, before you update, something is wrong with your update code in optimize that is altering the dimensions of w.

1 Like

I’ll bet it’s the shape of b that is 2 x 2.

1 Like

Yes, I guess you are right since it is a ‘broadcast’ error and not just a dims mismatch.

1 Like

Yes you was right !
It was a simply bad error in my code; when i update b i was using “w - learning_rate” instead of b…
Thank’s yall for your precious help, next time I will take the time to clearly understand the error to debug it correclty.

Again thank you so much ! And sorry for the screen capture of the code, won’t happen again.

1 Like