Package de.labathome.trustconstr
Class ScalarFunction.ScalarFunctionFactory
java.lang.Object
de.labathome.trustconstr.ScalarFunction.ScalarFunctionFactory
- Enclosing class:
- ScalarFunction
Builder for
ScalarFunction.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionProvide any additional fixed parameters needed to specify the scalar function (theargsargument forwarded tofun/grad/hess).build()Absolute step size for FD gradient/Hessian, taking precedence over the relative step.finiteDiffBounds(FiniteDifferenceBounds finiteDiffBounds) Bounds within which FD perturbations must stay.finiteDiffRelStep(Matrix finiteDiffRelStep) Per-component relative step size for the FD gradient/Hessian.fun(ToDoubleBiFunction<Matrix, Object> fun) Set the objective function to optimize.grad(FiniteDifferenceMethod grad) Compute the gradient by finite differences instead of analytically.grad(BiFunction<Matrix, Object, Matrix> grad) Provide an analytic gradientgrad(x, args) -> gradf(x).hess(FiniteDifferenceMethod hess) Compute the Hessian by finite differences instead of analytically.hess(HessianUpdateStrategy hess) Approximate the Hessian via a quasi-Newton update strategy (e.g.hess(BiFunction<Matrix, Object, Matrix> hess) Provide an analytic Hessianhess(x, args) -> grad^2f(x).Provide the initial point for evaluatingfun.
-
Constructor Details
-
ScalarFunctionFactory
public ScalarFunctionFactory()Default-construct an empty factory.
-
-
Method Details
-
fun
Set the objective function to optimize.- Parameters:
fun- objective(x, args) -> f(x)- Returns:
- this factory, for chaining
-
x0
Provide the initial point for evaluatingfun.- Parameters:
x0- starting iterate (n x 1)- Returns:
- this factory, for chaining
-
args
Provide any additional fixed parameters needed to specify the scalar function (theargsargument forwarded tofun/grad/hess).- Parameters:
args- fixed parameters (may benull)- Returns:
- this factory, for chaining
-
grad
Provide an analytic gradientgrad(x, args) -> gradf(x). Mutually exclusive withgrad(FiniteDifferenceMethod).- Parameters:
grad- analytic gradient- Returns:
- this factory, for chaining
- Throws:
RuntimeException- if a gradient (analytic or FD) was already specified
-
grad
Compute the gradient by finite differences instead of analytically. Mutually exclusive withgrad(BiFunction).- Parameters:
grad- FD scheme to use- Returns:
- this factory, for chaining
- Throws:
RuntimeException- if a gradient was already specified
-
hess
Provide an analytic Hessianhess(x, args) -> grad^2f(x). Mutually exclusive with the FD and quasi-Newton overloads.- Parameters:
hess- analytic Hessian evaluator- Returns:
- this factory, for chaining
- Throws:
RuntimeException- if a Hessian was already specified
-
hess
Compute the Hessian by finite differences instead of analytically. Note: cannot be combined with an FD gradient.- Parameters:
hess- FD scheme to use for the Hessian- Returns:
- this factory, for chaining
- Throws:
RuntimeException- if a Hessian was already specified
-
hess
- Parameters:
hess- Hessian-update strategy instance- Returns:
- this factory, for chaining
- Throws:
RuntimeException- if a Hessian was already specified
-
finiteDiffRelStep
Per-component relative step size for the FD gradient/Hessian. The absolute step ish = relStep * sign(x0) * max(1, |x0|), clamped tofiniteDiffBounds(FiniteDifferenceBounds). May benullto derive a default from machine epsilon.- Parameters:
finiteDiffRelStep- relative step size (n x 1); may benull- Returns:
- this factory, for chaining
-
finiteDiffBounds
public ScalarFunction.ScalarFunctionFactory finiteDiffBounds(FiniteDifferenceBounds finiteDiffBounds) Bounds within which FD perturbations must stay. Defaults to unbounded.- Parameters:
finiteDiffBounds- box bounds for FD perturbations- Returns:
- this factory, for chaining
-
epsilon
Absolute step size for FD gradient/Hessian, taking precedence over the relative step. May benull(use relative step instead).- Parameters:
epsilon- absolute step size (n x 1); may benull- Returns:
- this factory, for chaining
-
build
- Returns:
- a fully-configured
ScalarFunctionready for use - Throws:
RuntimeException- if neither analytic nor FD gradient/Hessian was set
-