Class NonlinearVectorFunction

java.lang.Object
de.labathome.trustconstr.NonlinearVectorFunction
All Implemented Interfaces:
VectorFunctionLike

public class NonlinearVectorFunction extends Object implements VectorFunctionLike
Light-weight nonlinear vector function carrier for use inside PreparedConstraint.

Wraps a user-supplied fun(x), jac(x), optional hess(x, v) triple, caching f and J at the iterate passed to the constructor. Subsequent fun(Matrix) / jac(Matrix) calls re-evaluate when x changes.

This class is the analytic-derivatives counterpart of scipy's VectorFunction when jac and hess are both supplied by the caller. The full VectorFunction carries the finite-difference / quasi-Newton fallbacks; this class skips them. NonlinearConstraint already resolves an FD Jacobian when the user omits one (its constructor wraps a 2-point NumDiff closure), so by the time we reach this class jac is always a working callable.

  • Constructor Details

    • NonlinearVectorFunction

      public NonlinearVectorFunction(Function<Matrix,Matrix> fun, Function<Matrix,Matrix> jac, BiFunction<Matrix,Matrix,Matrix> hess, Matrix x0, Optional<Boolean> sparseJacobian)
      Build a nonlinear vector function and cache f, J at x0.
      Parameters:
      fun - user constraint function R^n -> R^m
      jac - analytic Jacobian (or pre-built FD closure) R^n -> R^{m x n}
      hess - optional constraint Hessian-of-Lagrangian (x, v) -> Sum v[i] H_{f_i}(x); null is permitted (then hess(Matrix, Matrix) returns zeros)
      x0 - starting iterate (n x 1)
      sparseJacobian - Optional.of(true) forces sparse Jacobian storage; Optional.of(false) forces dense; Optional.empty() preserves whatever jac.apply(x0) returns
  • Method Details

    • fun

      public Matrix fun(Matrix newX)
      Description copied from interface: VectorFunctionLike
      Evaluate the function at x, updating any internal cache.
      Specified by:
      fun in interface VectorFunctionLike
      Parameters:
      newX - current iterate (n x 1)
      Returns:
      function value (m x 1)
    • jac

      public Matrix jac(Matrix newX)
      Description copied from interface: VectorFunctionLike
      Evaluate the Jacobian at x, updating any internal cache.
      Specified by:
      jac in interface VectorFunctionLike
      Parameters:
      newX - current iterate (n x 1)
      Returns:
      Jacobian (m x n)
    • hess

      public Matrix hess(Matrix newX, Matrix newV)
      Description copied from interface: VectorFunctionLike
      Evaluate the constraint Hessian-of-Lagrangian Sum_i v[i] * H_{f_i}(x) at x for the given multiplier vector v.
      Specified by:
      hess in interface VectorFunctionLike
      Parameters:
      newX - current iterate (n x 1)
      newV - multipliers (m x 1)
      Returns:
      summed Hessian (n x n)
    • v

      public Matrix v()
      Specified by:
      v in interface VectorFunctionLike
      Returns:
      most recently set Lagrange multipliers (from VectorFunctionLike.hess(Matrix, Matrix)); shape m x 1, or null if none ever set
    • numFunctionEvals

      public int numFunctionEvals()
      Specified by:
      numFunctionEvals in interface VectorFunctionLike
      Returns:
      total number of function evaluations performed so far
    • numJacobianEvals

      public int numJacobianEvals()
      Specified by:
      numJacobianEvals in interface VectorFunctionLike
      Returns:
      total number of Jacobian evaluations performed so far
    • numHessianEvals

      public int numHessianEvals()
      Specified by:
      numHessianEvals in interface VectorFunctionLike
      Returns:
      total number of Hessian evaluations performed so far
    • f

      public Matrix f()
      Specified by:
      f in interface VectorFunctionLike
      Returns:
      most recently computed f(x) (m x 1), or null if uncached
    • J

      public Matrix J()
      Specified by:
      J in interface VectorFunctionLike
      Returns:
      most recently computed Jacobian (m x n), or null if uncached
    • m

      public long m()
      Specified by:
      m in interface VectorFunctionLike
      Returns:
      number of output components (m in f : R^n -> R^m)
    • n

      public long n()
      Specified by:
      n in interface VectorFunctionLike
      Returns:
      number of input components (n in f : R^n -> R^m)
    • sparseJacobian

      public boolean sparseJacobian()
      Returns:
      true if J is stored as a SparseMatrix