class_docstr: Sequence-to-Sequence (seq2seq) structure with the so-called
  "Forking Sequence" proposed in [WTN+17]_.
  
  The basic idea is that, given a sequence :math:`x_1, x_2, \cdots, x_T`,
  with a decoding length :math:`\tau`, we learn a NN that solves the
  following series of seq2seq problems:
  
  .. math::
     :nowrap:
  
     \begin{eqnarray}
     x_1                     & \mapsto & x_{2:2+\tau}\\
     x_1, x_2                & \mapsto & x_{3:3+\tau}\\
     x_1, x_2, x_3           & \mapsto & x_{4:4+\tau}\\
                             & \ldots  & \\
     x_1, \ldots, x_{T-\tau} & \mapsto & x_{T-\tau+1:T}
     \end{eqnarray}
  
  Essentially, this means instead of having one cut in the standard seq2seq,
  one has multiple cuts that progress linearly.
  
  Parameters
  ----------
  encoder
      seq2seq encoder
  decoder
      seq2seq decoder
  quantile_output
      quantile output
  distr_output
      distribution output
  freq
      frequency of the time series.
  prediction_length
      length of the decoding sequence.
  context_length
      length of the encoding sequence. (default: 4 * prediction_length)
  use_past_feat_dynamic_real
      Whether to use the ``past_feat_dynamic_real`` field from the data.
      (default: False)
  use_feat_dynamic_real
      Whether to use the ``feat_dynamic_real`` field from the data.
      (default: False)
  use_feat_static_cat:
      Whether to use the ``feat_static_cat`` field from the data.
      (default: False)
  cardinality: List[int] = None,
      Number of values of each categorical feature.
      This must be set if ``use_feat_static_cat == True``. (default: None)
  embedding_dimension: List[int] = None,
      Dimension of the embeddings for categorical features.
      (default: [min(50, (cat+1)//2) for cat in cardinality])
  add_time_feature
      Adds a set of time features. (default: True)
  add_age_feature
      Adds an age feature. (default: False)
      The age feature starts with a small value at the start of the time
      series and grows over time.
  enable_encoder_dynamic_feature
      Whether the encoder should also be provided with the dynamic features
      (``age``, ``time`` and ``feat_dynamic_real`` if enabled respectively).
      (default: True)
  enable_decoder_dynamic_feature
      Whether the decoder should also be provided with the dynamic features
      (``age``, ``time`` and ``feat_dynamic_real`` if enabled respectively).
      (default: True)
      It makes sense to disable this, if you don't have ``feat_dynamic_real``
      for the prediction range.
  trainer
      trainer (default: Trainer())
  scaling
      Whether to automatically scale the target values. (default: False if
      quantile_output is used, True otherwise)
  scaling_decoder_dynamic_feature
      Whether to automatically scale the dynamic features for the decoder.
      (default: False)
  dtype
      (default: np.float32)
  num_forking
      Decides how much forking to do in the decoder. 1 reduces to seq2seq and
      enc_len reduces to MQ-C(R)NN.
  max_ts_len
      Returns the length of the longest time series in the dataset to be used
      in bounding context_length.
  train_sampler
      Controls the sampling of windows during training.
  validation_sampler
      Controls the sampling of windows during validation.
  batch_size
      The size of the batches to be used training and prediction.
class_docstr_tok: ["Sequence-to-Sequence","(","seq2seq",")","structure","with","the","so-called","''","Forking","Sequence","''","proposed","in","[","WTN+17","]","_",".","The","basic","idea","is","that",",","given","a","sequence",":","math",":","`","x_1",",","x_2",",","\\cdots",",","x_T","`",",","with","a","decoding","length",":","math",":","`","\\tau","`",",","we","learn","a","NN","that","solves","the","following","series","of","seq2seq","problems",":","..","math",":",":",":","nowrap",":","\\begin","{","eqnarray","}","x_1","&","\\mapsto","&","x_","{","2:2+\\tau","}","\\\\","x_1",",","x_2","&","\\mapsto","&","x_","{","3:3+\\tau","}","\\\\","x_1",",","x_2",",","x_3","&","\\mapsto","&","x_","{","4:4+\\tau","}","\\\\","&","\\ldots","&","\\\\","x_1",",","\\ldots",",","x_","{","T-\\tau","}","&","\\mapsto","&","x_","{","T-\\tau+1",":","T","}","\\end","{","eqnarray","}","Essentially",",","this","means","instead","of","having","one","cut","in","the","standard","seq2seq",",","one","has","multiple","cuts","that","progress","linearly",".","Parameters","--","--","--","--","--","encoder","seq2seq","encoder","decoder","seq2seq","decoder","quantile_output","quantile","output","distr_output","distribution","output","freq","frequency","of","the","time","series",".","prediction_length","length","of","the","decoding","sequence",".","context_length","length","of","the","encoding","sequence",".","(","default",":","4","*","prediction_length",")","use_past_feat_dynamic_real","Whether","to","use","the","``","past_feat_dynamic_real","``","field","from","the","data",".","(","default",":","False",")","use_feat_dynamic_real","Whether","to","use","the","``","feat_dynamic_real","``","field","from","the","data",".","(","default",":","False",")","use_feat_static_cat",":","Whether","to","use","the","``","feat_static_cat","``","field","from","the","data",".","(","default",":","False",")","cardinality",":","List","[","int","]","=","None",",","Number","of","values","of","each","categorical","feature",".","This","must","be","set","if","``","use_feat_static_cat","==","True","``",".","(","default",":","None",")","embedding_dimension",":","List","[","int","]","=","None",",","Dimension","of","the","embeddings","for","categorical","features",".","(","default",":","[","min","(","50",",","(","cat+1",")","\/\/2",")","for","cat","in","cardinality","]",")","add_time_feature","Adds","a","set","of","time","features",".","(","default",":","True",")","add_age_feature","Adds","an","age","feature",".","(","default",":","False",")","The","age","feature","starts","with","a","small","value","at","the","start","of","the","time","series","and","grows","over","time",".","enable_encoder_dynamic_feature","Whether","the","encoder","should","also","be","provided","with","the","dynamic","features","(","``","age","``",",","``","time","``","and","``","feat_dynamic_real","``","if","enabled","respectively",")",".","(","default",":","True",")","enable_decoder_dynamic_feature","Whether","the","decoder","should","also","be","provided","with","the","dynamic","features","(","``","age","``",",","``","time","``","and","``","feat_dynamic_real","``","if","enabled","respectively",")",".","(","default",":","True",")","It","makes","sense","to","disable","this",",","if","you","do","n't","have","``","feat_dynamic_real","``","for","the","prediction","range",".","trainer","trainer","(","default",":","Trainer","(",")",")","scaling","Whether","to","automatically","scale","the","target","values",".","(","default",":","False","if","quantile_output","is","used",",","True","otherwise",")","scaling_decoder_dynamic_feature","Whether","to","automatically","scale","the","dynamic","features","for","the","decoder",".","(","default",":","False",")","dtype","(","default",":","np.float32",")","num_forking","Decides","how","much","forking","to","do","in","the","decoder",".","1","reduces","to","seq2seq","and","enc_len","reduces","to","MQ-C","(","R",")","NN",".","max_ts_len","Returns","the","length","of","the","longest","time","series","in","the","dataset","to","be","used","in","bounding","context_length",".","train_sampler","Controls","the","sampling","of","windows","during","training",".","validation_sampler","Controls","the","sampling","of","windows","during","validation",".","batch_size","The","size","of","the","batches","to","be","used","training","and","prediction","."]
code: def create_transformation(self) -> Transformation:
      chain = []
      dynamic_feat_fields = []
      remove_field_names = [
          FieldName.FEAT_DYNAMIC_CAT,
          FieldName.FEAT_STATIC_REAL,
      ]
  
      # --- GENERAL TRANSFORMATION CHAIN ---
  
      # determine unused input
      if not self.use_past_feat_dynamic_real:
          remove_field_names.append(FieldName.PAST_FEAT_DYNAMIC_REAL)
      if not self.use_feat_dynamic_real:
          remove_field_names.append(FieldName.FEAT_DYNAMIC_REAL)
      if not self.use_feat_static_cat:
          remove_field_names.append(FieldName.FEAT_STATIC_CAT)
  
      chain.extend(
          [
              RemoveFields(field_names=remove_field_names),
              AddObservedValuesIndicator(
                  target_field=FieldName.TARGET,
                  output_field=FieldName.OBSERVED_VALUES,
                  dtype=self.dtype,
              ),
          ]
      )
  
      # --- TRANSFORMATION CHAIN FOR DYNAMIC FEATURES ---
  
      if self.add_time_feature:
          chain.append(
              AddTimeFeatures(
                  start_field=FieldName.START,
                  target_field=FieldName.TARGET,
                  output_field=FieldName.FEAT_TIME,
                  time_features=time_features_from_frequency_str(
                      self.freq
                  ),
                  pred_length=self.prediction_length,
                  dtype=self.dtype,
              )
          )
          dynamic_feat_fields.append(FieldName.FEAT_TIME)
  
      if self.add_age_feature:
          chain.append(
              AddAgeFeature(
                  target_field=FieldName.TARGET,
                  output_field=FieldName.FEAT_AGE,
                  pred_length=self.prediction_length,
                  dtype=self.dtype,
              )
          )
          dynamic_feat_fields.append(FieldName.FEAT_AGE)
  
      if self.use_feat_dynamic_real:
          # Backwards compatibility:
          chain.append(
              RenameFields(
                  {"dynamic_feat": FieldName.FEAT_DYNAMIC_REAL}
              )
          )
          dynamic_feat_fields.append(FieldName.FEAT_DYNAMIC_REAL)
  
      # we need to make sure that there is always some dynamic input we will
      # however disregard it in the hybrid forward. the time feature is
      # empty for yearly freq so also adding a dummy feature in the case
      # that the time feature is the only one on
      if len(dynamic_feat_fields) == 0 or (
          not self.add_age_feature
          and not self.use_feat_dynamic_real
          and self.freq == "Y"
      ):
          chain.append(
              AddConstFeature(
                  target_field=FieldName.TARGET,
                  output_field=FieldName.FEAT_CONST,
                  pred_length=self.prediction_length,
                  # For consistency in case with no dynamic features
                  const=0.0,
                  dtype=self.dtype,
              )
          )
          dynamic_feat_fields.append(FieldName.FEAT_CONST)
  
      # now we map all the dynamic input of length context_length +
      # prediction_length onto FieldName.FEAT_DYNAMIC we exclude
      # past_feat_dynamic_real since its length is only context_length
      if len(dynamic_feat_fields) > 1:
          chain.append(
              VstackFeatures(
                  output_field=FieldName.FEAT_DYNAMIC,
                  input_fields=dynamic_feat_fields,
              )
          )
      elif len(dynamic_feat_fields) == 1:
          chain.append(
              RenameFields(
                  {dynamic_feat_fields[0]: FieldName.FEAT_DYNAMIC}
              )
          )
  
      # --- TRANSFORMATION CHAIN FOR STATIC FEATURES ---
  
      if not self.use_feat_static_cat:
          chain.append(
              SetField(
                  output_field=FieldName.FEAT_STATIC_CAT,
                  value=np.array([0], dtype=np.int32),
              )
          )
  
      return Chain(chain)
  
imports: from functools import partial
  from typing import List, Optional, Type
  import numpy
  from gluonts.core.component import validated
  from gluonts.dataset.common import Dataset
  from gluonts.dataset.field_names import FieldName
  from gluonts.dataset.loader import DataLoader, TrainDataLoader, ValidationDataLoader
  from gluonts.model.forecast import Quantile
  from gluonts.model.forecast_generator import DistributionForecastGenerator, QuantileForecastGenerator
  from gluonts.model.predictor import Predictor
  from gluonts.mx.batchify import batchify
  from gluonts.mx.block.decoder import Seq2SeqDecoder
  from gluonts.mx.block.enc2dec import FutureFeatIntegratorEnc2Dec
  from gluonts.mx.block.encoder import Seq2SeqEncoder
  from gluonts.mx.block.quantile_output import QuantileOutput
  from gluonts.mx.distribution import DistributionOutput
  from gluonts.mx.model.estimator import GluonEstimator
  from gluonts.mx.model.predictor import RepresentableBlockPredictor
  from gluonts.mx.trainer import Trainer
  from gluonts.mx.util import copy_parameters, get_hybrid_forward_input_names
  from gluonts.time_feature import time_features_from_frequency_str
  from gluonts.transform import AddAgeFeature, AddConstFeature, AddObservedValuesIndicator, AddTimeFeatures, Chain, InstanceSampler, RemoveFields, RenameFields, SelectFields, SetField, TestSplitSampler, Transformation, ValidationSplitSampler, VstackFeatures
  from ._forking_network import ForkingSeq2SeqDistributionPredictionNetwork, ForkingSeq2SeqNetworkBase, ForkingSeq2SeqPredictionNetwork, ForkingSeq2SeqTrainingNetwork
  from ._transform import ForkingSequenceSplitter
label_desc: Use image node_id 2 for calling the ForkingSeq2SeqEstimator obj's underlying member method code with example usage: obj.create_transformation() and returns: Chain