docstr: Generates the autoregressive components for forecasting
  given the forecast horizon and time frequency.
  
  Only if ``forecast_horizon`` is less than or equal to 30 days
  auto-regression is used.
  If ``forecast_horizon`` is larger than 30, the function returns None.
  
  First, we calculate an integer called ``proper_order`` defined below:
  This will be the smallest integer which is
      (i) larger than ``forecast_horizon``
      (ii) multiple of number of observations per week
  For example, for daily data if ``forecast_horizon`` is 2,
  we let the ``proper_order`` to be 7.
  As another example, if ``forecast_horizon`` is 9, we let the ``proper_order``
  to be 14.
  This order is useful because often the same day of week is best
  correlated with the observed value.
  As an example, for daily data, one aggregated lag predictors
  can be constructed by averaging these lags:
      `[proper_order, proper_order+7, proper_order+7*2]`
  which is equal to `[7, 14, 21]` when `forecast_horizon = 1`.
  
  Parameters
  ----------
  freq_in_days : `float`
      The frequency of the timeseries in days. e.g. 7.0 for weekly data,
      1.0 for daily data, 0.04166... for hourly data.
  forecast_horizon : `int`
      The number of time intervals into the future which are to be forecasted.
  simulation_based : `bool`, default False
      A boolean to decide if the forecast is performed via simulations or
      without simulations.
  
  Returns
  -------
  autoreg_dict : `dict` or `None`
      A dictionary which can be passed to
      `~greykite.algo.forecast.silverkite.SilverkiteForecast.forecast`
      to specify the autoregressive structure.
      See that function's definition for details.
  proper_order : `int` or None
      This will be the smallest integer which is
          (i) larger than ``forecast_horizon``
          (ii) multiple of 7
code: def __get_default_autoreg_dict(
      self, freq_in_days, forecast_horizon, simulation_based=False
  ):
      """Generates the autoregressive components for forecasting
      given the forecast horizon and time frequency.
  
      Only if ``forecast_horizon`` is less than or equal to 30 days
      auto-regression is used.
      If ``forecast_horizon`` is larger than 30, the function returns None.
  
      First, we calculate an integer called ``proper_order`` defined below:
      This will be the smallest integer which is
          (i) larger than ``forecast_horizon``
          (ii) multiple of number of observations per week
      For example, for daily data if ``forecast_horizon`` is 2,
      we let the ``proper_order`` to be 7.
      As another example, if ``forecast_horizon`` is 9, we let the ``proper_order``
      to be 14.
      This order is useful because often the same day of week is best
      correlated with the observed value.
      As an example, for daily data, one aggregated lag predictors
      can be constructed by averaging these lags:
          `[proper_order, proper_order+7, proper_order+7*2]`
      which is equal to `[7, 14, 21]` when `forecast_horizon = 1`.
  
      Parameters
      ----------
      freq_in_days : `float`
          The frequency of the timeseries in days. e.g. 7.0 for weekly data,
          1.0 for daily data, 0.04166... for hourly data.
      forecast_horizon : `int`
          The number of time intervals into the future which are to be forecasted.
      simulation_based : `bool`, default False
          A boolean to decide if the forecast is performed via simulations or
          without simulations.
  
      Returns
      -------
      autoreg_dict : `dict` or `None`
          A dictionary which can be passed to
          `~greykite.algo.forecast.silverkite.SilverkiteForecast.forecast`
          to specify the autoregressive structure.
          See that function's definition for details.
      proper_order : `int` or None
          This will be the smallest integer which is
              (i) larger than ``forecast_horizon``
              (ii) multiple of 7
      """
      forecast_horizon_in_days = freq_in_days * forecast_horizon
  
      similar_lag = get_similar_lag(freq_in_days)
      proper_order = None
      if similar_lag is not None:
          proper_order = int(
              np.ceil(forecast_horizon / similar_lag) * similar_lag
          )
  
      autoreg_dict = None
      orders = None
      orders_list = []
      interval_list = []
  
      # Following considers two cases:
      # (i) simulation-based
      # (ii) non-simulation-based
      # In simulation-based we are able to use small orders
      # even for longer horizon ie we allow a orders for which
      # ``order < forecast_horizon``.
      # The above is not possible for non-simulation based approach.
      if simulation_based:
          orders = [1, 2, 3]  # 1st, 2nd, 3rd time lags
          if similar_lag is not None:
              interval_list = [
                  (1, similar_lag),
                  (similar_lag + 1, similar_lag * 2),
              ]  # weekly average of last week, and weekly average of two weeks ago
              orders_list = [
                  [
                      similar_lag,  # (i) same week day in a week which is 7 days prior
                      similar_lag
                      * 2,  # (ii) same week day a week before (i)
                      similar_lag * 3,
                  ]
              ]  # (iii) same week day in a week before (ii)
      else:  # non-simulation-based case
          if forecast_horizon_in_days <= 30:
              orders = [
                  forecast_horizon,
                  forecast_horizon + 1,
                  forecast_horizon + 2,
              ]
  
              if similar_lag is not None:
                  interval_list = [
                      (
                          forecast_horizon,
                          forecast_horizon + similar_lag - 1,
                      ),
                      (
                          forecast_horizon + similar_lag,
                          forecast_horizon + similar_lag * 2 - 1,
                      ),
                  ]
  
                  # The following will induce an average between three lags on the same time of week
                  orders_list = [
                      [
                          proper_order,  # (i) same time in week, in a week which is ``proper_order`` times prior
                          proper_order
                          + similar_lag,  # (ii) same time in a week before (i)
                          proper_order + similar_lag * 2,
                      ]
                  ]  # (iii) same time in a week before (ii)
  
      if forecast_horizon_in_days <= 30:
          autoreg_dict = {}
          autoreg_dict["lag_dict"] = None
          autoreg_dict["agg_lag_dict"] = None
          if orders is not None:
              autoreg_dict["lag_dict"] = {"orders": orders}
          if len(orders_list) > 0 or len(interval_list) > 0:
              autoreg_dict["agg_lag_dict"] = {
                  "orders_list": orders_list,
                  "interval_list": interval_list,
              }
          autoreg_dict[
              "series_na_fill_func"
          ] = lambda s: s.bfill().ffill()
  
      return {
          "proper_order": proper_order,
          "autoreg_dict": autoreg_dict,
      }
  
