code: def dcg_at_k(r, k, method=1):
      """Score is discounted cumulative gain (dcg)
      Relevance is positive real values.  Can use binary
      as the previous methods.
      Returns:
          Discounted cumulative gain
      """
      r = np.asfarray(r)[:k]
      if r.size:
          if method == 0:
              return r[0] + np.sum(
                  r[1:] / np.log2(np.arange(2, r.size + 1))
              )
          elif method == 1:
              return np.sum(r / np.log2(np.arange(2, r.size + 2)))
          else:
              raise ValueError("method must be 0 or 1.")
      return 0.0
  
file_path: dgl/examples/pytorch/NGCF/NGCF/utility/metrics.py
imports: import numpy
  from sklearn.metrics import roc_auc_score
label_desc: Use image node_id 5 for calling a global function with example usage: dcg_at_k(r, k, method) and returns: int, unknown, np