1+ """Statistical moments analysis module for signal processing.
2+
3+ This module provides tools for computing various statistical moments from
4+ multivariate signal data. Statistical moments characterize the shape and
5+ properties of probability distributions and are fundamental in signal analysis.
6+
7+ The available statistical moments include:
8+ 1. Mean - Central tendency of the data
9+ 2. Standard Deviation - Dispersion around the mean
10+ 3. Skewness - Asymmetry of the distribution
11+ 4. Kurtosis - Tailedness of the distribution
12+
13+ Typical use cases include:
14+ 1. Signal characterization and feature extraction
15+ 2. Quality assessment of sensor data
16+ 3. Motion pattern analysis in movement data
17+ 4. Anomaly detection in time series data
18+ 5. Distribution analysis in multivariate signals
19+
20+ References
21+ ----------
22+ 1. Pearson, K. (1895). Contributions to the Mathematical Theory of Evolution.
23+ 2. Fisher, R. A. (1925). Statistical Methods for Research Workers.
24+ """
25+
26+ import numpy as np
27+ from scipy import stats
28+ from pyeyesweb .data_models .sliding_window import SlidingWindow
29+
30+
31+ class StatisticalMoment :
32+ """Real time statistical moments analyzer for signal data.
33+
34+ This class computes various statistical moments (mean, standard deviation,
35+ skewness, kurtosis) from sliding window data to characterize signal
36+ distributions and properties.
37+ """
38+
39+ def __init__ (self ):
40+ # No parameters in constructor as per comments
41+ pass
42+
43+ def compute_statistics (self , signals : SlidingWindow , methods : list ) -> dict :
44+ """Compute statistical analysis for multivariate signals.
45+
46+ Parameters
47+ ----------
48+ signals : SlidingWindow
49+ Sliding window buffer containing multivariate signal data.
50+ methods : list of str
51+ List of statistical methods to compute. Available options:
52+ 'mean', 'std_dev', 'skewness', 'kurtosis'
53+
54+ Returns
55+ -------
56+ dict
57+ Dictionary containing statistical metrics.
58+ """
59+ if not signals .is_full ():
60+ return np .nan
61+
62+ data , _ = signals .to_array ()
63+ n_samples , n_features = data .shape
64+
65+ if n_samples < 2 :
66+ return np .nan
67+
68+ result = {}
69+
70+ # Compute only the requested statistical moments
71+ for method in methods :
72+ if method == 'mean' :
73+ values = np .mean (data , axis = 0 )
74+ result ['mean' ] = float (values [0 ]) if len (values ) == 1 else values .tolist ()
75+
76+ elif method == 'std_dev' :
77+ values = np .std (data , axis = 0 , ddof = 1 )
78+ result ['std' ] = float (values [0 ]) if len (values ) == 1 else values .tolist ()
79+
80+ elif method == 'skewness' :
81+ values = stats .skew (data , axis = 0 )
82+ result ['skewness' ] = float (values [0 ]) if len (values ) == 1 else values .tolist ()
83+
84+ elif method == 'kurtosis' :
85+ values = stats .kurtosis (data , axis = 0 )
86+ result ['kurtosis' ] = float (values [0 ]) if len (values ) == 1 else values .tolist ()
87+
88+ else :
89+ # Skip invalid methods silently
90+ continue
91+
92+ return result
93+
94+ def __call__ (self , sliding_window : SlidingWindow , methods : list ) -> dict :
95+ """Compute statistical metrics.
96+
97+ Parameters
98+ ----------
99+ sliding_window : SlidingWindow
100+ Buffer containing multivariate data to analyze.
101+ methods : list of str
102+ List of statistical methods to compute.
103+
104+ Returns
105+ -------
106+ dict
107+ Dictionary containing statistical metrics.
108+ """
109+ return self .compute_statistics (sliding_window , methods )
0 commit comments