docstr: Computes the loss for training DeepVAR, all inputs tensors representing
  time series have NTC layout.
  
  Parameters
  ----------
  feat_static_cat
  
  past_time_feat
      Dynamic features of past time series (batch_size, history_length,
      num_features)
  past_target_cdf
      Past marginal CDF transformed target values (batch_size,
      history_length, target_dim)
  past_observed_values
      Indicator whether or not the values were observed (batch_size,
      history_length, target_dim)
  past_is_pad
      Indicator whether the past target values have been padded
      (batch_size, history_length)
  future_time_feat
      Future time features (batch_size, prediction_length, num_features)
  future_target_cdf
      Future marginal CDF transformed target values (batch_size,
      prediction_length, target_dim)
  future_observed_values
      Indicator whether or not the future values were observed
      (batch_size, prediction_length, target_dim)
  
  Returns
  -------
  distr
      Loss with shape (batch_size, 1)
  likelihoods
      Likelihoods for each time step
      (batch_size, context + prediction_length, 1)
  distr_args
      Distribution arguments (context + prediction_length,
      number_of_arguments)
docstr_tok: ["Computes","the","loss","for","training","DeepVAR",",","all","inputs","tensors","representing","time","series","have","NTC","layout",".","Parameters","--","--","--","--","--","feat_static_cat","past_time_feat","Dynamic","features","of","past","time","series","(","batch_size",",","history_length",",","num_features",")","past_target_cdf","Past","marginal","CDF","transformed","target","values","(","batch_size",",","history_length",",","target_dim",")","past_observed_values","Indicator","whether","or","not","the","values","were","observed","(","batch_size",",","history_length",",","target_dim",")","past_is_pad","Indicator","whether","the","past","target","values","have","been","padded","(","batch_size",",","history_length",")","future_time_feat","Future","time","features","(","batch_size",",","prediction_length",",","num_features",")","future_target_cdf","Future","marginal","CDF","transformed","target","values","(","batch_size",",","prediction_length",",","target_dim",")","future_observed_values","Indicator","whether","or","not","the","future","values","were","observed","(","batch_size",",","prediction_length",",","target_dim",")","Returns","--","--","--","-","distr","Loss","with","shape","(","batch_size",",","1",")","likelihoods","Likelihoods","for","each","time","step","(","batch_size",",","context","+","prediction_length",",","1",")","distr_args","Distribution","arguments","(","context","+","prediction_length",",","number_of_arguments",")"]
code: def forward(
      self,
      feat_static_cat: torch.Tensor,
      feat_static_real: torch.Tensor,
      past_time_feat: torch.Tensor,
      past_target_cdf: torch.Tensor,
      past_observed_values: torch.Tensor,
      past_is_pad: torch.Tensor,
      future_time_feat: torch.Tensor,
      future_target_cdf: torch.Tensor,
      future_observed_values: torch.Tensor,
  ) -> Tuple[torch.Tensor, ...]:
      """
      Computes the loss for training DeepVAR, all inputs tensors representing
      time series have NTC layout.
  
      Parameters
      ----------
      feat_static_cat
  
      past_time_feat
          Dynamic features of past time series (batch_size, history_length,
          num_features)
      past_target_cdf
          Past marginal CDF transformed target values (batch_size,
          history_length, target_dim)
      past_observed_values
          Indicator whether or not the values were observed (batch_size,
          history_length, target_dim)
      past_is_pad
          Indicator whether the past target values have been padded
          (batch_size, history_length)
      future_time_feat
          Future time features (batch_size, prediction_length, num_features)
      future_target_cdf
          Future marginal CDF transformed target values (batch_size,
          prediction_length, target_dim)
      future_observed_values
          Indicator whether or not the future values were observed
          (batch_size, prediction_length, target_dim)
  
      Returns
      -------
      distr
          Loss with shape (batch_size, 1)
      likelihoods
          Likelihoods for each time step
          (batch_size, context + prediction_length, 1)
      distr_args
          Distribution arguments (context + prediction_length,
          number_of_arguments)
      """
  
      seq_len = self.context_length + self.prediction_length
  
      # unroll the decoder in "training mode", i.e. by providing future data
      # as well
      rnn_outputs, _, scale, _, inputs = self.unroll_encoder(
          feat_static_real=feat_static_real,
          past_time_feat=past_time_feat,
          past_target_cdf=past_target_cdf,
          past_observed_values=past_observed_values,
          past_is_pad=past_is_pad,
          future_time_feat=future_time_feat,
          future_target_cdf=future_target_cdf,
          feat_static_cat=feat_static_cat,
      )
  
      # put together target sequence
      # (batch_size, seq_len, target_dim)
      target = torch.cat(
          (
              past_target_cdf[:, -self.context_length :, ...],
              future_target_cdf,
          ),
          dim=1,
      )
  
      # assert_shape(target, (-1, seq_len, self.target_dim))
  
      distr, distr_args = self.distr(
          rnn_outputs=rnn_outputs, scale=scale
      )
      # self.distr._validate_args = False
  
      # we sum the last axis to have the same shape for all likelihoods
      # (batch_size, subseq_length, 1)
      likelihoods = -distr.log_prob(target).unsqueeze(-1)
  
      # assert_shape(likelihoods, (-1, seq_len, 1))
  
      past_observed_values = torch.min(
          past_observed_values, 1 - past_is_pad.unsqueeze(-1)
      )
  
      # (batch_size, subseq_length, target_dim)
      observed_values = torch.cat(
          (
              past_observed_values[:, -self.context_length :, ...],
              future_observed_values,
          ),
          dim=1,
      )
  
      # mask the loss at one time step if one or more observations is missing
      # in the target dimensions (batch_size, subseq_length, 1)
      loss_weights, _ = observed_values.min(dim=-1, keepdim=True)
  
      # assert_shape(loss_weights, (-1, seq_len, 1))
  
      loss = weighted_average(likelihoods, weights=loss_weights, dim=1)
  
      # assert_shape(loss, (-1, -1, 1))
      return (loss.mean(), likelihoods) + distr_args + (target,)
  
imports: from turtle import distance
  from typing import List, Optional, Tuple, Union
  from matplotlib.pyplot import sca
  import torch
  import torch.nn
  from gluonts.core.component import validated
  from gluonts.torch.modules.distribution_output import DistributionOutput
  from pts.model import weighted_average
  from pts.modules import MeanScaler, NOPScaler, FeatureEmbedder
  from torch.distributions import AffineTransform, Beta, Distribution, Gamma, NegativeBinomial, Normal, Poisson, StudentT, TransformedDistribution
label_desc: Use image node_id 6 for calling the DeepVARTrainingNetwork obj's underlying member method code with example usage: obj.forward(feat_static_cat, feat_static_real, past_time_feat, past_target_cdf, past_observed_values, past_is_pad, future_time_feat, future_target_cdf, future_observed_values) and returns: unknown