code: def soft_f1_score(y_true, y_pred, window):
      """Computes the soft F1 score for two classes, usually labeled 1 and 0 to denote
      an anomaly and not an anomaly.
      Soft F1 is simply calculated from
      - Soft Precision: `~greykite.detection.common.evaluation.soft_precision_score` and
      - Soft Recall: `~greykite.detection.common.evaluation.soft_recall_score`
      using the standard formula for F1: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html
  
      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 precision scores for various categories.
      """
      soft_precision = soft_precision_score(
          y_true=y_true, y_pred=y_pred, window=window
      )
  
      soft_recall = soft_recall_score(
          y_true=y_true, y_pred=y_pred, window=window
      )
  
      soft_f1 = {}
      # Soft f1 can only be defined for categories (e.g. True, False) that
      # appear in results of both precision and recall.
      # Therefore we first find the intersection.
      admissable_categories = set(soft_precision.keys()).intersection(
          soft_recall.keys()
      )
      for categ in admissable_categories:
          soft_f1[categ] = (
              2
              * (soft_precision[categ] * soft_recall[categ])
              / (soft_precision[categ] + soft_recall[categ])
          )
  
      return soft_f1
  
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 10 for calling a global function with example usage: soft_f1_score(y_true, y_pred, window) and returns: soft_f1