robustbase 3.1.0__tar.gz → 3.1.1__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.
- {robustbase-3.1.0 → robustbase-3.1.1}/MANIFEST.in +1 -0
- {robustbase-3.1.0/robustbase.egg-info → robustbase-3.1.1}/PKG-INFO +25 -10
- {robustbase-3.1.0 → robustbase-3.1.1}/README.md +4 -0
- robustbase-3.1.1/VERSION +1 -0
- robustbase-3.1.1/requirements.txt +2 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/stats/Qn.py +14 -8
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/stats/Sn.py +11 -9
- robustbase-3.1.1/robustbase/stats/__init__.py +7 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/stats/covComed.py +18 -4
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/stats/iqr.py +1 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/stats/mad.py +5 -3
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/utils/mean.py +2 -1
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/utils/median.py +2 -1
- robustbase-3.1.1/robustbase/version.py +7 -0
- {robustbase-3.1.0 → robustbase-3.1.1/robustbase.egg-info}/PKG-INFO +25 -10
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase.egg-info/SOURCES.txt +1 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase.egg-info/requires.txt +0 -3
- {robustbase-3.1.0 → robustbase-3.1.1}/setup.py +29 -25
- robustbase-3.1.1/tests/test_Qn.py +38 -0
- robustbase-3.1.1/tests/test_Sn.py +34 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/tests/test_covcomed.py +20 -10
- robustbase-3.1.1/tests/test_import.py +5 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/tests/test_iqr.py +2 -0
- robustbase-3.1.1/tests/test_mad.py +25 -0
- robustbase-3.1.0/requirements.txt +0 -4
- robustbase-3.1.0/robustbase/stats/__init__.py +0 -5
- robustbase-3.1.0/robustbase/version.py +0 -1
- robustbase-3.1.0/tests/test_Qn.py +0 -15
- robustbase-3.1.0/tests/test_Sn.py +0 -15
- robustbase-3.1.0/tests/test_import.py +0 -25
- robustbase-3.1.0/tests/test_mad.py +0 -15
- {robustbase-3.1.0 → robustbase-3.1.1}/LICENSE +0 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/__init__.py +0 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase/utils/__init__.py +0 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase.egg-info/dependency_links.txt +0 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/robustbase.egg-info/top_level.txt +0 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/setup.cfg +0 -0
- {robustbase-3.1.0 → robustbase-3.1.1}/tests/test_median.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: robustbase
|
|
3
|
-
Version: 3.1.
|
|
3
|
+
Version: 3.1.1
|
|
4
4
|
Summary: A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR, covComed)
|
|
5
5
|
Home-page: https://github.com/deepak7376/robustbase
|
|
6
6
|
Author: Deepak Yadav
|
|
@@ -13,23 +13,34 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.
|
|
20
|
-
Requires-Python: >=3.
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
License-File: LICENSE
|
|
23
|
-
Requires-Dist: certifi>=2019.11.28
|
|
24
|
-
Requires-Dist: docutils>=0.15.2
|
|
25
23
|
Requires-Dist: numpy>=1.18.0
|
|
26
24
|
Requires-Dist: scipy>=1.13.1
|
|
27
|
-
Requires-Dist: statistics>=1.0.3.5
|
|
28
25
|
Provides-Extra: dev
|
|
29
26
|
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
30
27
|
Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
|
|
31
28
|
Requires-Dist: coverage>=5.0; extra == "dev"
|
|
32
29
|
Requires-Dist: flake8>=3.8.0; extra == "dev"
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: author-email
|
|
32
|
+
Dynamic: classifier
|
|
33
|
+
Dynamic: description
|
|
34
|
+
Dynamic: description-content-type
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: keywords
|
|
37
|
+
Dynamic: license
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: project-url
|
|
40
|
+
Dynamic: provides-extra
|
|
41
|
+
Dynamic: requires-dist
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
Dynamic: summary
|
|
33
44
|
|
|
34
45
|
[](https://pepy.tech/project/robustbase)
|
|
35
46
|
[](https://pepy.tech/project/robustbase/month)
|
|
@@ -131,6 +142,10 @@ pip install -r requirements.txt -r requirements-dev.txt
|
|
|
131
142
|
|
|
132
143
|
## Recent Changes
|
|
133
144
|
|
|
145
|
+
### Version 3.0.8
|
|
146
|
+
- Fixed `Qn` returning wrong values when the sample contains tied values (#22).
|
|
147
|
+
- Fixed `Sn` using the plain median instead of R's low/high medians for even sample sizes.
|
|
148
|
+
|
|
134
149
|
### Version 3.0.0
|
|
135
150
|
- Changed the API's call
|
|
136
151
|
- Refactored the dir structure
|
|
@@ -98,6 +98,10 @@ pip install -r requirements.txt -r requirements-dev.txt
|
|
|
98
98
|
|
|
99
99
|
## Recent Changes
|
|
100
100
|
|
|
101
|
+
### Version 3.0.8
|
|
102
|
+
- Fixed `Qn` returning wrong values when the sample contains tied values (#22).
|
|
103
|
+
- Fixed `Sn` using the plain median instead of R's low/high medians for even sample sizes.
|
|
104
|
+
|
|
101
105
|
### Version 3.0.0
|
|
102
106
|
- Changed the API's call
|
|
103
107
|
- Refactored the dir structure
|
robustbase-3.1.1/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.1.1
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
def Qn(x, constant=2.21914, finite_corr=True):
|
|
4
5
|
"""
|
|
5
6
|
Qn scale estimator, Gaussian efficiency 82%
|
|
6
7
|
|
|
7
8
|
Parameters:
|
|
8
9
|
- x: list or array-like, numeric vector of observations.
|
|
9
|
-
- constant: float, number by which the result is multiplied; the default
|
|
10
|
-
|
|
10
|
+
- constant: float, number by which the result is multiplied; the default
|
|
11
|
+
achieves consistency for normally distributed data.
|
|
12
|
+
- finite_corr: bool, logical indicating if the finite sample bias correction
|
|
13
|
+
factor should be applied. Default to True unless constant is specified.
|
|
11
14
|
|
|
12
15
|
Returns:
|
|
13
16
|
- float: Qn scale estimator.
|
|
@@ -20,10 +23,9 @@ def Qn(x, constant=2.21914, finite_corr=True):
|
|
|
20
23
|
# Calculate all pairwise absolute differences using NumPy broadcasting
|
|
21
24
|
diffs = np.abs(x[:, np.newaxis] - x)
|
|
22
25
|
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
diffs_flat =
|
|
26
|
-
diffs_flat.sort()
|
|
26
|
+
# Take all pairs i < j by index (not by value) so that zero distances
|
|
27
|
+
# from tied observations are counted, as in R robustbase
|
|
28
|
+
diffs_flat = np.sort(diffs[np.triu_indices(n, k=1)])
|
|
27
29
|
|
|
28
30
|
# Calculate the index for Qn estimation
|
|
29
31
|
h = int(np.floor(n / 2) + 1)
|
|
@@ -33,10 +35,13 @@ def Qn(x, constant=2.21914, finite_corr=True):
|
|
|
33
35
|
corr_factor = bias_corr(n)
|
|
34
36
|
|
|
35
37
|
# Calculate the Qn estimator
|
|
36
|
-
qn = constant * diffs_flat[k - 1]
|
|
38
|
+
qn = constant * diffs_flat[k - 1]
|
|
39
|
+
if finite_corr:
|
|
40
|
+
qn = qn * corr_factor
|
|
37
41
|
|
|
38
42
|
return qn
|
|
39
43
|
|
|
44
|
+
|
|
40
45
|
def bias_corr(n):
|
|
41
46
|
"""
|
|
42
47
|
Bias correction factor for Qn estimator.
|
|
@@ -65,5 +70,6 @@ def bias_corr(n):
|
|
|
65
70
|
corr_factor = 1 / ((corr_factor / n) + 1)
|
|
66
71
|
else:
|
|
67
72
|
corr_factor = np.array([0.399356, 0.99365, 0.51321, 0.84401, 0.61220,
|
|
68
|
-
0.85877, 0.66993, 0.87344, 0.72014, 0.88906,
|
|
73
|
+
0.85877, 0.66993, 0.87344, 0.72014, 0.88906,
|
|
74
|
+
0.75743])[n - 2]
|
|
69
75
|
return corr_factor
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import numpy as np
|
|
2
|
+
from robustbase.utils.median import median
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
def Sn(x, constant=1.1926, finite_corr=True):
|
|
4
6
|
"""
|
|
@@ -6,8 +8,10 @@ def Sn(x, constant=1.1926, finite_corr=True):
|
|
|
6
8
|
|
|
7
9
|
Parameters:
|
|
8
10
|
- x: list or array-like, numeric vector of observations.
|
|
9
|
-
- constant: float, number by which the result is multiplied; the default
|
|
10
|
-
|
|
11
|
+
- constant: float, number by which the result is multiplied; the default
|
|
12
|
+
achieves consistency for normally distributed data.
|
|
13
|
+
- finite_corr: bool, logical indicating if the finite sample bias correction
|
|
14
|
+
factor should be applied. Default to True unless constant is specified.
|
|
11
15
|
|
|
12
16
|
Returns:
|
|
13
17
|
- float: Sn scale estimator.
|
|
@@ -17,14 +21,12 @@ def Sn(x, constant=1.1926, finite_corr=True):
|
|
|
17
21
|
if n < 2:
|
|
18
22
|
raise ValueError("At least 2 observations are required.")
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
pairwise_diffs = np.abs(np.subtract.outer(x, x))
|
|
22
|
-
|
|
23
|
-
# Calculate the medians of the pairwise absolute differences
|
|
24
|
-
medians = np.median(pairwise_diffs, axis=0)
|
|
24
|
+
x = np.asarray(x, dtype=float)
|
|
25
25
|
|
|
26
|
-
#
|
|
27
|
-
|
|
26
|
+
# Sn = c * LOMED_i HIMED_j |x_i - x_j|, with j over all points incl. i (as in R)
|
|
27
|
+
d = np.abs(x[:, np.newaxis] - x)
|
|
28
|
+
himeds = np.partition(d, n // 2, axis=1)[:, n // 2] # HIMED_j for each i
|
|
29
|
+
sn = constant * median(himeds, low=True) # LOMED_i
|
|
28
30
|
|
|
29
31
|
# Apply finite sample correction if specified
|
|
30
32
|
if finite_corr:
|
|
@@ -5,7 +5,16 @@ from collections import namedtuple
|
|
|
5
5
|
|
|
6
6
|
CovComedResult = namedtuple('CovComedResult', ['cov', 'center', 'weights'])
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
def covComed(
|
|
10
|
+
X,
|
|
11
|
+
n_iter=2,
|
|
12
|
+
reweight=False,
|
|
13
|
+
tol_solve=1e-7,
|
|
14
|
+
trace=False,
|
|
15
|
+
wgt_fun="01.original",
|
|
16
|
+
control=None,
|
|
17
|
+
):
|
|
9
18
|
if control is None:
|
|
10
19
|
control = {}
|
|
11
20
|
|
|
@@ -26,7 +35,9 @@ def covComed(X, n_iter=2, reweight=False, tol_solve=1e-7, trace=False, wgt_fun="
|
|
|
26
35
|
for i in range(n_iter):
|
|
27
36
|
# Check if covariance matrix is singular
|
|
28
37
|
if np.linalg.matrix_rank(cov) < cov.shape[0]:
|
|
29
|
-
raise LinAlgError(
|
|
38
|
+
raise LinAlgError(
|
|
39
|
+
"Covariance matrix is singular. Cannot proceed with computations."
|
|
40
|
+
)
|
|
30
41
|
|
|
31
42
|
# Compute Mahalanobis distances
|
|
32
43
|
inv_cov = solve(cov, np.eye(cov.shape[0]), assume_a='pos')
|
|
@@ -51,8 +62,10 @@ def covComed(X, n_iter=2, reweight=False, tol_solve=1e-7, trace=False, wgt_fun="
|
|
|
51
62
|
# Final reweighting step
|
|
52
63
|
if reweight:
|
|
53
64
|
if np.linalg.matrix_rank(cov) < cov.shape[0]:
|
|
54
|
-
raise LinAlgError(
|
|
55
|
-
|
|
65
|
+
raise LinAlgError(
|
|
66
|
+
"Covariance matrix is singular. Cannot proceed with computations."
|
|
67
|
+
)
|
|
68
|
+
|
|
56
69
|
inv_cov = solve(cov, np.eye(cov.shape[0]), assume_a='pos')
|
|
57
70
|
dists = np.array([mahalanobis(x, center, inv_cov) for x in X])
|
|
58
71
|
if wgt_fun == "01.original":
|
|
@@ -62,6 +75,7 @@ def covComed(X, n_iter=2, reweight=False, tol_solve=1e-7, trace=False, wgt_fun="
|
|
|
62
75
|
|
|
63
76
|
return CovComedResult(cov, center, weights)
|
|
64
77
|
|
|
78
|
+
|
|
65
79
|
# Example usage
|
|
66
80
|
if __name__ == "__main__":
|
|
67
81
|
# Example data matrix (with non-singular covariance matrix)
|
|
@@ -8,8 +8,10 @@ def mad(x, center=None, constant=1.4826, na=False, low=False, high=False):
|
|
|
8
8
|
|
|
9
9
|
Parameters:
|
|
10
10
|
- x: list or array-like, numeric vector of observations.
|
|
11
|
-
- center: float or None, value around which the MAD is computed. If None,
|
|
12
|
-
|
|
11
|
+
- center: float or None, value around which the MAD is computed. If None,
|
|
12
|
+
median of x is used.
|
|
13
|
+
- constant: float, scaling factor to make MAD consistent estimator of the
|
|
14
|
+
standard deviation.
|
|
13
15
|
- na: bool, if True, handle NA/NaN values in x. (Not implemented in this function)
|
|
14
16
|
- low: bool, if True, compute the ‘lo-median’. (Not applicable in this function)
|
|
15
17
|
- high: bool, if True, compute the ‘hi-median’. (Not applicable in this function)
|
|
@@ -25,5 +27,5 @@ def mad(x, center=None, constant=1.4826, na=False, low=False, high=False):
|
|
|
25
27
|
|
|
26
28
|
center = median(x) if center is None else center
|
|
27
29
|
amd = np.abs(x - center)
|
|
28
|
-
|
|
30
|
+
|
|
29
31
|
return constant * median(amd)
|
|
@@ -7,7 +7,8 @@ def median(x, low=False, high=False):
|
|
|
7
7
|
|
|
8
8
|
Parameters:
|
|
9
9
|
- x: list or array-like, numeric vector of observations.
|
|
10
|
-
- low: bool, if True, return the low median for even sample size. If ``True``,
|
|
10
|
+
- low: bool, if True, return the low median for even sample size. If ``True``,
|
|
11
|
+
``high`` is ignored.
|
|
11
12
|
- high: bool, if True, return the high median for even sample size.
|
|
12
13
|
|
|
13
14
|
Returns:
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
|
|
3
|
+
# The version comes from the git tag at build time (see setup.py); don't hardcode it.
|
|
4
|
+
try:
|
|
5
|
+
__version__ = version("robustbase")
|
|
6
|
+
except PackageNotFoundError: # running from a source checkout that isn't installed
|
|
7
|
+
__version__ = "unknown"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: robustbase
|
|
3
|
-
Version: 3.1.
|
|
3
|
+
Version: 3.1.1
|
|
4
4
|
Summary: A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR, covComed)
|
|
5
5
|
Home-page: https://github.com/deepak7376/robustbase
|
|
6
6
|
Author: Deepak Yadav
|
|
@@ -13,23 +13,34 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.
|
|
20
|
-
Requires-Python: >=3.
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
License-File: LICENSE
|
|
23
|
-
Requires-Dist: certifi>=2019.11.28
|
|
24
|
-
Requires-Dist: docutils>=0.15.2
|
|
25
23
|
Requires-Dist: numpy>=1.18.0
|
|
26
24
|
Requires-Dist: scipy>=1.13.1
|
|
27
|
-
Requires-Dist: statistics>=1.0.3.5
|
|
28
25
|
Provides-Extra: dev
|
|
29
26
|
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
30
27
|
Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
|
|
31
28
|
Requires-Dist: coverage>=5.0; extra == "dev"
|
|
32
29
|
Requires-Dist: flake8>=3.8.0; extra == "dev"
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: author-email
|
|
32
|
+
Dynamic: classifier
|
|
33
|
+
Dynamic: description
|
|
34
|
+
Dynamic: description-content-type
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: keywords
|
|
37
|
+
Dynamic: license
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: project-url
|
|
40
|
+
Dynamic: provides-extra
|
|
41
|
+
Dynamic: requires-dist
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
Dynamic: summary
|
|
33
44
|
|
|
34
45
|
[](https://pepy.tech/project/robustbase)
|
|
35
46
|
[](https://pepy.tech/project/robustbase/month)
|
|
@@ -131,6 +142,10 @@ pip install -r requirements.txt -r requirements-dev.txt
|
|
|
131
142
|
|
|
132
143
|
## Recent Changes
|
|
133
144
|
|
|
145
|
+
### Version 3.0.8
|
|
146
|
+
- Fixed `Qn` returning wrong values when the sample contains tied values (#22).
|
|
147
|
+
- Fixed `Sn` using the plain median instead of R's low/high medians for even sample sizes.
|
|
148
|
+
|
|
134
149
|
### Version 3.0.0
|
|
135
150
|
- Changed the API's call
|
|
136
151
|
- Refactored the dir structure
|
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
from setuptools import setup, find_packages
|
|
2
2
|
import subprocess
|
|
3
|
-
import os
|
|
4
3
|
|
|
5
4
|
# Get the version from git tags
|
|
6
5
|
version = (
|
|
7
|
-
subprocess.run(
|
|
6
|
+
subprocess.run(
|
|
7
|
+
["git", "describe", "--tags"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
|
|
8
|
+
)
|
|
8
9
|
.stdout.decode("utf-8")
|
|
9
10
|
.strip()
|
|
10
11
|
)
|
|
11
12
|
|
|
12
|
-
if
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
if version:
|
|
14
|
+
if "-" in version:
|
|
15
|
+
v, i, s = version.split("-")
|
|
16
|
+
version = v + "+" + i + ".git." + s
|
|
17
|
+
# Write the version to a file (shipped in the sdist via MANIFEST.in)
|
|
18
|
+
with open("VERSION", "w", encoding="utf-8") as fh:
|
|
19
|
+
fh.write("%s\n" % version)
|
|
20
|
+
else:
|
|
21
|
+
# No git checkout (e.g. building a wheel from the sdist): use the VERSION file
|
|
22
|
+
with open("VERSION", encoding="utf-8") as fh:
|
|
23
|
+
version = fh.read().strip()
|
|
15
24
|
|
|
16
25
|
assert "-" not in version
|
|
17
26
|
assert "." in version
|
|
18
27
|
|
|
19
|
-
# Write the version to a file
|
|
20
|
-
with open("VERSION", "w", encoding="utf-8") as fh:
|
|
21
|
-
fh.write("%s\n" % version)
|
|
22
|
-
|
|
23
28
|
# Read the long description from the README file
|
|
24
29
|
with open('README.md', encoding='utf-8') as f:
|
|
25
30
|
long_description = f.read()
|
|
26
31
|
|
|
27
32
|
# Setup function
|
|
28
33
|
setup(
|
|
29
|
-
name='robustbase',
|
|
30
|
-
version=version,
|
|
31
|
-
description=
|
|
32
|
-
|
|
34
|
+
name='robustbase',
|
|
35
|
+
version=version,
|
|
36
|
+
description=(
|
|
37
|
+
'A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR, covComed)'
|
|
38
|
+
),
|
|
39
|
+
long_description=long_description,
|
|
33
40
|
long_description_content_type='text/markdown',
|
|
34
|
-
url='https://github.com/deepak7376/robustbase',
|
|
35
|
-
author='Deepak Yadav',
|
|
36
|
-
author_email='dky.united@gmail.com',
|
|
37
|
-
license='MIT',
|
|
41
|
+
url='https://github.com/deepak7376/robustbase',
|
|
42
|
+
author='Deepak Yadav',
|
|
43
|
+
author_email='dky.united@gmail.com',
|
|
44
|
+
license='MIT',
|
|
38
45
|
packages=find_packages(), # Automatically find packages
|
|
39
46
|
include_package_data=True,
|
|
40
47
|
project_urls={
|
|
@@ -46,19 +53,16 @@ setup(
|
|
|
46
53
|
'Intended Audience :: Developers',
|
|
47
54
|
'License :: OSI Approved :: MIT License',
|
|
48
55
|
'Programming Language :: Python :: 3',
|
|
49
|
-
'Programming Language :: Python :: 3.
|
|
50
|
-
'Programming Language :: Python :: 3.
|
|
51
|
-
'Programming Language :: Python :: 3.
|
|
52
|
-
'Programming Language :: Python :: 3.
|
|
56
|
+
'Programming Language :: Python :: 3.10',
|
|
57
|
+
'Programming Language :: Python :: 3.11',
|
|
58
|
+
'Programming Language :: Python :: 3.12',
|
|
59
|
+
'Programming Language :: Python :: 3.13',
|
|
53
60
|
],
|
|
54
61
|
keywords='robust statistics robustness Sn Qn MAD IQR',
|
|
55
|
-
python_requires='>=3.
|
|
62
|
+
python_requires='>=3.10',
|
|
56
63
|
install_requires=[
|
|
57
|
-
'certifi>=2019.11.28',
|
|
58
|
-
'docutils>=0.15.2',
|
|
59
64
|
'numpy>=1.18.0',
|
|
60
65
|
'scipy>=1.13.1',
|
|
61
|
-
'statistics>=1.0.3.5',
|
|
62
66
|
],
|
|
63
67
|
extras_require={
|
|
64
68
|
'dev': [
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from robustbase.stats.Qn import Qn
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_Qn():
|
|
7
|
+
x1 = [x for x in range(1, 201)]
|
|
8
|
+
outlier = [x for x in range(501, 516)]
|
|
9
|
+
x2 = x1 + outlier
|
|
10
|
+
|
|
11
|
+
assert Qn(x2, finite_corr=True) == 68.28773488650255
|
|
12
|
+
assert Qn(x2, finite_corr=False) == 68.79334
|
|
13
|
+
assert Qn(x2, constant=1, finite_corr=True) == 30.772161687186276
|
|
14
|
+
assert Qn(x2, constant=1, finite_corr=False) == 31
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_Qn_ties():
|
|
18
|
+
# Reference values from R robustbase 0.99.7 (GitHub issue #22)
|
|
19
|
+
assert Qn([0, 0, 1, 3, 7]) == pytest.approx(1.8729764, abs=1e-6)
|
|
20
|
+
assert Qn([0, 0, 1, 3, 7], finite_corr=False) == pytest.approx(2.21914)
|
|
21
|
+
assert Qn([0, 0, 0, 1, 2]) == 0
|
|
22
|
+
assert Qn([1, 1, 1, 1, 1, 1, 2, 3]) == 0
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_Qn_all_equal():
|
|
26
|
+
assert Qn([5, 5]) == 0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_Qn_no_ties_unchanged():
|
|
30
|
+
assert Qn(range(1, 11)) == pytest.approx(3.196183, abs=1e-6)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
test_Qn()
|
|
35
|
+
test_Qn_ties()
|
|
36
|
+
test_Qn_all_equal()
|
|
37
|
+
test_Qn_no_ties_unchanged()
|
|
38
|
+
print("Qn tests passed!!!")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from robustbase.stats.Sn import Sn
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_Sn():
|
|
7
|
+
x1 = [x for x in range(1, 201)]
|
|
8
|
+
outlier = [x for x in range(501, 516)]
|
|
9
|
+
x2 = x1 + outlier
|
|
10
|
+
|
|
11
|
+
assert Sn(x2, finite_corr=True) == 73.05440915460066 # 73.05440915460065
|
|
12
|
+
assert Sn(x2, finite_corr=False) == 72.74860000000001 # 72.7486
|
|
13
|
+
assert Sn(x2, constant=1, finite_corr=True) == 61.25642223260159
|
|
14
|
+
assert Sn(x2, constant=1, finite_corr=False) == 61.0
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_Sn_even_n():
|
|
18
|
+
# R robustbase: Sn = c * LOMED_i HIMED_j |x_i - x_j|
|
|
19
|
+
assert Sn(range(1, 11)) == pytest.approx(3.5778)
|
|
20
|
+
assert Sn([0, 0, 1, 3, 7, 9], finite_corr=False) == pytest.approx(3.5778)
|
|
21
|
+
assert Sn([1.5, 2, 4, 8, 16, 32, 64, 128], finite_corr=False) == pytest.approx(
|
|
22
|
+
17.2927, abs=1e-4
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_Sn_odd_n_unchanged():
|
|
27
|
+
assert Sn(range(1, 12), finite_corr=False) == pytest.approx(3.5778)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
test_Sn()
|
|
32
|
+
test_Sn_even_n()
|
|
33
|
+
test_Sn_odd_n_unchanged()
|
|
34
|
+
print("Sn tests passed!!!")
|
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import pytest
|
|
3
|
-
from robustbase.stats.covComed import covComed, CovComedResult
|
|
3
|
+
from robustbase.stats.covComed import covComed, CovComedResult
|
|
4
|
+
|
|
4
5
|
|
|
5
6
|
def test_covcomed_basic():
|
|
6
7
|
np.random.seed(42)
|
|
7
8
|
X = np.random.rand(100, 3)
|
|
8
9
|
result = covComed(X)
|
|
9
|
-
|
|
10
|
-
assert isinstance(result, CovComedResult),
|
|
10
|
+
|
|
11
|
+
assert isinstance(result, CovComedResult), \
|
|
12
|
+
"Result should be of type CovComedResult"
|
|
11
13
|
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
12
14
|
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
13
15
|
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
14
16
|
|
|
17
|
+
|
|
15
18
|
def test_covcomed_reweight():
|
|
16
19
|
np.random.seed(42)
|
|
17
20
|
X = np.random.rand(100, 3)
|
|
18
21
|
result = covComed(X, reweight=True)
|
|
19
|
-
|
|
20
|
-
assert isinstance(result, CovComedResult),
|
|
22
|
+
|
|
23
|
+
assert isinstance(result, CovComedResult), \
|
|
24
|
+
"Result should be of type CovComedResult"
|
|
21
25
|
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
22
26
|
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
23
27
|
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
24
|
-
assert np.any(result.weights == 0),
|
|
28
|
+
assert np.any(result.weights == 0), \
|
|
29
|
+
"There should be some zero weights when reweighting"
|
|
30
|
+
|
|
25
31
|
|
|
26
32
|
def test_covcomed_custom_control():
|
|
27
33
|
np.random.seed(42)
|
|
28
34
|
X = np.random.rand(100, 3)
|
|
29
35
|
control = {'tolSolve': 1e-5, 'trace': True, 'wgtFUN': '01.original'}
|
|
30
36
|
result = covComed(X, n_iter=1, control=control)
|
|
31
|
-
|
|
32
|
-
assert isinstance(result, CovComedResult),
|
|
37
|
+
|
|
38
|
+
assert isinstance(result, CovComedResult), \
|
|
39
|
+
"Result should be of type CovComedResult"
|
|
33
40
|
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
34
41
|
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
35
42
|
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
@@ -38,12 +45,14 @@ def test_covcomed_custom_control():
|
|
|
38
45
|
# np.random.seed(42)
|
|
39
46
|
# X = np.random.rand(100, 3)
|
|
40
47
|
# result = covComed(X, n_iter=0)
|
|
41
|
-
|
|
42
|
-
# assert isinstance(result, CovComedResult),
|
|
48
|
+
|
|
49
|
+
# assert isinstance(result, CovComedResult), \
|
|
50
|
+
# "Result should be of type CovComedResult"
|
|
43
51
|
# assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
44
52
|
# assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
45
53
|
# assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
46
54
|
|
|
55
|
+
|
|
47
56
|
def test_covcomed_invalid_wgtfun():
|
|
48
57
|
np.random.seed(42)
|
|
49
58
|
X = np.random.rand(100, 3)
|
|
@@ -62,5 +71,6 @@ def test_covcomed_invalid_wgtfun():
|
|
|
62
71
|
# with pytest.raises(LinAlgError, match="Covariance matrix is singular"):
|
|
63
72
|
# result = covComed(hbk_x)
|
|
64
73
|
|
|
74
|
+
|
|
65
75
|
if __name__ == "__main__":
|
|
66
76
|
pytest.main()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from robustbase.stats.iqr import iqr
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
def test_iqr():
|
|
4
5
|
x1 = [x for x in range(1, 201)]
|
|
5
6
|
outlier = [x for x in range(501, 516)]
|
|
@@ -7,6 +8,7 @@ def test_iqr():
|
|
|
7
8
|
|
|
8
9
|
assert iqr(x2) == (161.5, 54.5)
|
|
9
10
|
|
|
11
|
+
|
|
10
12
|
if __name__ == "__main__":
|
|
11
13
|
test_iqr()
|
|
12
14
|
print("IQR test passed!!!")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from robustbase.stats.mad import mad
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_mad():
|
|
5
|
+
x1 = [x for x in range(1, 201)]
|
|
6
|
+
outlier = [x for x in range(501, 516)]
|
|
7
|
+
x2 = x1 + outlier
|
|
8
|
+
|
|
9
|
+
assert mad(
|
|
10
|
+
x2, center=None, constant=1.4826, na=False, low=False, high=False
|
|
11
|
+
) == 80.0604
|
|
12
|
+
assert mad(
|
|
13
|
+
x2, center=1.5, constant=1.4826, na=False, low=False, high=False
|
|
14
|
+
) == 157.8969
|
|
15
|
+
assert mad(
|
|
16
|
+
x2, center=None, constant=1.4826, na=False, low=True, high=False
|
|
17
|
+
) == 80.0604
|
|
18
|
+
assert mad(
|
|
19
|
+
x2, center=None, constant=1.4826, na=False, low=False, high=True
|
|
20
|
+
) == 80.0604
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if __name__ == "__main__":
|
|
24
|
+
test_mad()
|
|
25
|
+
print("MAD tests passed!!!")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '3.0.7'
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from robustbase.stats.Qn import Qn
|
|
2
|
-
|
|
3
|
-
def test_Qn():
|
|
4
|
-
x1 = [x for x in range(1, 201)]
|
|
5
|
-
outlier = [x for x in range(501, 516)]
|
|
6
|
-
x2 = x1 + outlier
|
|
7
|
-
|
|
8
|
-
assert Qn(x2, finite_corr=True) == 68.28773488650255
|
|
9
|
-
assert Qn(x2, finite_corr=False) == 68.79334
|
|
10
|
-
assert Qn(x2, constant=1, finite_corr=True) == 30.772161687186276
|
|
11
|
-
assert Qn(x2, constant=1, finite_corr=False) == 31
|
|
12
|
-
|
|
13
|
-
if __name__ == "__main__":
|
|
14
|
-
test_Qn()
|
|
15
|
-
print("Qn tests passed!!!")
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from robustbase.stats.Sn import Sn
|
|
2
|
-
|
|
3
|
-
def test_Sn():
|
|
4
|
-
x1 = [x for x in range(1, 201)]
|
|
5
|
-
outlier = [x for x in range(501, 516)]
|
|
6
|
-
x2 = x1 + outlier
|
|
7
|
-
|
|
8
|
-
assert Sn(x2, finite_corr=True) == 73.05440915460066 # 73.05440915460065
|
|
9
|
-
assert Sn(x2, finite_corr=False) == 72.74860000000001 # 72.7486
|
|
10
|
-
assert Sn(x2, constant=1, finite_corr=True) == 61.25642223260159
|
|
11
|
-
assert Sn(x2, constant=1, finite_corr=False) == 61.0
|
|
12
|
-
|
|
13
|
-
if __name__ == "__main__":
|
|
14
|
-
test_Sn()
|
|
15
|
-
print("Sn tests passed!!!")
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
try:
|
|
2
|
-
from robustbase import Qn
|
|
3
|
-
print("Importing Qn from robustbase... Success!")
|
|
4
|
-
except ImportError:
|
|
5
|
-
print("Failed to import Qn from robustbase!")
|
|
6
|
-
|
|
7
|
-
try:
|
|
8
|
-
from robustbase.stats import Qn as Qn_stat
|
|
9
|
-
print("Importing Qn from robustbase.stats... Success!")
|
|
10
|
-
except ImportError:
|
|
11
|
-
print("Failed to import Qn from robustbase.stats!")
|
|
12
|
-
|
|
13
|
-
try:
|
|
14
|
-
from robustbase import Sn
|
|
15
|
-
print("Importing Sn from robustbase... Success!")
|
|
16
|
-
except ImportError:
|
|
17
|
-
print("Failed to import Sn from robustbase!")
|
|
18
|
-
|
|
19
|
-
try:
|
|
20
|
-
from robustbase.stats import Sn as Sn_stat
|
|
21
|
-
print("Importing Sn from robustbase.stats... Success!")
|
|
22
|
-
except ImportError:
|
|
23
|
-
print("Failed to import Sn from robustbase.stats!")
|
|
24
|
-
|
|
25
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from robustbase.stats.mad import mad
|
|
2
|
-
|
|
3
|
-
def test_mad():
|
|
4
|
-
x1 = [x for x in range(1, 201)]
|
|
5
|
-
outlier = [x for x in range(501, 516)]
|
|
6
|
-
x2 = x1 + outlier
|
|
7
|
-
|
|
8
|
-
assert mad(x2, center=None, constant=1.4826, na=False, low=False, high=False) == 80.0604
|
|
9
|
-
assert mad(x2, center=1.5, constant=1.4826, na=False, low=False, high=False) == 157.8969
|
|
10
|
-
assert mad(x2, center=None, constant=1.4826, na=False, low=True, high=False) == 80.0604
|
|
11
|
-
assert mad(x2, center=None, constant=1.4826, na=False, low=False, high=True) == 80.0604
|
|
12
|
-
|
|
13
|
-
if __name__ == "__main__":
|
|
14
|
-
test_mad()
|
|
15
|
-
print("MAD tests passed!!!")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|