public abstract class SameDiffLoss extends Object implements ILossFunction
defineLoss(SameDiff, SDVariable, SDVariable)
. This method is used to define the loss function on a
per example basis - i.e., the output should be an array with shape [minibatch].return labels.squaredDifference(layerInput).mean(1);
Modifier and Type | Field and Description |
---|---|
protected SDVariable |
scorePerExampleVariable |
protected SameDiff |
sd |
Modifier | Constructor and Description |
---|---|
protected |
SameDiffLoss() |
Modifier and Type | Method and Description |
---|---|
INDArray |
computeGradient(INDArray labels,
INDArray preOutput,
IActivation activationFn,
INDArray mask)
Compute the gradient of the loss function with respect to the inputs: dL/dOutput
|
Pair<Double,INDArray> |
computeGradientAndScore(INDArray labels,
INDArray preOutput,
IActivation activationFn,
INDArray mask,
boolean average)
Compute both the score (loss function value) and gradient.
|
double |
computeScore(INDArray labels,
INDArray preOutput,
IActivation activationFn,
INDArray mask,
boolean average)
Compute the score (loss function value) for the given inputs.
|
INDArray |
computeScoreArray(INDArray labels,
INDArray preOutput,
IActivation activationFn,
INDArray mask)
Compute the score (loss function value) for each example individually.
|
protected void |
createSameDiffInstance(DataType dataType) |
abstract SDVariable |
defineLoss(SameDiff sd,
SDVariable layerInput,
SDVariable labels)
Define the loss function.
NOTE: The score on a *per example* basis - should return a SDVariable with shape [minibatch], where out[i] is the score for the ith minibatch |
String |
name()
The opName of this function
|
protected transient SameDiff sd
protected transient SDVariable scorePerExampleVariable
public abstract SDVariable defineLoss(SameDiff sd, SDVariable layerInput, SDVariable labels)
sd
- SameDiff instance to define the loss onlayerInput
- Input to the SameDiff loss functionlabels
- Labels placeholderprotected void createSameDiffInstance(DataType dataType)
public double computeScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average)
computeScore
in interface ILossFunction
labels
- Label/expected preOutputpreOutput
- Output of the model (neural network)activationFn
- Activation function that should be applied to preOutputmask
- Mask array; may be nullaverage
- Whether the score should be averaged (divided by number of rows in labels/preOutput) or not @return Loss function valuepublic INDArray computeScoreArray(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)
computeScoreArray
in interface ILossFunction
labels
- Labels/expected outputpreOutput
- Output of the model (neural network)activationFn
- Activation function that should be applied to preOutputmask
- @return Loss function value for each example; column vectorpublic INDArray computeGradient(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)
computeGradient
in interface ILossFunction
labels
- Label/expected outputpreOutput
- Output of the model (neural network), before the activation function is appliedactivationFn
- Activation function that should be applied to preOutputmask
- Mask array; may be nullpublic Pair<Double,INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average)
computeScore(INDArray, INDArray, IActivation, INDArray, boolean)
and computeGradient(INDArray, INDArray, IActivation, INDArray)
individuallycomputeGradientAndScore
in interface ILossFunction
labels
- Label/expected outputpreOutput
- Output of the model (neural network)activationFn
- Activation function that should be applied to preOutputmask
- Mask array; may be nullaverage
- Whether the score should be averaged (divided by number of rows in labels/output) or notpublic String name()
ILossFunction
name
in interface ILossFunction
Copyright © 2020. All rights reserved.