scvi.module.base.LossRecorder#

class scvi.module.base.LossRecorder(loss, reconstruction_loss=None, kl_local=None, kl_global=None, **kwargs)[source]#

Bases: object

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 : {str: Tensor | ndarray} | Tensor | ndarrayUnion[Dict[str, Union[Tensor, ndarray]], Tensor, ndarray]

Tensor with loss for minibatch. Should be one dimensional with one value. Note that loss should be a Tensor and not the result of .item().

reconstruction_loss : {str: Tensor | ndarray} | Tensor | ndarray | NoneUnion[Dict[str, Union[Tensor, ndarray]], Tensor, ndarray, None] (default: None)

Reconstruction loss for each observation in the minibatch.

kl_local : {str: Tensor | ndarray} | Tensor | ndarray | NoneUnion[Dict[str, Union[Tensor, ndarray]], Tensor, ndarray, None] (default: None)

KL divergence associated with each observation in the minibatch.

kl_global : {str: Tensor | ndarray} | Tensor | ndarray | NoneUnion[Dict[str, Union[Tensor, ndarray]], Tensor, ndarray, None] (default: None)

Global kl divergence term. Should be one dimensional with one value.

**kwargs

Additional metrics can be passed as keyword arguments and will be available as attributes of the object.

Attributes table#

Methods table#

Attributes#

kl_global#

LossRecorder.kl_global#
Return type:

Tensor | ndarrayUnion[Tensor, ndarray]

kl_local#

LossRecorder.kl_local#
Return type:

Tensor | ndarrayUnion[Tensor, ndarray]

loss#

LossRecorder.loss#
Return type:

Tensor | ndarrayUnion[Tensor, ndarray]

reconstruction_loss#

LossRecorder.reconstruction_loss#
Return type:

Tensor | ndarrayUnion[Tensor, ndarray]

Methods#