class_docstr: Implements Box-Cox transformation of a uni-variate random variable.
  The Box-Cox transformation of an observation :math:`z` is given by
  
  .. math::
  
      BoxCox(z; \lambda_1, \lambda_2) = \begin{cases}
            ((z + \lambda_2)^{\lambda_1} - 1) / \lambda_1, \quad & \text{if }
            \lambda_1 \neq 0, \\
            \log (z + \lambda_2), \quad & \text{otherwise.}
        \end{cases}
  
  Here, :math:`\lambda_1` and :math:`\lambda_2` are learnable parameters.
  Note that the domain of the transformation is not restricted.
  
  For numerical stability, instead of checking :math:`\lambda_1` is exactly
  zero, we use the condition
  
  .. math::
  
      |\lambda_1| < tol\_lambda\_1
  
  for a pre-specified tolerance `tol_lambda_1`.
  
  Inverse of the Box-Cox Transform is given by
  
  .. math::
  
      BoxCox^{-1}(y; \lambda_1, \lambda_2) = \begin{cases}
          (y \lambda_1 + 1)^{(1/\lambda_1)} - \lambda_2, \quad & \text{if }
          \lambda_1 \neq 0, \\
          \exp (y) - \lambda_2, \quad & \text{otherwise.}
         \end{cases}
  
  **Notes on numerical stability:**
  
  1.  For the forward transformation, :math:`\lambda_2` must always be chosen
  such that
  
      .. math::
  
          z + \lambda_2 > 0.
  
      To achieve this one needs to know a priori the lower bound on the
      observations. This is set in `BoxCoxTransformOutput`,
      since :math:`\lambda_2` is learnable.
  
  2.  Similarly for the inverse transformation to work reliably, a sufficient
  condition is
  
      .. math::
  
          y \lambda_1 + 1 \geq 0,
  
      where :math:`y` is the input to the inverse transformation.
  
      This cannot always be guaranteed especially when :math:`y` is a sample
      from a transformed distribution. Hence we always
      truncate :math:`y \lambda_1 + 1` at zero.
  
      An example showing why this could happen in our case: consider
      transforming observations from the unit interval (0, 1) with
      parameters
  
      .. math::
  
          \begin{align}
              \lambda_1 = &\ 1.1, \\
              \lambda_2 = &\ 0.
          \end{align}
  
      Then the range of the transformation is (-0.9090, 0.0). If Gaussian is
      fit to the transformed observations and a sample is drawn from it,
      then it is likely that the sample is outside this range, e.g., when
      the mean is close to -0.9. The subsequent inverse transformation of
      the sample is not a real number anymore.
  
      >>> y = -0.91
      >>> lambda_1 = 1.1
      >>> lambda_2 = 0.0
      >>> (y * lambda_1 + 1) ** (1 / lambda_1) + lambda_2
      (-0.0017979146510711471+0.0005279153735965289j)
  
  Parameters
  ----------
  lambda_1
  lambda_2
  tol_lambda_1
      For numerical stability, treat `lambda_1` as zero if it is less than
      `tol_lambda_1`
  F
