public class LossFunctionWrapper extends java.lang.Object implements ReconstructionDistribution
ReconstructionDistribution
as would normally be done with a VAE model.
Note: most functionality is supported, but clearly reconstruction log probability cannot be calculated when using LossFunctionWrapper, as ILossFunction instances do not have either (a) a probabilistic interpretation, or (b) a means of calculating the negative log probability.
Constructor and Description |
---|
LossFunctionWrapper(org.nd4j.linalg.activations.Activation activation,
org.nd4j.linalg.lossfunctions.ILossFunction lossFunction) |
LossFunctionWrapper(org.nd4j.linalg.activations.IActivation activationFn,
org.nd4j.linalg.lossfunctions.ILossFunction lossFunction) |
Modifier and Type | Method and Description |
---|---|
int |
distributionInputSize(int dataSize)
Get the number of distribution parameters for the given input data size.
|
org.nd4j.linalg.api.ndarray.INDArray |
exampleNegLogProbability(org.nd4j.linalg.api.ndarray.INDArray x,
org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
Calculate the negative log probability for each example individually
|
org.nd4j.linalg.api.ndarray.INDArray |
generateAtMean(org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
Generate a sample from P(x|z), where x = E[P(x|z)]
i.e., return the mean value for the distribution
|
org.nd4j.linalg.api.ndarray.INDArray |
generateRandom(org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
Randomly sample from P(x|z) using the specified distribution parameters
|
org.nd4j.linalg.api.ndarray.INDArray |
gradient(org.nd4j.linalg.api.ndarray.INDArray x,
org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
Calculate the gradient of the negative log probability with respect to the preOutDistributionParams
|
boolean |
hasLossFunction()
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?
|
double |
negLogProbability(org.nd4j.linalg.api.ndarray.INDArray x,
org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams,
boolean average)
Calculate the negative log probability (summed or averaged over each example in the minibatch)
|
java.lang.String |
toString() |
public LossFunctionWrapper(org.nd4j.linalg.activations.IActivation activationFn, org.nd4j.linalg.lossfunctions.ILossFunction lossFunction)
public LossFunctionWrapper(org.nd4j.linalg.activations.Activation activation, org.nd4j.linalg.lossfunctions.ILossFunction lossFunction)
public boolean hasLossFunction()
ReconstructionDistribution
hasLossFunction
in interface ReconstructionDistribution
public int distributionInputSize(int dataSize)
ReconstructionDistribution
distributionInputSize
in interface ReconstructionDistribution
dataSize
- Size of the data. i.e., nIn valuepublic double negLogProbability(org.nd4j.linalg.api.ndarray.INDArray x, org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams, boolean average)
ReconstructionDistribution
negLogProbability
in interface ReconstructionDistribution
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.public org.nd4j.linalg.api.ndarray.INDArray exampleNegLogProbability(org.nd4j.linalg.api.ndarray.INDArray x, org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
ReconstructionDistribution
exampleNegLogProbability
in interface ReconstructionDistribution
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 functionpublic org.nd4j.linalg.api.ndarray.INDArray gradient(org.nd4j.linalg.api.ndarray.INDArray x, org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
ReconstructionDistribution
gradient
in interface ReconstructionDistribution
x
- DatapreOutDistributionParams
- Distribution parameters used by this reconstruction distribution (for example,
mean and log variance values for Gaussian) - before applying activation functionpublic org.nd4j.linalg.api.ndarray.INDArray generateRandom(org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
ReconstructionDistribution
generateRandom
in interface ReconstructionDistribution
preOutDistributionParams
- Distribution parameters used by this reconstruction distribution (for example,
mean and log variance values for Gaussian) - before applying activation functionpublic org.nd4j.linalg.api.ndarray.INDArray generateAtMean(org.nd4j.linalg.api.ndarray.INDArray preOutDistributionParams)
ReconstructionDistribution
generateAtMean
in interface ReconstructionDistribution
preOutDistributionParams
- Distribution parameters used by this reconstruction distribution (for example,
mean and log variance values for Gaussian) - before applying activation functionpublic java.lang.String toString()
toString
in class java.lang.Object