scvi.external.cytovi.CytoVAE#

class scvi.external.cytovi.CytoVAE(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, log_variational=False, protein_likelihood='normal', latent_distribution='normal', encode_covariates=False, deeply_inject_covariates=True, use_batch_norm='both', use_layer_norm='none', var_activation=None, encoder_marker_mask=None, extra_encoder_kwargs=None, extra_decoder_kwargs=None, scale_activation=None, prior_mixture=True, prior_mixture_k=20, prior_label_weight=10)[source]#

Bases: BaseModuleClass

Variational auto-encoder model for Cytometry.

This is an implementation of the CytoVI model.

Parameters:
  • n_input (int) – Number of input proteins.

  • n_batch (int (default: 0)) – Number of batches, if 0, no batch correction is performed. Default is 0.

  • n_labels (int (default: 0)) – Number of labels. Default is 0.

  • n_hidden (int (default: 128)) – Number of nodes per hidden layer. Default is 128.

  • n_latent (int (default: 10)) – Dimensionality of the latent space. Default is 10.

  • n_layers (int (default: 1)) – Number of hidden layers used for encoder and decoder NNs. Default is 1.

  • n_continuous_cov (int (default: 0)) – Number of continuous covariates. Default is 0.

  • n_cats_per_cov (Iterable[int] | None (default: None)) – Number of categories for each extra categorical covariate. Default is None.

  • dropout_rate (float (default: 0.1)) – Dropout rate for neural networks. Default is 0.1.

  • log_variational (bool (default: False)) – Log(data+1) prior to encoding for numerical stability. Not normalization. Default is False.

  • protein_likelihood (Literal['normal', 'beta'] (default: 'normal')) – One of the following protein likelihood distributions: * 'normal' - Normal distribution * 'beta' - Beta distribution Default is “normal”.

  • latent_distribution (Literal['normal', 'ln'] (default: 'normal')) – One of the following latent space distributions: * 'normal' - Isotropic normal * 'ln' - Logistic normal with normal params N(0, 1) Default is “normal”.

  • encode_covariates (bool (default: False)) – Whether to concatenate covariates to expression in encoder. Default is False.

  • deeply_inject_covariates (bool (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. Default is True.

  • use_batch_norm (Literal['encoder', 'decoder', 'none', 'both'] (default: 'both')) – Whether to use batch norm in layers. Default is “both”.

  • use_layer_norm (Literal['encoder', 'decoder', 'none', 'both'] (default: 'none')) – Whether to use layer norm in layers. Default is “none”.

  • var_activation (Callable | None (default: None)) – Callable used to ensure positivity of the variational distributions’ variance. When None, defaults to torch.exp. Default is None.

  • encoder_marker_mask (list | None (default: None)) – List of indices to select specific markers for the encoder. Default is None.

  • extra_encoder_kwargs (dict | None (default: None)) – Extra keyword arguments for the encoder. Default is None.

  • extra_decoder_kwargs (dict | None (default: None)) – Extra keyword arguments for the decoder. Default is None.

  • scale_activation (Optional[Literal['softplus', None]] (default: None)) – Activation function for scaling factors. Default is None.

  • prior_mixture (bool | None (default: True)) – Whether to use a mixture of gaussian prior. Default is True.

  • prior_mixture_k (int (default: 20)) – Number of components in the mixture of gaussian prior. Default is 20.

  • prior_label_weight (int | None (default: 10)) – Weight for the prior label. Default is 10.

Attributes table#

Methods table#

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

Runs the generative model.

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

High level inference method.

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

Computes the loss function for the model.

marginal_ll(tensors, n_mc_samples)

Computes the marginal log likelihood of the model.

sample(tensors[, n_samples])

Generate observation samples from the posterior predictive distribution.

Attributes#

CytoVAE.training: bool#

Methods#

CytoVAE.generative(z, batch_index, cont_covs=None, cat_covs=None, y=None, transform_batch=None)[source]#

Runs the generative model.

CytoVAE.inference(x, batch_index, cont_covs=None, cat_covs=None, n_samples=1)[source]#

High level inference method.

Runs the inference (encoder) model.

CytoVAE.loss(tensors, inference_outputs, generative_outputs, kl_weight=1.0)[source]#

Computes the loss function for the model.

CytoVAE.marginal_ll(tensors, n_mc_samples)[source]#

Computes the marginal log likelihood of the model.

CytoVAE.sample(tensors, n_samples=1)[source]#

Generate observation samples from the posterior predictive distribution.

The posterior predictive distribution is written as \(p(\hat{x} \mid x)\).

Parameters:
  • tensors – Tensors dict

  • n_samples (default: 1) – Number of required samples for each cell

  • library_size – Library size to scale samples to

Return type:

ndarray

Returns:

x_new : torch.Tensor tensor with shape (n_cells, n_genes, n_samples)