code: def compute_loss(self, model_out, x, target_label):
      em = model_out["em"]
      ev = model_out["ev"]
      dm = model_out["x_pred"]
      mc_samples = model_out["mc_samples"]
      # KL Divergence
      kl_divergence = 0.5 * torch.mean(
          em**2 + ev - torch.log(ev) - 1, axis=1
      )
  
      # Reconstruction Term
      # Proximity: L1 Loss
      x_pred = dm[0]
      s = self.cf_vae.encoded_start_cat
      recon_err = -torch.sum(
          torch.abs(x[:, s:-1] - x_pred[:, s:-1]), axis=1
      )
      for key in self.normalise_weights.keys():
          recon_err += -(
              self.normalise_weights[key][1]
              - self.normalise_weights[key][0]
          ) * torch.abs(x[:, key] - x_pred[:, key])
  
      # Sum to 1 over the categorical indexes of a feature
      for v in self.cf_vae.encoded_categorical_feature_indexes:
          temp = -torch.abs(
              1.0 - torch.sum(x_pred[:, v[0] : v[-1] + 1], axis=1)
          )
          recon_err += temp
  
      # Validity
      temp_logits = self.pred_model(x_pred)
      validity_loss = torch.zeros(1)
      temp_1 = temp_logits[target_label == 1, :]
      temp_0 = temp_logits[target_label == 0, :]
      validity_loss += F.hinge_embedding_loss(
          F.sigmoid(temp_1[:, 1]) - F.sigmoid(temp_1[:, 0]),
          torch.tensor(-1),
          self.margin,
          reduction="mean",
      )
      validity_loss += F.hinge_embedding_loss(
          F.sigmoid(temp_0[:, 0]) - F.sigmoid(temp_0[:, 1]),
          torch.tensor(-1),
          self.margin,
          reduction="mean",
      )
  
      for i in range(1, mc_samples):
          x_pred = dm[i]
  
          recon_err += -torch.sum(
              torch.abs(x[:, s:-1] - x_pred[:, s:-1]), axis=1
          )
          for key in self.normalise_weights.keys():
              recon_err += -(
                  self.normalise_weights[key][1]
                  - self.normalise_weights[key][0]
              ) * torch.abs(x[:, key] - x_pred[:, key])
  
          # Sum to 1 over the categorical indexes of a feature
          for v in self.cf_vae.encoded_categorical_feature_indexes:
              temp = -torch.abs(
                  1.0 - torch.sum(x_pred[:, v[0] : v[-1] + 1], axis=1)
              )
              recon_err += temp
  
          # Validity
          temp_logits = self.pred_model(x_pred)
          temp_1 = temp_logits[target_label == 1, :]
          temp_0 = temp_logits[target_label == 0, :]
          validity_loss += F.hinge_embedding_loss(
              F.sigmoid(temp_1[:, 1]) - F.sigmoid(temp_1[:, 0]),
              torch.tensor(-1),
              self.margin,
              reduction="mean",
          )
          validity_loss += F.hinge_embedding_loss(
              F.sigmoid(temp_0[:, 0]) - F.sigmoid(temp_0[:, 1]),
              torch.tensor(-1),
              self.margin,
              reduction="mean",
          )
  
      recon_err = recon_err / mc_samples
      validity_loss = (
          -1 * self.validity_reg * validity_loss / mc_samples
      )
  
      print(
          "recon: ",
          -torch.mean(recon_err),
          " KL: ",
          torch.mean(kl_divergence),
          " Validity: ",
          -validity_loss,
      )
      return -torch.mean(recon_err - kl_divergence) - validity_loss
  
file_path: DiCE/dice_ml/explainer_interfaces/feasible_base_vae.py
imports: import numpy
  import torch
  import torch.utils.data
  from torch.nn import functional
  from dice_ml import diverse_counterfactuals
  from dice_ml.explainer_interfaces.explainer_base import ExplainerBase
  from dice_ml.utils.helpers import get_base_gen_cf_initialization
label_desc: Use image node_id 2 for calling the FeasibleBaseVAE obj's underlying member method code with example usage: obj.compute_loss(model_out, x, target_label) and returns: unknown