C2 Week-1 Assignment: All the exercises passes ,but final score is zero

Hi,

C2 Week-1 Assignment: All the exercises passes ,but final score is zero.

please help !!

β€” Bonny

3 Likes

C2_W1_Assignment
I get the following error:
Cell In [24], line 9
dLdOmega_array = dLdOmega.at[i].set(dLdOmega)
^
SyntaxError: invalid syntax

1 Like

thanks @Carlos_Merino . I fix it.

1 Like

Is everything ok here? Or do you need more help?

1 Like

@yjcb22 yes, all good. Thank you.

1 Like

unable to finish C2_W1_Assignment Machine Learning Calculus I get error in line 20:

This is organised as a function only for grading purposes.

def dLdOmega_of_omega_array(omega_array):
N = len(omega_array)
dLdOmega_array = np.zeros(N)

for i in range(N):
    ### START CODE HERE ### (~ 2 lines of code)
    dLdOmega = grad(omega_array([i])
    dLdOmega_array = dLdOmega.at[i].set(dLdOmega)
    
    #L = L_of_omega(omega_array[i])
    #L_array = L_array.at[i].set(L)
    ### END CODE HERE ###
    
return dLdOmega_array

dLdOmega_array = dLdOmega_of_omega_array(omega_array)

ell In [20], line 9
dLdOmega_array = dLdOmega.at[i].set(dLdOmega)
^
SyntaxError: invalid syntax

1 Like

This is correct!
You are getting an error because if you look at your code what you are trying to do is to place dLDOmega in the array named dLdOmega_array. But, you are trying to access dLDomega instead of dLDomega_array. Look at your code here:

dLdOmega_array = dLdOmega.at[i].set(dLdOmega)

Do you see something fishy after the = ?

1 Like

sorry no
I have followed
#L = L_of_omega(omega_array[i])
#L_array = L_array.at[i].set(L)

1 Like

I am not following. What do you mean by β€œsorry no”?

The error show in your thread is not with the comments but here: dLdOmega_array = dLdOmega.at[i].set(dLdOmega)

2 Likes

i mean that I do not see something wrong after the = dLdOmega.at[i].set(dLdOmega) so I do not know how to proceed .

1 Like

Probably we are talking about different things.

Can you please confirm if this is the part where you have issues?

1 Like

It is that exercise C2_W1_Assignment but I have issues in exercise 4:

for i in range(N):
### START CODE HERE ### (~ 2 lines of code)
dLdOmega = grad(omega_array([i])
dLdOmega_array = dLdOmega.at[i].set(dLdOmega)

#L = L_of_omega(omega_array[i])
#L_array = L_array.at[i].set(L)
### END CODE HERE ###
1 Like

I wanna exercise 4 in this assignment please

Thanks for your reply. Now, we are on the same page. I see multiple issues. Please find my comments:

  1. The idea here is to use the library named JAX to calculate the derivative of the function so you do not have to do it manually. This is why you are using the function grad(). However, the function is designed to take 2 arguments so it will look something like this:

grad(argument1)(argument2)

where:

  • argument1 will be the function you want to differentiate. In this case remember we want to differentiate the function defined with the name L_of_omega

  • argument2 will be the array with the values you want to evaluate for each iteration. In this case the name of the array is omega_array and you need to get the value at i so this one is correctly set as omega_array[i]

  1. You need to place the result dLdOmega into the array dLdOmega_array. For this you need to take the array and use the methods at.set(). But, currently instead of taking the array you are trying to take the dLdOmega variable. Let me see if you spot what is wrong with dLdOmega.at.set() based on what I just said. One more time. You need to use dLdOmega_array and apply at.set() on it

Please note that I cannot provide you with the answer of the exercise, but I can answer an specific question if that helps.

thanks, i understand that

1 Like

Dear Fatma,

Thanks for your message. I will be kindly enough to explain your issue here:

You have the same problem I explained to Carlos as follows:

  1. The idea here is to use the library named JAX to calculate the derivative of the function so you do not have to do it manually. This is why you are using the function grad(). However, the function is designed to take 2 arguments so it will look something like this:

grad(argument1)(argument2)

where:

  • argument1 will be the function you want to differentiate. In this case remember we want to differentiate the function defined with the name L_of_omega
  • argument2 will be the array with the values you want to evaluate for each iteration. In this case the name of the array is omega_array and you need to get the value at i so this one is correctly set as omega_array[i]
1 Like

Thank you yjcb22,
I have tried:

This is organised as a function only for grading purposes.

def dLdOmega_of_omega_array(omega_array):
N = len(omega_array)
dLdOmega_array = np.zeros(N)

for i in range(N):
    ### START CODE HERE ### (~ 2 lines of code)
    dLdOmega = grad(L_of_omega,omega_array[i])
    dLdOmega_array= dLdOmega_array.at[i].set(dLdOmega_array)
    
return dLdOmega_array

dLdOmega_array = dLdOmega_of_omega_array(omega_array)

But, it does not work either,

Very good!

The only issue now is the syntax. It needs to be like this:
dLdOmega = grad(L_of_omega)(omega_array[i])

The other issue is dLdOmega_array needs to be like this:
dLdOmega_array = dLdOmega_array.at[i].set(dLdOmega)

2 Likes

thanks, now it works!!