statmoments 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- statmoments-0.1.0/LICENSE +21 -0
- statmoments-0.1.0/PKG-INFO +28 -0
- statmoments-0.1.0/README.md +115 -0
- statmoments-0.1.0/setup.cfg +60 -0
- statmoments-0.1.0/setup.py +83 -0
- statmoments-0.1.0/statmoments/__init__.py +23 -0
- statmoments-0.1.0/statmoments/_native.c +69127 -0
- statmoments-0.1.0/statmoments/_native_shim.py +39 -0
- statmoments-0.1.0/statmoments/_statmoments_impl.py +359 -0
- statmoments-0.1.0/statmoments/_version.py +1 -0
- statmoments-0.1.0/statmoments/benchmark/__init__.py +0 -0
- statmoments-0.1.0/statmoments/benchmark/__main__.py +4 -0
- statmoments-0.1.0/statmoments/benchmark/bench_bivar.py +239 -0
- statmoments-0.1.0/statmoments/benchmark/benchlib.py +82 -0
- statmoments-0.1.0/statmoments/bivar.py +51 -0
- statmoments-0.1.0/statmoments/stattests.py +77 -0
- statmoments-0.1.0/statmoments/tests/__init__.py +0 -0
- statmoments-0.1.0/statmoments/tests/__main__.py +14 -0
- statmoments-0.1.0/statmoments/tests/test_bivar.py +235 -0
- statmoments-0.1.0/statmoments/tests/test_connect.py +148 -0
- statmoments-0.1.0/statmoments/tests/test_stattest.py +460 -0
- statmoments-0.1.0/statmoments/tests/test_univar.py +172 -0
- statmoments-0.1.0/statmoments/univar.py +41 -0
- statmoments-0.1.0/statmoments.egg-info/PKG-INFO +28 -0
- statmoments-0.1.0/statmoments.egg-info/SOURCES.txt +28 -0
- statmoments-0.1.0/statmoments.egg-info/dependency_links.txt +1 -0
- statmoments-0.1.0/statmoments.egg-info/not-zip-safe +1 -0
- statmoments-0.1.0/statmoments.egg-info/requires.txt +4 -0
- statmoments-0.1.0/statmoments.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Anton Kochepasov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: statmoments
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast streaming bivariate statistics and t-test
|
|
5
|
+
Author: Anton Kochepasov
|
|
6
|
+
Author-email: akss@me.com
|
|
7
|
+
Keywords: data-science,bivariate,statistics,streaming,numpy,vectorization
|
|
8
|
+
Platform: any
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Cython
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
28
|
+
License-File: LICENSE
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# statmoments
|
|
2
|
+
|
|
3
|
+
Fast streaming univariate and bivariate moments and t-statistics.
|
|
4
|
+
|
|
5
|
+
statmoments is a library for fast streaming one pass computation of univariate and bivariate moments and statistics for batch of multiple of waveforms or traces with thousands of sample points. Given the data sorting with classifier, it can compute Welch's t-test statistics of various orders for arbitrary data partitioning to allow finding relationships and statistical differences among many data splits, which are unknown beforehand. statmoments uses best of class BLAS implementation and preprocesses input data to take the most of computational power and perform computations as fast as possible.
|
|
6
|
+
|
|
7
|
+
## How is that different?
|
|
8
|
+
|
|
9
|
+
When the difference in input data is really subtle, millions of waveforms should be processed to find the statistical significant difference. Therefore, computationally efficient algorithms for analysing such volumes of data are crucial for practical use. Due to their nature, computing high-order moments and statistics requires 2- or 3-pass computations. However, not all the data can fit into the available memory. In another case, after initial input has been processed, new data may appear, which requires starting the process over. When the input waveforms contains many thousands of sample points, it adds another dimension to an already complex problem.
|
|
10
|
+
|
|
11
|
+
This can be overcome with a streaming approach. A streaming algorithm examines a sequence of inputs in a single pass, it processes data as it is collected, without waiting for it to be pre-collected and stored in a persistent storage. Streaming computation is often used to process data from real-time sources, such as oscilloscopes, sensors as well as financial markets. It can also be used to process large datasets that are too large to fit in memory or to process data that is constantly changing. Another name for such an approach is an online algorithm.
|
|
12
|
+
|
|
13
|
+
This library implements streaming algorithms to avoid recomputation, stores intermediate data in the accumulator. The algorithm also takes in the account that covariance and higher matrices are represented by a symmetric matrix, decreasing the memory requirement two-fold. The data update is blazingly fast and at any moment the internal accumulator can be converted to to (co-)moments on demand and the moments in turn can be converted to t-statistics with Welch's t-test. Once more data collected, it can be iteratively processed, increasing the precision of the moments, and discarded. The computation is optimized to consume significant input streams, hundreds of megabytes per second of waveforms, which may contain thousands of points.
|
|
14
|
+
Yet another dimension can be added when the data split is unknown. In other words, which bucket the input waveform belongs to. This library solves this with pre-classification of the input data and computing moments for all the requested data splits.
|
|
15
|
+
|
|
16
|
+
Some of the benefits of streaming computation include:
|
|
17
|
+
|
|
18
|
+
- Real-time insights from the data, such as identifying trends and detecting anomalies.
|
|
19
|
+
- Reduced latency of data processing, as the data is processed as generated and then discarded. This is important for applications where time is critical, from financial trading to online gaming.
|
|
20
|
+
- Scalability: Streaming computation can handle large volumes of data. This is important for research that generates large amounts of data, such as astrophysics and financial analysis.
|
|
21
|
+
|
|
22
|
+
## Where is this needed?
|
|
23
|
+
|
|
24
|
+
Univariate statistics are used in various fields and contexts to analyze and describe the characteristics of a single variable or data set. Common applications can be:
|
|
25
|
+
|
|
26
|
+
- Descriptive Statistics: summarizing and describing the central tendency, dispersion, and shape of a dataset.
|
|
27
|
+
- Hypothesis Testing: testing hypothesis to determine if there are significant differences or relationships between groups or conditions.
|
|
28
|
+
- Finance and Economics: Examining the performance of financial assets, track market trends, and assess risk in real time.
|
|
29
|
+
|
|
30
|
+
In summary, univariate statistics are a fundamental tool in data analysis and are widely used across a range of fields to explore, summarize, and draw conclusions from single-variable data. They provide essential insights into the characteristics and behavior of individual variables, which can inform decision-making and further research.
|
|
31
|
+
|
|
32
|
+
Bivariate statistics is a tool for understanding the relationships between two variables. Researchers and practitioners use it in a wide range of fields to make informed decisions and improve outcomes. The can be used to answer a variety of questions, such as:
|
|
33
|
+
|
|
34
|
+
- Is there a statistically significant relationship between variables?
|
|
35
|
+
- Which data points are related?
|
|
36
|
+
- If any, how strong is the relationship?
|
|
37
|
+
- Can we use one variable to predict the other variable?
|
|
38
|
+
|
|
39
|
+
These statistical methods are used in medical and bioinformatics research, astrophysics, seismology, market predictions, and many more where the input data may be measured in hundreds of gigabytes.
|
|
40
|
+
|
|
41
|
+
## Examples
|
|
42
|
+
|
|
43
|
+
Performing univariate data analysis
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
# Input data parameters
|
|
47
|
+
tr_count = 100 # M input waveforms
|
|
48
|
+
tr_len = 5 # N features or points in the input waveforms
|
|
49
|
+
cl_len = 2 # L hypotheses how to split input waveforms
|
|
50
|
+
|
|
51
|
+
# Create engine, which can compute up to kurtosis
|
|
52
|
+
uveng = statmoments.Univar(tr_len, cl_len, moment=4)
|
|
53
|
+
|
|
54
|
+
# Process input data and split hypotheses
|
|
55
|
+
uveng.update(wforms1, classification1)
|
|
56
|
+
|
|
57
|
+
# Process more input data and split hypotheses
|
|
58
|
+
uveng.update(wforms2, classification2)
|
|
59
|
+
|
|
60
|
+
# Get statistical moments
|
|
61
|
+
mean = [cm.copy() for cm in uveng.moments(moments=1)]
|
|
62
|
+
skeweness = [cm.copy() for cm in uveng.moments(moments=3)]
|
|
63
|
+
|
|
64
|
+
# Detect statistical differences in the first order t-test
|
|
65
|
+
for i, tt in enumerate(statmoments.stattests.ttests(uveng, moment=1)):
|
|
66
|
+
if np.any(np.abs(tt) > 5):
|
|
67
|
+
print(f"Data split {i} has different means")
|
|
68
|
+
|
|
69
|
+
# Process more input data and split hypotheses
|
|
70
|
+
uveng.update(wforms3, classification3)
|
|
71
|
+
|
|
72
|
+
# Get updated statistical moments and t-tests
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Performing bivariate data analysis
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# Input data parameters
|
|
79
|
+
tr_count = 100 # M input waveforms
|
|
80
|
+
tr_len = 5 # N features or points in the input waveforms
|
|
81
|
+
cl_len = 2 # L hypotheses how to split input waveforms
|
|
82
|
+
|
|
83
|
+
# Create bivariate engine, which can compute up to co-kurtosis
|
|
84
|
+
bveng = statmoments.Bivar(tr_len, cl_len, moment=4)
|
|
85
|
+
|
|
86
|
+
# Process input data and split hypotheses
|
|
87
|
+
bveng.update(wforms1, classification1)
|
|
88
|
+
|
|
89
|
+
# Process more input data and split hypotheses
|
|
90
|
+
bveng.update(wforms2, classification2)
|
|
91
|
+
|
|
92
|
+
# Get bivariate moments
|
|
93
|
+
covariance = [cm.copy() for cm in bveng.comoments(moments=(1, 1))]
|
|
94
|
+
cokurtosis22 = [cm.copy() for cm in bveng.comoments(moments=(2, 2))]
|
|
95
|
+
cokurtosis13 = [cm.copy() for cm in bveng.comoments(moments=(1, 3))]
|
|
96
|
+
|
|
97
|
+
# univariate statistical moments are also can be obtained
|
|
98
|
+
variance = [cm.copy() for cm in bveng.moments(moments=2)]
|
|
99
|
+
|
|
100
|
+
# Detect statistical differences in the second order t-test (covariances)
|
|
101
|
+
for i, tt in enumerate(statmoments.stattests.ttests(bveng, moment=(1,1))):
|
|
102
|
+
if np.any(np.abs(tt) > 5):
|
|
103
|
+
print(f"Found stat diff in the split {i}")
|
|
104
|
+
|
|
105
|
+
# Process more input data and split hypotheses
|
|
106
|
+
bveng.update(wforms3, classification3)
|
|
107
|
+
|
|
108
|
+
# Get updated statistical moments and t-tests
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
More examples can be found in the examples and tests directories.
|
|
112
|
+
|
|
113
|
+
## Installation
|
|
114
|
+
|
|
115
|
+
pip install -e .
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
description = Fast streaming bivariate statistics and t-test
|
|
3
|
+
classifiers =
|
|
4
|
+
Development Status :: 4 - Beta
|
|
5
|
+
Intended Audience :: Developers
|
|
6
|
+
Intended Audience :: Science/Research
|
|
7
|
+
Intended Audience :: Financial and Insurance Industry
|
|
8
|
+
License :: OSI Approved :: MIT License
|
|
9
|
+
Operating System :: OS Independent
|
|
10
|
+
Programming Language :: Cython
|
|
11
|
+
Programming Language :: Python
|
|
12
|
+
Programming Language :: Python :: 3
|
|
13
|
+
Programming Language :: Python :: 3.6
|
|
14
|
+
Programming Language :: Python :: 3.7
|
|
15
|
+
Programming Language :: Python :: 3.8
|
|
16
|
+
Programming Language :: Python :: 3.9
|
|
17
|
+
Programming Language :: Python :: 3.10
|
|
18
|
+
Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Topic :: Scientific/Engineering :: Image Processing
|
|
20
|
+
Topic :: Scientific/Engineering :: Information Analysis
|
|
21
|
+
Topic :: Scientific/Engineering :: Mathematics
|
|
22
|
+
Topic :: Scientific/Engineering :: Physics
|
|
23
|
+
keywords = data-science,bivariate,statistics,streaming,numpy,vectorization
|
|
24
|
+
platforms = any
|
|
25
|
+
|
|
26
|
+
[options]
|
|
27
|
+
zip_safe = False
|
|
28
|
+
install_requires =
|
|
29
|
+
h5py
|
|
30
|
+
numpy
|
|
31
|
+
scipy
|
|
32
|
+
psutil
|
|
33
|
+
setup_requires =
|
|
34
|
+
cython
|
|
35
|
+
|
|
36
|
+
[flake8]
|
|
37
|
+
ignore = E111,E114,E226,E231,E241,E272,E221
|
|
38
|
+
per-file-ignores =
|
|
39
|
+
__init__.py: F401
|
|
40
|
+
_statmoments_impl.py: F401
|
|
41
|
+
_native_shim.py: E402,F401,F403
|
|
42
|
+
bench_bivar.py: E121,E122,E201,E262,E265
|
|
43
|
+
examples/bivar.py: F841
|
|
44
|
+
examples/univar.py: F841
|
|
45
|
+
exclude =
|
|
46
|
+
.git,
|
|
47
|
+
__pycache__,
|
|
48
|
+
build
|
|
49
|
+
max-line-length = 160
|
|
50
|
+
statistics = yes
|
|
51
|
+
|
|
52
|
+
[pep8]
|
|
53
|
+
ignore = E111,E114,E226,E231,E241,E272,E221
|
|
54
|
+
max-line-length = 160
|
|
55
|
+
statistics = yes
|
|
56
|
+
|
|
57
|
+
[egg_info]
|
|
58
|
+
tag_build =
|
|
59
|
+
tag_date = 0
|
|
60
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import setuptools
|
|
6
|
+
|
|
7
|
+
from Cython.Build import cythonize
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
if sys.version_info < (3, 6, 0):
|
|
11
|
+
# It should work even with 2.7, just never really tested
|
|
12
|
+
raise RuntimeError("statmoments requires Python 3.6 or later")
|
|
13
|
+
|
|
14
|
+
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
15
|
+
USE_CYTHON = os.path.isfile(os.path.join(basedir, "statmoments/_native.pyx"))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def make_ext(modname, filename):
|
|
19
|
+
# This function required for in-place pyximport compilation over pyxbld
|
|
20
|
+
compile_args, link_args = [], []
|
|
21
|
+
|
|
22
|
+
if False:
|
|
23
|
+
pass
|
|
24
|
+
elif sys.platform == 'linux':
|
|
25
|
+
compile_args.extend(['-flto']) # Link-time code generation
|
|
26
|
+
link_args.extend(['-flto']) # Link-time code generation
|
|
27
|
+
pass
|
|
28
|
+
elif sys.platform == 'win32':
|
|
29
|
+
# Debugging
|
|
30
|
+
# compile_args.extend(['/Zi']) # Simple PDB format
|
|
31
|
+
# link_args.extend(['/DEBUG']) # Output PDB in link time
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
ext = setuptools.Extension(modname,
|
|
35
|
+
[filename],
|
|
36
|
+
extra_compile_args=compile_args,
|
|
37
|
+
extra_link_args=link_args)
|
|
38
|
+
return ext
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def get_version():
|
|
42
|
+
_version_dict = {}
|
|
43
|
+
version_path = os.path.join(basedir, 'statmoments/_version.py')
|
|
44
|
+
with open(version_path) as h:
|
|
45
|
+
exec(h.read(), None, _version_dict)
|
|
46
|
+
return _version_dict['__version__']
|
|
47
|
+
|
|
48
|
+
# TODO: Add CUDA
|
|
49
|
+
# from Cython.Distutils import build_ext
|
|
50
|
+
# class build_ext_cupy(build_ext):
|
|
51
|
+
# def __init__(self, *argc, **kw):
|
|
52
|
+
# super().__init__(*argc, **kw)
|
|
53
|
+
# cythonize_options = {
|
|
54
|
+
# 'CUPY_CUDA_VERSION' : 115,
|
|
55
|
+
# 'CUPY_HIP_VERSION' : 0,
|
|
56
|
+
# 'CUPY_USE_CUDA_PYTHON' : 0,
|
|
57
|
+
# }
|
|
58
|
+
|
|
59
|
+
# self.cython_compile_time_env = cythonize_options
|
|
60
|
+
# self.force = True # TODO: delete this later
|
|
61
|
+
|
|
62
|
+
# setuptools.setup(
|
|
63
|
+
# cmdclass = {'build_ext' : build_ext_cupy},
|
|
64
|
+
|
|
65
|
+
kwargs = {}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def main():
|
|
69
|
+
ext = '.pyx' if USE_CYTHON else '.c'
|
|
70
|
+
extensions = [make_ext("statmoments._native", 'statmoments/_native' + ext)]
|
|
71
|
+
extensions = cythonize('statmoments/_native' + ext) if USE_CYTHON else extensions
|
|
72
|
+
setuptools.setup(
|
|
73
|
+
name='statmoments',
|
|
74
|
+
packages = ['statmoments'],
|
|
75
|
+
author='Anton Kochepasov',
|
|
76
|
+
author_email='akss@me.com',
|
|
77
|
+
version=get_version(),
|
|
78
|
+
ext_modules=extensions,
|
|
79
|
+
**kwargs)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == '__main__':
|
|
83
|
+
main()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
"""A bivariate statistical library.
|
|
3
|
+
|
|
4
|
+
Example:
|
|
5
|
+
>>> python -m statmoments.bivar
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ._version import __version__
|
|
9
|
+
|
|
10
|
+
# Compiled or interpreted data from _native.pyx
|
|
11
|
+
from . import stattests
|
|
12
|
+
|
|
13
|
+
# Functionality
|
|
14
|
+
from ._statmoments_impl import bivar_sum, bivar_cntr, bivar_2pass # primary kernels
|
|
15
|
+
from ._statmoments_impl import bivar_sum_mix, bivar_sum_detrend # experimental
|
|
16
|
+
from ._statmoments_impl import bivar_txtbk, bivar_vtk # baseline test kernels
|
|
17
|
+
|
|
18
|
+
from ._statmoments_impl import univar_sum # primary kernels
|
|
19
|
+
from ._statmoments_impl import univar_sum_detrend # experimental
|
|
20
|
+
|
|
21
|
+
from ._statmoments_impl import Bivar, Univar
|
|
22
|
+
|
|
23
|
+
__name__ = "statmoments"
|