docstr: PyTorch module implementing one stack of the N-BEATS architecture that comprises multiple basic blocks.
  
  Parameters
  ----------
  input_chunk_length
      The length of the input sequence fed to the model.
  output_chunk_length
      The length of the forecast of the model.
  num_blocks
      The number of blocks making up this stack.
  num_layers
      The number of fully connected layers preceding the final forking layers in each block.
  layer_width
      The number of neurons that make up each fully connected layer in each block.
  nr_params
      The number of parameters of the likelihood (or 1 if no likelihood is used)
  pooling_kernel_sizes
      sizes of pooling kernels for every block in this stack
  n_freq_downsample
      downsampling factors to apply for block in this stack
  batch_norm
      whether to apply batch norm on first block of this stack
  dropout
      Dropout probability
  activation
      The activation function of encoder/decoder intermediate layer.
  MaxPool1d
      Use MaxPool1d pooling. False uses AvgPool1d
  
  Inputs
  ------
  stack_input of shape `(batch_size, input_chunk_length)`
      Tensor containing the input sequence.
  
  Outputs
  -------
  stack_residual of shape `(batch_size, input_chunk_length)`
      Tensor containing the 'backcast' of the block, which represents an approximation of `x`
      given the constraints of the functional space determined by `g`.
  stack_forecast of shape `(batch_size, output_chunk_length)`
      Tensor containing the forward forecast of the stack.
docstr_tok: ["PyTorch","module","implementing","one","stack","of","the","N-BEATS","architecture","that","comprises","multiple","basic","blocks",".","Parameters","--","--","--","--","--","input_chunk_length","The","length","of","the","input","sequence","fed","to","the","model",".","output_chunk_length","The","length","of","the","forecast","of","the","model",".","num_blocks","The","number","of","blocks","making","up","this","stack",".","num_layers","The","number","of","fully","connected","layers","preceding","the","final","forking","layers","in","each","block",".","layer_width","The","number","of","neurons","that","make","up","each","fully","connected","layer","in","each","block",".","nr_params","The","number","of","parameters","of","the","likelihood","(","or","1","if","no","likelihood","is","used",")","pooling_kernel_sizes","sizes","of","pooling","kernels","for","every","block","in","this","stack","n_freq_downsample","downsampling","factors","to","apply","for","block","in","this","stack","batch_norm","whether","to","apply","batch","norm","on","first","block","of","this","stack","dropout","Dropout","probability","activation","The","activation","function","of","encoder\/decoder","intermediate","layer",".","MaxPool1d","Use","MaxPool1d","pooling",".","False","uses","AvgPool1d","Inputs","--","--","--","stack_input","of","shape","`","(","batch_size",",","input_chunk_length",")","`","Tensor","containing","the","input","sequence",".","Outputs","--","--","--","-","stack_residual","of","shape","`","(","batch_size",",","input_chunk_length",")","`","Tensor","containing","the","'backcast","'","of","the","block",",","which","represents","an","approximation","of","`","x","`","given","the","constraints","of","the","functional","space","determined","by","`","g","`",".","stack_forecast","of","shape","`","(","batch_size",",","output_chunk_length",")","`","Tensor","containing","the","forward","forecast","of","the","stack","."]
code: def __init__(
      self,
      input_chunk_length: int,
      output_chunk_length: int,
      num_blocks: int,
      num_layers: int,
      layer_width: int,
      nr_params: int,
      pooling_kernel_sizes: Tuple[int],
      n_freq_downsample: Tuple[int],
      batch_norm: bool,
      dropout: float,
      activation: str,
      MaxPool1d: bool,
  ):
      """PyTorch module implementing one stack of the N-BEATS architecture that comprises multiple basic blocks.
  
      Parameters
      ----------
      input_chunk_length
          The length of the input sequence fed to the model.
      output_chunk_length
          The length of the forecast of the model.
      num_blocks
          The number of blocks making up this stack.
      num_layers
          The number of fully connected layers preceding the final forking layers in each block.
      layer_width
          The number of neurons that make up each fully connected layer in each block.
      nr_params
          The number of parameters of the likelihood (or 1 if no likelihood is used)
      pooling_kernel_sizes
          sizes of pooling kernels for every block in this stack
      n_freq_downsample
          downsampling factors to apply for block in this stack
      batch_norm
          whether to apply batch norm on first block of this stack
      dropout
          Dropout probability
      activation
          The activation function of encoder/decoder intermediate layer.
      MaxPool1d
          Use MaxPool1d pooling. False uses AvgPool1d
  
      Inputs
      ------
      stack_input of shape `(batch_size, input_chunk_length)`
          Tensor containing the input sequence.
  
      Outputs
      -------
      stack_residual of shape `(batch_size, input_chunk_length)`
          Tensor containing the 'backcast' of the block, which represents an approximation of `x`
          given the constraints of the functional space determined by `g`.
      stack_forecast of shape `(batch_size, output_chunk_length)`
          Tensor containing the forward forecast of the stack.
  
      """
      super().__init__()
  
      self.input_chunk_length = input_chunk_length
      self.output_chunk_length = output_chunk_length
      self.nr_params = nr_params
  
      # TODO: leave option to share weights across blocks?
      self.blocks_list = [
          _Block(
              input_chunk_length,
              output_chunk_length,
              num_layers,
              layer_width,
              nr_params,
              pooling_kernel_sizes[i],
              n_freq_downsample[i],
              batch_norm=(
                  batch_norm and i == 0
              ),  # batch norm only on first block of first stack
              dropout=dropout,
              activation=activation,
              MaxPool1d=MaxPool1d,
          )
          for i in range(num_blocks)
      ]
      self.blocks = nn.ModuleList(self.blocks_list)
  
imports: from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from darts.logging import get_logger, raise_if_not
  from darts.models.forecasting.pl_forecasting_module import PLPastCovariatesModule, io_processor
  from darts.models.forecasting.torch_forecasting_model import PastCovariatesTorchModel
  from darts.utils.torch import MonteCarloDropout
label_desc: Use image node_id 1 to create a new _Stack object from inherited base classes: nn with example: obj = _Stack(input_chunk_length, output_chunk_length, num_blocks, num_layers, layer_width, nr_params, pooling_kernel_sizes, n_freq_downsample, batch_norm, dropout, activation, MaxPool1d)