class_docstr: Implements discrete distribution where the underlying random variable
  takes a value from the finite set `values` with the corresponding
  probabilities.
  
  Note: `values` can have duplicates in which case the probability mass
  of duplicates is added up.
  
  A natural loss function, especially given that the new observation does
  not have to be from the finite set `values`, is ranked probability score
  (RPS). For this reason and to be consitent with terminology of other
  models, `log_prob` is implemented as the negative RPS.
class_docstr_tok: ["Implements","discrete","distribution","where","the","underlying","random","variable","takes","a","value","from","the","finite","set","`","values","`","with","the","corresponding","probabilities",".","Note",":","`","values","`","can","have","duplicates","in","which","case","the","probability","mass","of","duplicates","is","added","up",".","A","natural","loss","function",",","especially","given","that","the","new","observation","does","not","have","to","be","from","the","finite","set","`","values","`",",","is","ranked","probability","score","(","RPS",")",".","For","this","reason","and","to","be","consitent","with","terminology","of","other","models",",","`","log_prob","`","is","implemented","as","the","negative","RPS","."]
docstr: Implements ranked probability score which is the sum of the qunatile
  losses for all possible quantiles.
  
  Here, the number of quantiles is finite and is equal to the number of
  unique values in (each batch element of) `obs`.
  
  Parameters
  ----------
  obs
  check_for_duplicates
  
  Returns
  -------
docstr_tok: ["Implements","ranked","probability","score","which","is","the","sum","of","the","qunatile","losses","for","all","possible","quantiles",".","Here",",","the","number","of","quantiles","is","finite","and","is","equal","to","the","number","of","unique","values","in","(","each","batch","element","of",")","`","obs","`",".","Parameters","--","--","--","--","--","obs","check_for_duplicates","Returns","--","--","--","-"]
code: def rps(self, obs: torch.Tensor, check_for_duplicates: bool = True):
      """
      Implements ranked probability score which is the sum of the qunatile
      losses for all possible quantiles.
  
      Here, the number of quantiles is finite and is equal to the number of
      unique values in (each batch element of) `obs`.
  
      Parameters
      ----------
      obs
      check_for_duplicates
  
      Returns
      -------
  
      """
      if self._validate_args:
          self._validate_sample(obs)
  
      probs_sorted, values_sorted = (
          self.probs_sorted,
          self.values_sorted,
      )
      if (
          check_for_duplicates
          and torch.sum(torch.diff(values_sorted) == 0) > 0
      ):
          probs_sorted = self.adjust_probs(
              values_sorted=values_sorted, probs_sorted=probs_sorted
          )
  
      # Recompute CDF with adjusted probabilities.
      CDF = torch.cumsum(probs_sorted, dim=1)
  
      mask_non_zero_prob = (probs_sorted > 0).int()
      quantile_losses = mask_non_zero_prob * self.quantile_losses(
          obs,
          quantiles=values_sorted,
          levels=CDF,
      )
  
      # We return normalized RPS
      return torch.sum(quantile_losses, dim=-1) / torch.sum(
          mask_non_zero_prob, dim=-1
      )
  
file_path: gluonts/src/gluonts/torch/distributions/discrete_distribution.py
imports: from numbers import Number
  from typing import Optional
  import torch
label_desc: Use image node_id 5 for calling the DiscreteDistribution obj's underlying member method code with example usage: obj.rps(obs, check_for_duplicates) and returns: unknown