I know the jacobian is the first derivative, but I don't know how to compute it for my simple function (I tried online derivative calculators) and pass it to my scipy minimize function.
In code, here is the objective function (guess arrays can contain thousands of variables):
def objective(current_guesses_array, first_guesses_array):
return np.sum(np.divide(np.square(current_guesses_array - first_guesses_array), first_guesses_array))
I think the Jacobian is like this, but definitely may have messed up here:
dx = 2x/y - 2
dy = 1 - (x^2/y^2)
In code:
def jacobian_for_minimize(self, x,a):
dx = (2*x)/a - 2
dy = 1 - (np.square(x) / np.square(a))
return np.array([dx,dy])
minimize(objective,initial_guesses,args=initial_guesses,jac=jacobian_for_minimize,method='SLSQP')
After calling minimize, I get an error: _slsqp.error: failed in converting 8th argument `g' of _slsqp.slsqp to C/Fortran array
According to another Stack overflow page, it means the objective function isn't returning a scalar, and it has to.
Can anyone tell where I went wrong with this?