AutoZIVAE

class scvi.models.AutoZIVAE(n_input, alpha_prior=0.5, beta_prior=0.5, minimal_dropout=0.01, zero_inflation='gene', **args)[source]

Bases: scvi.models.vae.VAE

AutoZI variational auto-encoder model.

Implementation of AutoZI model [Clivio19].

n_input

Number of input genes

alpha_prior

Float denoting the alpha parameter of the prior Beta distribution of the zero-inflation Bernoulli parameter. Should be between 0 and 1, not included. When set to ``None’’, will be set to 1 - beta_prior if beta_prior is not ``None’’, otherwise the prior Beta distribution will be learned on an Empirical Bayes fashion.

beta_prior

Float denoting the beta parameter of the prior Beta distribution of the zero-inflation Bernoulli parameter. Should be between 0 and 1, not included. When set to ``None’’, will be set to 1 - alpha_prior if alpha_prior is not ``None’’, otherwise the prior Beta distribution will be learned on an Empirical Bayes fashion.

minimal_dropout

Float denoting the lower bound of the cell-gene ZI rate in the ZINB component. Must be non-negative. Can be set to 0 but not recommended as this may make the mixture problem ill-defined.

zero_inflation: One of the following

  • 'gene' - zero-inflation Bernoulli parameter of AutoZI is constant per gene across cells

  • 'gene-batch' - zero-inflation Bernoulli parameter can differ between different batches

  • 'gene-label' - zero-inflation Bernoulli parameter can differ between different labels

  • 'gene-cell' - zero-inflation Bernoulli parameter can differ for every gene in every cell

See VAE docstring (scvi/models/vae.py) for more parameters. reconstruction_loss should not be specified.

Examples

>>> gene_dataset = CortexDataset()
>>> autozivae = AutoZIVAE(gene_dataset.nb_genes, alpha_prior=0.5, beta_prior=0.5, minimal_dropout=0.01)

Methods Summary

compute_global_kl_divergence()

rtype

TensorTensor

cuda([device])

Moves all model parameters and also fixed prior alpha and beta values, when relevant, to the GPU.

forward(x, local_l_mean, local_l_var[, …])

Returns the reconstruction loss and the Kullback divergences

get_alphas_betas([as_numpy])

rtype

{str: Tensor, ndarray}Dict[str, Union[Tensor, ndarray]]

get_reconstruction_loss(x, px_rate, px_r, …)

rtype

TensorTensor

inference(x[, batch_index, y, n_samples, …])

Helper function used in forward pass

rescale_dropout(px_dropout[, eps_log])

rtype

TensorTensor

reshape_bernoulli(bernoulli_params[, …])

rtype

TensorTensor

sample_bernoulli_params([batch_index, y, …])

rtype

TensorTensor

sample_from_beta_distribution(alpha, beta[, …])

rtype

TensorTensor

Methods Documentation

compute_global_kl_divergence()[source]
Return type

TensorTensor

cuda(device=None)[source]

Moves all model parameters and also fixed prior alpha and beta values, when relevant, to the GPU.

Parameters

device (str, NoneOptional[str]) – string denoting the GPU device on which parameters and prior distribution values are copied.

Return type

ModuleModule

Returns

forward(x, local_l_mean, local_l_var, batch_index=None, y=None)[source]

Returns the reconstruction loss and the Kullback divergences

Parameters
  • x (TensorTensor) – tensor of values with shape (batch_size, n_input)

  • local_l_mean (TensorTensor) – tensor of means of the prior distribution of latent variable l with shape (batch_size, 1)

  • local_l_var (TensorTensor) – tensor of variancess of the prior distribution of latent variable l with shape (batch_size, 1)

  • batch_index (Tensor, NoneOptional[Tensor]) – array that indicates which batch the cells belong to with shape batch_size

  • y (Tensor, NoneOptional[Tensor]) – tensor of cell-types labels with shape (batch_size, n_labels)

Return type

Tuple[Tensor, Tensor, Tensor]Tuple[Tensor, Tensor, Tensor]

Returns

2-tuple of torch.FloatTensor the reconstruction loss and the Kullback divergences

get_alphas_betas(as_numpy=True)[source]
Return type

{str: Tensor, ndarray}Dict[str, Union[Tensor, ndarray]]

get_reconstruction_loss(x, px_rate, px_r, px_dropout, bernoulli_params, eps_log=1e-08, **kwargs)[source]
Return type

TensorTensor

inference(x, batch_index=None, y=None, n_samples=1, eps_log=1e-08)[source]

Helper function used in forward pass

Return type

{str: Tensor}Dict[str, Tensor]

rescale_dropout(px_dropout, eps_log=1e-08)[source]
Return type

TensorTensor

reshape_bernoulli(bernoulli_params, batch_index=None, y=None)[source]
Return type

TensorTensor

sample_bernoulli_params(batch_index=None, y=None, n_samples=1)[source]
Return type

TensorTensor

sample_from_beta_distribution(alpha, beta, eps_gamma=1e-30, eps_sample=1e-07)[source]
Return type

TensorTensor