Shortcuts

torch.logit

torch.logit(input, eps=None, *, out=None) → Tensor

Returns a new tensor with the logit of the elements of input. input is clamped to [eps, 1 - eps] when eps is not None. When eps is None and input < 0 or input > 1, the function will yields NaN.

yi=ln(zi1zi)zi={xiif eps is Noneepsif xi<epsxiif epsxi1eps1epsif xi>1epsy_{i} = \ln(\frac{z_{i}}{1 - z_{i}}) \\ z_{i} = \begin{cases} x_{i} & \text{if eps is None} \\ \text{eps} & \text{if } x_{i} < \text{eps} \\ x_{i} & \text{if } \text{eps} \leq x_{i} \leq 1 - \text{eps} \\ 1 - \text{eps} & \text{if } x_{i} > 1 - \text{eps} \end{cases}
Parameters
  • input (Tensor) – the input tensor.

  • eps (float, optional) – the epsilon for input clamp bound. Default: None

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.rand(5)
>>> a
tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
>>> torch.logit(a, eps=1e-6)
tensor([-0.9466,  2.6352,  0.6131, -1.7169,  0.6261])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources