I am getting the below error when i run the optimize_test(optimize) code. Please help.

w = [[0.04553606]
b = -0.12147494280342801
dw = [[-0.44605943]
db = -0.18386269739114
Costs = [array(0.5826722)]

AssertionError Traceback (most recent call last)
7 print("Costs = " + str(costs))
----> 9 optimize_test(optimize)

~/work/release/W2A2/public_tests.py in optimize_test(target)
73 assert type(costs) == list, “Wrong type for costs. It must be a list”
74 assert len(costs) == 2, f"Wrong length for costs. {len(costs)} != 2"
—> 75 assert np.allclose(costs, expected_cost), f"Wrong values for costs. {costs} != {expected_cost}"
77 assert type(grads[‘dw’]) == np.ndarray, f"Wrong type for grads[‘dw’]. {type(grads[‘dw’])} != np.ndarray"

AssertionError: Wrong values for costs. [array(5.80154532), array(0.69318437)] != [5.80154532, 0.31057104]

I have fixed the error, thankyou.


Notice that the first cost value (after 0 iterations) is correct, but the second one (after 100 iterations) is wrong. The whole point of the optimize function is updating the parameters based on the gradients generated by the propagate function. If your propagate function passed all the test cases, then that means there is something wrong with how you are applying the gradients to update the w and b values. Notice that your second cost value is higher than the initial cost, whereas the correct answer is lower. Are you sure you didn’t add instead of subtracting in the update formula?

Oh, sorry, I just replied the original post before I had seen the subsequent ones. Glad to hear that you found the bug. We can see from the deleted code that it was indeed a mistake in how you applied the update formulas, but not the theory that I suggested.