code: def get_overlap_size_and_position_reward(
      anomaly_range_1: List[int],
      anomaly_range_2: List[int],
      overlap_count,
      positional_bias: str = "flat",
  ):
      """Calculates overlap reward for both size and position of two anomaly ranges
  
      Parameters
      ----------
      anomaly_range_1 : list [int]
          A list of two integers, representing the start and end indexes of an anomaly range
      anomaly_range_2 : list [int]
          A list of two integers, representing the start and end indexes of an anomaly range
      overlap_count : array-like, 1-D
          Accumulator used to keep track of how of overlaps between an anomaly range and a set of anomaly ranges.
      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.
  
      Returns
      -------
      overlap_size_and_position_reward: `float`
          Overlap reward for both size and position of two anomaly ranges.
      """
      overlap_size_and_position_reward = 0
  
      if (
          anomaly_range_1[1] < anomaly_range_2[0]
          or anomaly_range_1[0] > anomaly_range_2[1]
      ):
          return overlap_size_and_position_reward
      else:
          overlap_count[0] += 1
          overlap = np.zeros(anomaly_range_1.shape)
          overlap[0] = max(anomaly_range_1[0], anomaly_range_2[0])
          overlap[1] = min(anomaly_range_1[1], anomaly_range_2[1])
  
          anomaly_length = anomaly_range_1[1] - anomaly_range_1[0] + 1
          overlap_positional_reward = 0
          max_positional_reward = 0
          for local_idx in range(1, anomaly_length + 1):
              temp_reward = get_positional_reward(
                  local_idx, anomaly_length, positional_bias
              )
              max_positional_reward += temp_reward
  
              idx = anomaly_range_1[0] + local_idx - 1
              if overlap[0] <= idx <= overlap[1]:
                  overlap_positional_reward += temp_reward
  
          if max_positional_reward > 0:
              overlap_size_and_position_reward = (
                  overlap_positional_reward / max_positional_reward
              )
  
          return overlap_size_and_position_reward
  
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 5 for calling a global function with example usage: get_overlap_size_and_position_reward(anomaly_range_1, anomaly_range_2, overlap_count, positional_bias) and returns: overlap_size_and_position_reward, overlap_size_and_position_reward