pfhedge.nn.functional.topp¶
- pfhedge.nn.functional.topp(input, p, dim=None, largest=True)[source]¶
Returns the largest \(p * N\) elements of the given input tensor, where \(N\) stands for the total number of elements in the input tensor.
If
dimis not given, the last dimension of theinputis chosen.If
largestisFalsethen the smallest elements are returned.A namedtuple of
(values, indices)is returned, where theindicesare the indices of the elements in the originalinputtensor.See also
torch.topk(): Returns theklargest elements of the given input tensor along a given dimension.
- Parameters
input (torch.Tensor) – The input tensor.
p (float) – The quantile level.
dim (int, optional) – The dimension to sort along.
largest (bool, default=True) – Controls whether to return largest or smallest elements.
- Returns
Tuple[Tensor, LongTensor] (named tuple)
Examples
>>> from pfhedge.nn.functional import topp >>> >>> input = torch.arange(1.0, 6.0) >>> input tensor([1., 2., 3., 4., 5.]) >>> topp(input, 3 / 5) torch.return_types.topk( values=tensor([5., 4., 3.]), indices=tensor([4, 3, 2]))