code: def calculate_seasonal_error(
      past_data: np.ndarray,
      freq: Optional[str] = None,
      seasonality: Optional[int] = None,
  ):
      r"""
      .. math::
  
          seasonal\_error = mean(|Y[t] - Y[t-m]|)
  
      where m is the seasonal frequency. See [HA21]_ for more details.
      """
      # Check if the length of the time series is larger than the seasonal
      # frequency
      if not seasonality:
          assert (
              freq is not None
          ), "Either freq or seasonality must be provided"
          seasonality = get_seasonality(freq)
  
      if seasonality < len(past_data):
          forecast_freq = seasonality
      else:
          # edge case: the seasonal freq is larger than the length of ts
          # revert to freq=1
  
          # logging.info('The seasonal frequency is larger than the length of the
          # time series. Reverting to freq=1.')
          forecast_freq = 1
  
      y_t = past_data[:-forecast_freq]
      y_tm = past_data[forecast_freq:]
  
      return np.mean(abs(y_t - y_tm))
  
file_path: gluonts/src/gluonts/evaluation/metrics.py
imports: from typing import Optional
  import numpy
  from gluonts.time_feature import get_seasonality
label_desc: Use image node_id 1 for calling a global function with example usage: calculate_seasonal_error(past_data, freq, seasonality) and returns: np