DLS Course 2 Week assignment Optimization methods

Hi the out put of the function update_parameters_with_adam is not matching the expected values.

AssertionError Traceback (most recent call last)
in
13 print(f"b2 = \n{parameters[‘b2’]}")
14
—> 15 update_parameters_with_adam_test(update_parameters_with_adam)

~/work/release/W2A1/public_tests.py in update_parameters_with_adam_test(target)
257 assert type(parameters[key]) == np.ndarray, f"Wrong type for parameters[’{key}’]. Expected np.ndarray"
258 assert parameters[key].shape == parametersi[key].shape, f"Wrong shape for parameters[’{key}’]. The update must keep the dimensions of parameters inputs"
→ 259 assert np.allclose(parameters[key][0], expected_parameters[key]), f"Wrong values. Check you formulas for parameters[’{key}’]"
260 #print(f"{key}: \n {str(parameters[key])}")
261

AssertionError: Wrong values. Check you formulas for parameters[‘W1’]

Calculated values:
W1 =
[[ 1.63949493 -0.62691477 -0.54326465]
[-1.08769515 0.85031501 -2.28657079]]
W2 =
[[ 0.33262355 -0.26414959 1.47708248]
[-2.0457142 -0.30744639 -0.36898502]
[ 1.14872646 -1.09849003 -0.15727519]]
b1 =
[[ 1.7549895]
[-0.7461017]]
b2 =
[[-0.89102966]
[ 0.02699863]
[ 0.56780324]]

Expected values:
W1 =
[[ 1.63942428 -0.6268425 -0.54320974]
[-1.08782943 0.85036983 -2.2865723 ]]
W2 =
[[ 0.33356139 -0.26425199 1.47707772]
[-2.04538458 -0.30744933 -0.36903141]
[ 1.14873036 -1.09256871 -0.15734651]]
b1 =
[[ 1.75854357]
[-0.74616067]]
b2 =
[[-0.89228024]
[ 0.02707193]
[ 0.56782561]]

I also notice that the argument values are not defaults.
t = 2
learning_rate = 0.02
beta1 = 0.8
beta2 = 0.888
epsilon = 1e-2

I have tried many things but no headway. Could you please review my solution to see if you can spot any bug if the notebook has some issue.

Please be aware that no-one else can see your work, so we cannot be the “deus ex machina” and just magically give you a solution. The most common problem on that section is the \epsilon value on the LHS of the main expressions. Look carefully at the formula and then at your code. Note that \epsilon is a) in the denominator and b) not under the square root. Are you sure you double checked the “order of operations” on that expression?

Thanks :slight_smile: “deus ex machina”. I was not sure if posting the code here was ok and hence was assuming I might be asked to share the code in some way.

Were you able to find the solution?

Yes, I was able to fix the issue. Thanks for checking. Epsilon was under the square-root.

1 Like