Class ScalarFunction

java.lang.Object
de.labathome.trustconstr.ScalarFunction

public class ScalarFunction extends Object
Scalar function and its derivatives.

This class defines a scalar function F: R^n->R and methods for computing or approximating its first and second derivatives.

This class implements a memoization logic. There are methods `fun`, `grad`, hess` and corresponding attributes `f`, `g` and `H`. The following things should be considered: 1. Use only public methods `fun`, `grad` and `hess`. 2. After one of the methods is called, the corresponding attribute will be set. However, a subsequent call with a different argument of *any* of the methods may overwrite the attribute.

  • Field Details

  • Method Details

    • fun

      public double fun(Matrix x)
      Parameters:
      x - current iterate (n x 1)
      Returns:
      cached objective value f(x)
    • grad

      public Matrix grad(Matrix x)
      Parameters:
      x - current iterate (n x 1)
      Returns:
      cached gradient gradf(x) (n x 1)
    • hess

      public Matrix hess(Matrix x)
      Parameters:
      x - current iterate (n x 1)
      Returns:
      cached Hessian grad^2f(x) (n x n)
    • numFunctionEvals

      public int numFunctionEvals()
      Returns:
      total number of fun evaluations performed so far
    • numGradientEvals

      public int numGradientEvals()
      Returns:
      total number of gradient evaluations performed so far
    • numHessianEvals

      public int numHessianEvals()
      Returns:
      total number of Hessian evaluations performed so far
    • f

      public double f()
      Returns:
      the most recently cached f(x)
    • g

      public Matrix g()
      DANGER ZONE: returns the live internal gradient buffer; callers must not mutate it.
      Returns:
      the most recently cached gradient (n x 1)
    • H

      public Matrix H()
      DANGER ZONE: returns the live internal Hessian buffer; callers must not mutate it.
      Returns:
      the most recently cached Hessian (n x n)
    • lowestF

      public double lowestF()
      Returns:
      the lowest objective value seen across all evaluations
    • lowestX

      public Matrix lowestX()
      Returns:
      a defensive copy of the iterate that produced lowestF()