Class LossFunctionWrapper
- java.lang.Object
-
- org.deeplearning4j.nn.conf.layers.variational.LossFunctionWrapper
-
- All Implemented Interfaces:
Serializable,ReconstructionDistribution
public class LossFunctionWrapper extends Object implements ReconstructionDistribution
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LossFunctionWrapper(Activation activation, ILossFunction lossFunction)LossFunctionWrapper(IActivation activationFn, ILossFunction lossFunction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdistributionInputSize(int dataSize)Get the number of distribution parameters for the given input data size.INDArrayexampleNegLogProbability(INDArray x, INDArray preOutDistributionParams)Calculate the negative log probability for each example individuallyINDArraygenerateAtMean(INDArray preOutDistributionParams)Generate a sample from P(x|z), where x = E[P(x|z)] i.e., return the mean value for the distributionINDArraygenerateRandom(INDArray preOutDistributionParams)Randomly sample from P(x|z) using the specified distribution parametersINDArraygradient(INDArray x, INDArray preOutDistributionParams)Calculate the gradient of the negative log probability with respect to the preOutDistributionParamsbooleanhasLossFunction()Does this reconstruction distribution has a standard neural network loss function (such as mean squared error, which is deterministic) or is it a standard VAE with a probabilistic reconstruction distribution?doublenegLogProbability(INDArray x, INDArray preOutDistributionParams, boolean average)Calculate the negative log probability (summed or averaged over each example in the minibatch)StringtoString()
-
-
-
Constructor Detail
-
LossFunctionWrapper
public LossFunctionWrapper(IActivation activationFn, ILossFunction lossFunction)
-
LossFunctionWrapper
public LossFunctionWrapper(Activation activation, ILossFunction lossFunction)
-
-
Method Detail
-
hasLossFunction
public boolean hasLossFunction()
Description copied from interface:ReconstructionDistributionDoes this reconstruction distribution has a standard neural network loss function (such as mean squared error, which is deterministic) or is it a standard VAE with a probabilistic reconstruction distribution?- Specified by:
hasLossFunctionin interfaceReconstructionDistribution- Returns:
- true if the reconstruction distribution has a loss function only (and no probabilistic reconstruction distribution)
-
distributionInputSize
public int distributionInputSize(int dataSize)
Description copied from interface:ReconstructionDistributionGet the number of distribution parameters for the given input data size. For example, a Gaussian distribution has 2 parameters value (mean and log(variance)) for each data value, whereas a Bernoulli distribution has only 1 parameter value (probability) for each data value.- Specified by:
distributionInputSizein interfaceReconstructionDistribution- Parameters:
dataSize- Size of the data. i.e., nIn value- Returns:
- Number of distribution parameters for the given reconstruction distribution
-
negLogProbability
public double negLogProbability(INDArray x, INDArray preOutDistributionParams, boolean average)
Description copied from interface:ReconstructionDistributionCalculate the negative log probability (summed or averaged over each example in the minibatch)- Specified by:
negLogProbabilityin interfaceReconstructionDistribution- Parameters:
x- Data to be modelled (reconstructions)preOutDistributionParams- Distribution parameters used by this reconstruction distribution (for example, mean and log variance values for Gaussian)average- Whether the log probability should be averaged over the minibatch, or simply summed.- Returns:
- Average or sum of negative log probability of the reconstruction given the distribution parameters
-
exampleNegLogProbability
public INDArray exampleNegLogProbability(INDArray x, INDArray preOutDistributionParams)
Description copied from interface:ReconstructionDistributionCalculate the negative log probability for each example individually- Specified by:
exampleNegLogProbabilityin interfaceReconstructionDistribution- Parameters:
x- Data to be modelled (reconstructions)preOutDistributionParams- Distribution parameters used by this reconstruction distribution (for example, mean and log variance values for Gaussian) - before applying activation function- Returns:
- Negative log probability of the reconstruction given the distribution parameters, for each example individually. Column vector, shape [numExamples, 1]
-
gradient
public INDArray gradient(INDArray x, INDArray preOutDistributionParams)
Description copied from interface:ReconstructionDistributionCalculate the gradient of the negative log probability with respect to the preOutDistributionParams- Specified by:
gradientin interfaceReconstructionDistribution- Parameters:
x- DatapreOutDistributionParams- Distribution parameters used by this reconstruction distribution (for example, mean and log variance values for Gaussian) - before applying activation function- Returns:
- Gradient with respect to the preOutDistributionParams
-
generateRandom
public INDArray generateRandom(INDArray preOutDistributionParams)
Description copied from interface:ReconstructionDistributionRandomly sample from P(x|z) using the specified distribution parameters- Specified by:
generateRandomin interfaceReconstructionDistribution- Parameters:
preOutDistributionParams- Distribution parameters used by this reconstruction distribution (for example, mean and log variance values for Gaussian) - before applying activation function- Returns:
- A random sample of x given the distribution parameters
-
generateAtMean
public INDArray generateAtMean(INDArray preOutDistributionParams)
Description copied from interface:ReconstructionDistributionGenerate a sample from P(x|z), where x = E[P(x|z)] i.e., return the mean value for the distribution- Specified by:
generateAtMeanin interfaceReconstructionDistribution- Parameters:
preOutDistributionParams- Distribution parameters used by this reconstruction distribution (for example, mean and log variance values for Gaussian) - before applying activation function- Returns:
- A deterministic sample of x (mean/expected value) given the distribution parameters
-
-