code: def calc_lof(
      set_index: set, neighborhoods: dict, local_reach: dict, lof: dict
  ):
      """
      Calculate local outlier factor (LOF) of affected points.
      """
      for i in set_index:
          denominator = len(neighborhoods[i]) * local_reach[i]
          lof[i] = (
              sum(local_reach[j] for j in neighborhoods[i])
              / denominator
              if denominator
              else 0
          )
      return lof
  
imports: from __future__ import annotations
  import copy
  import functools
  import pandas
  from river import anomaly, utils
  from river.neighbors.base import DistanceFunc
label_desc: Use image node_id 7 for calling a global function with example usage: calc_lof(set_index, neighborhoods, local_reach, lof) and returns: lof