Hello,
I am trying to understand/learn how to get errors for my minimized results, and was referred to statsmodels for this.
I'm new to statsmodels and just wanted to confirm my setup since there are no example for Hessians on the docs.
I have a script that is doing some minimization.
import numpy as np
from scipy.optimize import basinhopping
from statsmodels.tools.numdiff import approx_hess2
solution=basinhopping(fun,minimizer_kwargs={"args":(input1,input2),"method" : 'Powell',"bounds":((0,np.inf),)*2}, x0=np.array([1.0,1.0]))
What I wanted to see is whether or not the setup I have for the Hessian is correct, because it's results don't make much sense to me. This is how I have set it up
hessian=approx_hess2(solution.x,fun,args(input1,input2))
But the output doesn't make much sense to me. If the solution for basinhopping is this:
message: ['requested number of basinhopping iterations completed successfully']
success: True
fun: 2.9025799548976257
x: [ 8.341e+04 4.603e-03]
nit: 100
minimization_failures: 0
nfev: 11311
lowest_optimization_result: message: Optimization terminated successfully.
success: True
status: 0
fun: 2.9025799548976257
x: [ 8.341e+04 4.603e-03]
nit: 2
direc: [[ 1.000e+00 0.000e+00]
[ 0.000e+00 1.000e+00]]
nfev: 84
Then the Hessian I get is this:
[[1.66708814e-11 3.04307003e-04]
[3.04307003e-04 5.82690162e+03]
With the inverse diagonal being being [1.28435430e+12 3.67456319e-03]
Considering the values are 8e4 and 4e-3, the inverse hessian diagonal for these values is...really high?
Furthermore, I am a bit confused as to what is truly being calculated here. From my understanding, error propagation uses a covariance matrix as such
[df/dx df/dy][covariance matrix][df/dx df/dy]^T
I know the script calculates the derivative using finite differences (so this would calculate df/dx), but I believe the Hessian is the 2nd derivative, which from what I understand the inverse Hessian is therefore the covariance matrix, and the diagonal then the variances?
I apologize for the confusion here, I am just trying to understand/learn how to get errors for my minimized results, and am relatively new to the process.
Any help would greatly be appreciated!