Class LossSparseMCXENT
- java.lang.Object
-
- org.nd4j.linalg.lossfunctions.impl.LossMCXENT
-
- org.nd4j.linalg.lossfunctions.impl.LossSparseMCXENT
-
- All Implemented Interfaces:
Serializable,ILossFunction
public class LossSparseMCXENT extends LossMCXENT
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.nd4j.linalg.lossfunctions.impl.LossMCXENT
softmaxClipEps, weights
-
-
Constructor Summary
Constructors Constructor Description LossSparseMCXENT()LossSparseMCXENT(double softmaxClipEps, INDArray weights)Multi-Class Cross Entropy loss function where each the output is (optionally) weighted/scaled by a fixed scalar value.LossSparseMCXENT(INDArray weights)Multi-Class Cross Entropy loss function where each the output is (optionally) weighted/scaled by a flags scalar value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description INDArraycomputeGradient(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)Compute the gradient of the loss function with respect to the inputs: dL/dOutputPair<Double,INDArray>computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average)Compute both the score (loss function value) and gradient.doublecomputeScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average)Compute the score (loss function value) for the given inputs.INDArraycomputeScoreArray(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)Compute the score (loss function value) for each example individually.protected INDArraysparseScoreArray(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)StringtoString()-
Methods inherited from class org.nd4j.linalg.lossfunctions.impl.LossMCXENT
name, scoreArray
-
-
-
-
Constructor Detail
-
LossSparseMCXENT
public LossSparseMCXENT()
-
LossSparseMCXENT
public LossSparseMCXENT(INDArray weights)
Multi-Class Cross Entropy loss function where each the output is (optionally) weighted/scaled by a flags scalar value. Note that the weights array must be a row vector, of length equal to the labels/output dimension 1 size. A weight vector of 1s should give identical results to no weight vector.- Parameters:
weights- Weights array (row vector). May be null.
-
LossSparseMCXENT
public LossSparseMCXENT(double softmaxClipEps, INDArray weights)Multi-Class Cross Entropy loss function where each the output is (optionally) weighted/scaled by a fixed scalar value. Note that the weights array must be a row vector, of length equal to the labels/output dimension 1 size. A weight vector of 1s should give identical results to no weight vector.- Parameters:
weights- Weights array (row vector). May be null.
-
-
Method Detail
-
sparseScoreArray
protected INDArray sparseScoreArray(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)
-
computeScore
public double computeScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average)
Description copied from interface:ILossFunctionCompute the score (loss function value) for the given inputs.- Specified by:
computeScorein interfaceILossFunction- Overrides:
computeScorein classLossMCXENT- Parameters:
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 value
-
computeScoreArray
public INDArray computeScoreArray(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)
Description copied from interface:ILossFunctionCompute the score (loss function value) for each example individually. For input [numExamples,nOut] returns scores as a column vector: [numExamples,1]- Specified by:
computeScoreArrayin interfaceILossFunction- Overrides:
computeScoreArrayin classLossMCXENT- Parameters:
labels- Labels/expected outputpreOutput- Output of the model (neural network)activationFn- Activation function that should be applied to preOutput- Returns:
- Loss function value for each example; column vector
-
computeGradient
public INDArray computeGradient(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask)
Description copied from interface:ILossFunctionCompute the gradient of the loss function with respect to the inputs: dL/dOutput- Specified by:
computeGradientin interfaceILossFunction- Overrides:
computeGradientin classLossMCXENT- Parameters:
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 null- Returns:
- Gradient dL/dPreOut
-
computeGradientAndScore
public Pair<Double,INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average)
Description copied from interface:ILossFunctionCompute both the score (loss function value) and gradient. This is equivalent to callingILossFunction.computeScore(INDArray, INDArray, IActivation, INDArray, boolean)andILossFunction.computeGradient(INDArray, INDArray, IActivation, INDArray)individually- Specified by:
computeGradientAndScorein interfaceILossFunction- Overrides:
computeGradientAndScorein classLossMCXENT- Parameters:
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 not- Returns:
- The score (loss function value) and gradient
-
toString
public String toString()
- Overrides:
toStringin classLossMCXENT
-
-