scvi.external.gimvi.JVAE#
- class scvi.external.gimvi.JVAE(dim_input_list, total_genes, indices_mappings, gene_likelihoods, model_library_bools, library_log_means, library_log_vars, n_latent=10, n_layers_encoder_individual=1, n_layers_encoder_shared=1, dim_hidden_encoder=64, n_layers_decoder_individual=0, n_layers_decoder_shared=0, dim_hidden_decoder_individual=64, dim_hidden_decoder_shared=64, dropout_rate_encoder=0.2, dropout_rate_decoder=0.2, n_batch=0, n_labels=0, dispersion='gene-batch', log_variational=True)[source]#
Bases:
BaseModuleClass
Joint variational auto-encoder for imputing missing genes in spatial data.
Implementation of gimVI [Lopez et al., 2019].
- Parameters:
- List of number of input genes for each dataset. If
the datasets have different sizes, the dataloader will loop on the smallest until it reaches the size of the longest one
total_genes (
int
) – Total number of different genesindices_mappings (
list
[ndarray
|slice
]) – list of mapping the model inputs to the model output Eg:[[0,2], [0,1,3,2]]
means the first dataset has 2 genes that will be reconstructed at location[0,2]
the second dataset has 4 genes that will be reconstructed at[0,1,3,2]
gene_likelihoods (
list
[str
]) – list of distributions to use in the generative process ‘zinb’, ‘nb’, ‘poisson’list (library_log_vars np.ndarray) – model or not library size with a latent variable or use observed values
list – List of 1 x n_batch array of means of the log library sizes. Parameterizes prior on library size if not using observed library sizes.
list – List of 1 x n_batch array of variances of the log library sizes. Parameterizes prior on library size if not using observed library sizes.
n_latent (
int
(default:10
)) – dimension of latent spacen_layers_encoder_individual (
int
(default:1
)) – number of individual layers in the encodern_layers_encoder_shared (
int
(default:1
)) – number of shared layers in the encoderdim_hidden_encoder (
int
(default:64
)) – dimension of the hidden layers in the encodern_layers_decoder_individual (
int
(default:0
)) – number of layers that are conditionally batchnormed in the encodern_layers_decoder_shared (
int
(default:0
)) – number of shared layers in the decoderdim_hidden_decoder_individual (
int
(default:64
)) – dimension of the individual hidden layers in the decoderdim_hidden_decoder_shared (
int
(default:64
)) – dimension of the shared hidden layers in the decoderdropout_rate_encoder (
float
(default:0.2
)) – dropout encoderdropout_rate_decoder (
float
(default:0.2
)) – dropout decodern_batch (
int
(default:0
)) – total number of batchesn_labels (
int
(default:0
)) – total number of labelsdispersion (
str
(default:'gene-batch'
)) – Seevae.py
log_variational (
bool
(default:True
)) – Log(data+1) prior to encoding for numerical stability. Not normalization.
Attributes table#
Methods table#
|
Run the generative model. |
|
Get the sample rate for the model. |
|
Run the inference model. |
|
Return the reconstruction loss and the Kullback divergences. |
|
Compute the reconstruction loss. |
|
Sample the tensor of library sizes from the posterior. |
|
Sample tensor of latent values from the posterior. |
|
Returns the tensor of scaled frequencies of expression. |
|
Return the tensor of predicted frequencies of expression. |
Attributes#
- JVAE.training: bool#
Methods#
- JVAE.generative(z, library, batch_index=None, y=None, mode=0, transform_batch=None)[source]#
Run the generative model.
- Return type:
- JVAE.inference(x, mode=0, n_samples=1, batch_index=None)[source]#
Run the inference model.
- Return type:
- JVAE.loss(tensors, inference_outputs, generative_outputs, mode=None, kl_weight=1.0)[source]#
Return the reconstruction loss and the Kullback divergences.
- Parameters:
x – tensor of values with shape
(batch_size, n_input)
or(batch_size, n_input_fish)
depending on the modebatch_index – array that indicates which batch the cells belong to with shape
batch_size
y – tensor of cell-types labels with shape (batch_size, n_labels)
mode (
int
|None
(default:None
)) – indicates which head/tail to use in the joint network
- Return type:
tuple
[Tensor
,Tensor
]- Returns:
the reconstruction loss and the Kullback divergences
- JVAE.reconstruction_loss(x, px_rate, px_r, px_dropout, mode)[source]#
Compute the reconstruction loss.
- Return type:
Tensor
- JVAE.sample_from_posterior_l(x, mode=None, deterministic=False)[source]#
Sample the tensor of library sizes from the posterior.
- Parameters:
- Return type:
Tensor
- Returns:
type tensor of shape
(batch_size, 1)
- JVAE.sample_from_posterior_z(x, mode=None, deterministic=False)[source]#
Sample tensor of latent values from the posterior.
- JVAE.sample_rate(x, mode, batch_index, y=None, deterministic=False, decode_mode=None)[source]#
Returns the tensor of scaled frequencies of expression.
- Parameters:
x (
Tensor
) – tensor of values with shape(batch_size, n_input)
or(batch_size, n_input_fish)
depending on the modey (
Tensor
|None
(default:None
)) – tensor of cell-types labels with shape(batch_size, n_labels)
mode (
int
) – int encode mode (which input head to use in the model)batch_index (
Tensor
) – array that indicates which batch the cells belong to with shapebatch_size
deterministic (
bool
(default:False
)) – bool - whether to sample or notdecode_mode (
int
(default:None
)) – int use to a decode mode different from encoding mode
- Return type:
Tensor
- Returns:
type tensor of means of the scaled frequencies
- JVAE.sample_scale(x, mode, batch_index, y=None, deterministic=False, decode_mode=None)[source]#
Return the tensor of predicted frequencies of expression.
- Parameters:
x (
Tensor
) – tensor of values with shape(batch_size, n_input)
or(batch_size, n_input_fish)
depending on the modemode (
int
) – int encode mode (which input head to use in the model)batch_index (
Tensor
) – array that indicates which batch the cells belong to with shapebatch_size
y (
Tensor
|None
(default:None
)) – tensor of cell-types labels with shape(batch_size, n_labels)
deterministic (
bool
(default:False
)) – bool - whether to sample or notdecode_mode (
int
|None
(default:None
)) – int use to a decode mode different from encoding mode
- Return type:
Tensor
- Returns:
type tensor of predicted expression