scvi.core.modules.VAE

class scvi.core.modules.VAE(n_input, n_batch=0, n_labels=0, n_hidden=128, n_latent=10, n_layers=1, dropout_rate=0.1, dispersion='gene', log_variational=True, gene_likelihood='zinb', latent_distribution='normal')[source]

Variational auto-encoder model.

This is an implementation of the scVI model descibed in [Lopez18]

Parameters
n_input : intint

Number of input genes

n_batch : intint (default: 0)

Number of batches, if 0, no batch correction is performed.

n_labels : intint (default: 0)

Number of labels

n_hidden : intint (default: 128)

Number of nodes per hidden layer

n_latent : intint (default: 10)

Dimensionality of the latent space

n_layers : intint (default: 1)

Number of hidden layers used for encoder and decoder NNs

dropout_rate : floatfloat (default: 0.1)

Dropout rate for neural networks

dispersion : strstr (default: 'gene')

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 : boolbool (default: True)

Log(data+1) prior to encoding for numerical stability. Not normalization.

gene_likelihood : strstr (default: 'zinb')

One of

  • 'nb' - Negative binomial distribution

  • 'zinb' - Zero-inflated negative binomial distribution

  • 'poisson' - Poisson distribution

Attributes

T_destination

dump_patches

Methods

add_module(name, module)

Adds a child module to the current module.

apply(fn)

Applies fn recursively to every submodule (as returned by .children()) as well as self.

bfloat16()

Casts all floating point parameters and buffers to bfloat16 datatype.

buffers([recurse])

Returns an iterator over module buffers.

children()

Returns an iterator over immediate children modules.

cpu()

Moves all model parameters and buffers to the CPU.

cuda([device])

Moves all model parameters and buffers to the GPU.

double()

Casts all floating point parameters and buffers to double datatype.

eval()

Sets the module in evaluation mode.

extra_repr()

Set the extra representation of the module

float()

Casts all floating point parameters and buffers to float datatype.

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

Returns the reconstruction loss and the KL divergences.

get_latents(x[, y])

Returns the result of sample_from_posterior_z inside a list.

get_reconstruction_loss(x, px_rate, px_r, …)

rtype

TensorTensor

get_sample_rate(x[, batch_index, y, …])

Returns the tensor of means of the negative binomial distribution.

get_sample_scale(x[, batch_index, y, …])

Returns the tensor of predicted frequencies of expression.

half()

Casts all floating point parameters and buffers to half datatype.

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

Helper function used in forward pass.

load_state_dict(state_dict[, strict])

Copies parameters and buffers from state_dict into this module and its descendants.

modules()

Returns an iterator over all modules in the network.

named_buffers([prefix, recurse])

Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.

named_children()

Returns an iterator over immediate children modules, yielding both the name of the module as well as the module itself.

named_modules([memo, prefix])

Returns an iterator over all modules in the network, yielding both the name of the module as well as the module itself.

named_parameters([prefix, recurse])

Returns an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.

parameters([recurse])

Returns an iterator over module parameters.

register_backward_hook(hook)

Registers a backward hook on the module.

register_buffer(name, tensor[, persistent])

Adds a buffer to the module.

register_forward_hook(hook)

Registers a forward hook on the module.

register_forward_pre_hook(hook)

Registers a forward pre-hook on the module.

register_parameter(name, param)

Adds a parameter to the module.

requires_grad_([requires_grad])

Change if autograd should record operations on parameters in this module.

sample_from_posterior_l(x[, give_mean])

Samples the tensor of library sizes from the posterior.

sample_from_posterior_z(x[, y, give_mean, …])

Samples the tensor of latent values from the posterior.

share_memory()

rtype

~T~T

state_dict([destination, prefix, keep_vars])

Returns a dictionary containing a whole state of the module.

to(*args, **kwargs)

Moves and/or casts the parameters and buffers.

train([mode])

Sets the module in training mode.

type(dst_type)

Casts all parameters and buffers to dst_type.

zero_grad()

Sets gradients of all model parameters to zero.