scvi.model.base.VAEMixin#

class scvi.model.base.VAEMixin[source]#

Univseral VAE methods.

Methods table#

get_elbo([adata, indices, batch_size])

Return the ELBO for the data.

get_latent_representation([adata, indices, ...])

Return the latent representation for each cell.

get_marginal_ll([adata, indices, ...])

Return the marginal LL for the data.

get_reconstruction_error([adata, indices, ...])

Return the reconstruction error for the data.

Methods#

VAEMixin.get_elbo(adata=None, indices=None, batch_size=None)[source]#

Return the ELBO for the data.

The ELBO is a lower bound on the log likelihood of the data used for optimization of VAEs. Note, this is not the negative ELBO, higher is better.

Parameters:
  • adata (Optional[AnnData] (default: None)) – AnnData object with equivalent structure to initial AnnData. If None, defaults to the AnnData object used to initialize the model.

  • indices (Optional[Sequence[int]] (default: None)) – Indices of cells in adata to use. If None, all cells are used.

  • batch_size (Optional[int] (default: None)) – Minibatch size for data loading into model. Defaults to scvi.settings.batch_size.

Return type:

float

VAEMixin.get_latent_representation(adata=None, indices=None, give_mean=True, mc_samples=5000, batch_size=None, return_dist=False)[source]#

Return the latent representation for each cell.

This is typically denoted as \(z_n\).

Parameters:
  • adata (Optional[AnnData] (default: None)) – AnnData object with equivalent structure to initial AnnData. If None, defaults to the AnnData object used to initialize the model.

  • indices (Optional[Sequence[int]] (default: None)) – Indices of cells in adata to use. If None, all cells are used.

  • give_mean (bool (default: True)) – Give mean of distribution or sample from it.

  • mc_samples (int (default: 5000)) – For distributions with no closed-form mean (e.g., logistic normal), how many Monte Carlo samples to take for computing mean.

  • batch_size (Optional[int] (default: None)) – Minibatch size for data loading into model. Defaults to scvi.settings.batch_size.

  • return_dist (bool (default: False)) – Return (mean, variance) of distributions instead of just the mean. If True, ignores give_mean and mc_samples. In the case of the latter, mc_samples is used to compute the mean of a transformed distribution. If return_dist is true the untransformed mean and variance are returned.

Return type:

Union[ndarray, tuple[ndarray, ndarray]]

Returns:

Low-dimensional representation for each cell or a tuple containing its mean and variance.

VAEMixin.get_marginal_ll(adata=None, indices=None, n_mc_samples=1000, batch_size=None, return_mean=True, **kwargs)[source]#

Return the marginal LL for the data.

The computation here is a biased estimator of the marginal log likelihood of the data. Note, this is not the negative log likelihood, higher is better.

Parameters:
  • adata (Optional[AnnData] (default: None)) – AnnData object with equivalent structure to initial AnnData. If None, defaults to the AnnData object used to initialize the model.

  • indices (Optional[Sequence[int]] (default: None)) – Indices of cells in adata to use. If None, all cells are used.

  • n_mc_samples (int (default: 1000)) – Number of Monte Carlo samples to use for marginal LL estimation.

  • batch_size (Optional[int] (default: None)) – Minibatch size for data loading into model. Defaults to scvi.settings.batch_size.

  • return_mean (Optional[bool] (default: True)) – If False, return the marginal log likelihood for each observation. Otherwise, return the mmean arginal log likelihood.

Return type:

Union[Tensor, float]

VAEMixin.get_reconstruction_error(adata=None, indices=None, batch_size=None)[source]#

Return the reconstruction error for the data.

This is typically written as \(p(x \mid z)\), the likelihood term given one posterior sample. Note, this is not the negative likelihood, higher is better.

Parameters:
  • adata (Optional[AnnData] (default: None)) – AnnData object with equivalent structure to initial AnnData. If None, defaults to the AnnData object used to initialize the model.

  • indices (Optional[Sequence[int]] (default: None)) – Indices of cells in adata to use. If None, all cells are used.

  • batch_size (Optional[int] (default: None)) – Minibatch size for data loading into model. Defaults to scvi.settings.batch_size.

Return type:

float