scvi.nn.Encoder#
- class scvi.nn.Encoder(n_input, n_output, n_cat_list=None, n_layers=1, n_hidden=128, dropout_rate=0.1, distribution='normal', var_eps=0.0001, var_activation=None, return_dist=False, **kwargs)[source]#
Bases:
ModuleEncode data of
n_inputdimensions into a latent space ofn_outputdimensions.Uses a fully-connected neural network of
n_hiddenlayers.- Parameters:
n_input (
int) – The dimensionality of the input (data space)n_output (
int) – The dimensionality of the output (latent space)n_cat_list (
Iterable[int] (default:None)) – A list containing the number of categories for each category of interest. Each category will be included using a one-hot encodingn_layers (
int(default:1)) – The number of fully-connected hidden layersn_hidden (
int(default:128)) – The number of nodes per hidden layerdropout_rate (
float(default:0.1)) – Dropout rate to apply to each of the hidden layersdistribution (
str(default:'normal')) – Distribution of zvar_eps (
float(default:0.0001)) – Minimum value for the variance; used for numerical stabilityvar_activation (
Callable|None(default:None)) – Callable used to ensure positivity of the variance. Defaults totorch.exp().return_dist (
bool(default:False)) – Directly return the distribution of z instead of its parameters.**kwargs – Keyword args for
FCLayers
Attributes table#
Methods table#
|
The forward computation for a single sample. |
Attributes#
- Encoder.training: bool#
Methods#
- Encoder.forward(x, *cat_list)[source]#
The forward computation for a single sample.
Encodes the data into latent space using the encoder network
Generates a mean \( q_m \) and variance \( q_v \)
Samples a new value from i.i.d. multivariate normal \( \sim Ne(q_m, \mathbf{I}q_v) \)
- Parameters:
- Returns:
3-tuple of
torch.Tensortensors of shape(n_latent,)for mean and var, and sample