Class Vae

java.lang.Object
ai.beestream.jitnn.nn.Module
ai.beestream.jitnn.nn.models.Vae
All Implemented Interfaces:
AutoCloseable

public final class Vae extends Module
A fully connected variational autoencoder (Kingma and Welling, 2014), the layout of PyTorch's MNIST example: 784-400 encoder to a Gaussian latent (mean, log-variance), 400-784 decoder with a sigmoid output. Seeds, in order: encoder, mean, log-variance, decoder hidden, decoder output.
  • Constructor Details

    • Vae

      public Vae(int in, int hidden, int latent, long seed)
      An autoencoder of in features through hidden to a latent of latent values, initialised from seed.
  • Method Details

    • latent

      public int latent()
      The size of the latent vector.
    • run

      public Vae.Output run(Tensor x, Tensor eps)
      Encodes x [B, in], samples z = mu + exp(logvar / 2) eps with the given noise eps [B, latent], decodes.
    • decode

      public Tensor decode(Tensor z)
      Decodes latent vectors z [B, latent] to [B, in], each value in (0, 1).
    • loss

      public static Tensor loss(Vae.Output o, Tensor x)
      The negative ELBO per sample: (binary cross-entropy summed over pixels + KL) / B.
    • forward

      public Tensor forward(Tensor x)
      Reconstruction with the mean latent (no sampling).
      Specified by:
      forward in class Module