scvi.module.base.LossOutput#
- class scvi.module.base.LossOutput(loss, reconstruction_loss=None, kl_local=None, kl_global=None, classification_loss=None, logits=None, true_labels=None, extra_metrics=dict(), n_obs_minibatch=None, reconstruction_loss_sum=None, kl_local_sum=None, kl_global_sum=None)[source]#
Bases:
Loss signature for models.
This class provides an organized way to record the model loss, as well as the components of the ELBO. This may also be used in MLE, MAP, EM methods. The loss is used for backpropagation during inference. The other parameters are used for logging/early stopping during inference.
- Parameters:
- loss
dict[str,Tensor] |Tensor Tensor with loss for minibatch. Should be one dimensional with one value. Note that loss should be in an array/tensor and not a float.
- reconstruction_loss
dict[str,Tensor] |Tensor|None(default:None) Reconstruction loss for each observation in the minibatch. If a tensor, converted to a dictionary with the key “reconstruction_loss” and value as tensor.
- kl_local
dict[str,Tensor] |Tensor|None(default:None) KL divergence associated with each observation in the minibatch. If a tensor, converted to a dictionary with the key “kl_local” and value as tensor.
- kl_global
dict[str,Tensor] |Tensor|None(default:None) Global KL divergence term. Should be one dimensional with one value. If a tensor, converted to a dictionary with the key “kl_global” and value as tensor.
- classification_loss
dict[str,Tensor] |Tensor|None(default:None) Classification loss.
- logits torch.Tensor |
None(default:None) Logits for classification.
- true_labels torch.Tensor |
None(default:None) True labels for classification.
- extra_metrics
dict[str,Tensor] |None(default:dict()) Additional metrics can be passed as arrays/tensors or dictionaries of arrays/tensors.
- n_obs_minibatch
int|None(default:None) Number of observations in the minibatch. If None, it will be inferred from the shape of the reconstruction_loss tensor.
- loss
Examples
>>> loss_output = LossOutput( ... loss=loss, ... reconstruction_loss=reconstruction_loss, ... kl_local=kl_local, ... extra_metrics={"x": scalar_tensor_x, "y": scalar_tensor_y}, ... )
Attributes table#
Methods table#
|
Sum over elements of a dictionary. |
Attributes#
- LossOutput.extra_metrics_keys#
Keys for extra metrics.
- LossOutput.logits: torch.Tensor | None = None#
- LossOutput.true_labels: torch.Tensor | None = None#