Week 2 Assignment 2 Exercise 8 d['w'] values not matching


In the above error, I am not able to understand where the problem is. No hardcoding, nothing.
Here is my code for more clear picture:
{ mentor edit }
I am on it for a lot of time now. Need urgent help. thanks.

Hello, @Zain_Abbas1,

The error revealed that your d['w'] was an array of zeros, which might be explained by the fact that we were initializing w to zeros. Now the problem is why it didn’t get updated after optimize, right?

optimize returns a new value of w in params, and the exercise hint asked us to: -

image

Did you do that?

Note that the lines in my screenshot are included in the assignment, since this is only your 2nd assignment for the DLS, I would suggest you to make the most of it by (1) copying them (and the whole code skeleton provided), (2) pasting them in the solution section and (3) filling in the blanks.

Cheers,
Raymond

PS: Sharing your solution isn’t allowed here, but please don’t worry, I will remove it for you. Usually it’s sufficient to just share the full error traceback for mentors or others to make suggestions to you. Good luck! :wink:

1 Like

Hi Raymond,
Thanks for the quick response. Actually I did retrieve the values from params dictionary and assigned to w and b. But still it is picking up the initialized values.

Hello, @Zain_Abbas1,

Then the next thing to do is to inspect the variables’ values. For example, what do you see if you print the variable params returned from your optimize function? Can you share that with us?

params contains the value that should be assigned to w. If that is the correct value (which you can find in your screenshot above), then the question is why it didn’t get assigned to the d['w']; if that is an array of zeros, then optimize calculated something wrongly.

Cheers,
Raymond

Hi @rmwkwok ,
I resolved the issue. Thanks to you for assisting. It was such a minor mistake that I cannot believe I did that.
I was passing params[‘w’] and params[‘b’] directly into the optimize function without assigning these values to w and b to update them. Because of this the values in the variables w and b were not updating.

2 Likes

You are welcome, @Zain_Abbas1! It’s good to know that you solved it yourself.

Cheers,
Raymond