class_docstr: Spliced Binned-Pareto univariate distribution.
  
  Arguments
  ----------
      bins_lower_bound: The lower bound of the bin edges
      bins_upper_bound: The upper bound of the bin edges
      numb_bins: The number of equidistance bins to allocate between
          `bins_lower_bound` and `bins_upper_bound`. Default value is 100.
      tail_percentile_gen_pareto: The percentile of the distribution that is
          each tail. Default value is 0.05. NB: This symmetric percentile
          can still represent asymmetric upper and lower tails.
class_docstr_tok: ["Spliced","Binned-Pareto","univariate","distribution",".","Arguments","--","--","--","--","--","bins_lower_bound",":","The","lower","bound","of","the","bin","edges","bins_upper_bound",":","The","upper","bound","of","the","bin","edges","numb_bins",":","The","number","of","equidistance","bins","to","allocate","between","`","bins_lower_bound","`","and","`","bins_upper_bound","`",".","Default","value","is","100.","tail_percentile_gen_pareto",":","The","percentile","of","the","distribution","that","is","each","tail",".","Default","value","is","0.05",".","NB",":","This","symmetric","percentile","can","still","represent","asymmetric","upper","and","lower","tails","."]
docstr: Arguments
  ----------
  x: a tensor of size 'batch_size', 1
  for_training: boolean to indicate a return of the log-probability, or
      of the loss (which is an adjusted log-probability)
docstr_tok: ["Arguments","--","--","--","--","--","x",":","a","tensor","of","size","'batch_size","'",",","1","for_training",":","boolean","to","indicate","a","return","of","the","log-probability",",","or","of","the","loss","(","which","is","an","adjusted","log-probability",")"]
code: def log_prob(self, x: torch.Tensor, for_training=True):
      """
      Arguments
      ----------
      x: a tensor of size 'batch_size', 1
      for_training: boolean to indicate a return of the log-probability, or
          of the loss (which is an adjusted log-probability)
      """
  
      # Compute upper and lower tail thresholds at current time from
      # their percentiles
      upper_percentile = self._icdf_binned(
          torch.ones_like(x) * (1 - self.tail_percentile_gen_pareto)
      )
      lower_percentile = self._icdf_binned(
          torch.ones_like(x) * self.tail_percentile_gen_pareto
      )
      # upper_percentile.shape: (*batch_shape)
      # lower_percentile.shape: (*batch_shape)
  
      upper_percentile = upper_percentile.detach()
      lower_percentile = lower_percentile.detach()
  
      # Log-prob given binned distribution
      logp_bins = self.log_binned_p(x)
      logp = logp_bins.double()
      # logp.shape: (*batch_shape)
  
      # We obtain the log probabilities under the tail distributions:
      upper_gen_pareto_log_prob = self.upper_gen_pareto.log_prob(
          torch.abs(x.squeeze(dim=-1) - upper_percentile)
      ) + torch.log(self.tail_percentile_gen_pareto)
      lower_gen_pareto_log_prob = self.lower_gen_pareto.log_prob(
          torch.abs(lower_percentile - x.squeeze(dim=-1))
      ) + torch.log(self.tail_percentile_gen_pareto)
      # For the two log prob calls above, we adjust the value so that it
      # corresponds to the value in the tail. We take the absolute value of
      # what we give to the gen pareto because else the gradients are nan.
      # The torch,where select the correct ones and so the values lower than
      # zero are ignored, but the backward pass of pytorch has an issue with
      # nans in where even if they are not selected
  
      # By default during training we want to optimise the log-prob of both
      # the binned and the gen pareto at the tails
      # if not for training, we want to only have the gen pareto at the tails
      if for_training:
          # Log-prob given upper tail distribution
          logp += torch.where(
              x > upper_percentile,
              upper_gen_pareto_log_prob,
              torch.zeros_like(logp),
          )
  
          # Log-prob given upper tail distribution
          logp += torch.where(
              x < lower_percentile,
              lower_gen_pareto_log_prob,
              torch.zeros_like(logp),
          )
      else:
          # Log-prob given upper tail distribution
          logp = torch.where(
              x > upper_percentile,
              upper_gen_pareto_log_prob,
              logp,
          )
  
          # Log-prob given upper tail distribution
          logp = torch.where(
              x < lower_percentile,
              lower_gen_pareto_log_prob,
              logp,
          )
      return logp
  
file_path: gluonts/src/gluonts/torch/distributions/spliced_binned_pareto.py
imports: from typing import Dict, Optional, Tuple, cast
  import torch
  from torch.distributions import constraints
  from gluonts.core.component import validated
  from gluonts.torch.distributions import BinnedUniforms, GeneralizedPareto
  from .distribution_output import DistributionOutput
label_desc: Use image node_id 2 for calling the SplicedBinnedPareto obj's underlying member method code with example usage: obj.log_prob(x, for_training) and returns: logp