W2_Ex-3_Test failing_under test(test_cases, target)

Hi, I’m stuck for a week with it, and have no clue what am I doing wrong.

In the exercise 2, where we calculate sigmoid with “math”, the test it passed. When I’m using the same formula, but for np.array type (using np.exp(x)), it says the output is wrong.

I did a check in PyCharm this way:
print(str(sigmoid_math(1)))
x = np.array([1, 1, 1])
print(str(sigmoid(x)))

Where sigmoid_math(x) is a function calculating sigmoid with math.exp(x), and sigmoid(x) calculating it with np.exp(x). I’m getting following output in PyCharm, that looks to be correct:
0.7310585786300049
[0.73105858 0.73105858 0.73105858]

But in the assignment It says “wrong output”.

sigmoid(t_x) = [0.73105858 0.98201379 0.99987661]
Error: Wrong output.
2 Tests passed
1 Tests failed

AssertionError Traceback (most recent call last)
in
2 print("sigmoid(t_x) = " + str(sigmoid(t_x)))
3
----> 4 sigmoid_test(sigmoid)

~/work/release/W2A1/public_tests.py in sigmoid_test(target)
49 ]
50
—> 51 test(test_cases, target)
52
53

~/work/release/W2A1/test_utils.py in test(test_cases, target)
24 print(‘\033[92m’, success," Tests passed")
25 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
—> 26 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for sigmoid. Check your equations and avoid using global variables inside the function.

Hello @Michael_Derzhavets! I hope you are doing well.

It’s np.exp(-x), right?

Best,
Saif.

Here is my output for that test cell.

sigmoid(t_x) = [0.73105858 0.88079708 0.95257413]
 All tests passed.

You can see that your first value matches what I get, but the other two do not. Hmmmm. If the bug is the one that Saif suggests, then I’d expect all of them to be wrong. I’m having trouble coming up with a theory for how the answer could be right for x = 1. but wrong for 2. and 3.

Wow, thank you! I thought that “e to the power of -x” is “pow(np.exp(x), -x)”, and this was my problem. The fact that it worked in Ex.2 confused me :slight_smile:

Well, it would probably work if you used np.pow(np.exp(1), -x), although that’s a pretty strange way to write the code. That also explains why your first element was correct and the others weren’t. :nerd_face:

Right, for me it’s not only Deep Learning course, it’s also a math course :slight_smile:

But practice makes perfect. When I started this course, it was not only a Deep Learning course but also a math and programming course.

Best,
Saif.