quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) → Tensor¶
The documentation is referenced from: https://pytorch.org/docs/stable/generated/torch.quantile.html.
Computes the q-th quantiles of each row of the
inputtensor along the dimension
To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location of the quantile in the sorted input. If the quantile lies between two data points
a < bwith indices
jin the sorted order, result is computed according to the given
interpolationmethod as follows:
a + (b - a) * fraction, where
fractionis the fractional part of the computed quantile index.
b, whichever’s index is closer to the computed quantile index (rounding down for .5 fractions).
(a + b) / 2.
qis a 1D tensor, the first dimension of the output represents the quantiles and has size equal to the size of
q, the remaining dimensions are what remains from the reduction.
Noneresulting in the
inputtensor being flattened before computation.
input (oneflow.Tensor) – the input Tensor.
q (float or oneflow.Tensor) – a scalar or 1D tensor of values in the range [0, 1].
dim (int, optional) – the dimension to reduce. Default is None.
keepdim (bool, optional) – whether the output tensor has dim retained or not. Default is False
interpolation (str, optional) – interpolation method to use when the desired quantile lies between two data points. Can be
nearest. Default is
out (oneflow.Tensor, optional) – the output Tensor.
>>> import oneflow as flow >>> a = flow.arange(8.) >>> q = flow.tensor([0.25, 0.5, 0.75]) >>> flow.quantile(a, q, dim=0, keepdim=True) tensor([[1.7500], [3.5000], [5.2500]], dtype=oneflow.float32) >>> a = flow.arange(4.) >>> flow.quantile(a, 0.6, interpolation="linear") tensor(1.8000, dtype=oneflow.float32) >>> flow.quantile(a, 0.6, interpolation="lower") tensor(1., dtype=oneflow.float32) >>> flow.quantile(a, 0.6, interpolation="higher") tensor(2., dtype=oneflow.float32) >>> flow.quantile(a, 0.6, interpolation="midpoint") tensor(1.5000, dtype=oneflow.float32) >>> flow.quantile(a, 0.6, interpolation="nearest") tensor(2., dtype=oneflow.float32) >>> flow.quantile(a, 0.4, interpolation="nearest") tensor(1., dtype=oneflow.float32)