qfeval_functions.functions.nankurtosis

nankurtosis(x, dim=(), unbiased=True, *, fisher=True, keepdim=False)[source]

Compute the kurtosis along specified dimensions, ignoring NaN values.

This function calculates the kurtosis (fourth standardized moment) of a tensor along the specified dimension(s), excluding NaN values from the computation. Kurtosis measures the “tailedness” of a probability distribution, indicating how much of the data is concentrated in the tails versus the center.

The kurtosis is computed as:

\[\kappa = \frac{\text{E}[(X - \mu)^4]}{\sigma^4}\]

where \(\mu\) is the mean and \(\sigma\) is the standard deviation, computed only over valid (non-NaN) values. When fisher is True (default), Fisher’s definition is used where normal distribution has kurtosis 0. When False, Pearson’s definition is used where normal distribution has kurtosis 3.

Parameters:
  • x (Tensor) – The input tensor containing values.

  • dim (Union[int, Tuple[int, ...]]) – The dimension(s) along which to compute the kurtosis. If not specified (default is empty tuple), computes over all dimensions.

  • unbiased (bool) – If True (default), uses unbiased estimation with bias correction. If False, uses biased estimation.

  • fisher (bool) – If True (default), uses Fisher’s definition (normal distribution has kurtosis 0). If False, uses Pearson’s definition (normal distribution has kurtosis 3).

  • keepdim (bool) – Whether the output tensor has dim retained or not. Default is False.

Returns:

The kurtosis values computed only over valid (non-NaN) values. The shape depends on the input dimensions and the keepdim parameter.

Return type:

Tensor

Example

>>> # Simple kurtosis with some NaN values
>>> x = torch.tensor([1.0, 2.0, nan, 4.0, 5.0, 6.0])
>>> QF.nankurtosis(x, dim=0)
tensor(-1.9632)
>>> # 2D tensor with kurtosis along columns
>>> x = torch.tensor([[1.0, nan, 3.0, 4.0],
...                   [2.0, 5.0, nan, 6.0],
...                   [3.0, 7.0, 8.0, nan]])
>>> QF.nankurtosis(x, dim=1)
tensor([-inf, inf, nan])
>>> # Pearson's definition (fisher=False)
>>> x = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0])
>>> QF.nankurtosis(x, dim=0, fisher=False)
tensor(6.8000)
>>> # With keepdim
>>> x = torch.tensor([[1.0, 2.0, nan],
...                   [4.0, nan, 6.0]])
>>> QF.nankurtosis(x, dim=1, keepdim=True)
tensor([[nan],
        [nan]])
>>> # Biased estimation
>>> x = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
>>> QF.nankurtosis(x, dim=0, unbiased=False)
tensor(-1.2686)

See also

nanskew(): NaN-aware skewness function. nanvar(): NaN-aware variance function. nanstd(): NaN-aware standard deviation function.