Hi,
The hessian sparsity pattern would be useful for 2 cases:
- The first case is when the user is providing the exact hessian. It is useful in this case because the Knitro API expects the hessian to be provided as a sparse matrix and so we need to know the sparsity pattern (rows
and column indices) to match them to the hessian values returned in the user hessian callback.
- The second case is when the hessian is approximated via finite-differences. Knitro does not provide an option to approximate the full hessian via finite-differencing because it is generally too expensive for large-scale
problems. In the MATLAB example you reference, they are approximating the hessian via finite-differences, which is why they use the sparsity pattern here.
Knitro offers 4 methods for approximating the hessian, see:
The "bfgs" and "sr1" options are dense by construction so they cannot make use of the sparsity pattern (even when it might be available).
The "lbfgs" and "product_findiff" options do not explicitly store a hessian (approximation) so they cannot make use of the sparsity pattern. The first is able to build an approximation from a couple arrays of data, and the second only approximates directly
hessian-vector products (without storage of a hessian).
I hope this helps.
Regards,
-Richard Waltz