code: def _define_func(
      predict_fn: Callable,
      pred_class: int,
      target_class: Union[str, int] = "same",
  ) -> Tuple[Callable, Union[str, int]]:
      # TODO: convert to batchwise function
      """
      Define the class-specific prediction function to be used in the optimization.
  
      Parameters
      ----------
      predict_fn
          Classifier prediction function.
      pred_class
          Predicted class of the instance to be explained.
      target_class
          Target class of the explanation, one of ``'same'``, ``'other'`` or an integer class.
  
      Returns
      -------
      Class-specific prediction function and the target class used.
  
      """
      if target_class == "other":
          # TODO: need to optimize this
  
          def func(X):
              probas = predict_fn(X)
              sorted = np.argsort(
                  -probas
              )  # class indices in decreasing order of probability
  
              # take highest probability class different from class predicted for X
              if sorted[0, 0] == pred_class:
                  target_class = sorted[0, 1]
                  # logger.debug('Target class equals predicted class')
              else:
                  target_class = sorted[0, 0]
  
              # logger.debug('Current best target class: %s', target_class)
              return (predict_fn(X)[:, target_class]).reshape(-1, 1)
  
          return func, target_class
  
      elif target_class == "same":
          target_class = pred_class
  
      def func(X):  # type: ignore
          return (predict_fn(X)[:, target_class]).reshape(-1, 1)
  
      return func, target_class
  
imports: import copy
  import logging
  from typing import Callable, Optional, Tuple, Union
  import numpy
  import tensorflow.compat.v1
  from alibi.api.defaults import DEFAULT_DATA_CF, DEFAULT_META_CF
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.utils.gradients import num_grad_batch
label_desc: Use image node_id 1 for calling a global function with example usage: _define_func(predict_fn, pred_class, target_class) and returns: func,  target_class, func,  target_class, predict_fn, predict_fn