code: def soft_recall_score(y_true, y_pred, window):
      """Computes the soft recall score for two classes, usually labeled 1 and 0 to denote
      an anomaly/ alert and not an anomaly/ alert, for `y_true` and `y_pred` respectively.
  
      soft_recall(window) is defined as the proportion of anomalies that were correctly
      alerted within the window size. Mathematically,
  
      soft_precision(window) = TruePositive(window)/ sum_i (y_true_i == 1),
      where
      TruePositive(window) = sum_i(y_true_i == 1, max(y_pred_{i-window}, ..., y_pred_{i+window}) == 1).
  
      For example, let window = 2.
      If the ith value in `y_true` is an anomaly (labeled 1), then we say the anomaly
      is predicted if any of i-2, i-1, i, i+1, i+2 value in `y_pred` is an alert (labeled 1).
      True Positive (window) is the sum of all such predicted anomalies.
  
      As far as we know these soft metrics do not appear in related work at least in this simple form.
      These metric were introduced by Reza Hosseini and Sayan Patra as a part of this work.
      They are found to be a very simple yet powerful extension of Precision/Recall in our work.
  
      Parameters
      ----------
      y_true : array-like, 1-D
          The actual categories.
      y_pred : array-like, 1-D
          The predicted categories.
      window : `int`
          The window size to determine True Positives.
  
      Returns
      -------
      recall : `dict`
          The recall scores for various categories.
  
      Examples
      --------
      >>> y_true = [0, 1, 1, 1, 0, 0]
      >>> y_pred = [0, 0, 0, 1, 0, 1]
      >>> print([soft_recall_score(y_true, y_pred, window) for window in [0, 1, 2]])
      [0.3333333333333333, 0.6666666666666666, 1.0]
      """
      if not isinstance(window, int) or window < 0:
          raise ValueError(
              f"Input value of the parameter window ({window}) is not a non-negative integer."
          )
  
      # If `window` is 0, we revert to the standard definition directly (to save computation time).
      if window == 0:
          return recall_score(y_true=y_true, y_pred=y_pred)
  
      lag_y_pred = pd.DataFrame({"y_pred_0": y_pred})
  
      for i in np.arange(-window, window + 1):
          # Due to shifting there will be missing data at the beginning and the end of
          # the series. ffill and bfill interpolates these edge cases.
          lag_y_pred[f"y_pred_{i}"] = (
              lag_y_pred["y_pred_0"].shift(i).ffill().bfill()
          )
  
      y_pred_soft = lag_y_pred.any(axis="columns")
  
      return recall_score(y_true, y_pred_soft)
  
imports: import functools
  import warnings
  from typing import Optional
  from typing import Union
  import numpy
  import pandas
  from sklearn import metrics
  from greykite.detection.common.ad_evaluation_utils import compute_range_based_score
  from greykite.detection.common.ad_evaluation_utils import prepare_anomaly_ranges
label_desc: Use image node_id 8 for calling a global function with example usage: soft_recall_score(y_true, y_pred, window) and returns: recall_score, recall_score