Class CROperatorBilinearND
- All Implemented Interfaces:
CROperatorBackwardsJac<double[]>, CROperatorForward<double[]>
- Direct Known Subclasses:
CROperatorBilinearPolyND, CROperatorBilinearSplineND
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 Summary
FieldsModifier and TypeFieldDescriptionprotected double[]Derivative with respect to each coefficient of a knot, filled byfunctionDerivatives(double[])static final intstatic final intstatic final intstatic final intstatic final intstatic final intprotected final CRArray<double[]>[]Where each knot's polynomials live.protected final MathCRMatrixDprotected doublevalue that the polynomial is being sampled atprotected final CRMatrix<double[]> Workspace for the jacobian -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCopies grid into internal fieldsprotected abstract doubleevaluate(int knot, int polyOffset) Values the specified polynomial encoded in the knot usingvalue.protected abstract doubleevaluateDerivative(int knot, int polyOffset) Derivative ofevaluate(int, int)with respect tovaluevoidPerforms forward pass of the function.protected abstract voidfunctionDerivatives(double[] derivatives) Derivative ofevaluate(int, int)with respect to each of a knot's coefficients for one output.Class<double[]> Primitive data type for the arrayintNumber of inputsintgetInputSize(int which) Returns the specified input's vector sizeintReturns the output vector's sizeRetrieve a serialized description of the settingsvoidComputes the Jacobian of all the inputs and parameters to this function.protected voidjacobianKnot(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.protected voidjacobianValue(CRMatrix<double[]> dout, CRMatrix<double[]> output) Each knot's polynomial moves withvalue, and the four of them are mixed by the same weightsprotected voidjacobianWeights(CRMatrix<double[]> dout, CRMatrix<double[]> output) A weight enters linearly, so its derivative is the polynomial it scalesintknotOffset(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 vectorvoidSpecifies the value of an input's vector.voidsetSettings(Map<String, String> settings) Reconfigures the block using the specified settingsprotected voidsetValue(double value) Assigns the valueMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CROperatorForward
normalizeAfterStep
-
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
Where each knot's polynomials live. Pointed at the caller's array rather than holding a copy -
value
protected double valuevalue that the polynomial is being sampled at -
coefDeriv
protected double[] coefDerivDerivative with respect to each coefficient of a knot, filled byfunctionDerivatives(double[]) -
workJac
Workspace for the jacobian -
math
-
-
Constructor Details
-
CROperatorBilinearND
public CROperatorBilinearND()
-
-
Method Details
-
configureGrid
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
Description copied from interface:CROperatorForwardPerforms forward pass of the function. Must have already updatedCROperatorForward.setInput(int, CRArray).- Specified by:
forwardin interfaceCROperatorForward<double[]>- Parameters:
output- (Output) Output vector. Modified.
-
evaluate
protected abstract double evaluate(int knot, int polyOffset) Values the specified polynomial encoded in the knot usingvalue. -
evaluateDerivative
protected abstract double evaluateDerivative(int knot, int polyOffset) Derivative ofevaluate(int, int)with respect tovalue -
functionDerivatives
protected abstract void functionDerivatives(double[] derivatives) Derivative ofevaluate(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 isnumCoefs -
jacobian
Description copied from interface:CROperatorBackwardsJacComputes 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 ... ] * @???/@fWhere Out is the final output, 'f' is this function with two inputs (x,y). '@Out/@f' is dout.
- Specified by:
jacobianin interfaceCROperatorBackwardsJac<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
-
jacobianValue
-
jacobianKnot
-
setInput
Description copied from interface:CROperatorForwardSpecifies the value of an input's vector.
The implementation can safely save the array
inputpoints at along with its offset. Neither the values at that offset nor the array itself will change until afterCROperatorForward.forward(CRArray)or a derived function such asCROperatorBackwardsJac.jacobian(CRMatrix, List)has been called. Theinputreference itself cannot be saved: the caller is free to recycle theCRArraythe moment the call returns, including pointing it at another offset.- Specified by:
setInputin interfaceCROperatorForward<double[]>- Parameters:
which- Which inputinput- 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:CROperatorForwardReturns the specified input's vector size- Specified by:
getInputSizein interfaceCROperatorForward<double[]>
-
getSettings
Description copied from interface:CROperatorForwardRetrieve a serialized description of the settings- Specified by:
getSettingsin interfaceCROperatorForward<double[]>
-
setSettings
Description copied from interface:CROperatorForwardReconfigures the block using the specified settings- Specified by:
setSettingsin interfaceCROperatorForward<double[]>
-
getInputCount
public int getInputCount()Description copied from interface:CROperatorForwardNumber of inputs- Specified by:
getInputCountin interfaceCROperatorForward<double[]>
-
getOutputSize
public int getOutputSize()Description copied from interface:CROperatorForwardReturns the output vector's size- Specified by:
getOutputSizein interfaceCROperatorForward<double[]>
-
getArrayType
Description copied from interface:CROperatorForwardPrimitive data type for the array- Specified by:
getArrayTypein interfaceCROperatorForward<double[]>
-