For C2_W1_Assignment Exercise 4 All Test Case Passing Except One

For C2_W1_Assignment [Optimizing Functions of One Variable: Cost Minimization] Exercise 4 All Test Cases Passing Except 1 , getting following issue:

Test for index i = 5. 
	Expected: 
-83.240036
	Got: 
-83.239990234375
 7  Tests passed
 1  Tests failed

I tried rounding up the value set in dLdOmega_of_omega_array function. But same issue.

1 Like

Hi @Nitya_V. Welcome to the community!

Your output is very close to the expected output. Have you tried running the cell again?

If it still doesn’t work, can you privately send me your code? Thank you.

Yes, i have tried running multiple times. But output is same.

Attached the solution file which i have submitted for your reference.
{moderator edit: file removed}

Hi @Nitya_V.

The small problem was propagated way back to Exercise 2 where you are to build the f_of_omega function.

There are two things that you can try:

  1. Try using ‘float64’ (which is the default) instead of ‘float32’
  2. Try to rewrite this function with only 1 line of code (recommended). Because Python already does matrix operation, i.e. matrix multiplied by scalar, and there is no need to write a for loop for each value of the prices to calculate f_of_omega. But as far as I know, your function still works fine. I’m just not sure if it will pass all the tests.

Let me know if it works. Thanks!

Thank You Jonathan for inputs.
I will try them.

Hi, I also face this kind of error, but it cannot pass from one test that result is different in tiny value, what you can advice?

Please I also have the problem, how am I going to solve it, I’ve tried running again and again

I also have the same problem

Test for index i = 400.
Expected:
-124.38398
Got:
-124.38395690917969

I tried to run it with float64 but it didnt work

First, be very careful replying to old threads. This assignment has been updated many times, and information you read on the forum may not be applicable.

Second, the grader is very specific about what math it expects you to implement.

For example in the f_of_omega() function, your code will not pass the grader (due to internal floating point representations) unless you implement the math exactly as given in the instructions (shown below):
image

@JorgeAldana, I’m sure that you have resolved your issues, but I wanted to respond to this thread to relate my own experience.

It’s interesting that your error is just a matter of significant digits- your value is essentially correct. It just goes to more digits.

I used float32, and I was able to pass. What was weird in my experience is that I failed two of eight tests locally, getting really strange values. When I ran the same solution in the lab notebook, however, everything passed. I suspect this is caused by something in the JAX module.

1 Like