class_docstr: NBEATS
  
  The Neural Basis Expansion Analysis for Time Series (NBEATS), is a simple and yet
  effective architecture, it is built with a deep stack of MLPs with the doubly
  residual connections. It has a generic and interpretable architecture depending
  on the blocks it uses. Its interpretable architecture is recommended for scarce
  data settings, as it regularizes its predictions through projections unto harmonic
  and trend basis well-suited for most forecasting tasks.
  
  **Parameters:**<br>
  `h`: int, forecast horizon.<br>
  `input_size`: int, considered autorregresive inputs (lags), y=[1,2,3,4] input_size=2 -> lags=[1,2].<br>
  `n_harmonics`: int, Number of harmonic terms for seasonality stack type. Note that len(n_harmonics) = len(stack_types). Note that it will only be used if a seasonality stack is used.<br>
  `n_polynomials`: int, polynomial degree for trend stack. Note that len(n_polynomials) = len(stack_types). Note that it will only be used if a trend stack is used.<br>
  `stack_types`: List[str], List of stack types. Subset from ['seasonality', 'trend', 'identity'].<br>
  `n_blocks`: List[int], Number of blocks for each stack. Note that len(n_blocks) = len(stack_types).<br>
  `mlp_units`: List[List[int]], Structure of hidden layers for each stack type. Each internal list should contain the number of units of each hidden layer. Note that len(n_hidden) = len(stack_types).<br>
  `dropout_prob_theta`: float, Float between (0, 1). Dropout for N-BEATS basis.<br>
  `shared_weights`: bool, If True, all blocks within each stack will share parameters. <br>
  `activation`: str, activation from ['ReLU', 'Softplus', 'Tanh', 'SELU', 'LeakyReLU', 'PReLU', 'Sigmoid'].<br>
  `loss`: PyTorch module, instantiated train loss class from [losses collection](https://nixtla.github.io/neuralforecast/losses.pytorch.html).<br>
  `valid_loss`: PyTorch module=`loss`, instantiated valid loss class from [losses collection](https://nixtla.github.io/neuralforecast/losses.pytorch.html).<br>
  `max_steps`: int=1000, maximum number of training steps.<br>
  `learning_rate`: float=1e-3, Learning rate between (0, 1).<br>
  `num_lr_decays`: int=3, Number of learning rate decays, evenly distributed across max_steps.<br>
  `early_stop_patience_steps`: int=-1, Number of validation iterations before early stopping.<br>
  `val_check_steps`: int=100, Number of training steps between every validation loss check.<br>
  `batch_size`: int=32, number of different series in each batch.<br>
  `valid_batch_size`: int=None, number of different series in each validation and test batch, if None uses batch_size.<br>
  `windows_batch_size`: int=1024, number of windows to sample in each training batch, default uses all.<br>
  `inference_windows_batch_size`: int=-1, number of windows to sample in each inference batch, -1 uses all.<br>
  `start_padding_enabled`: bool=False, if True, the model will pad the time series with zeros at the beginning, by input size.<br>
  `step_size`: int=1, step size between each window of temporal data.<br>
  `scaler_type`: str='identity', type of scaler for temporal inputs normalization see [temporal scalers](https://nixtla.github.io/neuralforecast/common.scalers.html).<br>
  `random_seed`: int, random_seed for pytorch initializer and numpy generators.<br>
  `num_workers_loader`: int=os.cpu_count(), workers to be used by `TimeSeriesDataLoader`.<br>
  `drop_last_loader`: bool=False, if True `TimeSeriesDataLoader` drops last non-full batch.<br>
  `alias`: str, optional,  Custom name of the model.<br>
  `**trainer_kwargs`: int,  keyword trainer arguments inherited from [PyTorch Lighning's trainer](https://pytorch-lightning.readthedocs.io/en/stable/api/pytorch_lightning.trainer.trainer.Trainer.html?highlight=trainer).<br>
  
  **References:**<br>
  -[Boris N. Oreshkin, Dmitri Carpov, Nicolas Chapados, Yoshua Bengio (2019).
  "N-BEATS: Neural basis expansion analysis for interpretable time series forecasting".](https://arxiv.org/abs/1905.10437)
class_docstr_tok: ["NBEATS","The","Neural","Basis","Expansion","Analysis","for","Time","Series","(","NBEATS",")",",","is","a","simple","and","yet","effective","architecture",",","it","is","built","with","a","deep","stack","of","MLPs","with","the","doubly","residual","connections",".","It","has","a","generic","and","interpretable","architecture","depending","on","the","blocks","it","uses",".","Its","interpretable","architecture","is","recommended","for","scarce","data","settings",",","as","it","regularizes","its","predictions","through","projections","unto","harmonic","and","trend","basis","well-suited","for","most","forecasting","tasks",".","*","*","Parameters",":","*","*","<","br",">","`","h","`",":","int",",","forecast","horizon.","<","br",">","`","input_size","`",":","int",",","considered","autorregresive","inputs","(","lags",")",",","y=","[","1,2,3,4","]","input_size=2","-",">","lags=","[","1,2","]",".","<","br",">","`","n_harmonics","`",":","int",",","Number","of","harmonic","terms","for","seasonality","stack","type",".","Note","that","len","(","n_harmonics",")","=","len","(","stack_types",")",".","Note","that","it","will","only","be","used","if","a","seasonality","stack","is","used.","<","br",">","`","n_polynomials","`",":","int",",","polynomial","degree","for","trend","stack",".","Note","that","len","(","n_polynomials",")","=","len","(","stack_types",")",".","Note","that","it","will","only","be","used","if","a","trend","stack","is","used.","<","br",">","`","stack_types","`",":","List","[","str","]",",","List","of","stack","types",".","Subset","from","[","'seasonality","'",",","'trend","'",",","'identity","'","]",".","<","br",">","`","n_blocks","`",":","List","[","int","]",",","Number","of","blocks","for","each","stack",".","Note","that","len","(","n_blocks",")","=","len","(","stack_types",")",".","<","br",">","`","mlp_units","`",":","List","[","List","[","int","]","]",",","Structure","of","hidden","layers","for","each","stack","type",".","Each","internal","list","should","contain","the","number","of","units","of","each","hidden","layer",".","Note","that","len","(","n_hidden",")","=","len","(","stack_types",")",".","<","br",">","`","dropout_prob_theta","`",":","float",",","Float","between","(","0",",","1",")",".","Dropout","for","N-BEATS","basis.","<","br",">","`","shared_weights","`",":","bool",",","If","True",",","all","blocks","within","each","stack","will","share","parameters",".","<","br",">","`","activation","`",":","str",",","activation","from","[","'ReLU","'",",","'Softplus","'",",","'Tanh","'",",","'SELU","'",",","'LeakyReLU","'",",","'PReLU","'",",","'Sigmoid","'","]",".","<","br",">","`","loss","`",":","PyTorch","module",",","instantiated","train","loss","class","from","[","losses","collection","]","(","https",":","\/\/nixtla.github.io\/neuralforecast\/losses.pytorch.html",")",".","<","br",">","`","valid_loss","`",":","PyTorch","module=","`","loss","`",",","instantiated","valid","loss","class","from","[","losses","collection","]","(","https",":","\/\/nixtla.github.io\/neuralforecast\/losses.pytorch.html",")",".","<","br",">","`","max_steps","`",":","int=1000",",","maximum","number","of","training","steps.","<","br",">","`","learning_rate","`",":","float=1e-3",",","Learning","rate","between","(","0",",","1",")",".","<","br",">","`","num_lr_decays","`",":","int=3",",","Number","of","learning","rate","decays",",","evenly","distributed","across","max_steps.","<","br",">","`","early_stop_patience_steps","`",":","int=-1",",","Number","of","validation","iterations","before","early","stopping.","<","br",">","`","val_check_steps","`",":","int=100",",","Number","of","training","steps","between","every","validation","loss","check.","<","br",">","`","batch_size","`",":","int=32",",","number","of","different","series","in","each","batch.","<","br",">","`","valid_batch_size","`",":","int=None",",","number","of","different","series","in","each","validation","and","test","batch",",","if","None","uses","batch_size.","<","br",">","`","windows_batch_size","`",":","int=1024",",","number","of","windows","to","sample","in","each","training","batch",",","default","uses","all.","<","br",">","`","inference_windows_batch_size","`",":","int=-1",",","number","of","windows","to","sample","in","each","inference","batch",",","-1","uses","all.","<","br",">","`","start_padding_enabled","`",":","bool=False",",","if","True",",","the","model","will","pad","the","time","series","with","zeros","at","the","beginning",",","by","input","size.","<","br",">","`","step_size","`",":","int=1",",","step","size","between","each","window","of","temporal","data.","<","br",">","`","scaler_type","`",":","str='identity","'",",","type","of","scaler","for","temporal","inputs","normalization","see","[","temporal","scalers","]","(","https",":","\/\/nixtla.github.io\/neuralforecast\/common.scalers.html",")",".","<","br",">","`","random_seed","`",":","int",",","random_seed","for","pytorch","initializer","and","numpy","generators.","<","br",">","`","num_workers_loader","`",":","int=os.cpu_count","(",")",",","workers","to","be","used","by","`","TimeSeriesDataLoader","`",".","<","br",">","`","drop_last_loader","`",":","bool=False",",","if","True","`","TimeSeriesDataLoader","`","drops","last","non-full","batch.","<","br",">","`","alias","`",":","str",",","optional",",","Custom","name","of","the","model.","<","br",">","`","*","*","trainer_kwargs","`",":","int",",","keyword","trainer","arguments","inherited","from","[","PyTorch","Lighning","'s","trainer","]","(","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/api\/pytorch_lightning.trainer.trainer.Trainer.html","?","highlight=trainer",")",".","<","br",">","*","*","References",":","*","*","<","br",">","-","[","Boris","N.","Oreshkin",",","Dmitri","Carpov",",","Nicolas","Chapados",",","Yoshua","Bengio","(","2019",")",".","``","N-BEATS",":","Neural","basis","expansion","analysis","for","interpretable","time","series","forecasting","''",".","]","(","https",":","\/\/arxiv.org\/abs\/1905.10437",")"]
code: def create_stack(
      self,
      stack_types,
      n_blocks,
      input_size,
      h,
      mlp_units,
      dropout_prob_theta,
      activation,
      shared_weights,
      n_polynomials,
      n_harmonics,
  ):
      block_list = []
      for i in range(len(stack_types)):
          for block_id in range(n_blocks[i]):
              # Shared weights
              if shared_weights and block_id > 0:
                  nbeats_block = block_list[-1]
              else:
                  if stack_types[i] == "seasonality":
                      n_theta = (
                          2
                          * (self.loss.outputsize_multiplier + 1)
                          * int(
                              np.ceil(n_harmonics / 2 * h)
                              - (n_harmonics - 1)
                          )
                      )
                      basis = SeasonalityBasis(
                          harmonics=n_harmonics,
                          backcast_size=input_size,
                          forecast_size=h,
                          out_features=self.loss.outputsize_multiplier,
                      )
  
                  elif stack_types[i] == "trend":
                      n_theta = (
                          self.loss.outputsize_multiplier + 1
                      ) * (n_polynomials + 1)
                      basis = TrendBasis(
                          degree_of_polynomial=n_polynomials,
                          backcast_size=input_size,
                          forecast_size=h,
                          out_features=self.loss.outputsize_multiplier,
                      )
  
                  elif stack_types[i] == "identity":
                      n_theta = (
                          input_size
                          + self.loss.outputsize_multiplier * h
                      )
                      basis = IdentityBasis(
                          backcast_size=input_size,
                          forecast_size=h,
                          out_features=self.loss.outputsize_multiplier,
                      )
                  else:
                      raise ValueError(
                          f"Block type {stack_types[i]} not found!"
                      )
  
                  nbeats_block = NBEATSBlock(
                      input_size=input_size,
                      n_theta=n_theta,
                      mlp_units=mlp_units,
                      basis=basis,
                      dropout_prob=dropout_prob_theta,
                      activation=activation,
                  )
  
              # Select type of evaluation and apply it to all layers of block
              block_list.append(nbeats_block)
  
      return block_list
  
imports: from typing import Tuple, Optional
  import numpy
  import torch
  import torch.nn
  from ..losses.pytorch import MAE
  from ..common._base_windows import BaseWindows
label_desc: Use image node_id 2 for calling the NBEATS obj's underlying member method code with example usage: obj.create_stack(stack_types, n_blocks, input_size, h, mlp_units, dropout_prob_theta, activation, shared_weights, n_polynomials, n_harmonics) and returns: block_list