sigpyproc.core.stats#
Statistical functions for computing moments of data.
This module contains functions for computing statistical moments of data.
Classes
A class to compute the central moments of filterbank data in one pass. |
|
Container for Z-score calculation results. |
Functions
Downsample a 1D array by reduction factor using a specified method. |
|
Downsample a 2D array by averaging over bins in both dimensions. |
|
Downsample a flattened 2D array by averaging over bins in both dimensions. |
|
Estimate the location (central tendency) of an array. |
|
Estimate the scale (variability) or standard deviation of an array. |
|
Calculate robust Z-scores of an array. |
|
Calculate the running filter of an array. |
|
Calculate an approximate running filter of an array. |
- class sigpyproc.core.stats.ChannelStats(nchans, nsamps)[source]#
Bases:
objectA class to compute the central moments of filterbank data in one pass.
- Parameters:
- Attributes:
nchansGet the number of channels.
nsampsGet the number of samples.
momentsGet the central moments of the data.
maximaGet the maximum value of each channel.
minimaGet the minimum value of each channel.
meanGet the mean of each channel.
varGet the variance of each channel.
stdGet the standard deviation of each channel.
skewGet the skewness of each channel.
kurtosisGet the kurtosis of each channel.
Methods
push_data(array, start_index[, mode])Update the central moments of the data with new samples.
References
[1]Wikipedia, “Algorithms for calculating variance”, https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm
[2]John D. Cook, “Skewness and kurtosis formulas for normal distributions”, https://www.johndcook.com/blog/skewness_kurtosis/
[3]Pebay, Philippe P., “One-Pass covariances and Statistical Moments”, https://doi.org/10.2172/1028931
- property moments#
Get the central moments of the data.
- Returns:
ndarrayThe central moments of the data.
- property maxima#
Get the maximum value of each channel.
- Returns:
ndarrayThe maximum value of each channel.
- property minima#
Get the minimum value of each channel.
- Returns:
ndarrayThe minimum value of each channel.
- property std#
Get the standard deviation of each channel.
- Returns:
ndarrayThe standard deviation of each channel.
- push_data(array, start_index, mode='basic')[source]#
Update the central moments of the data with new samples.
- Parameters:
- array
ndarray The input array to update the moments with.
- start_index
int The starting time (sample) index of the data.
- mode{“basic”, “full”}, optional
The mode to use for computing the moments, by default “basic”.
“basic” : Compute the moments upto 2nd order (variance).
“full” : Compute the moments upto 4th order (kurtosis).
- array
- class sigpyproc.core.stats.ZScoreResult(*, data, loc, scale)[source]#
Bases:
objectContainer for Z-score calculation results.
- Parameters:
- Attributes:
- data
- loc
- scale
- data#
- loc#
- scale#
- sigpyproc.core.stats.downsample_1d(array, factor, method='mean')[source]#
Downsample a 1D array by reduction factor using a specified method.
Remainder samples are dropped.
- Parameters:
- Returns:
ndarrayThe downsampled array.
- Raises:
ValueErrorIf the
methodis not supported.
- sigpyproc.core.stats.downsample_2d(array, factors, method='mean')[source]#
Downsample a 2D array by averaging over bins in both dimensions.
- Parameters:
- array
np.ndarray Input 2D array to be downsampled.
- factors
tuple[int,int] Downsampling factors (factor1, factor2) for each dimension. Must be positive integers.
- method{“mean”, “median”}, optional
Downsampling method, by default “mean”.
- array
- Returns:
np.ndarrayDownsampled array with same layout as input.
- sigpyproc.core.stats.downsample_2d_flat(array, factor1, factor2, dim1, dim2, method='mean')[source]#
Downsample a flattened 2D array by averaging over bins in both dimensions.
- Parameters:
- array
np.ndarray Input flattened 2D array to be downsampled.
- factor1
int Downsampling factor for the first dimension. Must be a positive integer.
- factor2
int Downsampling factor for the second dimension. Must be a positive integer.
- dim1
int Number of bins in the first dimension.
- dim2
int Number of bins in the second dimension.
- method{“mean”, “median”}, optional
Downsampling method, by default “mean”.
- array
- Returns:
np.ndarrayDownsampled flattened 2D array
Notes
dim2 must ve the fastest varying dimension.
- sigpyproc.core.stats.estimate_loc(data, method='median', axis=None, *, keepdims=False)[source]#
Estimate the location (central tendency) of an array.
- Parameters:
- data
ArrayLike Input array or object that can be converted to an array.
- method{“median”, “mean”}, optional
The method to use for estimating the location, by default “median”.
- axis
int|tuple[int, …] |None, optional Axis or axes along which to compute the location, by default None.
- keepdims
bool, optional If True, the reduced axis is kept in the result, by default True.
- data
- Returns:
- Raises:
ValueErrorIf the
arrayis empty or if themethodis not supported.
- sigpyproc.core.stats.estimate_scale(data, method='mad', axis=None, *, keepdims=False)[source]#
Estimate the scale (variability) or standard deviation of an array.
- Parameters:
- data
ArrayLike Input array or object that can be converted to an array.
- method{“std”, “iqr”, “mad”, “doublemad”, “diffcov”, “biweight”, “qn”, “sn”, “gapper”}, optional
The method to use for estimating the scale, by default “mad”.
std: Standard Deviation.iqr: Normalized Inter-quartile Range.mad: Median Absolute Deviation.doublemad: Double MAD.diffcov: Difference Covariancebiweight: Biweight Midvarianceqn: Normalized Qn scalesn: Normalized Sn scalegapper: Gapper Estimator
- axis
int|tuple[int, …] |None, optional Axis or axes along which to compute the scale, by default None.
- keepdims
bool, optional If True, the reduced axis is kept in the result, by default True.
- data
- Returns:
- Raises:
ValueErrorIf the
arrayis empty or if themethodis not supported.
References
[1]Wikipedia, “Robust measures of scale”, https://en.wikipedia.org/wiki/Robust_measures_of_scale
- sigpyproc.core.stats.estimate_zscore(data, loc_method='median', scale_method='mad', axis=0)[source]#
Calculate robust Z-scores of an array.
- Parameters:
- data
ArrayLike Input array or object that can be converted to an array.
- loc_method{“median”, “mean”, “norm”}, optional
The method to use for estimating the location, by default “median”.
Use “norm” to set the location to 0.
- scale_method{“std”, “iqr”, “mad”, “doublemad”, “diffcov”, “biweight”, “qn”, “sn”, “gapper”, “norm”}, optional
The method to use for estimating the scale, by default “mad”.
Use “norm” to set the scale to 1.
- axis
int|None, optional Axis along which to compute the Z-scores, by default 0.
- data
- Returns:
ZScoreResultA container with the Z-scores, estimated location, and scale.
- Raises:
ValueErrorIf the
loc_methodorscale_methodis not supported.
See also
- sigpyproc.core.stats.running_filter(array, window, method='mean')[source]#
Calculate the running filter of an array.
Applies a sliding window filter to the input array using the specified method. Window edges are handled by reflecting about the edges of the input array.
- Parameters:
- Returns:
ndarrayThe filtered array with the same shape as the input array.
- Raises:
ValueErrorIf the
methodis not supported.
- sigpyproc.core.stats.running_filter_fast(array, window, method='mean', min_points=101)[source]#
Calculate an approximate running filter of an array.
Downsamples the input array, apply the running filter, and then interpolate back to the original size. This is faster than the regular running filter for large arrays.
- Parameters:
- array
ndarray The input array to filter.
- window
int The size of the sliding window.
- method{“mean”, “median”}, optional
The filtering method to use, by default “mean”.
- min_points
int, optional The minimum number of nsamples for the downsampled array, by default 101. Lower values will result in faster processing but less accurate results.
- array
- Returns:
ndarrayThe filtered array with the same shape as the input array.