docstr: Returns lagged subsequences of a given sequence.
  Parameters
  ----------
  sequence : Tensor
      the sequence from which lagged subsequences should be extracted.
      Shape: (N, T, C).
  sequence_length : int
      length of sequence in the T (time) dimension (axis = 1).
  indices : List[int]
      list of lag indices to be used.
  subsequences_length : int
      length of the subsequences to be extracted.
  Returns
  --------
  lagged : Tensor
      a tensor of shape (N, S, C, I), where S = subsequences_length and
      I = len(indices), containing lagged subsequences. Specifically,
      lagged[i, j, :, k] = sequence[i, -indices[k]-S+j, :].
docstr_tok: ["Returns","lagged","subsequences","of","a","given","sequence",".","Parameters","--","--","--","--","--","sequence",":","Tensor","the","sequence","from","which","lagged","subsequences","should","be","extracted",".","Shape",":","(","N",",","T",",","C",")",".","sequence_length",":","int","length","of","sequence","in","the","T","(","time",")","dimension","(","axis","=","1",")",".","indices",":","List","[","int","]","list","of","lag","indices","to","be","used",".","subsequences_length",":","int","length","of","the","subsequences","to","be","extracted",".","Returns","--","--","--","--","lagged",":","Tensor","a","tensor","of","shape","(","N",",","S",",","C",",","I",")",",","where","S","=","subsequences_length","and","I","=","len","(","indices",")",",","containing","lagged","subsequences",".","Specifically",",","lagged","[","i",",","j",",",":",",","k","]","=","sequence","[","i",",","-indices","[","k","]","-S+j",",",":","]","."]
code: def get_lagged_subsequences(
      F,
      sequence: Tensor,
      sequence_length: int,
      indices: List[int],
      subsequences_length: int = 1,
  ) -> Tensor:
      """
      Returns lagged subsequences of a given sequence.
      Parameters
      ----------
      sequence : Tensor
          the sequence from which lagged subsequences should be extracted.
          Shape: (N, T, C).
      sequence_length : int
          length of sequence in the T (time) dimension (axis = 1).
      indices : List[int]
          list of lag indices to be used.
      subsequences_length : int
          length of the subsequences to be extracted.
      Returns
      --------
      lagged : Tensor
          a tensor of shape (N, S, C, I), where S = subsequences_length and
          I = len(indices), containing lagged subsequences. Specifically,
          lagged[i, j, :, k] = sequence[i, -indices[k]-S+j, :].
      """
      # we must have: sequence_length - lag_index - subsequences_length >= 0
      # for all lag_index, hence the following assert
      assert max(indices) + subsequences_length <= sequence_length, (
          "lags cannot go further than history length, "
          f"found lag {max(indices)} while history length is only "
          f"{sequence_length}"
      )
      assert all(lag_index >= 0 for lag_index in indices)
  
      lagged_values = []
      for lag_index in indices:
          begin_index = -lag_index - subsequences_length
          end_index = -lag_index if lag_index > 0 else None
          lagged_values.append(
              F.slice_axis(
                  sequence, axis=1, begin=begin_index, end=end_index
              )
          )
  
      return F.stack(*lagged_values, axis=-1)
  
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 2 for calling the DeepARNetwork obj's underlying member method code with example usage: obj.get_lagged_subsequences(F, sequence, sequence_length, indices, subsequences_length) and returns: F