pythonpython-3.xhessian-matrixscipy-optimize

defining the Hessian as zero


While using scipy.optimize.minimize with the trust-constr method I got this UserWarning:

 scipy\optimize\_hessian_update_strategy.py:187: UserWarning: delta_grad == 0.0. Check if the approximated function is linear. If the function is linear better results can be obtained by defining the Hessian as zero instead of using quasi-Newton approximations. 'approximations.', UserWarning)

I have a linear function so I want to try to set the hessian as zero. But how does this work? I tried the easiest way with "hess = None" as parameter. Okay, a bad try.

This is the line calling the solver:

solution = scopt.minimize(minimizeFunction,initialGuess ,method='trust-constr', constraints=cons,options={'disp':True,'verbose':3},bounds=bnds)

Solution

  • When you define the constraint, you want to set

        hess = lambda x: numpy.zeros((n, n))
    

    Here n is the dimension of the array. Notice that you can also use a LinearConstraint object