alibi_detect.models.losses module

alibi_detect.models.losses.elbo(y_true, y_pred, cov_full=None, cov_diag=None, sim=0.05)[source]

Compute ELBO loss.

Parameters
  • y_true (tensorflow.Tensor) – Labels.

  • y_pred (tensorflow.Tensor) – Predictions.

  • cov_full (Optional[tensorflow.Tensor]) – Full covariance matrix.

  • cov_diag (Optional[tensorflow.Tensor]) – Diagonal (variance) of covariance matrix.

  • sim (float) – Scale identity multiplier.

Return type

tensorflow.Tensor

Returns

ELBO loss value.

alibi_detect.models.losses.loss_adv_vae(x_true, x_pred, model=None, w_model=1.0, w_recon=0.0, cov_full=None, cov_diag=None, sim=0.05)[source]

Loss function used for AdversarialVAE.

Parameters
  • x_true (tensorflow.Tensor) – Batch of instances.

  • x_pred (tensorflow.Tensor) – Batch of reconstructed instances by the variational autoencoder.

  • model (Optional[tensorflow.keras.Model]) – A trained tf.keras model with frozen layers (layers.trainable = False).

  • w_model (float) – Weight on model prediction loss term.

  • w_recon (float) – Weight on elbo loss term.

  • cov_full (Optional[tensorflow.Tensor]) – Full covariance matrix.

  • cov_diag (Optional[tensorflow.Tensor]) – Diagonal (variance) of covariance matrix.

  • sim (float) – Scale identity multiplier.

Return type

tensorflow.Tensor

Returns

Loss value.

alibi_detect.models.losses.loss_aegmm(x_true, x_pred, z, gamma, w_energy=0.1, w_cov_diag=0.005)[source]

Loss function used for OutlierAEGMM.

Parameters
  • x_true (tensorflow.Tensor) – Batch of instances.

  • x_pred (tensorflow.Tensor) – Batch of reconstructed instances by the autoencoder.

  • z (tensorflow.Tensor) – Latent space values.

  • gamma (tensorflow.Tensor) – Membership prediction for mixture model components.

  • w_energy (float) – Weight on sample energy loss term.

  • w_cov_diag (float) – Weight on covariance regularizing loss term.

Return type

tensorflow.Tensor

Returns

Loss value.

alibi_detect.models.losses.loss_vaegmm(x_true, x_pred, z, gamma, w_recon=1e-07, w_energy=0.1, w_cov_diag=0.005, cov_full=None, cov_diag=None, sim=0.05)[source]

Loss function used for OutlierVAEGMM.

Parameters
  • x_true (tensorflow.Tensor) – Batch of instances.

  • x_pred (tensorflow.Tensor) – Batch of reconstructed instances by the variational autoencoder.

  • z (tensorflow.Tensor) – Latent space values.

  • gamma (tensorflow.Tensor) – Membership prediction for mixture model components.

  • w_recon (float) – Weight on elbo loss term.

  • w_energy (float) – Weight on sample energy loss term.

  • w_cov_diag (float) – Weight on covariance regularizing loss term.

  • cov_full (Optional[tensorflow.Tensor]) – Full covariance matrix.

  • cov_diag (Optional[tensorflow.Tensor]) – Diagonal (variance) of covariance matrix.

  • sim (float) – Scale identity multiplier.

Return type

tensorflow.Tensor

Returns

Loss value.