def optimize(cost_function, init_params, steps):
opt = qml.GradientDescentOptimizer(stepsize = 0.4) # Change this as you see fit
params = init_params
for i in range(steps):
params = opt.step(cost_function, params)
return params, cost_function(params)
init_params = \[0.1, 0.2, 0.3, 0.4\]
# Run the optimizer for, say, 200 steps
opt_params, minimum = optimize(cost_function, init_params, 200)
# Convert the zero-dimensional result to a NumPy array
minimum = np.array(minimum) # An np.tensor of shape () containing the minimum of cost_function.
Error: Incorrect: The output of your cost function isn't quite right!. How to debug this code or Use the `optimize` to find the `minimum` of the cost function (`cost_function`) you defined on the previous codercise. You may use `cost_function` without defining it again here. Note that minimum should be an `np.ndarray` containing only the minimum value of `cost_function`
Hi!
I think your optimize function is correct. The problem is when you define the initial parameters. Try using a numpy array for that: init_params = np.array([0.1, 0.2, 0.3, 0.4])
Recall that this array should be differentiable.
Let me know if this helps.