docstr: Compute the attack loss.
  
  Parameters
  ----------
  pred_proba
      Prediction probabilities of an instance.
  Y
      One-hot representation of instance labels.
  
  Returns
  -------
  Loss of the attack.
docstr_tok: ["Compute","the","attack","loss",".","Parameters","--","--","--","--","--","pred_proba","Prediction","probabilities","of","an","instance",".","Y","One-hot","representation","of","instance","labels",".","Returns","--","--","--","-","Loss","of","the","attack","."]
code: def loss_fn(
      self, pred_proba: np.ndarray, Y: np.ndarray
  ) -> np.ndarray:
      """
      Compute the attack loss.
  
      Parameters
      ----------
      pred_proba
          Prediction probabilities of an instance.
      Y
          One-hot representation of instance labels.
  
      Returns
      -------
      Loss of the attack.
      """
      # probability of target label prediction
      target_proba = np.sum(pred_proba * Y)
      # max probability of non target label prediction
      nontarget_proba_max = np.max((1 - Y) * pred_proba - 10000 * Y)
  
      # loss term f(x,d) for PP (eq.4) and PN (eq.2)
      if self.mode == "PP":
          loss = np.maximum(
              0.0, nontarget_proba_max - target_proba + self.kappa
          )
      elif self.mode == "PN":
          loss = np.maximum(
              0.0, -nontarget_proba_max + target_proba + self.kappa
          )
  
      # c * f(x,d)
      loss_attack = np.sum(self.const.eval(session=self.sess) * loss)
      return loss_attack
  
file_path: alibi/alibi/explainers/cem.py
imports: import copy
  import logging
  import sys
  from typing import Any, Callable, Optional, Tuple, Union
  import numpy
  import tensorflow.compat.v1
  from alibi.api.defaults import DEFAULT_DATA_CEM, DEFAULT_META_CEM
  from alibi.api.interfaces import Explainer, Explanation, FitMixin
label_desc: Use image node_id 3 for calling the CEM obj's underlying member method code with example usage: obj.loss_fn(pred_proba, Y) and returns: loss_attack