Reputation: 57
I am using SciPy's 'minimize' function to minimize a function. The function returns the optimal value, along with an estimated Jacobian and Hessian. As below:
fun: -675.09792378630596
hess_inv: <8x8 LbfgsInvHessProduct with dtype=float64>
jac: array([ 6.34713615e-02, 1.15960574e-03, 1.63709046e-03, 2.16914486e-02, -8.02970135e-02, -4.39513315e-02,
6.69160727e-02, -5.68434189e-05])
message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
nfev: 684
nit: 60
status: 0
success: True
x: array([ 9.93756778e-01, 3.51823214e+00, -2.06368373e-01, 7.37395700e-04, 2.11222756e-02, 3.29367564e-02, 1.22886906e-01, -2.75434386e-01])
I want the estimated Hessian, but when I have it return hess_inv, all I get returned is
<8x8 LbfgsInvHessProduct with dtype=float64>
rather than the maxtrix itself. How do I have it return the matrix?
Upvotes: 3
Views: 2663
Reputation: 74
From the SciPy documentation for the LbfgsInvHessProduct; you can use the method todense() to obtain the LbfgsInvHessProduct's values as a dense array.
However, keep in mind the LbfgsInvHessProduct is still a matrix! It's a special memory-optimized format, but you can still call other matrix functions such as matmat(), transpose(), dot() etc.
Upvotes: 4