JVAETrainer¶
-
class
scvi.inference.
JVAETrainer
(model, discriminator, gene_dataset_list, train_size=0.9, use_cuda=True, kappa=1.0, n_epochs_kl_warmup=400, **kwargs)[source]¶ Bases:
scvi.inference.trainer.Trainer
The trainer class for the unsupervised training of JVAE.
- Parameters
model (
Module
Module
) – A model instance from classJVAE
discriminator (
Module
Module
) – A model instance of a classifier (with logit output)gene_dataset_list (
List
[GeneExpressionDataset
]List
[GeneExpressionDataset
]) – list of gene_dataset instance like[CortexDataset(), SmfishDataset()]
train_size (
float
float
) – Train-test split ratio in (0,1) to split cellsn_epochs_kl_warmup (
int
int
) – Number of epochs for linear warmup of KL(q(z|x)||p(z)) term. After n_epochs_kl_warmup, the training objective is the ELBO. This might be used to prevent inactivity of latent units, and/or to improve clustering of latent space, as a long warmup turns the model into something more of an autoencoder.**kwargs – Other keywords arguments from the general Trainer class.
Attributes Summary
Methods Summary
returns an zipped iterable corresponding to loss signature
A good mixing should lead to a uniform matrix.
get_imputed_values
([deterministic, …])Return imputed values for all genes for each dataset
get_latent
([deterministic])Return the latent space embedding for each dataset
get_loss_magnitude
([one_sample])Return the different losses of the model separately.
loss
(tensors[, return_details])Compute the loss of vae (reconstruction + kl_divergence)
loss_discriminator
(latent_tensors[, …])Compute the loss of the discriminator (either for the true labels or the fool labels)
on_training_loop
(tensors_list)Place to put extra models in eval mode, etc.
training_extras_init
([lr_d, eps])Other necessary models to simultaneously train
Attributes Documentation
-
default_metrics_to_monitor
= ['elbo']¶
-
posteriors_loop
¶
Methods Documentation
-
get_imputed_values
(deterministic=True, normalized=True, decode_mode=None)[source]¶ Return imputed values for all genes for each dataset
- Parameters
deterministic (
bool
bool
) – If true, use the mean of the encoder instead of a Gaussian sample for the latent vectornormalized (
bool
bool
) – Return imputed normalized values or notdecode_mode (
int
,None
Optional
[int
]) – If a decode_mode is given, use the encoder specific to each dataset as usual but use the decoder of the dataset of id decode_mode to impute values
- Return type
-
get_loss_magnitude
(one_sample=False)[source]¶ Return the different losses of the model separately. Useful to inspect and compare their magnitude.
-
loss
(tensors, return_details=False)[source]¶ Compute the loss of vae (reconstruction + kl_divergence)
-
loss_discriminator
(latent_tensors, predict_true_class=True, return_details=False)[source]¶ Compute the loss of the discriminator (either for the true labels or the fool labels)
- Parameters
latent_tensors (List[torch.Tensor]) – Tensors for each dataset of the latent space
predict_true_class (
bool
bool
) – Specify if the loss aims at minimizing the accuracy or the mixingreturn_details (
bool
bool
) – Boolean used to inspect the loss values, return detailed loss for each datasetlatent_tensors –
- Return type
- Returns
type scalar loss if return_details is False, else list of scalar losses for each dataset