code: def precision_recall_curve_per_ts(
      labels: List[bool],
      scores: List[float],
      thresholds: np.ndarray,
      partial_filter: Optional[Callable] = None,
      singleton_curve: bool = False,
      precision_recall_fn: Callable = buffered_precision_recall,
  ) -> PrecisionRecallAndWeights:
      true_ranges = labels_to_ranges(labels)
      precisions = np.zeros(len(thresholds))
      recalls = np.zeros(len(thresholds))
  
      precision_weights, recall_weights = (
          np.zeros(len(thresholds)),
          np.zeros(len(thresholds)),
      )
  
      for ix, th in enumerate(thresholds):
          if partial_filter is None:
              pred_labels = scores >= th
          else:
              pred_labels = partial_filter(th)
  
          if singleton_curve:
              true_labels_np = np.array(labels, dtype=float)
              pred_labels_np = np.array(pred_labels, dtype=float)
              _prec, _reca = singleton_precision_recall(
                  true_labels_np, pred_labels_np
              )
              _prec_w, _reca_w = np.sum(pred_labels_np), np.sum(
                  true_labels_np
              )
          else:
              pred_ranges = labels_to_ranges(pred_labels)
              _prec, _reca = precision_recall_fn(
                  true_ranges, pred_ranges
              )
              _prec_w, _reca_w = len(pred_ranges), len(true_ranges)
  
          precisions[ix] += _prec * _prec_w
          recalls[ix] += _reca * _reca_w
  
          precision_weights[ix] += _prec_w
          recall_weights[ix] += _reca_w
  
      return PrecisionRecallAndWeights(
          precisions, recalls, precision_weights, recall_weights
      )
  
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 2 for calling a global function with example usage: precision_recall_curve_per_ts(labels, scores, thresholds, partial_filter, singleton_curve, precision_recall_fn) and returns: PrecisionRecallAndWeights