Hi, I am having problem with getting the expected value of Cost with regularization and cannot past the Public tests, have 13.67 instead of 28.09, even if I use the hints code. Can I get some help on this please?

Hi!

Is it possible the regularization terms are being divided by 4?

If the regularization terms are calculated as above then added to the total_sum of the function then the total_sum is divided by 2 it’s the same as dividing the regularization terms by 4.

The solutions are either to divide each term by 2 as it’s calculated.

Or add all terms and divide by 2 at the end.

Hi Sam, I think there might be some problems with my regulation term, but after I make changes it went wrong even further. Can you please check my regulation term and see what’s the problem?

“Mentor Edit, Removed Code”

Hi!

The regularization terms are being calculated nu * nm times.

They only need to be calculated once.

Oh！ I managed to get it works now. Thank you!!

Hi Sam, exactly the problem that I was facing – perhaps I was too tired to see it?

Thanks!

Sorry, I am still not getting it. Please help.

I do not understand why the regularization should be calculated only once and not for every `nu`

and `nm`

in the loop.

As the sum for every j, all the object in the vector (over k element) and also

the sum is for every i, all the object in the vector (again, over k elements).

thanks

tal

Hi!

In the original question the entire regularization term was being calculated nu * nm times.

So

the sum for every j, all the object in the vector (over k element) and also

the sum is for every i, all the object in the vector (again, over k elements).

was being done nu * nm times.

And just as a reminder this is the cost function:

Hello!

I am kind of confused on this part of the assignment as well. I have looked at the hints that come along with the first exercise and understand we are first supposed to implement the non-regularized code. However, I am unsure of where exactly I need to put the regularized code. Would anyone be willing to point me in the right direction?

Many thanks in advance!

Never mind, I was able to resolve the issue!

The first test with regularization works, but the second test seems wrong.

I put in a print function to tell me what R[i,j] was for each loop.

print(“R[”,i,", “,j,”]= ",R[i,j])

The expected output is 27, but if every R[i,j] is zero, how could the cost function it be anything other than zero?

Output:

# Public tests

##
from public_tests import *

test_cofi_cost_func(cofi_cost_func)

R[ 0 , 0 ]= 0.0

R[ 1 , 0 ]= 0.0

R[ 2 , 0 ]= 0.0

R[ 3 , 0 ]= 0.0

R[ 4 , 0 ]= 0.0

R[ 0 , 1 ]= 0.0

R[ 1 , 1 ]= 0.0

R[ 2 , 1 ]= 0.0

R[ 3 , 1 ]= 0.0

R[ 4 , 1 ]= 0.0

R[ 0 , 2 ]= 0.0

R[ 1 , 2 ]= 0.0

R[ 2 , 2 ]= 0.0

R[ 3 , 2 ]= 0.0

R[ 4 , 2 ]= 0.0

R[ 0 , 3 ]= 0.0

R[ 1 , 3 ]= 0.0

R[ 2 , 3 ]= 0.0

R[ 3 , 3 ]= 0.0

R[ 4 , 3 ]= 0.0

AssertionError Traceback (most recent call last)

in

1 # Public tests

2 from public_tests import *

----> 3 test_cofi_cost_func(cofi_cost_func)

~/work/public_tests.py in test_cofi_cost_func(target)

14 J = target(X_r, W_r, b_r, Y_r, R_r, 2);

15 assert not np.isclose(J, 13.5), f"Wrong value. Got {J}. Did you multiply the regularization term by lambda_?"

—> 16 assert np.isclose(J, 27), f"Wrong value. Expected {27}, got {J}. Check the regularization term"

17

18

AssertionError: Wrong value. Expected 27, got 0. Check the regularization term

Because we still have the regularization term. Did you add it?

Raymond

Ding Ding Ding!!!

Thank you!

You are welcome Jake!

Raymond