Jacob2309
Jacob2309

Reputation: 91

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')

Upvotes: 3

Views: 3241

Answers (2)

Jacob2309
Jacob2309

Reputation: 91

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

opt.hess_inv.todense()

Upvotes: 4

Ben Rhodes
Ben Rhodes

Reputation: 33

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

Upvotes: 1

Related Questions