My error is shown below. My propagate function tests no problem, I don’t know why there is an error after optimization calls propagate.
AssertionError Traceback (most recent call last)
in
7 print("Costs = " + str(costs))
8
----> 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}"
76
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.59716577)] != [5.80154532, 0.31057104]
Hey @Yunbo_LYU,
Welcome to the community. The issue is with the data type and not with the numerical values. As you can see in your error, the numerical values are exactly the same, but your costs
variable is an array of arrays, while the expected costs
variable is simply an array.
I guess the problem lies in the propagate
function, since the optimize
function doesn’t modify the cost
variable anyhow. It simply appends cost
to costs
. Here, the cost
variable should be a single numeric value, while in your code, it is an array. Check your propagate
function once, especially the np.squeeze
part. I hope this helps.
Also, just a suggestion regarding the use of Forums, do try to mention the Week and Assignment designations in your title, so that the mentors and the fellow learners have an easy time figuring out your query. For now, I have done it for you using the little pencil icon next to the title.
Regards,
Elemento
1 Like
Hi Yunbo,
Welcome to the community.
Check the codes that you are calling for the function. The traceback says, it must be a list.
Thanks.
1 Like
Thanks for your help!
I’ve modified the code about np.squeeze, but the problem still exists. It seems that the second numerical value in the list is wrong.
New traceback is show bellow:
AssertionError Traceback (most recent call last)
in
7 print("Costs = " + str(costs))
8
----> 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}"
76
77 assert type(grads[‘dw’]) == np.ndarray, f"Wrong type for grads[‘dw’]. {type(grads[‘dw’])} != np.ndarray"
AssertionError: Wrong values for costs. [5.801545319394553, 0.5971657673564212] != [5.80154532, 0.31057104]
Thanks for your help!
I’ve modified the code about np.squeeze, but the problem still exists. It seems that the second numerical value in the list is wrong.
New traceback is show bellow:
AssertionError Traceback (most recent call last)
in
7 print("Costs = " + str(costs))
8
----> 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}"
76
77 assert type(grads[‘dw’]) == np.ndarray, f"Wrong type for grads[‘dw’]. {type(grads[‘dw’])} != np.ndarray"
AssertionError: Wrong values for costs. [5.801545319394553, 0.5971657673564212] != [5.80154532, 0.31057104]
Hi Yunbo,
A similar kind of query has been discussed in this thread. Please have a look and if it doesn’t solve your problem, we can discuss it further.
Thanks.
1 Like
Finally solved the problem, thanks to Elemento‘s help.
There is a typo in your optimize
function. You have written b = b = learning_rate * db
whereas it should be b = b - learning_rate * db
. I hope this helps.
Thanks for your help.
Finally solved the problem, thanks to Elemento‘s help. There is a typo.
Regards,
Yunbo