code: def compute_range_based_score(
      anomaly_ranges_1,
      anomaly_ranges_2,
      alpha: float = 0.5,
      positional_bias: str = "flat",
      cardinality_bias: Optional[str] = None,
  ):
      """Given two lists of anomaly ranges, calculate a range-based score over the time series represented by the first list
      of anomaly ranges. If ``anomaly_ranges_1`` is the predicted anomaly ranges, the result is range-based precision score. If
      ``anomaly_range_1`` is the real anomaly ranges, the result is range-based recall score.
  
      Parameters
      ----------
      anomaly_ranges_1 : array-like, 2D
          2D-array representing anomaly ranges, with each element indicating the
          start and end indexes for an anomaly period.
      anomaly_ranges_2 : array-like, 2D
          2D-array representing anomaly ranges, with each element indicating the
          start and end indexes for an anomaly period.
      alpha : `float`
          Reward weighting term for the two main reward terms for the real anomaly range recall score: existence
          and overlap rewards.
      positional_bias : `str`, default "flat"
          If "flat", each index position of an anomaly range is equally important. Return the same
            number, 1.0, as the positional reward regardless of the location of the pointwise anomaly
            within the anomaly range.
          If "front", reward is biased towards early detection, as earlier overlap locations of pointwise
            anomalies with an anomaly range are assigned higher rewards.
          If "middle", reward is biased towards the detection of anomaly closer to its middle point, as
            overlap locations closer to the middle of an anomaly range are assigned higher rewards.
          If "back", reward is biased towards later detection, as later overlap locations of pointwise
            anomalies with an anomaly range are assigned higher rewards.
      cardinality_bias: `str` or None, default None
          In the overlap reward, this is a penalization factor. If None, no cardinality penalty will be applied. If "reciprocal", the
          overlap reward will be penalized as it gets multiplied by the reciprocal of the number of detected anomaly ranges overlapping
          with the predicted anomaly range.
  
      Returns
      -------
      overlap_size_and_position_reward: `float`
          Overlap reward for both size and position of two anomaly ranges.
      """
  
      assert 0 <= alpha <= 1
      assert positional_bias in ["flat", "front", "middle", "back"]
      if cardinality_bias is not None:
          assert cardinality_bias == "reciprocal"
  
      score = 0.0
  
      for range_idx1 in range(len(anomaly_ranges_1)):
          overlap_count = [0]
          overlap_size_and_position_reward = 0
          real_range = anomaly_ranges_1[range_idx1, :]
          for range_idx2 in range(len(anomaly_ranges_2)):
              predicted_range = anomaly_ranges_2[range_idx2, :]
              overlap_size_and_position_reward += (
                  get_overlap_size_and_position_reward(
                      real_range,
                      predicted_range,
                      overlap_count,
                      positional_bias,
                  )
              )
  
          cardinality_factor = get_cardinality_factor(
              overlap_count, cardinality_bias
          )
          overlap_reward = (
              cardinality_factor * overlap_size_and_position_reward
          )
  
          existence_reward = 1 if overlap_count[0] > 0 else 0
          score += (
              alpha * existence_reward + (1 - alpha) * overlap_reward
          )
  
      score /= len(anomaly_ranges_1)
      return score
  
file_path: greykite/greykite/detection/common/ad_evaluation_utils.py
imports: from typing import List
  from typing import Optional
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: compute_range_based_score(anomaly_ranges_1, anomaly_ranges_2, alpha, positional_bias, cardinality_bias) and returns: score