plenoptic.process.kurtosis#
- plenoptic.process.kurtosis(x, mean=None, var=None, dim=None, keepdim=False)[source]#
Calculate sample estimate of tailedness (presence of outliers).
To help with interpretation:
Kurtosis of univariate normal is 3.
Smaller than 3: platykurtic (e.g. uniform distribution).
Greater than 3: leptokurtic (e.g. Laplace distribution).
- Parameters:
x (
Tensor) – The input tensor.mean (
float|Tensor|None(default:None)) – Reuse a precomputed mean.var (
float|Tensor|None(default:None)) – Reuse a precomputed variance.dim (
int|list[int] |None(default:None)) – The dimension or dimensions to reduce.keepdim (
bool(default:False)) – Whether to retain the reduced dimensions (as singletons) or not.
- Return type:
- Returns:
out – The kurtosis tensor.
Examples
>>> import plenoptic as po >>> import matplotlib.pyplot as plt >>> import torch >>> po.set_seed(42) >>> x = torch.randn(10000) >>> k = po.process.kurtosis(x) >>> x_platy = torch.rand(10000) * 10 - 5 >>> k_platy = po.process.kurtosis(x_platy) >>> x_lepto = torch.distributions.Laplace(loc=0.0, scale=1.0).sample((10000,)) >>> k_lepto = po.process.kurtosis(x_lepto) >>> fig, (ax_platy, ax, ax_lepto) = plt.subplots( ... 1, 3, sharex=True, figsize=(12, 4) ... ) >>> _ = ax_platy.hist(x_platy.numpy(), bins=50) >>> _ = ax_platy.set( ... title=f"Platykurtic (Uniform)\nKurtosis: {k_platy:.4f}", ... ylabel="Frequency", ... xlim=(-5, 5), ... ) >>> _ = ax.hist(x.numpy(), bins=50) >>> _ = ax.set(title=f"Standard Gaussian\nKurtosis: {k:.4f}") >>> _ = ax_lepto.hist(x_lepto.numpy(), bins=50) >>> _ = ax_lepto.set(title=f"Leptokurtic (Laplace)\nKurtosis: {k_lepto:.4f}")
If you have precomputed the mean and/or variance, you can pass them and avoid recomputing:
>>> precomputed_mean = torch.mean(x) >>> precomputed_var = variance(x) >>> k = po.process.kurtosis(x, mean=precomputed_mean, var=precomputed_var) >>> k tensor(2.9354)
If you want to compute along a specific dimension, you can specify it:
>>> x = torch.randn(10000, 2) >>> k = po.process.kurtosis(x, dim=0) >>> k tensor([3.0057, 2.9506])