code: def define_episode_stats(
      reduce_function: Callable,
      input_name: Optional[str] = None,
      output_name: Optional[str] = None,
      group_by: Optional[str] = None,
      cumulative: bool = False,
  ) -> Callable:
      """
      Event method decorator, defines a new episode statistics calculation for this event.
  
      :input: all step statistics in the current episode
              and side-loaded episode statistics, see 'reduce_function' set to None
      :output: episode statistics
  
  
      :param reduce_function: A function that takes a list of values and returns the calculated statistics
      :param input_name: The name of the step statistics, whose values are to be passed to the reduce function.
                         Can be omitted, for which there are two reasons
  
                         * no naming necessary, there is only a single step statistics available
                         * we want all step statistics to be passed to the reduce_function as dictionaries (or our
                           reduce function does not care, e.g. counting with `len`)
  
      :param output_name: The name of the generated episode statistics, how it should be passed to the logger respective
                          the following aggregation stage. Will be the same as input_name if None is provided.
      :param group_by: If there are multiple groups defined for an event, per default the statistics
                       is collected at the 'cell' level. This option allows to project the statistics
                       onto a single group (e.g. for inventory statistics we might define location and product as
                       groups, but prefer to monitor statistics grouped only per product, regardless of location
                       and vice versa)
      :param cumulative: Enable cumulative statistics
  
      :return: The decorator function
      """
      return _decorator_factory(
          LogStatsLevel.EPISODE,
          reduce_function,
          input_name,
          output_name,
          group_by,
          cumulative,
      )
  
file_path: maze/maze/core/log_stats/event_decorators.py
imports: import inspect
  from collections import defaultdict
  from typing import Callable, Optional, List, Dict
  from maze.core.log_stats.log_stats import LogStatsLevel
label_desc: Use image node_id 6 for calling a global function with example usage: define_episode_stats(reduce_function, input_name, output_name, group_by, cumulative) and returns: _decorator_factory