Package de.labathome.trustconstr
Class NonlinearVectorFunction
java.lang.Object
de.labathome.trustconstr.NonlinearVectorFunction
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionf()Evaluate the function atx, updating any internal cache.Evaluate the constraint Hessian-of-LagrangianSum_i v[i] * H_{f_i}(x)atxfor the given multiplier vectorv.J()Evaluate the Jacobian atx, updating any internal cache.longm()longn()intintintbooleanv()
-
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 cachef,Jatx0.- Parameters:
fun- user constraint functionR^n -> R^mjac- 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);nullis permitted (thenhess(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 whateverjac.apply(x0)returns
-
-
Method Details
-
fun
Description copied from interface:VectorFunctionLikeEvaluate the function atx, updating any internal cache.- Specified by:
funin interfaceVectorFunctionLike- Parameters:
newX- current iterate (n x 1)- Returns:
- function value (
m x 1)
-
jac
Description copied from interface:VectorFunctionLikeEvaluate the Jacobian atx, updating any internal cache.- Specified by:
jacin interfaceVectorFunctionLike- Parameters:
newX- current iterate (n x 1)- Returns:
- Jacobian (
m x n)
-
hess
Description copied from interface:VectorFunctionLikeEvaluate the constraint Hessian-of-LagrangianSum_i v[i] * H_{f_i}(x)atxfor the given multiplier vectorv.- Specified by:
hessin interfaceVectorFunctionLike- Parameters:
newX- current iterate (n x 1)newV- multipliers (m x 1)- Returns:
- summed Hessian (
n x n)
-
v
- Specified by:
vin interfaceVectorFunctionLike- Returns:
- most recently set Lagrange multipliers (from
VectorFunctionLike.hess(Matrix, Matrix)); shapem x 1, ornullif none ever set
-
numFunctionEvals
public int numFunctionEvals()- Specified by:
numFunctionEvalsin interfaceVectorFunctionLike- Returns:
- total number of function evaluations performed so far
-
numJacobianEvals
public int numJacobianEvals()- Specified by:
numJacobianEvalsin interfaceVectorFunctionLike- Returns:
- total number of Jacobian evaluations performed so far
-
numHessianEvals
public int numHessianEvals()- Specified by:
numHessianEvalsin interfaceVectorFunctionLike- Returns:
- total number of Hessian evaluations performed so far
-
f
- Specified by:
fin interfaceVectorFunctionLike- Returns:
- most recently computed
f(x)(m x 1), ornullif uncached
-
J
- Specified by:
Jin interfaceVectorFunctionLike- Returns:
- most recently computed Jacobian (
m x n), ornullif uncached
-
m
public long m()- Specified by:
min interfaceVectorFunctionLike- Returns:
- number of output components (
minf : R^n -> R^m)
-
n
public long n()- Specified by:
nin interfaceVectorFunctionLike- Returns:
- number of input components (
ninf : R^n -> R^m)
-
sparseJacobian
public boolean sparseJacobian()- Returns:
trueifJis stored as aSparseMatrix
-