class_docstr: The APMeter measures the average precision per class.
  
  The APMeter is designed to operate on `NxK` Tensors `output` and
  `target`, and optionally a `Nx1` Tensor weight where (1) the `output`
  contains model output scores for `N` examples and `K` classes that ought to
  be higher when the model is more convinced that the example should be
  positively labeled, and smaller when the model believes the example should
  be negatively labeled (for instance, the output of a sigmoid function); (2)
  the `target` contains only values 0 (for negative examples) and 1
  (for positive examples); and (3) the `weight` ( > 0) represents weight for
  each sample.
docstr: Returns the model's average precision for each class
  
  Return:
      ap (FloatTensor): 1xK tensor, with avg precision for each class k
docstr_tok: ["Returns","the","model","'s","average","precision","for","each","class","Return",":","ap","(","FloatTensor",")",":","1xK","tensor",",","with","avg","precision","for","each","class","k"]
code: def value(self):
      """Returns the model's average precision for each class
  
      Return:
          ap (FloatTensor): 1xK tensor, with avg precision for each class k
  
      """
  
      if self.scores.numel() == 0:
          return 0
      ap = torch.zeros(self.scores.size(1))
      if hasattr(torch, "arange"):
          rg = torch.arange(1, self.scores.size(0) + 1).float()
      else:
          rg = torch.range(1, self.scores.size(0)).float()
      if self.weights.numel() > 0:
          weight = self.weights.new(self.weights.size())
          weighted_truth = self.weights.new(self.weights.size())
  
      # compute average precision for each class
      for k in range(self.scores.size(1)):
          # sort scores
          scores = self.scores[:, k]
          targets = self.targets[:, k]
          _, sortind = torch.sort(scores, 0, True)
          truth = targets[sortind]
          if self.weights.numel() > 0:
              weight = self.weights[sortind]
              weighted_truth = truth.float() * weight
              rg = weight.cumsum(0)
  
          # compute true positive sums
          if self.weights.numel() > 0:
              tp = weighted_truth.cumsum(0)
          else:
              tp = truth.float().cumsum(0)
  
          # compute precision curve
          precision = tp.div(rg)
  
          # compute average precision
          ap[k] = precision[truth.byte()].sum() / max(
              float(truth.sum()), 1
          )
      return ap
  
file_path: pywick/pywick/meters/apmeter.py
imports: import math
  from .None import meter
  import torch
label_desc: Use image node_id 4 for calling the APMeter obj's underlying member method code with example usage: obj.value() and returns: ap, int