class_docstr: Rank hinge loss.
  
  Examples:
      >>> from keras import backend as K
      >>> x_pred = K.variable(np.array([[1.0], [1.2], [0.8], [1.4]]))
      >>> x_true = K.variable(np.array([[1], [0], [1], [0]]))
      >>> expect = ((1.0 + 1.2 - 1.0) + (1.0 + 1.4 - 0.8)) / 2
      >>> expect
      1.4
      >>> loss = K.eval(RankHingeLoss(num_neg=1, margin=1.0)(x_true, x_pred))
      >>> np.isclose(loss, expect)
      True
class_docstr_tok: ["Rank","hinge","loss",".","Examples",":",">",">",">","from","keras","import","backend","as","K",">",">",">","x_pred","=","K.variable","(","np.array","(","[","[","1.0","]",",","[","1.2","]",",","[","0.8","]",",","[","1.4","]","]",")",")",">",">",">","x_true","=","K.variable","(","np.array","(","[","[","1","]",",","[","0","]",",","[","1","]",",","[","0","]","]",")",")",">",">",">","expect","=","(","(","1.0","+","1.2","-","1.0",")","+","(","1.0","+","1.4","-","0.8",")",")","\/","2",">",">",">","expect","1.4",">",">",">","loss","=","K.eval","(","RankHingeLoss","(","num_neg=1",",","margin=1.0",")","(","x_true",",","x_pred",")",")",">",">",">","np.isclose","(","loss",",","expect",")","True"]
docstr: Calculate rank hinge loss.
  
  :param y_true: Label.
  :param y_pred: Predicted result.
  :return: Hinge loss computed by user-defined margin.
docstr_tok: ["Calculate","rank","hinge","loss",".",":","param","y_true",":","Label",".",":","param","y_pred",":","Predicted","result",".",":","return",":","Hinge","loss","computed","by","user-defined","margin","."]
code: def call(
      self, y_true: np.array, y_pred: np.array, sample_weight=None
  ) -> np.array:
      """
      Calculate rank hinge loss.
  
      :param y_true: Label.
      :param y_pred: Predicted result.
      :return: Hinge loss computed by user-defined margin.
      """
      y_pos = layers.Lambda(
          lambda a: a[:: (self._num_neg + 1), :], output_shape=(1,)
      )(y_pred)
      y_neg = []
      for neg_idx in range(self._num_neg):
          y_neg.append(
              layers.Lambda(
                  lambda a: a[(neg_idx + 1) :: (self._num_neg + 1), :],
                  output_shape=(1,),
              )(y_pred)
          )
      y_neg = tf.concat(y_neg, axis=-1)
      y_neg = tf.reduce_mean(y_neg, axis=-1, keepdims=True)
      loss = tf.maximum(0.0, self._margin + y_neg - y_pos)
      return losses_utils.compute_weighted_loss(
          loss, sample_weight, reduction=self.reduction
      )
  
file_path: MatchZoo/matchzoo/losses/rank_hinge_loss.py
imports: import numpy
  import tensorflow
  from keras import layers, backend
  from keras.losses import Loss
  from keras.utils import losses_utils
label_desc: Use image node_id 2 for calling the RankHingeLoss obj's underlying member method code with example usage: obj.call(y_true, y_pred, sample_weight) and returns: losses_utils