class_docstr: Distribution class for the model MQF2 proposed in the paper
  ``Multivariate Quantile Function Forecaster``
  by Kan, Aubet, Januschowski, Park, Benidis, Ruthotto, Gasthaus
  Parameters
  ----------
  picnn
      A SequentialNet instance of a
      partially input convex neural network (picnn)
  hidden_state
      hidden_state obtained by unrolling the RNN encoder
      shape = (batch_size, context_length, hidden_size) in training
      shape = (batch_size, hidden_size) in inference
  prediction_length
      Length of the prediction horizon
  is_energy_score
      If True, use energy score as objective function
      otherwise use maximum likelihood as
      objective function (normalizing flows)
  es_num_samples
      Number of samples drawn to approximate the energy score
  beta
      Hyperparameter of the energy score (power of the two terms)
  threshold_input
      Clamping threshold of the (scaled) input when maximum
      likelihood is used as objective function
      this is used to make the forecaster more robust
      to outliers in training samples
  validate_args
      Sets whether validation is enabled or disabled
      For more details, refer to the descriptions in
      torch.distributions.distribution.Distribution
docstr: Computes the (approximated) energy score sum_i ES(g,z_i),
  where ES(g,z_i) =
  -1/(2*es_num_samples^2) * sum_{w,w'} ||w-w'||_2^beta
  + 1/es_num_samples * sum_{w''} ||w''-z_i||_2^beta,
  w's are samples drawn from the
  quantile function g(., h_i) (gradient of picnn),
  h_i is the hidden state associated with z_i,
  and es_num_samples is the number of samples drawn
  for each of w, w', w'' in energy score approximation
  Parameters
  ----------
  z
      A batch of time series with shape
      (batch_size, context_length + prediction_length - 1)
  Returns
  -------
  loss
      Tensor of shape (batch_size * context_length,)
docstr_tok: ["Computes","the","(","approximated",")","energy","score","sum_i","ES","(","g",",","z_i",")",",","where","ES","(","g",",","z_i",")","=","-1\/","(","2","*","es_num_samples^2",")","*","sum_","{","w",",","w","'","}","||w-w'||_2^beta","+","1\/es_num_samples","*","sum_","{","w","''","}","||w","''","-z_i||_2^beta",",","w","'s","are","samples","drawn","from","the","quantile","function","g","(",".",",","h_i",")","(","gradient","of","picnn",")",",","h_i","is","the","hidden","state","associated","with","z_i",",","and","es_num_samples","is","the","number","of","samples","drawn","for","each","of","w",",","w","'",",","w","''","in","energy","score","approximation","Parameters","--","--","--","--","--","z","A","batch","of","time","series","with","shape","(","batch_size",",","context_length","+","prediction_length","-","1",")","Returns","--","--","--","-","loss","Tensor","of","shape","(","batch_size","*","context_length",",",")"]
code: def energy_score(self, z: torch.Tensor) -> torch.Tensor:
      """
      Computes the (approximated) energy score sum_i ES(g,z_i),
      where ES(g,z_i) =
      -1/(2*es_num_samples^2) * sum_{w,w'} ||w-w'||_2^beta
      + 1/es_num_samples * sum_{w''} ||w''-z_i||_2^beta,
      w's are samples drawn from the
      quantile function g(., h_i) (gradient of picnn),
      h_i is the hidden state associated with z_i,
      and es_num_samples is the number of samples drawn
      for each of w, w', w'' in energy score approximation
      Parameters
      ----------
      z
          A batch of time series with shape
          (batch_size, context_length + prediction_length - 1)
      Returns
      -------
      loss
          Tensor of shape (batch_size * context_length,)
      """
  
      es_num_samples = self.es_num_samples
      beta = self.beta
  
      z = self.stack_sliding_view(z)
      reshaped_hidden_state = self.hidden_state.reshape(
          -1, self.hidden_state.shape[-1]
      )
  
      loss = self.picnn.energy_score(
          z,
          reshaped_hidden_state,
          es_num_samples=es_num_samples,
          beta=beta,
      )
  
      return loss
  
imports: from typing import List, Optional, Tuple
  from cpflows.flows import DeepConvexFlow, SequentialFlow
  import torch
  from torch.distributions import AffineTransform, Distribution, Normal, TransformedDistribution
  import torch.nn.functional
label_desc: Use image node_id 5 for calling the MQF2Distribution obj's underlying member method code with example usage: obj.energy_score(z) and returns: loss