docstr: evaluate encodings assuming using associated labels
  parameters:
      encs: TxD encoding matrix
      labels: array/list of T labels
docstr_tok: ["evaluate","encodings","assuming","using","associated","labels","parameters",":","encs",":","TxD","encoding","matrix","labels",":","array\/list","of","T","labels"]
code: def evaluate(self, encs, labels, max_k=None, ecfss=False):
      """
      evaluate encodings assuming using associated labels
      parameters:
          encs: TxD encoding matrix
          labels: array/list of T labels
      """
  
      # let's use Musgrave's knn
      torch_encs = torch.from_numpy(encs)
      k = len(encs) - 1 if ecfss else len(encs)
      knn_func = inference.FaissKNN()
      _, all_indices = knn_func(torch_encs, k, torch_encs, ecfss)
      if max_k is None:
          max_k = k
          indices = all_indices
      else:
          if max_k == "max_bin_count":
              max_k = int(max(np.bincount(labels))) - int(ecfss)
          _, indices = knn_func(torch_encs, max_k, torch_encs, ecfss)
  
      # let's use the most simple mAP implementation
      # of course this can be computed much faster using cumsum, etc.
      n_encs = len(encs)
      mAP = []
      mAP_at_r = []
      correct = 0
      for r in range(n_encs):
          precisions = []
          rel = 0
          # indices doesn't contain the query index itself anymore, so no correction w. -1 necessary
          all_rel = np.count_nonzero(
              labels[all_indices[r]] == labels[r]
          )
          prec_at_r = []
          for k in range(max_k):
              if labels[indices[r, k]] == labels[r]:
                  rel += 1
                  precisions.append(rel / float(k + 1))
                  if k == 0:
                      correct += 1
  
                  # mAP@R
                  if k < all_rel:
                      prec_at_r.append(rel / float(k + 1))
  
          avg_precision = (
              np.sum(precisions) / all_rel if all_rel > 0 else 0
          )
          mAP.append(avg_precision)
          # mAP@R
          avg_prec_at_r = (
              np.sum(prec_at_r) / all_rel if all_rel > 0 else 0
          )
          mAP_at_r.append(avg_prec_at_r)
  
      mAP = np.mean(mAP)
      mAP_at_r = np.mean(mAP_at_r)
      return float(correct) / n_encs, mAP, mAP_at_r
  
file_path: pytorch-metric-learning/tests/utils/test_calculate_accuracies_large_k.py
imports: import unittest
  import numpy
  import torch
  from pytorch_metric_learning.utils import accuracy_calculator, inference
  from ..None import TEST_DEVICE
label_desc: Use image node_id 2 for calling the TestCalculateAccuraciesLargeK obj's underlying member method code with example usage: obj.evaluate(encs, labels, max_k, ecfss) and returns: unknown,  mAP,  mAP_at_r