code: def aggregate_precision_recall_curve(
      label_score_iterable: Iterable,
      thresholds: Optional[np.array] = None,
      partial_filter: Optional[Callable] = None,
      singleton_curve: bool = False,
      precision_recall_fn: Callable = buffered_precision_recall,
      n_jobs: int = -1,
  ):
      """
      Computes aggregate range-based precision recall curves over a data set,
      iterating over individual time series. Optionally takes partially
      constructed filter that converts given scores/thresholds to anomaly labels.
      See `gluonts.nursery.anomaly_detection.supervised_metrics.filters` for
      example filters.
  
      Parameters
      ----------
      label_score_iterable: Iterable
          An iterable that gives 2-tuples of np.arrays (of identical length),
          corresponding to `true_labels` and `pred_scores` respectively.
      thresholds: np.ndarray
          An np.array of score thresholds for which to compute precision recall values.
          If the filter_type argument is provided, these are the threshold values of
          the filter. If not, they will be applied as a single step hard threshold to
          predicted scores.
      partial_filter: Callable
          Partial constructor for a "filter" object. If provided, this function can be called with a "score_threshold" to
          return labels used for precision and recall computation. If not provided, labels will be assigned with a hard
          threshold.
          See `gluonts.nursery.anomaly_detection.supervised_metrics.filters` for example filters.
      singleton_curve: bool
          If true, range-based precision recall will not be computed
      precision_recall_fn:
          Function to call in order to get the precision, recall metrics.
      n_jobs: int
          How many concurrent threads for parallelization, default is -1 (use all cpu available)
  
      Returns
      -------
      (Same as output of `sklearn.metrics.precision_recall_curve`)
      precision : array, shape = [n_thresholds + 1]
          Precision values such that element i is the precision of
          predictions with score >= thresholds[i] and the last element is 1.
  
      recall : array, shape = [n_thresholds + 1]
          Decreasing recall values such that element i is the recall of
          predictions with score >= thresholds[i] and the last element is 0.
  
      thresholds : array, shape = [n_thresholds <= len(np.unique(scores))]
          Increasing thresholds on the decision function used to compute
          precision and recall.
      """
      if thresholds is None:
          thresholds = np.unique(
              np.concatenate(
                  [scores for _, scores in label_score_iterable]
              )
          )
  
      all_metrics = Parallel(n_jobs=n_jobs, verbose=10)(
          delayed(precision_recall_curve_per_ts)(
              labels,
              scores,
              thresholds,
              partial_filter,
              singleton_curve,
              precision_recall_fn,
          )
          for labels, scores in label_score_iterable
      )
      (
          all_precisions,
          all_recalls,
          all_precision_weights,
          all_recall_weights,
      ) = zip(*all_metrics)
  
      precisions = np.sum(all_precisions, axis=0)
      recalls = np.sum(all_recalls, axis=0)
      precision_weights = np.sum(all_precision_weights, axis=0)
      recall_weights = np.sum(all_recall_weights, axis=0)
  
      # normalize
      with np.errstate(divide="ignore", invalid="ignore"):
          precisions = np.where(
              precision_weights > 0, precisions / precision_weights, 0.0
          )
          recalls = np.where(
              recall_weights > 0, recalls / recall_weights, 0.0
          )
  
      # Start from the latest threshold where the full recall is attained.
      perfect_recall_ixs = np.where(recalls == 1.0)[0]
      first_ind = (
          perfect_recall_ixs[-1] if len(perfect_recall_ixs) > 0 else 0
      )
      return (
          np.r_[precisions[first_ind:], 1],
          np.r_[recalls[first_ind:], 0],
          thresholds[first_ind:],
      )
  
file_path: gluonts/src/gluonts/nursery/anomaly_detection/supervised_metrics/_precision_recall_utils.py
imports: from typing import Callable, Iterable, List, NamedTuple, Optional, Tuple
  import numpy
  from joblib import Parallel, delayed
  from .None import buffered_precision_recall
  from .utils import labels_to_ranges
label_desc: Use image node_id 3 for calling a global function with example usage: aggregate_precision_recall_curve(label_score_iterable, thresholds, partial_filter, singleton_curve, precision_recall_fn, n_jobs) and returns: np,  np,  thresholds