Grad-checking-error


please help

you code for numerator or denominator is incorrect, you are not using np.linalg.norm for numerator or denominator

I am using np.linalg, the error happens before reaching this code

Hello,

Can you share the this part of code in personal DM, with description of which specialisation, course, week and assignment name, so that I can have a look. Click on name, then message to share the required code.

Regards
DP

Hello,

1.Your first graded cell code is incorrect for J where you have only mentioned the variable but forgot to put the function as we want an array as an output.
2. Second error.

GRADED FUNCTION: gradient_check

def gradient_check(x, theta, epsilon=1e-7, print_msg=False)

Although you have mentioned correctly for theta plus and minus, you didn’t include a necessitating part of the function to both J_plus and J_minus for the propagation to go forward.

  1. You hard coded J_minus[ i ] by recalling in that code layer with theta_minus[I ], remove the i from the theta_minus.

Do these corrections, if still having trouble let me know.

Regards
DP

i removed the [i] but now is giving type error with the increment J_plus[i]

Did you do the first correction? J =??

yes

What about the second error? did you forward propagated the j_minus and j_plus

yes, i did

GRADED FUNCTION: forward_propagation

def forward_propagation(x, theta):
“”"
Implement the linear forward propagation (compute J) presented in Figure 1 (J(theta) = theta * x)

Arguments:
x -- a real-valued input
theta -- our parameter, a real number as well

Returns:
J -- the value of function J, computed using the formula J(theta) = theta * x
"""

# YOUR CODE STARTS HERE # (approx. 1 line)
J = whatever code you written should be called with a function for array, which function do you call for such function, do you remember?/
# YOUR CODE ENDS HERE

return J

it has to do with tupple assignments

the forward propagation function is given and is not graded

forward_propagation_n(X, Y, parameters)

please only share your updated code in the personal DM only the code part I am asking for. copy and paste in the message inbox after clicking on my name.

  1. FOR J CODE INCLUDE THE FUNCTION FOR ARRAY WITH WHAT CODE YOU HAVE ALREADY WRITTEN IN A TUPLE.

Compute gradapprox using right side of formula (1). epsilon is small enough, you don’t need to worry about the limit.

# YOUR CODE STARTS HERE # (approx. 5 lines)
theta_plus =                                 # Step 1
theta_minus =                               # Step 2
J_plus = THIS CODE NEEDS CORRECTION                 # Step 3
J_minus = THIS CODE NEEDS CORRECTION              # Step 4
gradapprox =             # Step 5
# YOUR CODE ENDS HERE

Compute J_plus[i]. Inputs: “parameters_values, epsilon”. Output = “J_plus[i]”.

    # "_" is used because the function you have outputs two parameters but we only care about the first one
    # YOUR CODE STARTS HERE#(approx. 3 lines)
    theta_plus =                                  # Step 1
    theta_plus[i] =                                   # Step 2
    J_plus[i], _ = HERE YOU HAVE HARD CODED YOUR CODE REMOVE THE i FOR THE THETA_PLUS (theta_plus))  # Step 3
    # YOUR CODE ENDS HERE

REGARDS
DP

FORWARD PROPAGATION cell IS FOR THE PARAMETERS WHICH IS NOT PART OF THE GRADED CELL. TRY TO LOOK AT THE GRADER CELLS WHERE PARAMETERS NEED TO PASS THROUGH THE GRADIENT CHECK. IF YOU NOTICE BOTH FORWARD AND BACKWARD PROPAGATION PARAMETERS ARE NOT PART OF GRADED CELL FOR THIS ASSIGNMENT BUT THE GRADIENT DESCENT NEED TO BE DEFINED FOR FORWARD PROPAGATION.

Please go through the assignment carefully and patiently. I understand your issue. as there are many code layers to be written we tend to miss out some or don’t get the correct one. read the response again as I have explained in detail. By now you should get the correct. if still having trouble, share the updated code for the cells I have asked for in the personal DM.

Regards
DP

Hint:
“epsilon” is the change in the weight values - not the change in the cost.

Hello,

You have totally mismatch the corrections. Also you didn’t correct or sent me the first cell code which I told you to change for J, for this
Arguments:
x – a real-valued input
theta – our parameter, a real number as well

Returns:
J – the value of function J, computed using the formula J(theta) = theta * x
“”"

YOUR CODE STARTS HERE # (approx. 1 line)

J = whatever code you written should be called with a function for array, which function do you call for such function, do you remember?/

YOUR CODE ENDS HERE

return J

Kindly go back to your notebook, match with each of my response and do the corrections one by one, and if you still not able to pass, share the updated notebook again.

Regards
DP

I ran your notebook with the corrections, and all test passed.