imports: import re
  import warnings
  from typing import Type
  import numpy
  import pandas
  from pandas.plotting import register_matplotlib_converters
  from pandas.tseries.frequencies import to_offset
  from greykite.algo.changepoint.adalasso.changepoint_detector import get_changepoints_dict
  from greykite.algo.changepoint.adalasso.changepoint_detector import get_seasonality_changepoints
  from greykite.algo.changepoint.adalasso.changepoints_utils import build_seasonality_feature_df_from_detection_result
  from greykite.algo.changepoint.adalasso.changepoints_utils import get_seasonality_changepoint_df_cols
  from greykite.algo.common.ml_models import fit_ml_model_with_evaluation
  from greykite.algo.common.ml_models import predict_ml
  from greykite.algo.common.ml_models import predict_ml_with_uncertainty
  from greykite.algo.forecast.silverkite.constants.silverkite_constant import default_silverkite_constant
  from greykite.algo.forecast.silverkite.constants.silverkite_seasonality import SilverkiteSeasonalityEnum
  from greykite.algo.forecast.silverkite.constants.silverkite_seasonality import SilverkiteSeasonalityEnumMixin
  from greykite.algo.forecast.silverkite.forecast_silverkite_helper import get_fourier_feature_col_names
  from greykite.algo.forecast.silverkite.forecast_silverkite_helper import get_similar_lag
  from greykite.common.constants import CHANGEPOINT_COL_PREFIX
  from greykite.common.constants import ERR_STD_COL
  from greykite.common.constants import QUANTILE_SUMMARY_COL
  from greykite.common.constants import SEASONALITY_REGEX
  from greykite.common.constants import TimeFeaturesEnum
  from greykite.common.enums import TimeEnum
  from greykite.common.features.timeseries_features import add_daily_events
  from greykite.common.features.timeseries_features import add_time_features_df
  from greykite.common.features.timeseries_features import fourier_series_multi_fcn
  from greykite.common.features.timeseries_features import get_changepoint_dates_from_changepoints_dict
  from greykite.common.features.timeseries_features import get_changepoint_features
  from greykite.common.features.timeseries_features import get_changepoint_features_and_values_from_config
  from greykite.common.features.timeseries_features import get_default_origin_for_time_vars
  from greykite.common.features.timeseries_lags import build_autoreg_df
  from greykite.common.features.timeseries_lags import build_autoreg_df_multi
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import get_pattern_cols
  from greykite.common.python_utils import unique_elements_in_list
  from greykite.common.time_properties import describe_timeseries
  from greykite.common.time_properties import fill_missing_dates
  from greykite.common.time_properties import min_gap_in_seconds
  from greykite.common.time_properties_forecast import get_default_horizon_from_period
label_desc: Use image node_id 16 for calling the SilverkiteForecast obj's underlying member method code with example usage: obj.__get_default_autoreg_dict(freq_in_days, forecast_horizon, simulation_based) and returns: dict