docstr: Computes loss given the output of the network in the form of
  distribution. The loss is given by:
  
      `self.CRPS_weight` * `loss_CRPS` + `self.likelihood_weight` *
      `neg_likelihoods`,
  
   where
    * `loss_CRPS` is computed on the samples drawn from the predicted
      `distr` (optionally after reconciling them),
    * `neg_likelihoods` are either computed directly using the predicted
      `distr` or from the estimated distribution based on (coherent)
      samples, depending on the `sample_LH` flag.
  
  Parameters
  ----------
  F
  target
      Tensor with shape (batch_size, seq_len, target_dim)
  distr
      Distribution instances
  
  Returns
  -------
  Loss
      Tensor with shape (batch_size, seq_length, 1)
docstr_tok: ["Computes","loss","given","the","output","of","the","network","in","the","form","of","distribution",".","The","loss","is","given","by",":","`","self.CRPS_weight","`","*","`","loss_CRPS","`","+","`","self.likelihood_weight","`","*","`","neg_likelihoods","`",",","where","*","`","loss_CRPS","`","is","computed","on","the","samples","drawn","from","the","predicted","`","distr","`","(","optionally","after","reconciling","them",")",",","*","`","neg_likelihoods","`","are","either","computed","directly","using","the","predicted","`","distr","`","or","from","the","estimated","distribution","based","on","(","coherent",")","samples",",","depending","on","the","`","sample_LH","`","flag",".","Parameters","--","--","--","--","--","F","target","Tensor","with","shape","(","batch_size",",","seq_len",",","target_dim",")","distr","Distribution","instances","Returns","--","--","--","-","Loss","Tensor","with","shape","(","batch_size",",","seq_length",",","1",")"]
code: def loss(self, F, target: Tensor, distr: Distribution) -> Tensor:
      """
      Computes loss given the output of the network in the form of
      distribution. The loss is given by:
  
          `self.CRPS_weight` * `loss_CRPS` + `self.likelihood_weight` *
          `neg_likelihoods`,
  
       where
        * `loss_CRPS` is computed on the samples drawn from the predicted
          `distr` (optionally after reconciling them),
        * `neg_likelihoods` are either computed directly using the predicted
          `distr` or from the estimated distribution based on (coherent)
          samples, depending on the `sample_LH` flag.
  
      Parameters
      ----------
      F
      target
          Tensor with shape (batch_size, seq_len, target_dim)
      distr
          Distribution instances
  
      Returns
      -------
      Loss
          Tensor with shape (batch_size, seq_length, 1)
      """
  
      # Sample from the predicted distribution if we are computing CRPS loss
      # or likelihood using the distribution based on (coherent) samples.
      # Samples shape: (num_samples, batch_size, seq_len, target_dim)
      if self.sample_LH or (self.CRPS_weight > 0.0):
          samples = self.get_samples_for_loss(distr=distr)
  
      if self.sample_LH:
          # Estimate the distribution based on (coherent) samples.
          distr = LowrankMultivariateGaussian.fit(
              F, samples=samples, rank=0
          )
  
      neg_likelihoods = -distr.log_prob(target).expand_dims(axis=-1)
  
      loss_CRPS = F.zeros_like(neg_likelihoods)
      if self.CRPS_weight > 0.0:
          loss_CRPS = (
              EmpiricalDistribution(samples=samples, event_dim=1)
              .crps_univariate(x=target)
              .expand_dims(axis=-1)
          )
  
      return (
          self.CRPS_weight * loss_CRPS
          + self.likelihood_weight * neg_likelihoods
      )
  
imports: import logging
  from typing import List, Optional
  from itertools import product
  import mxnet
  import numpy
  from gluonts.core.component import validated
  from gluonts.mx import Tensor
  from gluonts.mx.distribution import Distribution, DistributionOutput
  from gluonts.mx.distribution import EmpiricalDistribution
  from gluonts.mx.util import assert_shape
  from gluonts.mx.distribution import LowrankMultivariateGaussian
  from gluonts.mx.model.deepvar._network import DeepVARNetwork, DeepVARTrainingNetwork, DeepVARPredictionNetwork
label_desc: Use image node_id 3 for calling the DeepVARHierarchicalNetwork obj's underlying member method code with example usage: obj.loss(F, target, distr) and returns: unknown