parameters: (stat_pos, stat_neg, scope=None, util=None)
return_statement: return auc_value
docstring: distributed auc in fleet
  
      Args:
          stat_pos(numpy.array|Variable|string): stat_pos in output of fluid.layers.auc
          stat_neg(numpy.array|Variable|string): stat_neg in output of fluid.layers.auc
          scope(Scope): specific scope
  
      Returns:
          auc_value(float): auc value
  
      Example:
          .. code-block:: python
  
            # in model.py
            similarity_norm = fluid.layers.sigmoid(fluid.layers.clip(output, min=-15.0, max=15.0))
            binary_predict = fluid.layers.concat(
                input=[fluid.layers.elementwise_sub(fluid.layers.ceil(similarity_norm), similarity_norm), similarity_norm], axis=1)
            self.auc, batch_auc, [batch_stat_pos, batch_stat_neg, stat_pos, stat_neg] =
                fluid.layers.auc(input=binary_predict, label=label, curve='ROC', num_thresholds=4096)
  
            # in train.py, after train or infer
            pos = np.array(scope.find_var(stat_pos.name).get_tensor())
            neg = np.array(scope.find_var(stat_neg.name).get_tensor())
            print("auc: ", paddle.distributed.fleet.auc(pos, neg))
docstring_summary: distributed auc in fleet
docstring_tokens: distributed auc in fleet
function: def auc(stat_pos, stat_neg, scope=None, util=None):
      """
      distributed auc in fleet
  
      Args:
          stat_pos(numpy.array|Variable|string): stat_pos in output of fluid.layers.auc
          stat_neg(numpy.array|Variable|string): stat_neg in output of fluid.layers.auc
          scope(Scope): specific scope
  
      Returns:
          auc_value(float): auc value
  
      Example:
          .. code-block:: python
  
            # in model.py
            similarity_norm = fluid.layers.sigmoid(fluid.layers.clip(output, min=-15.0, max=15.0))
            binary_predict = fluid.layers.concat(
                input=[fluid.layers.elementwise_sub(fluid.layers.ceil(similarity_norm), similarity_norm), similarity_norm], axis=1)
            self.auc, batch_auc, [batch_stat_pos, batch_stat_neg, stat_pos, stat_neg] =
                fluid.layers.auc(input=binary_predict, label=label, curve='ROC', num_thresholds=4096)
  
            # in train.py, after train or infer
            pos = np.array(scope.find_var(stat_pos.name).get_tensor())
            neg = np.array(scope.find_var(stat_neg.name).get_tensor())
            print("auc: ", paddle.distributed.fleet.auc(pos, neg))
      """
      if scope is None:
          scope = paddle.static.global_scope()
      if util is None:
          util = paddle.distributed.fleet.util
  
      if isinstance(stat_pos, Variable):
          stat_pos = np.array(scope.find_var(stat_pos.name).get_tensor())
      elif isinstance(stat_pos, str):
          stat_pos = np.array(scope.find_var(stat_pos).get_tensor())
      if isinstance(stat_neg, Variable):
          stat_neg = np.array(scope.find_var(stat_neg.name).get_tensor())
      elif isinstance(stat_neg, str):
          stat_neg = np.array(scope.find_var(stat_neg).get_tensor())
      # auc pos bucket shape
      old_pos_shape = np.array(stat_pos.shape)
      # reshape to one dim
      stat_pos = stat_pos.reshape(-1)
      global_pos = np.copy(stat_pos) * 0
      # mpi allreduce
      global_pos = util.all_reduce(stat_pos, "sum")
      global_pos = global_pos.reshape(old_pos_shape)
  
      # auc neg bucket
      old_neg_shape = np.array(stat_neg.shape)
      stat_neg = stat_neg.reshape(-1)
      global_neg = np.copy(stat_neg) * 0
      global_neg = util.all_reduce(stat_neg, "sum")
      global_neg = global_neg.reshape(old_neg_shape)
  
      # calculate auc
      num_bucket = len(global_pos[0])
      area = 0.0
      pos = 0.0
      neg = 0.0
      new_pos = 0.0
      new_neg = 0.0
      total_ins_num = 0
      for i in range(num_bucket):
          index = num_bucket - 1 - i
          new_pos = pos + global_pos[0][index]
          total_ins_num += global_pos[0][index]
          new_neg = neg + global_neg[0][index]
          total_ins_num += global_neg[0][index]
          area += (new_neg - neg) * (pos + new_pos) / 2
          pos = new_pos
          neg = new_neg
  
      auc_value = None
      if pos * neg == 0 or total_ins_num == 0:
          auc_value = 0.5
      else:
          auc_value = area / (pos * neg)
  
      return auc_value
function_tokens: def auc ( stat_pos , stat_neg , scope = None , util = None ) : if scope is None : scope = paddle . static . global_scope ( ) if util is None : util = paddle . distributed . fleet . util if isinstance ( stat_pos , Variable ) : stat_pos = np . array ( scope . find_var ( stat_pos . name ) . get_tensor ( ) ) elif isinstance ( stat_pos , str ) : stat_pos = np . array ( scope . find_var ( stat_pos ) . get_tensor ( ) ) if isinstance ( stat_neg , Variable ) : stat_neg = np . array ( scope . find_var ( stat_neg . name ) . get_tensor ( ) ) elif isinstance ( stat_neg , str ) : stat_neg = np . array ( scope . find_var ( stat_neg ) . get_tensor ( ) ) # auc pos bucket shape old_pos_shape = np . array ( stat_pos . shape ) # reshape to one dim stat_pos = stat_pos . reshape ( - 1 ) global_pos = np . copy ( stat_pos ) * 0 # mpi allreduce global_pos = util . all_reduce ( stat_pos , "sum" ) global_pos = global_pos . reshape ( old_pos_shape ) # auc neg bucket old_neg_shape = np . array ( stat_neg . shape ) stat_neg = stat_neg . reshape ( - 1 ) global_neg = np . copy ( stat_neg ) * 0 global_neg = util . all_reduce ( stat_neg , "sum" ) global_neg = global_neg . reshape ( old_neg_shape ) # calculate auc num_bucket = len ( global_pos [ 0 ] ) area = 0.0 pos = 0.0 neg = 0.0 new_pos = 0.0 new_neg = 0.0 total_ins_num = 0 for i in range ( num_bucket ) : index = num_bucket - 1 - i new_pos = pos + global_pos [ 0 ] [ index ] total_ins_num += global_pos [ 0 ] [ index ] new_neg = neg + global_neg [ 0 ] [ index ] total_ins_num += global_neg [ 0 ] [ index ] area += ( new_neg - neg ) * ( pos + new_pos ) / 2 pos = new_pos neg = new_neg auc_value = None if pos * neg == 0 or total_ins_num == 0 : auc_value = 0.5 else : auc_value = area / ( pos * neg ) return auc_value