code: def loss_vaegmm(
      x_true: tf.Tensor,
      x_pred: tf.Tensor,
      z: tf.Tensor,
      gamma: tf.Tensor,
      w_recon: float = 1e-7,
      w_energy: float = 0.1,
      w_cov_diag: float = 0.005,
      cov_full: tf.Tensor = None,
      cov_diag: tf.Tensor = None,
      sim: float = 0.05,
  ) -> tf.Tensor:
      """
      Loss function used for OutlierVAEGMM.
  
      Parameters
      ----------
      x_true
          Batch of instances.
      x_pred
          Batch of reconstructed instances by the variational autoencoder.
      z
          Latent space values.
      gamma
          Membership prediction for mixture model components.
      w_recon
          Weight on elbo loss term.
      w_energy
          Weight on sample energy loss term.
      w_cov_diag
          Weight on covariance regularizing loss term.
      cov_full
          Full covariance matrix.
      cov_diag
          Diagonal (variance) of covariance matrix.
      sim
          Scale identity multiplier.
  
      Returns
      -------
      Loss value.
      """
      recon_loss = elbo(
          x_true, x_pred, cov_full=cov_full, cov_diag=cov_diag, sim=sim
      )
      phi, mu, cov, L, log_det_cov = gmm_params(z, gamma)
      sample_energy, cov_diag = gmm_energy(
          z, phi, mu, cov, L, log_det_cov
      )
      loss = (
          w_recon * recon_loss
          + w_energy * sample_energy
          + w_cov_diag * cov_diag
      )
      return loss
  
file_path: alibi-detect/alibi_detect/models/tensorflow/losses.py
imports: from typing import Optional
  import tensorflow
  from tensorflow.keras.layers import Flatten
  from tensorflow.keras.losses import kld, categorical_crossentropy
  import tensorflow_probability
  from alibi_detect.models.tensorflow.gmm import gmm_params, gmm_energy
label_desc: Use image node_id 3 for calling a global function with example usage: loss_vaegmm(x_true, x_pred, z, gamma, w_recon, w_energy, w_cov_diag, cov_full, cov_diag, sim) and returns: loss