CUTEstProblem.gradsphess

CUTEstProblem.gradsphess(x, v=None, gradient_of_lagrangian=True)

Evaluate the sparse gradient of objective or Lagrangian, sparse Jacobian of constraints, and sparse Hessian of objective or Lagrangian. For constrained problems, the gradient is L_{x}(x,v) and the Hessian is L_{x,x}(x,v).

# For unconstrained problems
g, H    = problem.gradsphess(x)
# For constrained problem (g = grad Lagrangian)
g, J, H = problem.gradsphess(x, v=v)
# For constrained problems (g = grad objective)
g, J, H = problem.gradsphess(x, v=v, gradient_of_lagrangian=False)

For constrained problems, v must be specified, and the Hessian of the Lagrangian is always returned. For Hessian of the objective, use problem.ihess().

The vector g and matrices J and H are of type scipy.sparse.coo_matrix.

For small problems, problem.gradhess returns dense matrices.

This calls CUTEst routine CUTEST_csgrsh or CUTEST_ugrsh.

Note: in CUTEst, the sign convention is such that the Lagrangian = objective + lagrange_multipliers * constraints

Parameters:
  • x (numpy.ndarray with shape (n,)) – input vector

  • v (numpy.ndarray with shape (m,), optional) – vector of Lagrange multipliers (must be specified for constrained problems)

  • gradient_of_lagrangian (bool, optional) – for constrained problems, return gradient of objective or Lagrangian?

Returns:

sparse gradient of objective or Lagrangian, (sparse Jacobian of constraints), and sparse Hessian of objective or Lagrangian at x

Return type:

(scipy.sparse.coo_matrix(n,), scipy.sparse.coo_matrix(n,n)) or (scipy.sparse.coo_matrix(n,), scipy.sparse.coo_matrix(m,n), scipy.sparse.coo_matrix(n,n)