class_docstr: Calculate the average precision and average precision at n.
docstr: Construct an AveragePrecisionCalculator to calculate average precision.
  
  This class is used to calculate the average precision for a single label.
  
  Args:
    top_n: A positive Integer specifying the average precision at n, or
      None to use all provided data points.
  
  Raises:
    ValueError: An error occurred when the top_n is not a positive integer.
docstr_tok: ["Construct","an","AveragePrecisionCalculator","to","calculate","average","precision",".","This","class","is","used","to","calculate","the","average","precision","for","a","single","label",".","Args",":","top_n",":","A","positive","Integer","specifying","the","average","precision","at","n",",","or","None","to","use","all","provided","data","points",".","Raises",":","ValueError",":","An","error","occurred","when","the","top_n","is","not","a","positive","integer","."]
code: def __init__(self, top_n=None):
      """Construct an AveragePrecisionCalculator to calculate average precision.
  
      This class is used to calculate the average precision for a single label.
  
      Args:
        top_n: A positive Integer specifying the average precision at n, or
          None to use all provided data points.
  
      Raises:
        ValueError: An error occurred when the top_n is not a positive integer.
      """
      if not ((isinstance(top_n, int) and top_n >= 0) or top_n is None):
          raise ValueError("top_n must be a positive integer or None.")
  
      self._top_n = top_n  # average precision at n
      self._total_positives = 0  # total number of positives have seen
      self._heap = []
  
file_path: PaddleHub/modules/video/classification/videotag_tsn_lstm/resource/metrics/youtube8m/average_precision_calculator.py
imports: import heapq
  import random
  import numbers
  import numpy
label_desc: Use image node_id 1 to create a new AveragePrecisionCalculator object from inherited base classes: object with example: obj = AveragePrecisionCalculator(top_n)