简体   繁体   中英

How to get Hessian Matrix from python minimize function?

Is there any way that we could get the Hessian matrix (so as to calculate the standard error) after getting the optimization result through scipy.minimize function?

The parameter of hessian in the minimize function seems to be input instead of an output.

from scipy import minimize

opt = minimize(logitfn, args=df, x0=x_start, method='Nelder-Mead')

Use 'L-BFGS-B' method, and then:

opt.hess_inv.todense()

Given a function f and initial point x0, and assuming we use L-BFGS-B, then the following code works:

opt = minimize(f, x0=x0, method='L-BFGS-B')
B = opt.hess_inv  # LinearOperator object
B = B * np.identity(B.shape[1])  # numpy array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM