Airy function Ai ( input ) \text{Ai}\left(\text{input}\right) Ai(input).
Bessel function of the first kind of order 0 0 0.
Bessel function of the first kind of order 1 1 1.
Bessel function of the second kind of order 0 0 0.
Bessel function of the second kind of order 1 1 1.
Chebyshev polynomial of the first kind T n ( input ) T_{n}(\text{input}) Tn(input).
If n = 0 n = 0 n=0, 1 1 1 is returned. If n = 1 n = 1 n=1, input \text{input} input is returned. If n < 6 n < 6 n<6 or ∣ input ∣ > 1 |\text{input}| > 1 ∣input∣>1 the recursion:
T n + 1 ( input ) = 2 × input × T n ( input ) − T n − 1 ( input ) T_{n + 1}(\text{input}) = 2 \times \text{input} \times T_{n}(\text{input}) - T_{n - 1}(\text{input}) Tn+1(input)=2×input×Tn(input)−Tn−1(input)
is evaluated. Otherwise, the explicit trigonometric formula:
T n ( input ) = cos ( n × arccos ( x ) ) T_{n}(\text{input}) = \text{cos}(n \times \text{arccos}(x)) Tn(input)=cos(n×arccos(x))
is evaluated.
Chebyshev polynomial of the second kind U n ( input ) U_{n}(\text{input}) Un(input).
If n = 0 n = 0 n=0, 1 1 1 is returned. If n = 1 n = 1 n=1, 2 × input 2 \times \text{input} 2×input is returned. If n < 6 n < 6 n<6 or ∣ input ∣ > 1 |\text{input}| > 1 ∣input∣>1, the recursion:
U n + 1 ( input ) = 2 × input × U n ( input ) − U n − 1 ( input ) U_{n + 1}(\text{input}) = 2 \times \text{input} \times U_{n}(\text{input}) - U_{n - 1}(\text{input}) Un+1(input)=2×input×Un(input)−Un−1(input)
is evaluated. Otherwise, the explicit trigonometric formula:
sin ( ( n + 1 ) × arccos ( input ) ) sin ( arccos ( input ) ) \frac{\text{sin}((n + 1) \times \text{arccos}(\text{input}))}{\text{sin}(\text{arccos}(\text{input}))} sin(arccos(input))sin((n+1)×arccos(input))
is evaluated.
Chebyshev polynomial of the third kind V n ∗ ( input ) V_{n}^{\ast}(\text{input}) Vn∗(input).
Chebyshev polynomial of the fourth kind W n ∗ ( input ) W_{n}^{\ast}(\text{input}) Wn∗(input).
Computes the logarithmic derivative of the gamma function on input.
ϝ ( x ) = d d x ln ( Γ ( x ) ) = Γ′ ( x ) Γ ( x ) \digamma(x) = \frac{d}{dx} \ln\left(\Gamma\left(x\right)\right) = \frac{\Gamma'(x)}{\Gamma(x)} ϝ(x)=dxdln(Γ(x))=Γ(x)Γ′(x)
input (Tensor) – the tensor to compute the digamma function on
out (Tensor, optional) – the output tensor.
Note
This function is similar to SciPy’s scipy.special.digamma.
Note
From PyTorch 1.8 onwards, the digamma function returns -Inf for 0. Previously it returned NaN for 0.
Example:
>>> a = torch.tensor([1, 0.5]) >>> torch.special.digamma(a) tensor([-0.5772, -1.9635])
Computes the entropy on input
(as defined below), elementwise.
entr(x) = { − x ∗ ln ( x ) x > 0 0 x = 0.0 − ∞ x < 0 \begin{align} \text{entr(x)} = \begin{cases} -x * \ln(x) & x > 0 \\ 0 & x = 0.0 \\ -\infty & x < 0 \end{cases} \end{align} entr(x)=⎩ ⎨ ⎧−x∗ln(x)0−∞x>0x=0.0x<0
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.arange(-0.5, 1, 0.5) >>> a tensor([-0.5000, 0.0000, 0.5000]) >>> torch.special.entr(a) tensor([ -inf, 0.0000, 0.3466])
Computes the error function of input
. The error function is defined as follows:
e r f ( x ) = 2 π ∫ 0 x e − t2 d t \mathrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt erf(x)=π 2∫0xe−t2dt
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.erf(torch.tensor([0, -1., 10.])) tensor([ 0.0000, -0.8427, 1.0000])
Computes the complementary error function of input
. The complementary error function is defined as follows:
e r f c ( x ) = 1 − 2 π ∫ 0 x e − t2 d t \mathrm{erfc}(x) = 1 - \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt erfc(x)=1−π 2∫0xe−t2dt
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.erfc(torch.tensor([0, -1., 10.])) tensor([ 1.0000, 1.8427, 0.0000])
Computes the scaled complementary error function for each element of input
. The scaled complementary error function is defined as follows:
e r f c x ( x ) = ex2 e r f c ( x ) \mathrm{erfcx}(x) = e^{x^2} \mathrm{erfc}(x) erfcx(x)=ex2erfc(x)
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.erfcx(torch.tensor([0, -1., 10.])) tensor([ 1.0000, 5.0090, 0.0561])
Computes the inverse error function of input
. The inverse error function is defined in the range ( − 1 , 1 ) (-1, 1) (−1,1) as:
e r f i n v ( e r f ( x ) ) = x \mathrm{erfinv}(\mathrm{erf}(x)) = x erfinv(erf(x))=x
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.erfinv(torch.tensor([0, 0.5, -1.])) tensor([ 0.0000, 0.4769, -inf])
Computes the base two exponential function of input
.
y i = 2 x i y_{i} = 2^{x_{i}} yi=2xi
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.exp2(torch.tensor([0, math.log2(2.), 3, 4])) tensor([ 1., 2., 8., 16.])
Computes the expit (also known as the logistic sigmoid function) of the elements of input
.
out i = 1 1 + e − input i \text{out}_{i} = \frac{1}{1 + e^{-\text{input}_{i}}} outi=1+e−inputi1
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> t = torch.randn(4) >>> t tensor([ 0.9213, 1.0887, -0.8858, -1.7683]) >>> torch.special.expit(t) tensor([ 0.7153, 0.7481, 0.2920, 0.1458])
Computes the exponential of the elements minus 1 of input
.
y i = e x i − 1 y_{i} = e^{x_{i}} - 1 yi=exi−1
Note
This function provides greater precision than exp(x) - 1 for small values of x.
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.expm1(torch.tensor([0, math.log(2.)])) tensor([ 0., 1.])
Computes the regularized lower incomplete gamma function:
out i = 1 Γ ( input i ) ∫ 0 other i t input i − 1 e − t d t \text{out}_{i} = \frac{1}{\Gamma(\text{input}_i)} \int_0^{\text{other}_i} t^{\text{input}_i-1} e^{-t} dt outi=Γ(inputi)1∫0otheritinputi−1e−tdt
where both input i \text{input}_i inputi and other i \text{other}_i otheri are weakly positive and at least one is strictly positive. If both are zero or either is negative then out i = nan \text{out}_i=\text{nan} outi=nan. Γ ( ⋅ ) \Gamma(\cdot) Γ(⋅) in the equation above is the gamma function,
Γ ( input i ) = ∫ 0 ∞ t ( input i − 1 ) e − t d t . \Gamma(\text{input}_i) = \int_0^\infty t^{(\text{input}_i-1)} e^{-t} dt. Γ(inputi)=∫0∞t(inputi−1)e−tdt.
See torch.special.gammaincc()
and torch.special.gammaln()
for related functions.
Supports broadcasting to a common shape and float inputs.
Note
The backward pass with respect to input
is not yet supported. Please open an issue on PyTorch’s Github to request it.
out (Tensor, optional) – the output tensor.
Example:
>>> a1 = torch.tensor([4.0]) >>> a2 = torch.tensor([3.0, 4.0, 5.0]) >>> a = torch.special.gammaincc(a1, a2) tensor([0.3528, 0.5665, 0.7350]) tensor([0.3528, 0.5665, 0.7350]) >>> b = torch.special.gammainc(a1, a2) + torch.special.gammaincc(a1, a2) tensor([1., 1., 1.])
Computes the regularized upper incomplete gamma function:
out i = 1 Γ ( input i ) ∫ other i ∞ t input i − 1 e − t d t \text{out}_{i} = \frac{1}{\Gamma(\text{input}_i)} \int_{\text{other}_i}^{\infty} t^{\text{input}_i-1} e^{-t} dt outi=Γ(inputi)1∫otheri∞tinputi−1e−tdt
where both input i \text{input}_i inputi and other i \text{other}_i otheri are weakly positive and at least one is strictly positive. If both are zero or either is negative then out i = nan \text{out}_i=\text{nan} outi=nan. Γ ( ⋅ ) \Gamma(\cdot) Γ(⋅) in the equation above is the gamma function,
Γ ( input i ) = ∫ 0 ∞ t ( input i − 1 ) e − t d t . \Gamma(\text{input}_i) = \int_0^\infty t^{(\text{input}_i-1)} e^{-t} dt. Γ(inputi)=∫0∞t(inputi−1)e−tdt.
See torch.special.gammainc()
and torch.special.gammaln()
for related functions.
Supports broadcasting to a common shape and float inputs.
Note
The backward pass with respect to input
is not yet supported. Please open an issue on PyTorch’s Github to request it.
out (Tensor, optional) – the output tensor.
Example:
>>> a1 = torch.tensor([4.0]) >>> a2 = torch.tensor([3.0, 4.0, 5.0]) >>> a = torch.special.gammaincc(a1, a2) tensor([0.6472, 0.4335, 0.2650]) >>> b = torch.special.gammainc(a1, a2) + torch.special.gammaincc(a1, a2) tensor([1., 1., 1.])
Computes the natural logarithm of the absolute value of the gamma function on input
.
out i = ln Γ ( ∣ input i ∣ ) \text{out}_{i} = \ln \Gamma(|\text{input}_{i}|) outi=lnΓ(∣inputi∣)
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.arange(0.5, 2, 0.5) >>> torch.special.gammaln(a) tensor([ 0.5724, 0.0000, -0.1208])
Physicist’s Hermite polynomial H n ( input ) H_{n}(\text{input}) Hn(input).
If n = 0 n = 0 n=0, 1 1 1 is returned. If n = 1 n = 1 n=1, input \text{input} input is returned. Otherwise, the recursion:
H n + 1 ( input ) = 2 × input × H n ( input ) − H n − 1 ( input ) H_{n + 1}(\text{input}) = 2 \times \text{input} \times H_{n}(\text{input}) - H_{n - 1}(\text{input}) Hn+1(input)=2×input×Hn(input)−Hn−1(input)
is evaluated.
Probabilist’s Hermite polynomial H e n ( input ) He_{n}(\text{input}) Hen(input).
If n = 0 n = 0 n=0, 1 1 1 is returned. If n = 1 n = 1 n=1, input \text{input} input is returned. Otherwise, the recursion:
H e n + 1 ( input ) = 2 × input × H e n ( input ) − H e n − 1 ( input ) He_{n + 1}(\text{input}) = 2 \times \text{input} \times He_{n}(\text{input}) - He_{n - 1}(\text{input}) Hen+1(input)=2×input×Hen(input)−Hen−1(input)
is evaluated.
Computes the zeroth order modified Bessel function of the first kind for each element of input
.
out i = I 0 ( input i ) = ∑ k = 0 ∞ ( input i 2 / 4 )k ( k ! )2 \text{out}_{i} = I_0(\text{input}_{i}) = \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!)^2} outi=I0(inputi)=k=0∑∞(k!)2(inputi2/4)k
input (Tensor) – the input tensor
out (Tensor, optional) – the output tensor.
Example:
>>> torch.i0(torch.arange(5, dtype=torch.float32)) tensor([ 1.0000, 1.2661, 2.2796, 4.8808, 11.3019])
Computes the exponentially scaled zeroth order modified Bessel function of the first kind (as defined below) for each element of input
.
out i = exp ( − ∣ x ∣ ) ∗ i 0 ( x ) = exp ( − ∣ x ∣ ) ∗ ∑ k = 0 ∞ ( input i 2 / 4 )k ( k ! )2 \text{out}_{i} = \exp(-|x|) * i0(x) = \exp(-|x|) * \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!)^2} outi=exp(−∣x∣)∗i0(x)=exp(−∣x∣)∗k=0∑∞(k!)2(inputi2/4)k
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.i0e(torch.arange(5, dtype=torch.float32)) tensor([1.0000, 0.4658, 0.3085, 0.2430, 0.2070])
Computes the first order modified Bessel function of the first kind (as defined below) for each element of input
.
out i = ( input i ) 2 ∗ ∑ k = 0 ∞ ( input i 2 / 4 )k ( k ! ) ∗ ( k + 1 ) ! \text{out}_{i} = \frac{(\text{input}_{i})}{2} * \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!) * (k+1)!} outi=2(inputi)∗k=0∑∞(k!)∗(k+1)!(inputi2/4)k
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.i1(torch.arange(5, dtype=torch.float32)) tensor([0.0000, 0.5652, 1.5906, 3.9534, 9.7595])
Computes the exponentially scaled first order modified Bessel function of the first kind (as defined below) for each element of input
.
out i = exp ( − ∣ x ∣ ) ∗ i 1 ( x ) = exp ( − ∣ x ∣ ) ∗ ( input i ) 2 ∗ ∑ k = 0 ∞ ( input i 2 / 4 )k ( k ! ) ∗ ( k + 1 ) ! \text{out}_{i} = \exp(-|x|) * i1(x) = \exp(-|x|) * \frac{(\text{input}_{i})}{2} * \sum_{k=0}^{\infty} \frac{(\text{input}_{i}^2/4)^k}{(k!) * (k+1)!} outi=exp(−∣x∣)∗i1(x)=exp(−∣x∣)∗2(inputi)∗k=0∑∞(k!)∗(k+1)!(inputi2/4)k
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.i1e(torch.arange(5, dtype=torch.float32)) tensor([0.0000, 0.2079, 0.2153, 0.1968, 0.1788])
Laguerre polynomial L n ( input ) L_{n}(\text{input}) Ln(input).
If n = 0 n = 0 n=0, 1 1 1 is returned. If n = 1 n = 1 n=1, input \text{input} input is returned. Otherwise, the recursion:
L n + 1 ( input ) = 2 × input × L n ( input ) − L n − 1 ( input ) L_{n + 1}(\text{input}) = 2 \times \text{input} \times L_{n}(\text{input}) - L_{n - 1}(\text{input}) Ln+1(input)=2×input×Ln(input)−Ln−1(input)
is evaluated.
Legendre polynomial P n ( input ) P_{n}(\text{input}) Pn(input).
If n = 0 n = 0 n=0, 1 1 1 is returned. If n = 1 n = 1 n=1, input \text{input} input is returned. Otherwise, the recursion:
P n + 1 ( input ) = 2 × input × P n ( input ) − P n − 1 ( input ) P_{n + 1}(\text{input}) = 2 \times \text{input} \times P_{n}(\text{input}) - P_{n - 1}(\text{input}) Pn+1(input)=2×input×Pn(input)−Pn−1(input)
is evaluated.
Alias for torch.log1p()
.
Computes the log of the area under the standard Gaussian probability density function, integrated from minus infinity to input
, elementwise.
log_ndtr ( x ) = log ( 1 2 π ∫ − ∞ x e − 1 2 t2 d t ) \text{log\_ndtr}(x) = \log\left(\frac{1}{\sqrt{2 \pi}}\int_{-\infty}^{x} e^{-\frac{1}{2}t^2} dt \right) log_ndtr(x)=log(2π 1∫−∞xe−21t2dt)
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.log_ndtr(torch.tensor([-3., -2, -1, 0, 1, 2, 3])) tensor([-6.6077 -3.7832 -1.841 -0.6931 -0.1728 -0.023 -0.0014])
Computes softmax followed by a logarithm.
While mathematically equivalent to log(softmax(x)), doing these two operations separately is slower and numerically unstable. This function is computed as:
log_softmax ( x i ) = log ( exp ( x i ) ∑ j exp ( x j ) ) \text{log\_softmax}(x_{i}) = \log\left(\frac{\exp(x_i) }{ \sum_j \exp(x_j)} \right) log_softmax(xi)=log(∑jexp(xj)exp(xi))
input (Tensor) – input
dim (int) – A dimension along which log_softmax will be computed.
dtype (torch.dtype
, optional) – the desired data type of returned tensor. If specified, the input tensor is cast to dtype
before the operation is performed. This is useful for preventing data type overflows. Default: None.
Example:
>>> t = torch.ones(2, 2) >>> torch.special.log_softmax(t, 0) tensor([[-0.6931, -0.6931], [-0.6931, -0.6931]])
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.
y i = ln ( z i 1 − z i ) z i = { x i if eps is None eps if x i < eps x i if eps ≤ x i ≤ 1 − eps 1 − eps if x i > 1 − eps \begin{align} y_{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} \end{align} yizi=ln(1−zizi)=⎩ ⎨ ⎧xiepsxi1−epsif eps is Noneif xi<epsif eps≤xi≤1−epsif xi>1−eps
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.rand(5) >>> a tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516]) >>> torch.special.logit(a, eps=1e-6) tensor([-0.9466, 2.6352, 0.6131, -1.7169, 0.6261])
Alias for torch.logsumexp()
.
Modified Bessel function of the first kind of order 0 0 0.
Modified Bessel function of the first kind of order 1 1 1.
Modified Bessel function of the second kind of order 0 0 0.
Modified Bessel function of the second kind of order 1 1 1.
Computes the multivariate log-gamma function with dimension p p p element-wise, given by
log ( Γ p ( a ) ) = C + ∑ i = 1 p log ( Γ ( a − i − 1 2 ) ) \log(\Gamma_{p}(a)) = C + \displaystyle \sum_{i=1}^{p} \log\left(\Gamma\left(a - \frac{i - 1}{2}\right)\right) log(Γp(a))=C+i=1∑plog(Γ(a−2i−1))
where C = log ( π ) ⋅ p ( p − 1 ) 4 C = \log(\pi) \cdot \frac{p (p - 1)}{4} C=log(π)⋅4p(p−1) and Γ ( − ) \Gamma(-) Γ(−) is the Gamma function.
All elements must be greater than p − 1 2 \frac{p - 1}{2} 2p−1, otherwise the behavior is undefined.
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.empty(2, 3).uniform_(1, 2) >>> a tensor([[1.6835, 1.8474, 1.1929], [1.0475, 1.7162, 1.4180]]) >>> torch.special.multigammaln(a, 2) tensor([[0.3928, 0.4007, 0.7586], [1.0311, 0.3901, 0.5049]])
Computes the area under the standard Gaussian probability density function, integrated from minus infinity to input
, elementwise.
ndtr ( x ) = 1 2 π ∫ − ∞ x e − 1 2 t2 d t \text{ndtr}(x) = \frac{1}{\sqrt{2 \pi}}\int_{-\infty}^{x} e^{-\frac{1}{2}t^2} dt ndtr(x)=2π 1∫−∞xe−21t2dt
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.ndtr(torch.tensor([-3., -2, -1, 0, 1, 2, 3])) tensor([0.0013, 0.0228, 0.1587, 0.5000, 0.8413, 0.9772, 0.9987])
Computes the argument, x, for which the area under the Gaussian probability density function (integrated from minus infinity to x) is equal to input
, elementwise.
ndtri ( p ) = 2 erf − 1 ( 2 p − 1 ) \text{ndtri}(p) = \sqrt{2}\text{erf}^{-1}(2p - 1) ndtri(p)=2 erf−1(2p−1)
Note
Also known as quantile function for Normal Distribution.
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> torch.special.ndtri(torch.tensor([0, 0.25, 0.5, 0.75, 1])) tensor([ -inf, -0.6745, 0.0000, 0.6745, inf])
Computes the n t h n^{th} nth derivative of the digamma function on input
. n ≥ 0 n \geq 0 n≥0 is called the order of the polygamma function.
ψ ( n ) ( x ) = d ( n ) d x ( n ) ψ ( x ) \psi^{(n)}(x) = \frac{d^{(n)}}{dx^{(n)}} \psi(x) ψ(n)(x)=dx(n)d(n)ψ(x)
Note
This function is implemented only for nonnegative integers n ≥ 0 n \geq 0 n≥0.
out (Tensor, optional) – the output tensor.
Example:
>>> a = torch.tensor([1, 0.5]) >>> torch.special.polygamma(1, a) tensor([1.64493, 4.9348]) >>> torch.special.polygamma(2, a) tensor([ -2.4041, -16.8288]) >>> torch.special.polygamma(3, a) tensor([ 6.4939, 97.4091]) >>> torch.special.polygamma(4, a) tensor([ -24.8863, -771.4742])
Alias for torch.special.digamma()
.
Alias for torch.round()
.
Scaled modified Bessel function of the second kind of order 0 0 0.
Scaled modified Bessel function of the second kind of order 1 1 1.
Chebyshev polynomial of the first kind T n ∗ ( input ) T_{n}^{\ast}(\text{input}) Tn∗(input).
Chebyshev polynomial of the second kind U n ∗ ( input ) U_{n}^{\ast}(\text{input}) Un∗(input).
Chebyshev polynomial of the third kind V n ∗ ( input ) V_{n}^{\ast}(\text{input}) Vn∗(input).
Chebyshev polynomial of the fourth kind W n ∗ ( input ) W_{n}^{\ast}(\text{input}) Wn∗(input).
Computes the normalized sinc of input.
out i = { 1 , if input i = 0 sin ( π input i ) / ( π input i ) , otherwise \text{out}_{i} = \begin{cases} 1, & \text{if}\ \text{input}_{i}=0 \\ \sin(\pi \text{input}_{i}) / (\pi \text{input}_{i}), & \text{otherwise} \end{cases} outi={1,sin(πinputi)/(πinputi),if inputi=0otherwise
input (Tensor) – the input tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> t = torch.randn(4) >>> t tensor([ 0.2252, -0.2948, 1.0267, -1.1566]) >>> torch.special.sinc(t) tensor([ 0.9186, 0.8631, -0.0259, -0.1300])
Computes the softmax function.
Softmax is defined as:
Softmax ( x i ) = exp ( x i ) ∑ j exp ( x j ) \text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)} Softmax(xi)=∑jexp(xj)exp(xi)
It is applied to all slices along dim, and will re-scale them so that the elements lie in the range [0, 1] and sum to 1.
input (Tensor) – input
dim (int) – A dimension along which softmax will be computed.
dtype (torch.dtype
, optional) – the desired data type of returned tensor. If specified, the input tensor is cast to dtype
before the operation is performed. This is useful for preventing data type overflows. Default: None.
>>> t = torch.ones(2, 2) >>> torch.special.softmax(t, 0) tensor([[0.5000, 0.5000], [0.5000, 0.5000]])
Spherical Bessel function of the first kind of order 0 0 0.
Computes input * log1p(other)
with the following cases.
out i = { NaN if other i = NaN 0 if input i = 0.0 and other i ! = NaN input i ∗ log1p ( other i ) otherwise \text{out}_{i} = \begin{cases} \text{NaN} & \text{if } \text{other}_{i} = \text{NaN} \\ 0 & \text{if } \text{input}_{i} = 0.0 \text{ and } \text{other}_{i} != \text{NaN} \\ \text{input}_{i} * \text{log1p}(\text{other}_{i})& \text{otherwise} \end{cases} outi=⎩ ⎨ ⎧NaN0inputi∗log1p(otheri)if otheri=NaNif inputi=0.0 and otheri!=NaNotherwise
Similar to SciPy’s scipy.special.xlog1py.
Note
At least one of input
or other
must be a tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> x = torch.zeros(5,) >>> y = torch.tensor([-1, 0, 1, float('inf'), float('nan')]) >>> torch.special.xlog1py(x, y) tensor([0., 0., 0., 0., nan]) >>> x = torch.tensor([1, 2, 3]) >>> y = torch.tensor([3, 2, 1]) >>> torch.special.xlog1py(x, y) tensor([1.3863, 2.1972, 2.0794]) >>> torch.special.xlog1py(x, 4) tensor([1.6094, 3.2189, 4.8283]) >>> torch.special.xlog1py(2, y) tensor([2.7726, 2.1972, 1.3863])
Computes input * log(other)
with the following cases.
out i = { NaN if other i = NaN 0 if input i = 0.0 input i ∗ log ( other i ) otherwise \text{out}_{i} = \begin{cases} \text{NaN} & \text{if } \text{other}_{i} = \text{NaN} \\ 0 & \text{if } \text{input}_{i} = 0.0 \\ \text{input}_{i} * \log{(\text{other}_{i})} & \text{otherwise} \end{cases} outi=⎩ ⎨ ⎧NaN0inputi∗log(otheri)if otheri=NaNif inputi=0.0otherwise
Similar to SciPy’s scipy.special.xlogy.
Note
At least one of input
or other
must be a tensor.
out (Tensor, optional) – the output tensor.
Example:
>>> x = torch.zeros(5,) >>> y = torch.tensor([-1, 0, 1, float('inf'), float('nan')]) >>> torch.special.xlogy(x, y) tensor([0., 0., 0., 0., nan]) >>> x = torch.tensor([1, 2, 3]) >>> y = torch.tensor([3, 2, 1]) >>> torch.special.xlogy(x, y) tensor([1.0986, 1.3863, 0.0000]) >>> torch.special.xlogy(x, 4) tensor([1.3863, 2.7726, 4.1589]) >>> torch.special.xlogy(2, y) tensor([2.1972, 1.3863, 0.0000])
Computes the Hurwitz zeta function, elementwise.
ζ ( x , q ) = ∑ k = 0 ∞ 1 ( k + q )x \zeta(x, q) = \sum_{k=0}^{\infty} \frac{1}{(k + q)^x} ζ(x,q)=k=0∑∞(k+q)x1
Note
The Riemann zeta function corresponds to the case when q = 1
out (Tensor, optional) – the output tensor.
Example:
>>> x = torch.tensor([2., 4.]) >>> torch.special.zeta(x, 1) tensor([1.6449, 1.0823]) >>> torch.special.zeta(x, torch.tensor([1., 2.])) tensor([1.6449, 0.0823]) >>> torch.special.zeta(2, torch.tensor([1., 2.])) tensor([1.6449, 0.6449])
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4