class scvi.module.SCANVAE(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', y_prior=None, labels_groups=None, use_labels_groups=False, classifier_parameters=None, use_batch_norm='both', use_layer_norm='none', **vae_kwargs)[source]#

Bases: VAE

Single-cell annotation using variational inference.

This is an implementation of the scANVI model described in [Xu et al., 2021], inspired from M1 + M2 model, as described in (

  • n_input (int) – Number of input genes

  • n_batch (int) – Number of batches

  • n_labels (int) – Number of labels

  • n_hidden (Tunable_[int]) – Number of nodes per hidden layer

  • n_latent (Tunable_[int]) – Dimensionality of the latent space

  • n_layers (Tunable_[int]) – Number of hidden layers used for encoder and decoder NNs

  • n_continuous_cov (int) – Number of continuous covarites

  • n_cats_per_cov (Optional[Iterable[int]]) – Number of categories for each extra categorical covariate

  • dropout_rate (Tunable_[float]) – Dropout rate for neural networks

  • dispersion (Tunable_[Literal['gene', 'gene-batch', 'gene-label', 'gene-cell']]) –

    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 (Tunable_[bool]) – Log(data+1) prior to encoding for numerical stability. Not normalization.

  • gene_likelihood (Tunable_[Literal['zinb', 'nb']]) –

    One of:

    • 'nb' - Negative binomial distribution

    • 'zinb' - Zero-inflated negative binomial distribution

  • y_prior – If None, initialized to uniform probability over cell types

  • labels_groups (Sequence[int]) – Label group designations

  • use_labels_groups (bool) – Whether to use the label groups

  • use_batch_norm (Tunable_[Literal['encoder', 'decoder', 'none', 'both']]) – Whether to use batch norm in layers

  • use_layer_norm (Tunable_[Literal['encoder', 'decoder', 'none', 'both']]) – Whether to use layer norm in layers

  • **vae_kwargs – Keyword args for VAE

  • classifier_parameters (Optional[dict]) –

Attributes table#

Methods table#


classify(x[, batch_index, cont_covs, cat_covs])

Classify cells into cell types.

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

Compute the loss.


training bool#





SCANVAE.classify(x, batch_index=None, cont_covs=None, cat_covs=None)[source]#

Classify cells into cell types.


SCANVAE.loss(tensors, inference_outputs, generative_ouputs, feed_labels=False, kl_weight=1, labelled_tensors=None, classification_ratio=None)[source]#

Compute the loss.