Encoder

class scvi.models.modules.Encoder(n_input, n_output, n_cat_list=None, n_layers=1, n_hidden=128, dropout_rate=0.1, distribution='normal')[source]

Bases: torch.nn.modules.module.Module

Encodes data of n_input dimensions into a latent space of n_output dimensions using a fully-connected neural network of n_hidden layers.

Parameters
  • n_input (intint) – The dimensionality of the input (data space)

  • n_output (intint) – The dimensionality of the output (latent space)

  • n_cat_list (Iterable[int], NoneOptional[Iterable[int]]) – A list containing the number of categories for each category of interest. Each category will be included using a one-hot encoding

  • n_layers (intint) – The number of fully-connected hidden layers

  • n_hidden (intint) – The number of nodes per hidden layer :dropout_rate: Dropout rate to apply to each of the hidden layers

  • distribution (strstr) – Distribution of z

Returns

Methods Summary

forward(x, *cat_list)

The forward computation for a single sample.

Methods Documentation

forward(x, *cat_list)[source]

The forward computation for a single sample.

  1. Encodes the data into latent space using the encoder network

  2. Generates a mean ( q_m ) and variance ( q_v )

  3. Samples a new value from an i.i.d. multivariate normal ( sim Ne(q_m, mathbf{I}q_v) )

Parameters
  • x (TensorTensor) – tensor with shape (n_input,)

  • cat_list (intint) – list of category membership(s) for this sample

Returns

3-tuple of torch.Tensor tensors of shape (n_latent,) for mean and var, and sample