scvi.external.mrvi.MRVAE#

class scvi.external.mrvi.MRVAE(n_input, n_sample, n_batch, n_labels, n_latent=30, n_latent_u=10, encoder_n_hidden=128, encoder_n_layers=2, z_u_prior=True, z_u_prior_scale=0.0, u_prior_scale=0.0, u_prior_mixture=True, u_prior_mixture_k=20, learn_z_u_prior_scale=False, scale_observations=False, px_kwargs=None, qz_kwargs=None, qu_kwargs=None, n_obs_per_sample=None)[source]#

Bases: BaseModuleClass

Multi-resolution Variational Inference (MrVI) module.

Parameters:
n_input int

Number of input features.

n_sample int

Number of samples.

n_batch int

Number of batches.

n_labels int

Number of labels.

n_latent int (default: 30)

Number of latent variables for z.

n_latent_u int (default: 10)

Number of latent variables for u.

encoder_n_hidden int (default: 128)

Number of hidden units in the encoder.

encoder_n_layers int (default: 2)

Number of layers in the encoder.

z_u_prior bool (default: True)

Whether to place a Gaussian prior on z given u.

z_u_prior_scale float (default: 0.0)

Natural log of the scale parameter of the Gaussian prior placed on z given u. Only applies of learn_z_u_prior_scale is False.

u_prior_scale float (default: 0.0)

Natural log of the scale parameter of the Gaussian prior placed on u. If u_prior_mixture is True, this scale applies to each mixture component distribution.

u_prior_mixture bool (default: True)

Whether to use a mixture of Gaussians prior for u.

u_prior_mixture_k int (default: 20)

Number of mixture components to use for the mixture of Gaussians prior on u.

learn_z_u_prior_scale bool (default: False)

Whether to learn the scale parameter of the prior distribution of z given u.

scale_observations bool (default: False)

Whether to scale the loss associated with each observation by the total number of observations linked to the associated sample.

px_kwargs dict | None (default: None)

Keyword arguments for the generative model.

qz_kwargs dict | None (default: None)

Keyword arguments for the inference model from u to z.

qu_kwargs dict | None (default: None)

Keyword arguments for the inference model from x to u.

training

Whether the model is in training mode.

n_obs_per_sample Tensor | None (default: None)

Number of observations per sample.

Attributes table#

Methods table#

compute_h_from_x_eps(x, sample_index, ...[, ...])

Compute normalized gene expression from observations using predefined eps

generative(z, library, batch_index, label_index)

Generative model.

inference(x, sample_index[, mc_samples, ...])

Run the recognition model.

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

Compute the loss function value.

Attributes#

MRVAE.training: bool#

Methods#

MRVAE.compute_h_from_x_eps(x, sample_index, batch_index, extra_eps, cf_sample=None, mc_samples=10)[source]#

Compute normalized gene expression from observations using predefined eps

MRVAE.generative(z, library, batch_index, label_index, transform_batch=None)[source]#

Generative model.

Return type:

dict[str, Tensor | Distribution]

MRVAE.inference(x, sample_index, mc_samples=None, cf_sample=None, use_mean=False)[source]#

Run the recognition model.

In the case of variational inference, this function will perform steps related to computing variational distribution parameters. In a VAE, this will involve running data through encoder networks.

This function should return a dictionary with str keys and Tensor values.

Return type:

dict[str, Tensor]

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

Compute the loss function value.

Return type:

LossOutput