qfeval_functions.functions.mmax
- mmax(x, span, dim=-1)[source]
Compute the moving (sliding window) maximum of a tensor.
This function calculates the maximum value within a sliding window of size
spanalong the specified dimension. The output tensor has the same shape as the input tensor. For positions where the sliding window cannot fully cover preceding elements (i.e., the firstspan - 1elements along the selected dimension), the result is computed using available values by padding with the first element.The moving maximum is computed as:
\[\text{MMAX}[i] = \max_{j=\max(0, i-\text{span}+1)}^{i} x[j]\]- Parameters:
- Returns:
A tensor of the same shape as the input, containing the moving maximum values.
- Return type:
Example
>>> # Simple moving maximum with window size 3 >>> x = torch.tensor([1.0, 5.0, 3.0, 8.0, 2.0]) >>> QF.mmax(x, span=3) tensor([1., 5., 5., 8., 8.])
>>> # 2D tensor with moving maximum along columns >>> x = torch.tensor([[1.0, 4.0, 2.0, 6.0], ... [3.0, 1.0, 5.0, 2.0], ... [2.0, 7.0, 3.0, 4.0]]) >>> QF.mmax(x, span=2, dim=1) tensor([[1., 4., 4., 6.], [3., 3., 5., 5.], [2., 7., 7., 4.]])
>>> # Moving maximum along the first dimension >>> x = torch.tensor([[1.0, 2.0], ... [4.0, 1.0], ... [2.0, 5.0], ... [3.0, 2.0]]) >>> QF.mmax(x, span=3, dim=0) tensor([[1., 2.], [4., 2.], [4., 5.], [4., 5.]])
>>> # Handling negative values >>> x = torch.tensor([-2.0, -1.0, -5.0, -3.0, -1.0]) >>> QF.mmax(x, span=2) tensor([-2., -1., -1., -3., -1.])