code: def aggregator_epochs_elapsed(
      on_run=True, on_fold=True, on_rep=True, on_exp=True
  ):
      """Callback function to aggregate and average the number of epochs elapsed during model training
      at each stage of the Experiment
  
      Parameters
      ----------
      on_run: Boolean, default=True
          If False, skip recording epochs elapsed for individual Experiment runs
      on_fold: Boolean, default=True
          If False, skip making epochs-elapsed averages for individual Experiment folds
      on_rep: Boolean, default=True
          If False, skip making epochs-elapsed averages for individual Experiment repetitions
      on_exp: Boolean, default=True
          If False, skip making epochs-elapsed average for the Experiment
  
      Returns
      -------
      LambdaCallback
          An uninitialized :class:`LambdaCallback` to aggregate the number of epochs elapsed during
          training, produced by :func:`hyperparameter_hunter.callbacks.bases.lambda_callback`
      """
  
      def _on_run_end(model):
          """Return the number of epochs elapsed after fitting model"""
          if model.epochs_elapsed is not None:
              return model.epochs_elapsed
  
      def _on_fold_end(stat_aggregates, _run):
          """Average the number of epochs elapsed across all runs in the fold"""
          run_results = stat_aggregates["_epochs_elapsed"]["runs"]
          if len(run_results) > 0:
              return np.average(run_results[-_run:])
  
      def _on_rep_end(stat_aggregates, _run, _fold):
          """Average the number of epochs elapsed across all runs in the repetition"""
          run_results = stat_aggregates["_epochs_elapsed"]["runs"]
          if len(run_results) > 0:
              num_runs = _run * _fold
              return np.average(run_results[-num_runs:])
  
      def _on_exp_end(stat_aggregates, _run, _fold, _rep):
          """Average the number of epochs elapsed across all runs in the Experiment"""
          run_results = stat_aggregates["_epochs_elapsed"]["runs"]
          if len(run_results) > 0:
              num_runs = _run * _fold * _rep
              return np.average(run_results[-num_runs:])
  
      return lambda_callback(
          on_run_end=_on_run_end if on_run else None,
          on_fold_end=_on_fold_end if on_fold else None,
          on_rep_end=_on_rep_end if on_rep else None,
          on_exp_end=_on_exp_end if on_exp else None,
          agg_name="epochs_elapsed",
      )
  
file_path: hyperparameter_hunter/hyperparameter_hunter/callbacks/recipes.py
imports: from hyperparameter_hunter.callbacks.bases import lambda_callback
  from hyperparameter_hunter.data.data_chunks.target_chunks import TrainTargetChunk
  from hyperparameter_hunter.metrics import get_clean_prediction
  from copy import deepcopy
  import numpy
  from typing import List, Optional
  from sklearn.metrics import confusion_matrix
label_desc: Use image node_id 6 for calling a global function with example usage: aggregator_epochs_elapsed(on_run, on_fold, on_rep, on_exp) and returns: lambda_callback, model, np, np, np