Class CRErrorVectorSW

java.lang.Object
org.ddogleg.chainrule.ops.CRErrorVectorSW
All Implemented Interfaces:
CROperatorBackwardsJac<double[]>, CROperatorForward<double[]>

public class CRErrorVectorSW extends Object implements CROperatorBackwardsJac<double[]>
Computes the error between a known prior and an estimated value. A single weight is applied to all elements
  • Field Details

    • estimated

      protected double[] estimated
      input[0] the estimated value
    • observed

      protected double[] observed
      input[1] the observed value. Often this is known no Jacobian is needed.
    • weight

      protected double weight
      Error weight applied to all elements
    • math

      protected final MathCRMatrixD math
    • workJac

      protected final CRMatrix<double[]> workJac
  • Constructor Details

    • CRErrorVectorSW

      public CRErrorVectorSW(int length)
    • CRErrorVectorSW

      public CRErrorVectorSW(int length, double weight)
  • Method Details

    • zeroObserved

      public void zeroObserved()
      Sets the observed vector to zero. This is a common assumption for parameter priors
    • setObserved

      public void setObserved(double[] values, int offset)
      Convenient way to set observed values without using CRArray
    • setEstimated

      public void setEstimated(double[] values, int offset)
      Convenient way to set estimated values without using CRArray
    • 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.
    • 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.
    • 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.
    • 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[]>
    • getInputCount

      public int getInputCount()
      Description copied from interface: CROperatorForward
      Number of inputs
      Specified by:
      getInputCount 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[]>
    • getSettings

      public Map<String,String> getSettings()
      Encodes all weights that are not 1.0
      Specified by:
      getSettings 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[]>