docstr: Initialize N-HiTS Model - use its :py:meth:`~from_dataset` method if possible.
  
  Based on the article
  `N-HiTS: Neural Hierarchical Interpolation for Time Series Forecasting <http://arxiv.org/abs/2201.12886>`_.
  The network has shown to increase accuracy by ~25% against
  :py:class:`~pytorch_forecasting.models.nbeats.NBeats` and also supports covariates.
  
  Args:
      hidden_size (int): size of hidden layers and can range from 8 to 1024 - use 32-128 if no
          covariates are employed. Defaults to 512.
      static_hidden_size (Optional[int], optional): size of hidden layers for static variables.
          Defaults to hidden_size.
      loss: loss to optimize. Defaults to MASE(). QuantileLoss is also supported
      shared_weights (bool, optional): if True, weights of blocks are shared in each stack. Defaults to True.
      naive_level (bool, optional): if True, native forecast of last observation is added at the beginnging.
          Defaults to True.
      initialization (str, optional): Initialization method. One of ['orthogonal', 'he_uniform', 'glorot_uniform',
          'glorot_normal', 'lecun_normal']. Defaults to "lecun_normal".
      n_blocks (List[int], optional): list of blocks used in each stack (i.e. length of stacks).
          Defaults to [1, 1, 1].
      n_layers (Union[int, List[int]], optional): Number of layers per block or list of number of
          layers used by blocks in each stack (i.e. length of stacks). Defaults to 2.
      pooling_sizes (Optional[List[int]], optional): List of pooling sizes for input for each stack,
          i.e. higher means more smoothing of input. Using an ordering of higher to lower in the list
          improves results.
          Defaults to a heuristic.
      pooling_mode (str, optional): Pooling mode for summarizing input. One of ['max','average'].
          Defaults to "max".
      downsample_frequencies (Optional[List[int]], optional): Downsample multiplier of output for each stack, i.e.
          higher means more interpolation at forecast time is required. Should be equal or higher
          than pooling_sizes but smaller equal prediction_length.
          Defaults to a heuristic to match pooling_sizes.
      interpolation_mode (str, optional): Interpolation mode for forecasting. One of ['linear', 'nearest',
          'cubic-x'] where 'x' is replaced by a batch size for the interpolation. Defaults to "linear".
      batch_normalization (bool, optional): Whether carry out batch normalization. Defaults to False.
      dropout (float, optional): dropout rate for hidden layers. Defaults to 0.0.
      activation (str, optional): activation function. One of ['ReLU', 'Softplus', 'Tanh', 'SELU',
          'LeakyReLU', 'PReLU', 'Sigmoid']. Defaults to "ReLU".
      output_size: number of outputs (typically number of quantiles for QuantileLoss and one target or list
          of output sizes but currently only point-forecasts allowed). Set automatically.
      static_categoricals: names of static categorical variables
      static_reals: names of static continuous variables
      time_varying_categoricals_encoder: names of categorical variables for encoder
      time_varying_categoricals_decoder: names of categorical variables for decoder
      time_varying_reals_encoder: names of continuous variables for encoder
      time_varying_reals_decoder: names of continuous variables for decoder
      categorical_groups: dictionary where values
          are list of categorical variables that are forming together a new categorical
          variable which is the key in the dictionary
      x_reals: order of continuous variables in tensor passed to forward function
      x_categoricals: order of categorical variables in tensor passed to forward function
      hidden_continuous_size: default for hidden size for processing continous variables (similar to categorical
          embedding size)
      hidden_continuous_sizes: dictionary mapping continuous input indices to sizes for variable selection
          (fallback to hidden_continuous_size if index is not in dictionary)
      embedding_sizes: dictionary mapping (string) indices to tuple of number of categorical classes and
          embedding size
      embedding_paddings: list of indices for embeddings which transform the zero's embedding to a zero vector
      embedding_labels: dictionary mapping (string) indices to list of categorical labels
      learning_rate: learning rate
      log_interval: log predictions every x batches, do not log if 0 or less, log interpretation if > 0. If < 1.0
          , will log multiple entries per batch. Defaults to -1.
      log_val_interval: frequency with which to log validation set metrics, defaults to log_interval
      log_gradient_flow: if to log gradient flow, this takes time and should be only done to diagnose training
          failures
      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.
      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","N-HiTS","Model","-","use","its",":","py",":","meth",":","`","~from_dataset","`","method","if","possible",".","Based","on","the","article","`","N-HiTS",":","Neural","Hierarchical","Interpolation","for","Time","Series","Forecasting","<","http",":","\/\/arxiv.org\/abs\/2201.12886",">","`","_",".","The","network","has","shown","to","increase","accuracy","by","~25","%","against",":","py",":","class",":","`","~pytorch_forecasting.models.nbeats.NBeats","`","and","also","supports","covariates",".","Args",":","hidden_size","(","int",")",":","size","of","hidden","layers","and","can","range","from","8","to","1024","-","use","32-128","if","no","covariates","are","employed",".","Defaults","to","512.","static_hidden_size","(","Optional","[","int","]",",","optional",")",":","size","of","hidden","layers","for","static","variables",".","Defaults","to","hidden_size",".","loss",":","loss","to","optimize",".","Defaults","to","MASE","(",")",".","QuantileLoss","is","also","supported","shared_weights","(","bool",",","optional",")",":","if","True",",","weights","of","blocks","are","shared","in","each","stack",".","Defaults","to","True",".","naive_level","(","bool",",","optional",")",":","if","True",",","native","forecast","of","last","observation","is","added","at","the","beginnging",".","Defaults","to","True",".","initialization","(","str",",","optional",")",":","Initialization","method",".","One","of","[","'orthogonal","'",",","'he_uniform","'",",","'glorot_uniform","'",",","'glorot_normal","'",",","'lecun_normal","'","]",".","Defaults","to","``","lecun_normal","''",".","n_blocks","(","List","[","int","]",",","optional",")",":","list","of","blocks","used","in","each","stack","(","i.e",".","length","of","stacks",")",".","Defaults","to","[","1",",","1",",","1","]",".","n_layers","(","Union","[","int",",","List","[","int","]","]",",","optional",")",":","Number","of","layers","per","block","or","list","of","number","of","layers","used","by","blocks","in","each","stack","(","i.e",".","length","of","stacks",")",".","Defaults","to","2.","pooling_sizes","(","Optional","[","List","[","int","]","]",",","optional",")",":","List","of","pooling","sizes","for","input","for","each","stack",",","i.e",".","higher","means","more","smoothing","of","input",".","Using","an","ordering","of","higher","to","lower","in","the","list","improves","results",".","Defaults","to","a","heuristic",".","pooling_mode","(","str",",","optional",")",":","Pooling","mode","for","summarizing","input",".","One","of","[","'max","'",",","'average","'","]",".","Defaults","to","``","max","''",".","downsample_frequencies","(","Optional","[","List","[","int","]","]",",","optional",")",":","Downsample","multiplier","of","output","for","each","stack",",","i.e",".","higher","means","more","interpolation","at","forecast","time","is","required",".","Should","be","equal","or","higher","than","pooling_sizes","but","smaller","equal","prediction_length",".","Defaults","to","a","heuristic","to","match","pooling_sizes",".","interpolation_mode","(","str",",","optional",")",":","Interpolation","mode","for","forecasting",".","One","of","[","'linear","'",",","'nearest","'",",","'cubic-x","'","]","where","'","x","'","is","replaced","by","a","batch","size","for","the","interpolation",".","Defaults","to","``","linear","''",".","batch_normalization","(","bool",",","optional",")",":","Whether","carry","out","batch","normalization",".","Defaults","to","False",".","dropout","(","float",",","optional",")",":","dropout","rate","for","hidden","layers",".","Defaults","to","0.0.","activation","(","str",",","optional",")",":","activation","function",".","One","of","[","'ReLU","'",",","'Softplus","'",",","'Tanh","'",",","'SELU","'",",","'LeakyReLU","'",",","'PReLU","'",",","'Sigmoid","'","]",".","Defaults","to","``","ReLU","''",".","output_size",":","number","of","outputs","(","typically","number","of","quantiles","for","QuantileLoss","and","one","target","or","list","of","output","sizes","but","currently","only","point-forecasts","allowed",")",".","Set","automatically",".","static_categoricals",":","names","of","static","categorical","variables","static_reals",":","names","of","static","continuous","variables","time_varying_categoricals_encoder",":","names","of","categorical","variables","for","encoder","time_varying_categoricals_decoder",":","names","of","categorical","variables","for","decoder","time_varying_reals_encoder",":","names","of","continuous","variables","for","encoder","time_varying_reals_decoder",":","names","of","continuous","variables","for","decoder","categorical_groups",":","dictionary","where","values","are","list","of","categorical","variables","that","are","forming","together","a","new","categorical","variable","which","is","the","key","in","the","dictionary","x_reals",":","order","of","continuous","variables","in","tensor","passed","to","forward","function","x_categoricals",":","order","of","categorical","variables","in","tensor","passed","to","forward","function","hidden_continuous_size",":","default","for","hidden","size","for","processing","continous","variables","(","similar","to","categorical","embedding","size",")","hidden_continuous_sizes",":","dictionary","mapping","continuous","input","indices","to","sizes","for","variable","selection","(","fallback","to","hidden_continuous_size","if","index","is","not","in","dictionary",")","embedding_sizes",":","dictionary","mapping","(","string",")","indices","to","tuple","of","number","of","categorical","classes","and","embedding","size","embedding_paddings",":","list","of","indices","for","embeddings","which","transform","the","zero","'s","embedding","to","a","zero","vector","embedding_labels",":","dictionary","mapping","(","string",")","indices","to","list","of","categorical","labels","learning_rate",":","learning","rate","log_interval",":","log","predictions","every","x","batches",",","do","not","log","if","0","or","less",",","log","interpretation","if",">","0",".","If","<","1.0",",","will","log","multiple","entries","per","batch",".","Defaults","to","-1.","log_val_interval",":","frequency","with","which","to","log","validation","set","metrics",",","defaults","to","log_interval","log_gradient_flow",":","if","to","log","gradient","flow",",","this","takes","time","and","should","be","only","done","to","diagnose","training","failures","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",".","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,
      output_size: Union[int, List[int]] = 1,
      static_categoricals: List[str] = [],
      static_reals: List[str] = [],
      time_varying_categoricals_encoder: List[str] = [],
      time_varying_categoricals_decoder: List[str] = [],
      categorical_groups: Dict[str, List[str]] = {},
      time_varying_reals_encoder: List[str] = [],
      time_varying_reals_decoder: List[str] = [],
      embedding_sizes: Dict[str, Tuple[int, int]] = {},
      embedding_paddings: List[str] = [],
      embedding_labels: Dict[str, np.ndarray] = {},
      x_reals: List[str] = [],
      x_categoricals: List[str] = [],
      context_length: int = 1,
      prediction_length: int = 1,
      static_hidden_size: Optional[int] = None,
      naive_level: bool = True,
      shared_weights: bool = True,
      activation: str = "ReLU",
      initialization: str = "lecun_normal",
      n_blocks: List[int] = [1, 1, 1],
      n_layers: Union[int, List[int]] = 2,
      hidden_size: int = 512,
      pooling_sizes: Optional[List[int]] = None,
      downsample_frequencies: Optional[List[int]] = None,
      pooling_mode: str = "max",
      interpolation_mode: str = "linear",
      batch_normalization: bool = False,
      dropout: float = 0.0,
      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 N-HiTS Model - use its :py:meth:`~from_dataset` method if possible.
  
      Based on the article
      `N-HiTS: Neural Hierarchical Interpolation for Time Series Forecasting <http://arxiv.org/abs/2201.12886>`_.
      The network has shown to increase accuracy by ~25% against
      :py:class:`~pytorch_forecasting.models.nbeats.NBeats` and also supports covariates.
  
      Args:
          hidden_size (int): size of hidden layers and can range from 8 to 1024 - use 32-128 if no
              covariates are employed. Defaults to 512.
          static_hidden_size (Optional[int], optional): size of hidden layers for static variables.
              Defaults to hidden_size.
          loss: loss to optimize. Defaults to MASE(). QuantileLoss is also supported
          shared_weights (bool, optional): if True, weights of blocks are shared in each stack. Defaults to True.
          naive_level (bool, optional): if True, native forecast of last observation is added at the beginnging.
              Defaults to True.
          initialization (str, optional): Initialization method. One of ['orthogonal', 'he_uniform', 'glorot_uniform',
              'glorot_normal', 'lecun_normal']. Defaults to "lecun_normal".
          n_blocks (List[int], optional): list of blocks used in each stack (i.e. length of stacks).
              Defaults to [1, 1, 1].
          n_layers (Union[int, List[int]], optional): Number of layers per block or list of number of
              layers used by blocks in each stack (i.e. length of stacks). Defaults to 2.
          pooling_sizes (Optional[List[int]], optional): List of pooling sizes for input for each stack,
              i.e. higher means more smoothing of input. Using an ordering of higher to lower in the list
              improves results.
              Defaults to a heuristic.
          pooling_mode (str, optional): Pooling mode for summarizing input. One of ['max','average'].
              Defaults to "max".
          downsample_frequencies (Optional[List[int]], optional): Downsample multiplier of output for each stack, i.e.
              higher means more interpolation at forecast time is required. Should be equal or higher
              than pooling_sizes but smaller equal prediction_length.
              Defaults to a heuristic to match pooling_sizes.
          interpolation_mode (str, optional): Interpolation mode for forecasting. One of ['linear', 'nearest',
              'cubic-x'] where 'x' is replaced by a batch size for the interpolation. Defaults to "linear".
          batch_normalization (bool, optional): Whether carry out batch normalization. Defaults to False.
          dropout (float, optional): dropout rate for hidden layers. Defaults to 0.0.
          activation (str, optional): activation function. One of ['ReLU', 'Softplus', 'Tanh', 'SELU',
              'LeakyReLU', 'PReLU', 'Sigmoid']. Defaults to "ReLU".
          output_size: number of outputs (typically number of quantiles for QuantileLoss and one target or list
              of output sizes but currently only point-forecasts allowed). Set automatically.
          static_categoricals: names of static categorical variables
          static_reals: names of static continuous variables
          time_varying_categoricals_encoder: names of categorical variables for encoder
          time_varying_categoricals_decoder: names of categorical variables for decoder
          time_varying_reals_encoder: names of continuous variables for encoder
          time_varying_reals_decoder: names of continuous variables for decoder
          categorical_groups: dictionary where values
              are list of categorical variables that are forming together a new categorical
              variable which is the key in the dictionary
          x_reals: order of continuous variables in tensor passed to forward function
          x_categoricals: order of categorical variables in tensor passed to forward function
          hidden_continuous_size: default for hidden size for processing continous variables (similar to categorical
              embedding size)
          hidden_continuous_sizes: dictionary mapping continuous input indices to sizes for variable selection
              (fallback to hidden_continuous_size if index is not in dictionary)
          embedding_sizes: dictionary mapping (string) indices to tuple of number of categorical classes and
              embedding size
          embedding_paddings: list of indices for embeddings which transform the zero's embedding to a zero vector
          embedding_labels: dictionary mapping (string) indices to list of categorical labels
          learning_rate: learning rate
          log_interval: log predictions every x batches, do not log if 0 or less, log interpretation if > 0. If < 1.0
              , will log multiple entries per batch. Defaults to -1.
          log_val_interval: frequency with which to log validation set metrics, defaults to log_interval
          log_gradient_flow: if to log gradient flow, this takes time and should be only done to diagnose training
              failures
          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.
          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()
  
      if activation == "SELU":
          self.hparams.initialization = "lecun_normal"
  
      # provide default downsampling sizes
      n_stacks = len(n_blocks)
      if pooling_sizes is None:
          pooling_sizes = np.exp2(
              np.round(
                  np.linspace(
                      0.49, np.log2(prediction_length / 2), n_stacks
                  )
              )
          )
          pooling_sizes = [int(x) for x in pooling_sizes[::-1]]
      if downsample_frequencies is None:
          downsample_frequencies = [
              min(prediction_length, int(np.power(x, 1.5)))
              for x in pooling_sizes
          ]
  
      # set static hidden size
      if static_hidden_size is None:
          static_hidden_size = hidden_size
  
      # set layers
      if isinstance(n_layers, int):
          n_layers = [n_layers] * n_stacks
  
      self.save_hyperparameters()
      super().__init__(
          loss=loss, logging_metrics=logging_metrics, **kwargs
      )
  
      self.embeddings = MultiEmbedding(
          embedding_sizes=self.hparams.embedding_sizes,
          categorical_groups=self.hparams.categorical_groups,
          embedding_paddings=self.hparams.embedding_paddings,
          x_categoricals=self.hparams.x_categoricals,
      )
  
      self.model = NHiTSModule(
          context_length=self.hparams.context_length,
          prediction_length=self.hparams.prediction_length,
          output_size=to_list(output_size),
          static_size=self.static_size,
          encoder_covariate_size=self.encoder_covariate_size,
          decoder_covariate_size=self.decoder_covariate_size,
          static_hidden_size=self.hparams.static_hidden_size,
          n_blocks=self.hparams.n_blocks,
          n_layers=self.hparams.n_layers,
          hidden_size=self.n_stacks * [2 * [self.hparams.hidden_size]],
          pooling_sizes=self.hparams.pooling_sizes,
          downsample_frequencies=self.hparams.downsample_frequencies,
          pooling_mode=self.hparams.pooling_mode,
          interpolation_mode=self.hparams.interpolation_mode,
          dropout=self.hparams.dropout,
          activation=self.hparams.activation,
          initialization=self.hparams.initialization,
          batch_normalization=self.hparams.batch_normalization,
          shared_weights=self.hparams.shared_weights,
          naive_level=self.hparams.naive_level,
      )
  
imports: from copy import copy
  from typing import Dict, List, Optional, Tuple, Union
  from matplotlib import pyplot
  import numpy
  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, MultiLoss
  from pytorch_forecasting.models.base_model import BaseModelWithCovariates
  from pytorch_forecasting.models.nhits.sub_modules import NHiTS
  from pytorch_forecasting.models.nn.embeddings import MultiEmbedding
  from pytorch_forecasting.utils import create_mask, detach, to_list
label_desc: Use image node_id 1 to create a new NHiTS object from inherited base classes: BaseModelWithCovariates with example: obj = NHiTS(output_size, static_categoricals, static_reals, time_varying_categoricals_encoder, time_varying_categoricals_decoder, categorical_groups, time_varying_reals_encoder, time_varying_reals_decoder, embedding_sizes, embedding_paddings, embedding_labels, x_reals, x_categoricals, context_length, prediction_length, static_hidden_size, naive_level, shared_weights, activation, initialization, n_blocks, n_layers, hidden_size, pooling_sizes, downsample_frequencies, pooling_mode, interpolation_mode, batch_normalization, dropout, learning_rate, log_interval, log_gradient_flow, log_val_interval, weight_decay, loss, reduce_on_plateau_patience, backcast_loss_ratio, logging_metrics)