class_docstr_tok: ["Implements","Box-Cox","transformation","of","a","uni-variate","random","variable",".","The","Box-Cox","transformation","of","an","observation",":","math",":","`","z","`","is","given","by","..","math",":",":","BoxCox","(","z",";","\\lambda_1",",","\\lambda_2",")","=","\\begin","{","cases","}","(","(","z","+","\\lambda_2",")","^","{","\\lambda_1","}","-","1",")","\/","\\lambda_1",",","\\quad","&","\\text","{","if","}","\\lambda_1","\\neq","0",",","\\\\","\\log","(","z","+","\\lambda_2",")",",","\\quad","&","\\text","{","otherwise",".","}","\\end","{","cases","}","Here",",",":","math",":","`","\\lambda_1","`","and",":","math",":","`","\\lambda_2","`","are","learnable","parameters",".","Note","that","the","domain","of","the","transformation","is","not","restricted",".","For","numerical","stability",",","instead","of","checking",":","math",":","`","\\lambda_1","`","is","exactly","zero",",","we","use","the","condition","..","math",":",":","|\\lambda_1|","<","tol\\_lambda\\_1","for","a","pre-specified","tolerance","`","tol_lambda_1","`",".","Inverse","of","the","Box-Cox","Transform","is","given","by","..","math",":",":","BoxCox^","{","-1","}","(","y",";","\\lambda_1",",","\\lambda_2",")","=","\\begin","{","cases","}","(","y","\\lambda_1","+","1",")","^","{","(","1\/\\lambda_1",")","}","-","\\lambda_2",",","\\quad","&","\\text","{","if","}","\\lambda_1","\\neq","0",",","\\\\","\\exp","(","y",")","-","\\lambda_2",",","\\quad","&","\\text","{","otherwise",".","}","\\end","{","cases","}","*","*","Notes","on","numerical","stability",":","*","*","1",".","For","the","forward","transformation",",",":","math",":","`","\\lambda_2","`","must","always","be","chosen","such","that","..","math",":",":","z","+","\\lambda_2",">","0",".","To","achieve","this","one","needs","to","know","a","priori","the","lower","bound","on","the","observations",".","This","is","set","in","`","BoxCoxTransformOutput","`",",","since",":","math",":","`","\\lambda_2","`","is","learnable",".","2",".","Similarly","for","the","inverse","transformation","to","work","reliably",",","a","sufficient","condition","is","..","math",":",":","y","\\lambda_1","+","1","\\geq","0",",","where",":","math",":","`","y","`","is","the","input","to","the","inverse","transformation",".","This","can","not","always","be","guaranteed","especially","when",":","math",":","`","y","`","is","a","sample","from","a","transformed","distribution",".","Hence","we","always","truncate",":","math",":","`","y","\\lambda_1","+","1","`","at","zero",".","An","example","showing","why","this","could","happen","in","our","case",":","consider","transforming","observations","from","the","unit","interval","(","0",",","1",")","with","parameters","..","math",":",":","\\begin","{","align","}","\\lambda_1","=","&","\\","1.1",",","\\\\","\\lambda_2","=","&","\\","0",".","\\end","{","align","}","Then","the","range","of","the","transformation","is","(","-0.9090",",","0.0",")",".","If","Gaussian","is","fit","to","the","transformed","observations","and","a","sample","is","drawn","from","it",",","then","it","is","likely","that","the","sample","is","outside","this","range",",","e.g.",",","when","the","mean","is","close","to","-0.9",".","The","subsequent","inverse","transformation","of","the","sample","is","not","a","real","number","anymore",".",">",">",">","y","=","-0.91",">",">",">","lambda_1","=","1.1",">",">",">","lambda_2","=","0.0",">",">",">","(","y","*","lambda_1","+","1",")","*","*","(","1","\/","lambda_1",")","+","lambda_2","(","-0.0017979146510711471+0.0005279153735965289j",")","Parameters","--","--","--","--","--","lambda_1","lambda_2","tol_lambda_1","For","numerical","stability",",","treat","`","lambda_1","`","as","zero","if","it","is","less","than","`","tol_lambda_1","`","F"]
docstr: Inverse of the Box-Cox Transform
  
  Parameters
  ----------
  y
      Transformed observations
  
  Returns
  -------
  Tensor
      Observations
docstr_tok: ["Inverse","of","the","Box-Cox","Transform","Parameters","--","--","--","--","--","y","Transformed","observations","Returns","--","--","--","-","Tensor","Observations"]
code: def f_inv(self, y: Tensor) -> Tensor:
      r"""Inverse of the Box-Cox Transform
  
      Parameters
      ----------
      y
          Transformed observations
  
      Returns
      -------
      Tensor
          Observations
  
      """
      F = self.F
      lambda_1 = self.lambda_1
      lambda_2 = self.lambda_2
      tol_lambda_1 = self.tol_lambda_1
      _power = self._power
  
      # For numerical stability we truncate :math:`y * \lambda_1 + 1.0` at
      # zero.
      base = F.relu(y * lambda_1 + 1.0)
  
      return F.where(
          condition=(
              F.abs(lambda_1).__ge__(tol_lambda_1)
          ).broadcast_like(y),
          x=_power(base, 1.0 / lambda_1) - lambda_2,
          y=F.exp(y) - lambda_2,
          name="Box_Cox_inverse_trans",
      )
  
imports: from typing import Dict, List, Tuple
  import mxnet
  from gluonts.core.component import validated
  from gluonts.mx import Tensor
  from .bijection import Bijection, InverseBijection
  from .bijection_output import BijectionOutput
  from .distribution import getF, softplus
label_desc: Use image node_id 6 for calling the BoxCoxTransform obj's underlying member method code with example usage: obj.f_inv(y) and returns: F