docstr: Initialize NBeats Model - use its :py:meth:`~from_dataset` method if possible.
  
  Based on the article
  `N-BEATS: Neural basis expansion analysis for interpretable time series
  forecasting <http://arxiv.org/abs/1905.10437>`_. The network has (if used as ensemble) outperformed all
  other methods
  including ensembles of traditional statical methods in the M4 competition. The M4 competition is arguably
  the most
  important benchmark for univariate time series forecasting.
  
  The :py:class:`~pytorch_forecasting.models.nhits.NHiTS` network has recently shown to consistently outperform
  N-BEATS.
  
  Args:
      stack_types: One of the following values: “generic”, “seasonality" or “trend". A list of strings
          of length 1 or ‘num_stacks’. Default and recommended value
          for generic mode: [“generic”] Recommended value for interpretable mode: [“trend”,”seasonality”]
      num_blocks: The number of blocks per stack. A list of ints of length 1 or ‘num_stacks’.
          Default and recommended value for generic mode: [1] Recommended value for interpretable mode: [3]
      num_block_layers: Number of fully connected layers with ReLu activation per block. A list of ints of length
          1 or ‘num_stacks’.
          Default and recommended value for generic mode: [4] Recommended value for interpretable mode: [4]
      width: Widths of the fully connected layers with ReLu activation in the blocks.
          A list of ints of length 1 or ‘num_stacks’. Default and recommended value for generic mode: [512]
          Recommended value for interpretable mode: [256, 2048]
      sharing: Whether the weights are shared with the other blocks per stack.
          A list of ints of length 1 or ‘num_stacks’. Default and recommended value for generic mode: [False]
          Recommended value for interpretable mode: [True]
      expansion_coefficient_length: If the type is “G” (generic), then the length of the expansion
          coefficient.
          If type is “T” (trend), then it corresponds to the degree of the polynomial. If the type is “S”
          (seasonal) then this is the minimum period allowed, e.g. 2 for changes every timestep.
          A list of ints of length 1 or ‘num_stacks’. Default value for generic mode: [32] Recommended value for
          interpretable mode: [3]
      prediction_length: Length of the prediction. Also known as 'horizon'.
      context_length: Number of time units that condition the predictions. Also known as 'lookback period'.
          Should be between 1-10 times the prediction length.
      backcast_loss_ratio: weight of backcast in comparison to forecast when calculating the loss.
          A weight of 1.0 means that forecast and backcast loss is weighted the same (regardless of backcast and
          forecast lengths). Defaults to 0.0, i.e. no weight.
      loss: loss to optimize. Defaults to MASE().
      log_gradient_flow: if to log gradient flow, this takes time and should be only done to diagnose training
          failures
      reduce_on_plateau_patience (int): patience after which learning rate is reduced by a factor of 10
      logging_metrics (nn.ModuleList[MultiHorizonMetric]): list of metrics that are logged during training.
          Defaults to nn.ModuleList([SMAPE(), MAE(), RMSE(), MAPE(), MASE()])
      **kwargs: additional arguments to :py:class:`~BaseModel`.
