code: def __init__(
      self,
      num_layers: int,
      num_cells: int,
      cell_type: str,
      history_length: int,
      context_length: int,
      prediction_length: int,
      distr_output: DistributionOutput,
      dropout_rate: float,
      cardinality: List[int],
      embedding_dimension: List[int],
      lags_seq: List[int],
      dropoutcell_type: str = "ZoneoutCell",
      scaling: bool = True,
      dtype: Type = np.float32,
      num_imputation_samples: int = 1,
      minimum_scale: float = 1e-10,
      impute_missing_values: bool = False,
      default_scale: Optional[float] = None,
      nonnegative_pred_samples: bool = False,
      **kwargs,
  ) -> None:
      super().__init__(**kwargs)
      self.num_layers = num_layers
      self.num_cells = num_cells
      self.cell_type = cell_type
      self.history_length = history_length
      self.context_length = context_length
      self.prediction_length = prediction_length
      self.dropoutcell_type = dropoutcell_type
      self.dropout_rate = dropout_rate
      self.cardinality = cardinality
      self.embedding_dimension = embedding_dimension
      self.num_cat = len(cardinality)
      self.scaling = scaling
      self.dtype = dtype
      self.nonnegative_pred_samples = nonnegative_pred_samples
  
      assert len(cardinality) == len(embedding_dimension), (
          "embedding_dimension should be a list with the same size as"
          " cardinality"
      )
  
      assert len(set(lags_seq)) == len(
          lags_seq
      ), "no duplicated lags allowed!"
      lags_seq.sort()
  
      self.lags_seq = lags_seq
  
      self.distr_output = distr_output
      RnnCell = {
          "lstm": mx.gluon.rnn.LSTMCell,
          "gru": mx.gluon.rnn.GRUCell,
      }[self.cell_type]
  
      self.target_shape = distr_output.event_shape
  
      # TODO: is the following restriction needed?
      assert (
          len(self.target_shape) <= 1
      ), "Argument `target_shape` should be a tuple with 1 element at most"
  
      Dropout = {
          "ZoneoutCell": ZoneoutCell,
          "RNNZoneoutCell": RNNZoneoutCell,
          "VariationalDropoutCell": VariationalDropoutCell,
          "VariationalZoneoutCell": VariationalZoneoutCell,
      }[self.dropoutcell_type]
  
      with self.name_scope():
          self.proj_distr_args = distr_output.get_args_proj()
          self.rnn = mx.gluon.rnn.HybridSequentialRNNCell()
          for k in range(num_layers):
              cell = RnnCell(hidden_size=num_cells)
              cell = mx.gluon.rnn.ResidualCell(cell) if k > 0 else cell
              # we found that adding dropout to outputs doesn't improve the
              # performance, so we only drop states
              if "Zoneout" in self.dropoutcell_type:
                  cell = (
                      Dropout(cell, zoneout_states=dropout_rate)
                      if dropout_rate > 0.0
                      else cell
                  )
              elif "Dropout" in self.dropoutcell_type:
                  cell = (
                      Dropout(cell, drop_states=dropout_rate)
                      if dropout_rate > 0.0
                      else cell
                  )
              self.rnn.add(cell)
          self.rnn.cast(dtype=dtype)
          self.embedder = FeatureEmbedder(
              cardinalities=cardinality,
              embedding_dims=embedding_dimension,
              dtype=self.dtype,
          )
  
          if scaling:
              self.scaler = MeanScaler(
                  keepdims=True,
                  default_scale=default_scale,
                  minimum_scale=minimum_scale,
              )
          else:
              self.scaler = NOPScaler(keepdims=True)
  
          self.num_imputation_samples = num_imputation_samples
  
          # Switch between vanilla mode and imputing the missing values
          # with the model during training/prediction
          if impute_missing_values:
              self.unroll_encoder = self.unroll_encoder_imputation
              self.include_zeros_in_denominator = True
          else:
              self.unroll_encoder = self.unroll_encoder_default
              self.include_zeros_in_denominator = False
  
imports: from typing import List, Optional, Tuple, Union, Type
  import mxnet
  import numpy
  from mxnet.gluon.contrib.rnn import VariationalDropoutCell
  from mxnet.gluon.rnn import ZoneoutCell
  from gluonts.core.component import validated
  from gluonts.itertools import prod
  from gluonts.mx import Tensor
  from gluonts.mx.block.dropout import RNNZoneoutCell, VariationalZoneoutCell
  from gluonts.mx.block.feature import FeatureEmbedder
  from gluonts.mx.block.regularization import ActivationRegularizationLoss, TemporalActivationRegularizationLoss
  from gluonts.mx.block.scaler import MeanScaler, NOPScaler
  from gluonts.mx.distribution import Distribution, DistributionOutput
  from gluonts.mx.distribution.distribution import getF
  from gluonts.mx.util import weighted_average, mx_switch
  from mxnet import autograd
label_desc: Use image node_id 1 to create a new DeepARNetwork object from inherited base classes: mx.gluon with example: obj = DeepARNetwork(num_layers, num_cells, cell_type, history_length, context_length, prediction_length, distr_output, dropout_rate, cardinality, embedding_dimension, lags_seq, dropoutcell_type, scaling, dtype, num_imputation_samples, minimum_scale, impute_missing_values, default_scale, nonnegative_pred_samples)