docstr: PyTorch module implementing the basic building block of the N-BEATS architecture.
  
  The blocks produce outputs of size (target_length, nr_params); i.e.
  "one vector per parameter". The parameters are predicted only for forecast outputs.
  Backcast outputs are in the original "domain".
  
  Parameters
  ----------
  num_layers
      The number of fully connected layers preceding the final forking layers.
  layer_width
      The number of neurons that make up each fully connected layer.
  nr_params
      The number of parameters of the likelihood (or 1 if no likelihood is used)
  expansion_coefficient_dim
      The dimensionality of the waveform generator parameters, also known as expansion coefficients.
      Used in the generic architecture and the trend module of the interpretable architecture, where it determines
      the degree of the polynomial basis.
  input_chunk_length
      The length of the input sequence fed to the model.
  target_length
      The length of the forecast of the model.
  g_type
      The type of function that is implemented by the waveform generator.
  batch_norm
      Whether to use batch norm
  dropout
      Dropout probability
  activation
      The activation function of encoder/decoder intermediate layer.
  
  Inputs
  ------
  x of shape `(batch_size, input_chunk_length)`
      Tensor containing the input sequence.
  
  Outputs
  -------
  x_hat 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`.
  y_hat of shape `(batch_size, output_chunk_length)`
      Tensor containing the forward forecast of the block.
docstr_tok: ["PyTorch","module","implementing","the","basic","building","block","of","the","N-BEATS","architecture",".","The","blocks","produce","outputs","of","size","(","target_length",",","nr_params",")",";","i.e",".","``","one","vector","per","parameter","''",".","The","parameters","are","predicted","only","for","forecast","outputs",".","Backcast","outputs","are","in","the","original","``","domain","''",".","Parameters","--","--","--","--","--","num_layers","The","number","of","fully","connected","layers","preceding","the","final","forking","layers",".","layer_width","The","number","of","neurons","that","make","up","each","fully","connected","layer",".","nr_params","The","number","of","parameters","of","the","likelihood","(","or","1","if","no","likelihood","is","used",")","expansion_coefficient_dim","The","dimensionality","of","the","waveform","generator","parameters",",","also","known","as","expansion","coefficients",".","Used","in","the","generic","architecture","and","the","trend","module","of","the","interpretable","architecture",",","where","it","determines","the","degree","of","the","polynomial","basis",".","input_chunk_length","The","length","of","the","input","sequence","fed","to","the","model",".","target_length","The","length","of","the","forecast","of","the","model",".","g_type","The","type","of","function","that","is","implemented","by","the","waveform","generator",".","batch_norm","Whether","to","use","batch","norm","dropout","Dropout","probability","activation","The","activation","function","of","encoder\/decoder","intermediate","layer",".","Inputs","--","--","--","x","of","shape","`","(","batch_size",",","input_chunk_length",")","`","Tensor","containing","the","input","sequence",".","Outputs","--","--","--","-","x_hat","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","`",".","y_hat","of","shape","`","(","batch_size",",","output_chunk_length",")","`","Tensor","containing","the","forward","forecast","of","the","block","."]
code: def __init__(
      self,
      num_layers: int,
      layer_width: int,
      nr_params: int,
      expansion_coefficient_dim: int,
      input_chunk_length: int,
      target_length: int,
      g_type: GTypes,
      batch_norm: bool,
      dropout: float,
      activation: str,
  ):
      """PyTorch module implementing the basic building block of the N-BEATS architecture.
  
      The blocks produce outputs of size (target_length, nr_params); i.e.
      "one vector per parameter". The parameters are predicted only for forecast outputs.
      Backcast outputs are in the original "domain".
  
      Parameters
      ----------
      num_layers
          The number of fully connected layers preceding the final forking layers.
      layer_width
          The number of neurons that make up each fully connected layer.
      nr_params
          The number of parameters of the likelihood (or 1 if no likelihood is used)
      expansion_coefficient_dim
          The dimensionality of the waveform generator parameters, also known as expansion coefficients.
          Used in the generic architecture and the trend module of the interpretable architecture, where it determines
          the degree of the polynomial basis.
      input_chunk_length
          The length of the input sequence fed to the model.
      target_length
          The length of the forecast of the model.
      g_type
          The type of function that is implemented by the waveform generator.
      batch_norm
          Whether to use batch norm
      dropout
          Dropout probability
      activation
          The activation function of encoder/decoder intermediate layer.
  
      Inputs
      ------
      x of shape `(batch_size, input_chunk_length)`
          Tensor containing the input sequence.
  
      Outputs
      -------
      x_hat 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`.
      y_hat of shape `(batch_size, output_chunk_length)`
          Tensor containing the forward forecast of the block.
  
      """
      super().__init__()
  
      self.num_layers = num_layers
      self.layer_width = layer_width
      self.target_length = target_length
      self.nr_params = nr_params
      self.g_type = g_type
      self.dropout = dropout
      self.batch_norm = batch_norm
  
      raise_if_not(
          activation in ACTIVATIONS,
          f"'{activation}' is not in {ACTIVATIONS}",
      )
      self.activation = getattr(nn, activation)()
  
      # fully connected stack before fork
      self.linear_layer_stack_list = [
          nn.Linear(input_chunk_length, layer_width)
      ]
      for _ in range(num_layers - 1):
          self.linear_layer_stack_list.append(
              nn.Linear(layer_width, layer_width)
          )
  
          if self.batch_norm:
              self.linear_layer_stack_list.append(
                  nn.BatchNorm1d(num_features=self.layer_width)
              )
  
          if self.dropout > 0:
              self.linear_layer_stack_list.append(
                  MonteCarloDropout(p=self.dropout)
              )
  
      self.fc_stack = nn.ModuleList(self.linear_layer_stack_list)
  
      # Fully connected layer producing forecast/backcast expansion coefficients (waveform generator parameters).
      # The coefficients are emitted for each parameter of the likelihood.
      if g_type == _GType.SEASONALITY:
          self.backcast_linear_layer = nn.Linear(
              layer_width, 2 * int(input_chunk_length / 2 - 1) + 1
          )
          self.forecast_linear_layer = nn.Linear(
              layer_width,
              nr_params * (2 * int(target_length / 2 - 1) + 1),
          )
      else:
          self.backcast_linear_layer = nn.Linear(
              layer_width, expansion_coefficient_dim
          )
          self.forecast_linear_layer = nn.Linear(
              layer_width, nr_params * expansion_coefficient_dim
          )
  
      # waveform generator functions
      if g_type == _GType.GENERIC:
          self.backcast_g = nn.Linear(
              expansion_coefficient_dim, input_chunk_length
          )
          self.forecast_g = nn.Linear(
              expansion_coefficient_dim, target_length
          )
      elif g_type == _GType.TREND:
          self.backcast_g = _TrendGenerator(
              expansion_coefficient_dim, input_chunk_length
          )
          self.forecast_g = _TrendGenerator(
              expansion_coefficient_dim, target_length
          )
      elif g_type == _GType.SEASONALITY:
          self.backcast_g = _SeasonalityGenerator(input_chunk_length)
          self.forecast_g = _SeasonalityGenerator(target_length)
      else:
          raise_log(ValueError("g_type not supported"), logger)
  
imports: from enum import Enum
  from typing import List, NewType, Tuple, Union
  import numpy
  import torch
  import torch.nn
  from darts.logging import get_logger, raise_if_not, raise_log
  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 _Block object from inherited base classes: nn with example: obj = _Block(num_layers, layer_width, nr_params, expansion_coefficient_dim, input_chunk_length, target_length, g_type, batch_norm, dropout, activation)