code: def early_stopping(
      log_value,
      best_value,
      stopping_step,
      expected_order="acc",
      flag_step=100,
  ):
      # early stopping strategy:
      assert expected_order in ["acc", "dec"]
  
      if (expected_order == "acc" and log_value >= best_value) or (
          expected_order == "dec" and log_value <= best_value
      ):
          stopping_step = 0
          best_value = log_value
      else:
          stopping_step += 1
  
      if stopping_step >= flag_step:
          print(
              "Early stopping is trigger at step: {} log:{}".format(
                  flag_step, log_value
              )
          )
          should_stop = True
      else:
          should_stop = False
      return best_value, stopping_step, should_stop
  
file_path: dgl/examples/pytorch/NGCF/NGCF/utility/helper.py
imports: import os
  import re
label_desc: Use image node_id 7 for calling a global function with example usage: early_stopping(log_value, best_value, stopping_step, expected_order, flag_step) and returns: best_value,  stopping_step,  should_stop