Class CROperatorBilinearND

java.lang.Object
org.ddogleg.chainrule.ops.CROperatorBilinearND
All Implemented Interfaces:
CROperatorBackwardsJac<double[]>, CROperatorForward<double[]>
Direct Known Subclasses:
CROperatorBilinearPolyND, CROperatorBilinearSplineND

public abstract class CROperatorBilinearND extends Object implements CROperatorBackwardsJac<double[]>

General purpose operator for blending 4 knots into an N-D output, each knot stores N-coefficients for a yet to be defined function. The value the function is evaluated at is specified by 'value'.

Nothing here knows about pixels or grids. The weights are an input, so whatever produced them owns the interpolation scheme and this only has to blend. The derivative with respect to whatever the weights were computed from then follows through the chain.

Functions for each knot are externally specified to avoid a large sparse output Jacobian. It's up to the user to make sure the correct 4 are passed in.

See Also:
  • Field Details

    • IN_WEIGHTS

      public static final int IN_WEIGHTS
      See Also:
    • IN_VALUE

      public static final int IN_VALUE
      See Also:
    • IN_KNOT_0

      public static final int IN_KNOT_0
      See Also:
    • IN_KNOT_1

      public static final int IN_KNOT_1
      See Also:
    • IN_KNOT_2

      public static final int IN_KNOT_2
      See Also:
    • IN_KNOT_3

      public static final int IN_KNOT_3
      See Also:
    • knots

      protected final CRArray<double[]>[] knots
      Where each knot's polynomials live. Pointed at the caller's array rather than holding a copy
    • value

      protected double value
      value that the polynomial is being sampled at
    • coefDeriv

      protected double[] coefDeriv
      Derivative with respect to each coefficient of a knot, filled by functionDerivatives(double[])
    • workJac

      protected final CRMatrix<double[]> workJac
      Workspace for the jacobian
    • math

      protected final MathCRMatrixD math
  • Constructor Details

    • CROperatorBilinearND

      public CROperatorBilinearND()
  • Method Details

    • configureGrid

      protected void configureGrid(ConfigGridCoefND grid)
      Copies grid into internal fields
    • knotOffset

      public int knotOffset(int knot)
      Where the specified knot's polynomials start in the array they came from, which is also the column its Jacobian belongs to when that array is the system's parameter vector
    • forward

      public void forward(CRArray<double[]> output)
      Description copied from interface: CROperatorForward
      Performs forward pass of the function. Must have already updated CROperatorForward.setInput(int, CRArray).
      Specified by:
      forward in interface CROperatorForward<double[]>
      Parameters:
      output - (Output) Output vector. Modified.
    • evaluate

      protected abstract double evaluate(int knot, int polyOffset)
      Values the specified polynomial encoded in the knot using value.
    • evaluateDerivative

      protected abstract double evaluateDerivative(int knot, int polyOffset)
      Derivative of evaluate(int, int) with respect to value
    • functionDerivatives

      protected abstract void functionDerivatives(double[] derivatives)
      Derivative of evaluate(int, int) with respect to each of a knot's coefficients for one output. Every coefficient enters linearly and the same way in every knot and every output, so this is filled once and reused. Length is numCoefs
    • jacobian

      public void jacobian(CRMatrix<double[]> dout, List<CRMatrix<double[]>> jacobianInputs)
      Description copied from interface: CROperatorBackwardsJac

      Computes the Jacobian of all the inputs and parameters to this function.

      Mathematical explanation of how the partial derivatives are computed:

      @Out(..)/@x = [@f1(x,y)/@x @f1(x,y)/@y ; @f2(x,y)/@x ...  ] * @???/@f
      

      Where Out is the final output, 'f' is this function with two inputs (x,y). '@Out/@f' is dout.

      Specified by:
      jacobian in interface CROperatorBackwardsJac<double[]>
      Parameters:
      dout - (Input) Jacobian of output conditional on this function, computed from next layer.
      jacobianInputs - (Output) Storage for all the Jacobian inputs. All matrices must be pre-declared and included in the list. If a matrix is marked as invalid, then the jacobian is skipped for that input.
    • jacobianWeights

      protected void jacobianWeights(CRMatrix<double[]> dout, CRMatrix<double[]> output)
      A weight enters linearly, so its derivative is the polynomial it scales
    • jacobianValue

      protected void jacobianValue(CRMatrix<double[]> dout, CRMatrix<double[]> output)
      Each knot's polynomial moves with value, and the four of them are mixed by the same weights
    • jacobianKnot

      protected void jacobianKnot(CRMatrix<double[]> dout, CRMatrix<double[]> output, int knot)
      A coefficient enters linearly, so its derivative is its knot's weight times whatever the function makes of it. Each output reads its own run of the knot, so the rest stays zero
    • setInput

      public void setInput(int which, CRArray<double[]> input)
      Description copied from interface: CROperatorForward

      Specifies the value of an input's vector.

      The implementation can safely save the array input points at along with its offset. Neither the values at that offset nor the array itself will change until after CROperatorForward.forward(CRArray) or a derived function such as CROperatorBackwardsJac.jacobian(CRMatrix, List) has been called. The input reference itself cannot be saved: the caller is free to recycle the CRArray the moment the call returns, including pointing it at another offset.

      Specified by:
      setInput in interface CROperatorForward<double[]>
      Parameters:
      which - Which input
      input - The input's value. This reference can't be saved internally but the array and offset can be.
    • setValue

      protected void setValue(double value)
      Assigns the value
    • getInputSize

      public int getInputSize(int which)
      Description copied from interface: CROperatorForward
      Returns the specified input's vector size
      Specified by:
      getInputSize in interface CROperatorForward<double[]>
    • getSettings

      public Map<String,String> getSettings()
      Description copied from interface: CROperatorForward
      Retrieve a serialized description of the settings
      Specified by:
      getSettings in interface CROperatorForward<double[]>
    • setSettings

      public void setSettings(Map<String,String> settings)
      Description copied from interface: CROperatorForward
      Reconfigures the block using the specified settings
      Specified by:
      setSettings in interface CROperatorForward<double[]>
    • getInputCount

      public int getInputCount()
      Description copied from interface: CROperatorForward
      Number of inputs
      Specified by:
      getInputCount in interface CROperatorForward<double[]>
    • getOutputSize

      public int getOutputSize()
      Description copied from interface: CROperatorForward
      Returns the output vector's size
      Specified by:
      getOutputSize in interface CROperatorForward<double[]>
    • getArrayType

      public Class<double[]> getArrayType()
      Description copied from interface: CROperatorForward
      Primitive data type for the array
      Specified by:
      getArrayType in interface CROperatorForward<double[]>