class scvi.module.VAE(n_input, n_batch=0, n_labels=0, n_hidden=128, n_latent=10, n_layers=1, n_continuous_cov=0, n_cats_per_cov=None, dropout_rate=0.1, dispersion='gene', log_variational=True, gene_likelihood='zinb', latent_distribution='normal', encode_covariates=False, deeply_inject_covariates=True, use_batch_norm='both', use_layer_norm='none', use_observed_lib_size=True, library_log_means=None, library_log_vars=None, var_activation=None)[source]

Bases: scvi.module.base._base_module.BaseModuleClass

Variational auto-encoder model.

This is an implementation of the scVI model described in [Lopez18]

n_input : intint

Number of input genes

n_batch : intint (default: 0)

Number of batches, if 0, no batch correction is performed.

n_labels : intint (default: 0)

Number of labels

n_hidden : intint (default: 128)

Number of nodes per hidden layer

n_latent : intint (default: 10)

Dimensionality of the latent space

n_layers : intint (default: 1)

Number of hidden layers used for encoder and decoder NNs

n_continuous_cov : intint (default: 0)

Number of continuous covarites

n_cats_per_cov : Iterable[int] | NoneOptional[Iterable[int]] (default: None)

Number of categories for each extra categorical covariate

dropout_rate : floatfloat (default: 0.1)

Dropout rate for neural networks

dispersion : strstr (default: 'gene')

One of the following

  • 'gene' - dispersion parameter of NB is constant per gene across cells

  • 'gene-batch' - dispersion can differ between different batches

  • 'gene-label' - dispersion can differ between different labels

  • 'gene-cell' - dispersion can differ for every gene in every cell

log_variational : boolbool (default: True)

Log(data+1) prior to encoding for numerical stability. Not normalization.

gene_likelihood : strstr (default: 'zinb')

One of

  • 'nb' - Negative binomial distribution

  • 'zinb' - Zero-inflated negative binomial distribution

  • 'poisson' - Poisson distribution

latent_distribution : strstr (default: 'normal')

One of

  • 'normal' - Isotropic normal

  • 'ln' - Logistic normal with normal params N(0, 1)

encode_covariates : boolbool (default: False)

Whether to concatenate covariates to expression in encoder

deeply_inject_covariates : boolbool (default: True)

Whether to concatenate covariates into output of hidden layers in encoder/decoder. This option only applies when n_layers > 1. The covariates are concatenated to the input of subsequent hidden layers.

use_layer_norm : {‘encoder’, ‘decoder’, ‘none’, ‘both’}Literal[‘encoder’, ‘decoder’, ‘none’, ‘both’] (default: 'none')

Whether to use layer norm in layers

use_observed_lib_size : boolbool (default: True)

Use observed library size for RNA as scaling factor in mean of conditional distribution

library_log_means : ndarray | NoneOptional[ndarray] (default: None)

1 x n_batch array of means of the log library sizes. Parameterizes prior on library size if not using observed library size.

library_log_vars : ndarray | NoneOptional[ndarray] (default: None)

1 x n_batch array of variances of the log library sizes. Parameterizes prior on library size if not using observed library size.

var_activation : Callable | NoneOptional[Callable] (default: None)

Callable used to ensure positivity of the variational distributions’ variance. When None, defaults to torch.exp.



generative(z, library, batch_index[, ...])

Runs the generative model.

get_reconstruction_loss(x, px_rate, px_r, ...)



inference(x, batch_index[, cont_covs, ...])

High level inference method.

loss(tensors, inference_outputs, ...[, ...])

Compute the loss for a minibatch of data.

marginal_ll(tensors, n_mc_samples)

sample(tensors[, n_samples, library_size])

Generate observation samples from the posterior predictive distribution.