docstr: Computes sample paths by unrolling the RNN starting with a initial
  input and state.
  
  Parameters
  ----------
  past_target_cdf
      Past marginal CDF transformed target values (batch_size,
      history_length, target_dim)
  target_dimension_indicator
      Indices of the target dimension (batch_size, target_dim)
  time_feat
      Dynamic features of future time series (batch_size, history_length,
      num_features)
  scale
      Mean scale for each time series (batch_size, 1, target_dim)
  begin_states
      List of initial states for the RNN layers (batch_size, num_cells)
  Returns
  --------
  sample_paths : Tensor
      A tensor containing sampled paths. Shape: (1, num_sample_paths,
      prediction_length, target_dim).
docstr_tok: ["Computes","sample","paths","by","unrolling","the","RNN","starting","with","a","initial","input","and","state",".","Parameters","--","--","--","--","--","past_target_cdf","Past","marginal","CDF","transformed","target","values","(","batch_size",",","history_length",",","target_dim",")","target_dimension_indicator","Indices","of","the","target","dimension","(","batch_size",",","target_dim",")","time_feat","Dynamic","features","of","future","time","series","(","batch_size",",","history_length",",","num_features",")","scale","Mean","scale","for","each","time","series","(","batch_size",",","1",",","target_dim",")","begin_states","List","of","initial","states","for","the","RNN","layers","(","batch_size",",","num_cells",")","Returns","--","--","--","--","sample_paths",":","Tensor","A","tensor","containing","sampled","paths",".","Shape",":","(","1",",","num_sample_paths",",","prediction_length",",","target_dim",")","."]
code: def sampling_decoder(
      self,
      past_target_cdf: torch.Tensor,
      target_dimension_indicator: torch.Tensor,
      time_feat: torch.Tensor,
      scale: torch.Tensor,
      enc_out: torch.Tensor,
  ) -> torch.Tensor:
      """
      Computes sample paths by unrolling the RNN starting with a initial
      input and state.
  
      Parameters
      ----------
      past_target_cdf
          Past marginal CDF transformed target values (batch_size,
          history_length, target_dim)
      target_dimension_indicator
          Indices of the target dimension (batch_size, target_dim)
      time_feat
          Dynamic features of future time series (batch_size, history_length,
          num_features)
      scale
          Mean scale for each time series (batch_size, 1, target_dim)
      begin_states
          List of initial states for the RNN layers (batch_size, num_cells)
      Returns
      --------
      sample_paths : Tensor
          A tensor containing sampled paths. Shape: (1, num_sample_paths,
          prediction_length, target_dim).
      """
  
      def repeat(tensor, dim=0):
          return tensor.repeat_interleave(
              repeats=self.num_parallel_samples, dim=dim
          )
  
      # blows-up the dimension of each tensor to
      # batch_size * self.num_sample_paths for increasing parallelism
      repeated_past_target_cdf = repeat(past_target_cdf)
      repeated_time_feat = repeat(time_feat)
      repeated_scale = repeat(scale)
      if self.scaling:
          self.flow.scale = repeated_scale
      repeated_target_dimension_indicator = repeat(
          target_dimension_indicator
      )
      repeated_enc_out = repeat(enc_out, dim=1)
  
      future_samples = []
  
      # for each future time-units we draw new samples for this time-unit
      # and update the state
      for k in range(self.prediction_length):
          lags = self.get_lagged_subsequences(
              sequence=repeated_past_target_cdf,
              sequence_length=self.history_length + k,
              indices=self.shifted_lags,
              subsequences_length=1,
          )
  
          lags_scaled = lags / repeated_scale.unsqueeze(-1)
  
          input_lags = lags_scaled.reshape(
              (-1, 1, len(self.lags_seq) * self.target_dim)
          )
  
          # (batch_size, target_dim, embed_dim)
          index_embeddings = self.embed(
              repeated_target_dimension_indicator
          )
          # assert_shape(index_embeddings, (-1, self.target_dim, self.embed_dim))
  
          # (batch_size, seq_len, target_dim * embed_dim)
          repeated_index_embeddings = (
              index_embeddings.unsqueeze(1)
              .expand(-1, 1, -1, -1)
              .reshape((-1, 1, self.target_dim * self.embed_dim))
          )
  
          # (batch_size, sub_seq_len, input_dim)
          dec_input = torch.cat(
              (
                  input_lags,
                  repeated_index_embeddings,
                  repeated_time_feat[:, k : k + 1, ...],
              ),
              dim=-1,
          )
  
          dec_output = self.transformer.decoder(
              self.decoder_input(dec_input).permute(1, 0, 2),
              repeated_enc_out,
          )
  
          distr_args = self.distr_args(
              decoder_output=dec_output.permute(1, 0, 2)
          )
  
          # (batch_size, 1, target_dim)
          new_samples = self.flow.sample(cond=distr_args)
  
          # (batch_size, seq_len, target_dim)
          future_samples.append(new_samples)
          repeated_past_target_cdf = torch.cat(
              (repeated_past_target_cdf, new_samples), dim=1
          )
  
      # (batch_size * num_samples, prediction_length, target_dim)
      samples = torch.cat(future_samples, dim=1)
  
      # (batch_size, num_samples, prediction_length, target_dim)
      return samples.reshape(
          (
              -1,
              self.num_parallel_samples,
              self.prediction_length,
              self.target_dim,
          )
      )
  
file_path: gluonts/src/gluonts/nursery/robust-mts-attack/pts/model/transformer_tempflow/transformer_tempflow_network.py
imports: from typing import List, Optional, Tuple
  import torch
  import torch.nn
  from gluonts.core.component import validated
  from pts.modules import RealNVP, MAF, FlowOutput, MeanScaler, NOPScaler
label_desc: Use image node_id 2 for calling the TransformerTempFlowPredictionNetwork obj's underlying member method code with example usage: obj.sampling_decoder(past_target_cdf, target_dimension_indicator, time_feat, scale, enc_out) and returns: samples, tensor