altx.extract_methods#
Statistical feature extraction methods for the altx algorithm.
- type altx.extract_methods.ExtrMethod = list[str] | list[str | float]#
- type altx.extract_methods.ExtrMethods = list[ExtrMethod]#
- class altx.extract_methods.ExtractMethods[source]#
Bases:
objectProvide statistical feature extraction methods for Altx.
Implement the most common statistical methods used for feature extraction in the Adaptive Law-Based Transformation.
- extract(F, extr_methods, device)[source]#
Extract features from F with the given extraction methods.
- static excess_kurtosis(percentiles)[source]#
Calculate the excess kurtosis of percentiles along dimension 1.
- Parameters:
percentiles (
Tensor) – Input tensor of pre-computed percentiles.- Returns:
The excess kurtosis of the computed percentiles.
- Return type:
Tensor
Examples
>>> import torch >>> from altx import ExtractMethods >>> p = torch.tensor([[[1.], [2.], [3.], [4.], [5.]]]) >>> print(ExtractMethods.excess_kurtosis(p)) tensor([[-1.3000]])
- static extract(F, extr_methods, device='cpu')[source]#
Extract features from F using the given extraction methods.
- Parameters:
F (
Tensor) – Input tensor.extr_methods (
list[list[str] |list[str|float]]) – Each element is either a one-element list[method]or a two-element list[method, percentile].device (
device|str) – The device to calculate on. Default is CPU.
- Returns:
The tensor of the collected features.
- Return type:
Tensor- Raises:
ValueError – If the given extraction method is not implemented.
Notes
The return tensor has the shape (n, m), where n is the number of used extraction methods and m is the size of the input tensor along the third dimension.
Examples
>>> import torch >>> from altx import ExtractMethods >>> F = torch.ones(5, 20, 2) >>> print(ExtractMethods.extract(F, [["mean", 0.5]])) tensor([[1., 1.]]) >>> print(ExtractMethods.extract(F, [["var", 0.5]])) tensor([[0., 0.]]) >>> # Note: Here None has to be given for the `mean_all` >>> print(ExtractMethods.extract(F, [["mean_all", None]])) tensor([[1., 1.]]) >>> _ = torch.manual_seed(0) >>> F2 = torch.randn(5, 20, 1).abs() + 0.5 >>> methods = [["mean", 0.05], ["var", 0.1], ["mean_all", None]] >>> print(ExtractMethods.extract(F2, methods)) tensor([[0.4577], [0.0499], [2.1054]])
- static nth_moment(percentiles, n=4)[source]#
Calculate the n-th moment of percentiles along dimension 1.
- Parameters:
percentiles (
Tensor) – Input tensor of pre-computed percentiles.n (
int) – The order of the moment to compute. Default is 4.
- Returns:
The n-th moment of the computed percentiles.
- Return type:
Tensor
Examples
>>> import torch >>> from altx import ExtractMethods >>> p = torch.tensor([[[1.], [2.], [3.], [4.], [5.]]]) >>> print(ExtractMethods.nth_moment(p, n=2)) tensor([[2.]]) >>> print(ExtractMethods.nth_moment(p, n=4)) tensor([[6.8000]])