docstr_tok: ["Initialize","NBeats","Model","-","use","its",":","py",":","meth",":","`","~from_dataset","`","method","if","possible",".","Based","on","the","article","`","N-BEATS",":","Neural","basis","expansion","analysis","for","interpretable","time","series","forecasting","<","http",":","\/\/arxiv.org\/abs\/1905.10437",">","`","_",".","The","network","has","(","if","used","as","ensemble",")","outperformed","all","other","methods","including","ensembles","of","traditional","statical","methods","in","the","M4","competition",".","The","M4","competition","is","arguably","the","most","important","benchmark","for","univariate","time","series","forecasting",".","The",":","py",":","class",":","`","~pytorch_forecasting.models.nhits.NHiTS","`","network","has","recently","shown","to","consistently","outperform","N-BEATS",".","Args",":","stack_types",":","One","of","the","following","values",":","\u201c","generic","\u201d",",","\u201c","seasonality","''","or","\u201c","trend","''",".","A","list","of","strings","of","length","1","or","\u2018","num_stacks","\u2019",".","Default","and","recommended","value","for","generic","mode",":","[","\u201c","generic","\u201d","]","Recommended","value","for","interpretable","mode",":","[","\u201c","trend","\u201d",",","\u201d","seasonality","\u201d","]","num_blocks",":","The","number","of","blocks","per","stack",".","A","list","of","ints","of","length","1","or","\u2018","num_stacks","\u2019",".","Default","and","recommended","value","for","generic","mode",":","[","1","]","Recommended","value","for","interpretable","mode",":","[","3","]","num_block_layers",":","Number","of","fully","connected","layers","with","ReLu","activation","per","block",".","A","list","of","ints","of","length","1","or","\u2018","num_stacks","\u2019",".","Default","and","recommended","value","for","generic","mode",":","[","4","]","Recommended","value","for","interpretable","mode",":","[","4","]","width",":","Widths","of","the","fully","connected","layers","with","ReLu","activation","in","the","blocks",".","A","list","of","ints","of","length","1","or","\u2018","num_stacks","\u2019",".","Default","and","recommended","value","for","generic","mode",":","[","512","]","Recommended","value","for","interpretable","mode",":","[","256",",","2048","]","sharing",":","Whether","the","weights","are","shared","with","the","other","blocks","per","stack",".","A","list","of","ints","of","length","1","or","\u2018","num_stacks","\u2019",".","Default","and","recommended","value","for","generic","mode",":","[","False","]","Recommended","value","for","interpretable","mode",":","[","True","]","expansion_coefficient_length",":","If","the","type","is","\u201c","G","\u201d","(","generic",")",",","then","the","length","of","the","expansion","coefficient",".","If","type","is","\u201c","T","\u201d","(","trend",")",",","then","it","corresponds","to","the","degree","of","the","polynomial",".","If","the","type","is","\u201c","S","\u201d","(","seasonal",")","then","this","is","the","minimum","period","allowed",",","e.g",".","2","for","changes","every","timestep",".","A","list","of","ints","of","length","1","or","\u2018","num_stacks","\u2019",".","Default","value","for","generic","mode",":","[","32","]","Recommended","value","for","interpretable","mode",":","[","3","]","prediction_length",":","Length","of","the","prediction",".","Also","known","as","'horizon","'",".","context_length",":","Number","of","time","units","that","condition","the","predictions",".","Also","known","as","'lookback","period","'",".","Should","be","between","1-10","times","the","prediction","length",".","backcast_loss_ratio",":","weight","of","backcast","in","comparison","to","forecast","when","calculating","the","loss",".","A","weight","of","1.0","means","that","forecast","and","backcast","loss","is","weighted","the","same","(","regardless","of","backcast","and","forecast","lengths",")",".","Defaults","to","0.0",",","i.e",".","no","weight",".","loss",":","loss","to","optimize",".","Defaults","to","MASE","(",")",".","log_gradient_flow",":","if","to","log","gradient","flow",",","this","takes","time","and","should","be","only","done","to","diagnose","training","failures","reduce_on_plateau_patience","(","int",")",":","patience","after","which","learning","rate","is","reduced","by","a","factor","of","10","logging_metrics","(","nn.ModuleList","[","MultiHorizonMetric","]",")",":","list","of","metrics","that","are","logged","during","training",".","Defaults","to","nn.ModuleList","(","[","SMAPE","(",")",",","MAE","(",")",",","RMSE","(",")",",","MAPE","(",")",",","MASE","(",")","]",")","*","*","kwargs",":","additional","arguments","to",":","py",":","class",":","`","~BaseModel","`","."]
code: def __init__(
      self,
      stack_types: List[str] = ["trend", "seasonality"],
      num_blocks=[3, 3],
      num_block_layers=[3, 3],
      widths=[32, 512],
      sharing: List[int] = [True, True],
      expansion_coefficient_lengths: List[int] = [3, 7],
      prediction_length: int = 1,
      context_length: int = 1,
      dropout: float = 0.1,
      learning_rate: float = 1e-2,
      log_interval: int = -1,
      log_gradient_flow: bool = False,
      log_val_interval: int = None,
      weight_decay: float = 1e-3,
      loss: MultiHorizonMetric = None,
      reduce_on_plateau_patience: int = 1000,
      backcast_loss_ratio: float = 0.0,
      logging_metrics: nn.ModuleList = None,
      **kwargs,
  ):
      """
      Initialize NBeats Model - use its :py:meth:`~from_dataset` method if possible.
  
      Based on the article
      `N-BEATS: Neural basis expansion analysis for interpretable time series
      forecasting <http://arxiv.org/abs/1905.10437>`_. The network has (if used as ensemble) outperformed all
      other methods
      including ensembles of traditional statical methods in the M4 competition. The M4 competition is arguably
      the most
      important benchmark for univariate time series forecasting.
  
      The :py:class:`~pytorch_forecasting.models.nhits.NHiTS` network has recently shown to consistently outperform
      N-BEATS.
  
      Args:
          stack_types: One of the following values: “generic”, “seasonality" or “trend". A list of strings
              of length 1 or ‘num_stacks’. Default and recommended value
              for generic mode: [“generic”] Recommended value for interpretable mode: [“trend”,”seasonality”]
          num_blocks: The number of blocks per stack. A list of ints of length 1 or ‘num_stacks’.
              Default and recommended value for generic mode: [1] Recommended value for interpretable mode: [3]
          num_block_layers: Number of fully connected layers with ReLu activation per block. A list of ints of length
              1 or ‘num_stacks’.
              Default and recommended value for generic mode: [4] Recommended value for interpretable mode: [4]
          width: Widths of the fully connected layers with ReLu activation in the blocks.
              A list of ints of length 1 or ‘num_stacks’. Default and recommended value for generic mode: [512]
              Recommended value for interpretable mode: [256, 2048]
          sharing: Whether the weights are shared with the other blocks per stack.
              A list of ints of length 1 or ‘num_stacks’. Default and recommended value for generic mode: [False]
              Recommended value for interpretable mode: [True]
          expansion_coefficient_length: If the type is “G” (generic), then the length of the expansion
              coefficient.
              If type is “T” (trend), then it corresponds to the degree of the polynomial. If the type is “S”
              (seasonal) then this is the minimum period allowed, e.g. 2 for changes every timestep.
              A list of ints of length 1 or ‘num_stacks’. Default value for generic mode: [32] Recommended value for
              interpretable mode: [3]
          prediction_length: Length of the prediction. Also known as 'horizon'.
          context_length: Number of time units that condition the predictions. Also known as 'lookback period'.
              Should be between 1-10 times the prediction length.
          backcast_loss_ratio: weight of backcast in comparison to forecast when calculating the loss.
              A weight of 1.0 means that forecast and backcast loss is weighted the same (regardless of backcast and
              forecast lengths). Defaults to 0.0, i.e. no weight.
          loss: loss to optimize. Defaults to MASE().
          log_gradient_flow: if to log gradient flow, this takes time and should be only done to diagnose training
              failures
          reduce_on_plateau_patience (int): patience after which learning rate is reduced by a factor of 10
          logging_metrics (nn.ModuleList[MultiHorizonMetric]): list of metrics that are logged during training.
              Defaults to nn.ModuleList([SMAPE(), MAE(), RMSE(), MAPE(), MASE()])
          **kwargs: additional arguments to :py:class:`~BaseModel`.
      """
      if logging_metrics is None:
          logging_metrics = nn.ModuleList(
              [SMAPE(), MAE(), RMSE(), MAPE(), MASE()]
          )
      if loss is None:
          loss = MASE()
      self.save_hyperparameters()
      super().__init__(
          loss=loss, logging_metrics=logging_metrics, **kwargs
      )
  
      # setup stacks
      self.net_blocks = nn.ModuleList()
      for stack_id, stack_type in enumerate(stack_types):
          for _ in range(num_blocks[stack_id]):
              if stack_type == "generic":
                  net_block = NBEATSGenericBlock(
                      units=self.hparams.widths[stack_id],
                      thetas_dim=self.hparams.expansion_coefficient_lengths[
                          stack_id
                      ],
                      num_block_layers=self.hparams.num_block_layers[
                          stack_id
                      ],
                      backcast_length=context_length,
                      forecast_length=prediction_length,
                      dropout=self.hparams.dropout,
                  )
              elif stack_type == "seasonality":
                  net_block = NBEATSSeasonalBlock(
                      units=self.hparams.widths[stack_id],
                      num_block_layers=self.hparams.num_block_layers[
                          stack_id
                      ],
                      backcast_length=context_length,
                      forecast_length=prediction_length,
                      min_period=self.hparams.expansion_coefficient_lengths[
                          stack_id
                      ],
                      dropout=self.hparams.dropout,
                  )
              elif stack_type == "trend":
                  net_block = NBEATSTrendBlock(
                      units=self.hparams.widths[stack_id],
                      thetas_dim=self.hparams.expansion_coefficient_lengths[
                          stack_id
                      ],
                      num_block_layers=self.hparams.num_block_layers[
                          stack_id
                      ],
                      backcast_length=context_length,
                      forecast_length=prediction_length,
                      dropout=self.hparams.dropout,
                  )
              else:
                  raise ValueError(f"Unknown stack type {stack_type}")
  
              self.net_blocks.append(net_block)
  
file_path: pytorch-forecasting/pytorch_forecasting/models/nbeats/__init__.py
imports: from typing import Dict, List
  import matplotlib.pyplot
  import torch
  from torch import nn
  from pytorch_forecasting.data import TimeSeriesDataSet
  from pytorch_forecasting.data.encoders import NaNLabelEncoder
  from pytorch_forecasting.metrics import MAE, MAPE, MASE, RMSE, SMAPE, MultiHorizonMetric
  from pytorch_forecasting.models.base_model import BaseModel
  from pytorch_forecasting.models.nbeats.sub_modules import NBEATSGenericBlock, NBEATSSeasonalBlock, NBEATSTrendBlock
label_desc: Use image node_id 1 to create a new NBeats object from inherited base classes: BaseModel with example: obj = NBeats(stack_types, num_blocks, num_block_layers, widths, sharing, expansion_coefficient_lengths, prediction_length, context_length, dropout, learning_rate, log_interval, log_gradient_flow, log_val_interval, weight_decay, loss, reduce_on_plateau_patience, backcast_loss_ratio, logging_metrics)