logit¶
该OP实现了logit层。若eps为默认值None,并且 x
< 0 或者 x
> 1,该函数将返回NaN,OP的计算公式如下:
\[logit(x) = ln(\frac{x}{1-x})\]
其中,\(x\) 为输入的 Tensor, 且和eps有着如下关系:
\[\begin{split}x_i=\left\{ \begin{aligned} x_i & &if &eps == Default \\ eps & & if&x_i < eps\\ x_i & & if&eps <= x_i<=1-eps \\ 1-eps & & if&x_i > 1-eps \end{aligned} \right.\end{split}\]
返回¶
Tensor
,数据类型和形状同x
一致。
代码示例¶
import paddle
x = paddle.to_tensor([0.1, 0.2, 0.3, 0.4])
out1 = paddle.logit(x)
#[-2.19722462, -1.38629436, -0.84729779, -0.40546516]
x = paddle.to_tensor([-0.1, 2, 0.3, 0.4])
out2 = paddle.logit(x)
#[-inf. , inf. , -0.84729779, -0.40546516]