class_docstr: Linear time regression fun and some not so linear fun.
  A modular model that models classic time-series components
      * trend
      * seasonality
      * auto-regression (as AR-Net)
      * covariates (as AR-Net)
      * apriori regressors
      * events and holidays
  by using Neural Network components.
  The Auto-regression and covariate components can be configured as a deeper network (AR-Net).
class_docstr_tok: ["Linear","time","regression","fun","and","some","not","so","linear","fun",".","A","modular","model","that","models","classic","time-series","components","*","trend","*","seasonality","*","auto-regression","(","as","AR-Net",")","*","covariates","(","as","AR-Net",")","*","apriori","regressors","*","events","and","holidays","by","using","Neural","Network","components",".","The","Auto-regression","and","covariate","components","can","be","configured","as","a","deeper","network","(","AR-Net",")","."]
docstr: Parameters
  ----------
      quantiles : list
          the set of quantiles estimated
      config_train : configure.Train
      config_trend : configure.Trend
      config_seasonality : configure.ConfigSeasonality
      config_ar : configure.AR
      config_lagged_regressors : configure.ConfigLaggedRegressors
          Configurations for lagged regressors
      config_regressors : configure.ConfigFutureRegressors
          Configs of regressors with mode and index.
      config_events : configure.ConfigEvents
      config_holidays : OrderedDict
      config_normalization: OrderedDict
      n_forecasts : int
          number of steps to forecast. Aka number of model outputs
      n_lags : int
          number of previous steps of time series used as input (aka AR-order)
          Note
          ----
          The default value is ``0``, which initializes no auto-regression.
  
      max_lags : int
          Number of max. previous steps of time series used as input (aka AR-order).
  
      ar_layers : list
          List of hidden layers (for AR-Net).
  
          Note
          ----
          The default value is ``[]``, which initializes no hidden layers.
  
      lagged_reg_layers : list
          List of hidden layers (for covariate-Net).
  
          Note
          ----
          The default value is ``[]``, which initializes no hidden layers.
  
  
      compute_components_flag : bool
          Flag whether to compute the components of the model or not.
      metrics : dict
          Dictionary of torchmetrics to be used during training and for evaluation.
      id_list : list
          List of different time series IDs, used for global-local modelling (if enabled)
          Note
          ----
          This parameter is set to  ``['__df__']`` if only one time series is input.
      num_trends_modelled : int
          Number of different trends modelled.
          Note
          ----
          If only 1 time series is modelled, it will be always 1.
          Note
          ----
          For multiple time series. If trend is modelled globally the value is set
          to 1, otherwise it is set to the number of time series modelled.
      num_seasonalities_modelled : int
          Number of different seasonalities modelled.
          Note
          ----
          If only 1 time series is modelled, it will be always 1.
          Note
          ----
          For multiple time series. If seasonality is modelled globally the value is set
          to 1, otherwise it is set to the number of time series modelled.
      meta_used_in_model : boolean
          Whether we need to know the time series ID when we interact with the Model.
          Note
          ----
          Will be set to ``True`` if more than one component is modelled locally.
docstr_tok: ["Parameters","--","--","--","--","--","quantiles",":","list","the","set","of","quantiles","estimated","config_train",":","configure.Train","config_trend",":","configure.Trend","config_seasonality",":","configure.ConfigSeasonality","config_ar",":","configure.AR","config_lagged_regressors",":","configure.ConfigLaggedRegressors","Configurations","for","lagged","regressors","config_regressors",":","configure.ConfigFutureRegressors","Configs","of","regressors","with","mode","and","index",".","config_events",":","configure.ConfigEvents","config_holidays",":","OrderedDict","config_normalization",":","OrderedDict","n_forecasts",":","int","number","of","steps","to","forecast",".","Aka","number","of","model","outputs","n_lags",":","int","number","of","previous","steps","of","time","series","used","as","input","(","aka","AR-order",")","Note","--","--","The","default","value","is","``","0","``",",","which","initializes","no","auto-regression",".","max_lags",":","int","Number","of","max",".","previous","steps","of","time","series","used","as","input","(","aka","AR-order",")",".","ar_layers",":","list","List","of","hidden","layers","(","for","AR-Net",")",".","Note","--","--","The","default","value","is","``","[","]","``",",","which","initializes","no","hidden","layers",".","lagged_reg_layers",":","list","List","of","hidden","layers","(","for","covariate-Net",")",".","Note","--","--","The","default","value","is","``","[","]","``",",","which","initializes","no","hidden","layers",".","compute_components_flag",":","bool","Flag","whether","to","compute","the","components","of","the","model","or","not",".","metrics",":","dict","Dictionary","of","torchmetrics","to","be","used","during","training","and","for","evaluation",".","id_list",":","list","List","of","different","time","series","IDs",",","used","for","global-local","modelling","(","if","enabled",")","Note","--","--","This","parameter","is","set","to","``","[","'__df__","'","]","``","if","only","one","time","series","is","input",".","num_trends_modelled",":","int","Number","of","different","trends","modelled",".","Note","--","--","If","only","1","time","series","is","modelled",",","it","will","be","always","1",".","Note","--","--","For","multiple","time","series",".","If","trend","is","modelled","globally","the","value","is","set","to","1",",","otherwise","it","is","set","to","the","number","of","time","series","modelled",".","num_seasonalities_modelled",":","int","Number","of","different","seasonalities","modelled",".","Note","--","--","If","only","1","time","series","is","modelled",",","it","will","be","always","1",".","Note","--","--","For","multiple","time","series",".","If","seasonality","is","modelled","globally","the","value","is","set","to","1",",","otherwise","it","is","set","to","the","number","of","time","series","modelled",".","meta_used_in_model",":","boolean","Whether","we","need","to","know","the","time","series","ID","when","we","interact","with","the","Model",".","Note","--","--","Will","be","set","to","``","True","``","if","more","than","one","component","is","modelled","locally","."]
code: def __init__(
      self,
      config_seasonality: configure.ConfigSeasonality,
      config_train: Optional[configure.Train] = None,
      config_trend: Optional[configure.Trend] = None,
      config_ar: Optional[configure.AR] = None,
      config_normalization: Optional[configure.Normalization] = None,
      config_lagged_regressors: Optional[
          configure.ConfigLaggedRegressors
      ] = None,
      config_regressors: Optional[
          configure.ConfigFutureRegressors
      ] = None,
      config_events: Optional[configure.ConfigEvents] = None,
      config_holidays: Optional[configure.ConfigCountryHolidays] = None,
      n_forecasts: int = 1,
      n_lags: int = 0,
      max_lags: int = 0,
      ar_layers: Optional[List[int]] = [],
      lagged_reg_layers: Optional[List[int]] = [],
      compute_components_flag: bool = False,
      metrics: Optional[np_types.CollectMetricsMode] = {},
      id_list: List[str] = ["__df__"],
      num_trends_modelled: int = 1,
      num_seasonalities_modelled: int = 1,
      meta_used_in_model: bool = False,
  ):
      """
      Parameters
      ----------
          quantiles : list
              the set of quantiles estimated
          config_train : configure.Train
          config_trend : configure.Trend
          config_seasonality : configure.ConfigSeasonality
          config_ar : configure.AR
          config_lagged_regressors : configure.ConfigLaggedRegressors
              Configurations for lagged regressors
          config_regressors : configure.ConfigFutureRegressors
              Configs of regressors with mode and index.
          config_events : configure.ConfigEvents
          config_holidays : OrderedDict
          config_normalization: OrderedDict
          n_forecasts : int
              number of steps to forecast. Aka number of model outputs
          n_lags : int
              number of previous steps of time series used as input (aka AR-order)
              Note
              ----
              The default value is ``0``, which initializes no auto-regression.
  
          max_lags : int
              Number of max. previous steps of time series used as input (aka AR-order).
  
          ar_layers : list
              List of hidden layers (for AR-Net).
  
              Note
              ----
              The default value is ``[]``, which initializes no hidden layers.
  
          lagged_reg_layers : list
              List of hidden layers (for covariate-Net).
  
              Note
              ----
              The default value is ``[]``, which initializes no hidden layers.
  
  
          compute_components_flag : bool
              Flag whether to compute the components of the model or not.
          metrics : dict
              Dictionary of torchmetrics to be used during training and for evaluation.
          id_list : list
              List of different time series IDs, used for global-local modelling (if enabled)
              Note
              ----
              This parameter is set to  ``['__df__']`` if only one time series is input.
          num_trends_modelled : int
              Number of different trends modelled.
              Note
              ----
              If only 1 time series is modelled, it will be always 1.
              Note
              ----
              For multiple time series. If trend is modelled globally the value is set
              to 1, otherwise it is set to the number of time series modelled.
          num_seasonalities_modelled : int
              Number of different seasonalities modelled.
              Note
              ----
              If only 1 time series is modelled, it will be always 1.
              Note
              ----
              For multiple time series. If seasonality is modelled globally the value is set
              to 1, otherwise it is set to the number of time series modelled.
          meta_used_in_model : boolean
              Whether we need to know the time series ID when we interact with the Model.
              Note
              ----
              Will be set to ``True`` if more than one component is modelled locally.
      """
      super().__init__()
  
      # Store hyerparameters in model checkpoint
      # TODO: causes a RuntimeError under certain conditions, investigate and handle better
      try:
          self.save_hyperparameters()
      except RuntimeError:
          pass
  
      # General
      self.n_forecasts = n_forecasts
  
      # Lightning Config
      self.config_train = config_train
      self.config_normalization = config_normalization
      self.compute_components_flag = compute_components_flag
  
      # Optimizer and LR Scheduler
      self._optimizer = self.config_train.optimizer
      self._scheduler = self.config_train.scheduler
      self.automatic_optimization = False
  
      # Hyperparameters (can be tuned using trainer.tune())
      self.learning_rate = (
          self.config_train.learning_rate
          if self.config_train.learning_rate is not None
          else 1e-3
      )
      self.batch_size = self.config_train.batch_size
  
      # Metrics Config
      self.metrics_enabled = bool(
          metrics
      )  # yields True if metrics is not an empty dictionary
      if self.metrics_enabled:
          metrics = {
              metric: torchmetrics.__dict__[metrics[metric][0]](
                  **metrics[metric][1]
              )
              for metric in metrics
          }
          self.log_args = {
              "on_step": False,
              "on_epoch": True,
              "prog_bar": True,
              "batch_size": self.config_train.batch_size,
          }
          self.metrics_train = torchmetrics.MetricCollection(
              metrics=metrics
          )
          self.metrics_val = torchmetrics.MetricCollection(
              metrics=metrics, postfix="_val"
          )
  
      # For Multiple Time Series Analysis
      self.id_list = id_list
      self.id_dict = dict((key, i) for i, key in enumerate(id_list))
      self.num_trends_modelled = num_trends_modelled
      self.num_seasonalities_modelled = num_seasonalities_modelled
      self.meta_used_in_model = meta_used_in_model
  
      # Regularization
      self.reg_enabled = check_for_regularization(
          [
              config_seasonality,
              config_regressors,
              config_lagged_regressors,
              config_ar,
              config_events,
              config_trend,
              config_holidays,
          ]
      )
  
      # Quantiles
      self.quantiles = self.config_train.quantiles
  
      # Trend
      self.config_trend = config_trend
      self.trend = get_trend(
          config=config_trend,
          id_list=id_list,
          quantiles=self.quantiles,
          num_trends_modelled=num_trends_modelled,
          n_forecasts=n_forecasts,
          device=self.device,
      )
  
      # Seasonalities
      self.config_seasonality = config_seasonality
      # Error handling
      if self.config_seasonality is not None:
          if (
              self.config_seasonality.mode == "multiplicative"
              and self.config_trend is None
          ):
              raise ValueError(
                  "Multiplicative seasonality requires trend."
              )
          if self.config_seasonality.mode not in [
              "additive",
              "multiplicative",
          ]:
              raise ValueError(
                  f"Seasonality Mode {self.config_seasonality.mode} not implemented."
              )
          # Initialize seasonality
          self.seasonality = get_seasonality(
              config=config_seasonality,
              id_list=id_list,
              quantiles=self.quantiles,
              num_seasonalities_modelled=num_seasonalities_modelled,
              n_forecasts=n_forecasts,
              device=self.device,
          )
  
      # Events
      self.config_events = config_events
      self.config_holidays = config_holidays
      self.events_dims = config_events_to_model_dims(
          self.config_events, self.config_holidays
      )
      if self.events_dims is not None:
          n_additive_event_params = 0
          n_multiplicative_event_params = 0
          for event, configs in self.events_dims.items():
              if configs["mode"] not in ["additive", "multiplicative"]:
                  log.error(
                      "Event Mode {} not implemented. Defaulting to 'additive'.".format(
                          configs["mode"]
                      )
                  )
                  self.events_dims[event]["mode"] = "additive"
              if configs["mode"] == "additive":
                  n_additive_event_params += len(
                      configs["event_indices"]
                  )
              elif configs["mode"] == "multiplicative":
                  if self.config_trend is None:
                      log.error("Multiplicative events require trend.")
                      raise ValueError
                  n_multiplicative_event_params += len(
                      configs["event_indices"]
                  )
          self.event_params = nn.ParameterDict(
              {
                  # dimensions - [no. of quantiles, no. of additive events]
                  "additive": init_parameter(
                      dims=[
                          len(self.quantiles),
                          n_additive_event_params,
                      ]
                  ),
                  # dimensions - [no. of quantiles, no. of multiplicative events]
                  "multiplicative": init_parameter(
                      dims=[
                          len(self.quantiles),
                          n_multiplicative_event_params,
                      ]
                  ),
              }
          )
      else:
          self.config_events = None
          self.config_holidays = None
  
      # Autoregression
      self.config_ar = config_ar
      self.n_lags = n_lags
      self.ar_layers = ar_layers
      self.max_lags = max_lags
      if self.n_lags > 0:
          self.ar_net = nn.ModuleList()
          d_inputs = self.n_lags
          for d_hidden_i in self.ar_layers:
              self.ar_net.append(
                  nn.Linear(d_inputs, d_hidden_i, bias=True)
              )
              d_inputs = d_hidden_i
          # final layer has input size d_inputs and output size equal to no. of forecasts * no. of quantiles
          self.ar_net.append(
              nn.Linear(
                  d_inputs,
                  self.n_forecasts * len(self.quantiles),
                  bias=False,
              )
          )
          for lay in self.ar_net:
              nn.init.kaiming_normal_(lay.weight, mode="fan_in")
  
      # Lagged regressors
      self.lagged_reg_layers = lagged_reg_layers
      self.config_lagged_regressors = config_lagged_regressors
      if self.config_lagged_regressors is not None:
          self.covar_net = nn.ModuleList()
          d_inputs = sum(
              [
                  covar.n_lags
                  for _, covar in self.config_lagged_regressors.items()
              ]
          )
          for d_hidden_i in self.lagged_reg_layers:
              self.covar_net.append(
                  nn.Linear(d_inputs, d_hidden_i, bias=True)
              )
              d_inputs = d_hidden_i
          self.covar_net.append(
              nn.Linear(
                  d_inputs,
                  self.n_forecasts * len(self.quantiles),
                  bias=False,
              )
          )
          for lay in self.covar_net:
              nn.init.kaiming_normal_(lay.weight, mode="fan_in")
  
      # Regressors
      self.config_regressors = config_regressors
      if self.config_regressors is not None:
          # Initialize future_regressors
          self.future_regressors = get_future_regressors(
              config=config_regressors,
              id_list=id_list,
              quantiles=self.quantiles,
              n_forecasts=n_forecasts,
              device=self.device,
              config_trend_none_bool=self.config_trend is None,
          )
      else:
          self.config_regressors = None
  
imports: import logging
  import math
  from collections import OrderedDict
  from functools import reduce
  from typing import Dict, List, Optional, Union
  import numpy
  import pytorch_lightning
  import torch
  import torch.nn
  import torchmetrics
  from neuralprophet import configure, np_types
  from neuralprophet.components.router import get_future_regressors, get_seasonality, get_trend
  from neuralprophet.utils import check_for_regularization, config_events_to_model_dims, reg_func_events, reg_func_regressors, reg_func_season, reg_func_trend
  from neuralprophet.utils_torch import init_parameter, interprete_model
label_desc: Use image node_id 1 to create a new TimeNet object from inherited base classes: pl with example: obj = TimeNet(config_seasonality, config_train, config_trend, config_ar, config_normalization, config_lagged_regressors, config_regressors, config_events, config_holidays, n_forecasts, n_lags, max_lags, ar_layers, lagged_reg_layers, compute_components_flag, metrics, id_list, num_trends_modelled, num_seasonalities_modelled, meta_used_in_model)