robustbase 3.0.8__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.0.8 → robustbase-3.1.1}/MANIFEST.in +1 -0
- {robustbase-3.0.8/robustbase.egg-info → robustbase-3.1.1}/PKG-INFO +45 -11
- {robustbase-3.0.8 → robustbase-3.1.1}/README.md +22 -0
- robustbase-3.1.1/VERSION +1 -0
- robustbase-3.1.1/requirements.txt +2 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/stats/Qn.py +14 -8
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/stats/Sn.py +11 -9
- robustbase-3.1.1/robustbase/stats/__init__.py +7 -0
- robustbase-3.1.1/robustbase/stats/covComed.py +90 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/stats/iqr.py +1 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/stats/mad.py +5 -3
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/utils/mean.py +2 -1
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/utils/median.py +2 -1
- robustbase-3.1.1/robustbase/version.py +7 -0
- {robustbase-3.0.8 → robustbase-3.1.1/robustbase.egg-info}/PKG-INFO +45 -11
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase.egg-info/SOURCES.txt +3 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase.egg-info/requires.txt +1 -3
- robustbase-3.1.1/setup.py +75 -0
- robustbase-3.1.1/tests/test_Qn.py +38 -0
- robustbase-3.1.1/tests/test_Sn.py +34 -0
- robustbase-3.1.1/tests/test_covcomed.py +76 -0
- robustbase-3.1.1/tests/test_import.py +5 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/tests/test_iqr.py +2 -0
- robustbase-3.1.1/tests/test_mad.py +25 -0
- robustbase-3.0.8/requirements.txt +0 -4
- robustbase-3.0.8/robustbase/stats/__init__.py +0 -4
- robustbase-3.0.8/robustbase/version.py +0 -1
- robustbase-3.0.8/setup.py +0 -70
- robustbase-3.0.8/tests/test_Qn.py +0 -15
- robustbase-3.0.8/tests/test_Sn.py +0 -15
- robustbase-3.0.8/tests/test_import.py +0 -25
- robustbase-3.0.8/tests/test_mad.py +0 -15
- {robustbase-3.0.8 → robustbase-3.1.1}/LICENSE +0 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/__init__.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase/utils/__init__.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase.egg-info/dependency_links.txt +0 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/robustbase.egg-info/top_level.txt +0 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/setup.cfg +0 -0
- {robustbase-3.0.8 → robustbase-3.1.1}/tests/test_median.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: robustbase
|
|
3
|
-
Version: 3.
|
|
4
|
-
Summary: A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR)
|
|
3
|
+
Version: 3.1.1
|
|
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
|
|
7
7
|
Author-email: dky.united@gmail.com
|
|
@@ -13,22 +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
|
-
Requires-Dist:
|
|
24
|
+
Requires-Dist: scipy>=1.13.1
|
|
27
25
|
Provides-Extra: dev
|
|
28
26
|
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
29
27
|
Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
|
|
30
28
|
Requires-Dist: coverage>=5.0; extra == "dev"
|
|
31
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
|
|
32
44
|
|
|
33
45
|
[](https://pepy.tech/project/robustbase)
|
|
34
46
|
[](https://pepy.tech/project/robustbase/month)
|
|
@@ -100,6 +112,24 @@ x = [1, 2, 3, 4, 5]
|
|
|
100
112
|
res = iqr(x)
|
|
101
113
|
```
|
|
102
114
|
|
|
115
|
+
* **Co-Median Location and Scatter "Covariance" Estimator**
|
|
116
|
+
* Compute the multivariate "Comedian" covariance, a robust measure of multivariate location and scatter. Read More
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from robustbase.stats import covComed
|
|
120
|
+
|
|
121
|
+
# Example data matrix
|
|
122
|
+
X = np.random.rand(100, 3)
|
|
123
|
+
|
|
124
|
+
# Compute the Co-Median covariance estimator
|
|
125
|
+
result = covComed(X)
|
|
126
|
+
|
|
127
|
+
# Access the components of the result
|
|
128
|
+
print("Covariance Matrix:", result.cov)
|
|
129
|
+
print("Center:", result.center)
|
|
130
|
+
print("Weights:", result.weights)
|
|
131
|
+
```
|
|
132
|
+
|
|
103
133
|
## Development Setup
|
|
104
134
|
|
|
105
135
|
For local development setup:
|
|
@@ -112,6 +142,10 @@ pip install -r requirements.txt -r requirements-dev.txt
|
|
|
112
142
|
|
|
113
143
|
## Recent Changes
|
|
114
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
|
+
|
|
115
149
|
### Version 3.0.0
|
|
116
150
|
- Changed the API's call
|
|
117
151
|
- Refactored the dir structure
|
|
@@ -68,6 +68,24 @@ x = [1, 2, 3, 4, 5]
|
|
|
68
68
|
res = iqr(x)
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
* **Co-Median Location and Scatter "Covariance" Estimator**
|
|
72
|
+
* Compute the multivariate "Comedian" covariance, a robust measure of multivariate location and scatter. Read More
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from robustbase.stats import covComed
|
|
76
|
+
|
|
77
|
+
# Example data matrix
|
|
78
|
+
X = np.random.rand(100, 3)
|
|
79
|
+
|
|
80
|
+
# Compute the Co-Median covariance estimator
|
|
81
|
+
result = covComed(X)
|
|
82
|
+
|
|
83
|
+
# Access the components of the result
|
|
84
|
+
print("Covariance Matrix:", result.cov)
|
|
85
|
+
print("Center:", result.center)
|
|
86
|
+
print("Weights:", result.weights)
|
|
87
|
+
```
|
|
88
|
+
|
|
71
89
|
## Development Setup
|
|
72
90
|
|
|
73
91
|
For local development setup:
|
|
@@ -80,6 +98,10 @@ pip install -r requirements.txt -r requirements-dev.txt
|
|
|
80
98
|
|
|
81
99
|
## Recent Changes
|
|
82
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
|
+
|
|
83
105
|
### Version 3.0.0
|
|
84
106
|
- Changed the API's call
|
|
85
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:
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from scipy.linalg import solve, LinAlgError
|
|
3
|
+
from scipy.spatial.distance import mahalanobis
|
|
4
|
+
from collections import namedtuple
|
|
5
|
+
|
|
6
|
+
CovComedResult = namedtuple('CovComedResult', ['cov', 'center', 'weights'])
|
|
7
|
+
|
|
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
|
+
):
|
|
18
|
+
if control is None:
|
|
19
|
+
control = {}
|
|
20
|
+
|
|
21
|
+
# Default control values
|
|
22
|
+
control_defaults = {
|
|
23
|
+
'tolSolve': tol_solve,
|
|
24
|
+
'trace': trace,
|
|
25
|
+
'wgtFUN': wgt_fun
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Update control with any additional parameters provided
|
|
29
|
+
control.update(control_defaults)
|
|
30
|
+
|
|
31
|
+
# Initial center and covariance
|
|
32
|
+
center = np.median(X, axis=0)
|
|
33
|
+
cov = np.cov(X, rowvar=False)
|
|
34
|
+
|
|
35
|
+
for i in range(n_iter):
|
|
36
|
+
# Check if covariance matrix is singular
|
|
37
|
+
if np.linalg.matrix_rank(cov) < cov.shape[0]:
|
|
38
|
+
raise LinAlgError(
|
|
39
|
+
"Covariance matrix is singular. Cannot proceed with computations."
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Compute Mahalanobis distances
|
|
43
|
+
inv_cov = solve(cov, np.eye(cov.shape[0]), assume_a='pos')
|
|
44
|
+
dists = np.array([mahalanobis(x, center, inv_cov) for x in X])
|
|
45
|
+
|
|
46
|
+
if control['trace']:
|
|
47
|
+
print(f"Iteration {i}: center={center}, cov={cov}")
|
|
48
|
+
|
|
49
|
+
# Compute weights
|
|
50
|
+
if wgt_fun == "01.original":
|
|
51
|
+
weights = (dists <= 1).astype(int)
|
|
52
|
+
else:
|
|
53
|
+
raise ValueError("Only '01.original' wgtFUN is implemented")
|
|
54
|
+
|
|
55
|
+
# Update center and covariance with weights
|
|
56
|
+
if np.sum(weights) == 0:
|
|
57
|
+
break
|
|
58
|
+
|
|
59
|
+
center = np.average(X, axis=0, weights=weights)
|
|
60
|
+
cov = np.cov(X.T, aweights=weights)
|
|
61
|
+
|
|
62
|
+
# Final reweighting step
|
|
63
|
+
if reweight:
|
|
64
|
+
if np.linalg.matrix_rank(cov) < cov.shape[0]:
|
|
65
|
+
raise LinAlgError(
|
|
66
|
+
"Covariance matrix is singular. Cannot proceed with computations."
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
inv_cov = solve(cov, np.eye(cov.shape[0]), assume_a='pos')
|
|
70
|
+
dists = np.array([mahalanobis(x, center, inv_cov) for x in X])
|
|
71
|
+
if wgt_fun == "01.original":
|
|
72
|
+
weights = (dists <= 1).astype(int)
|
|
73
|
+
else:
|
|
74
|
+
raise ValueError("Only '01.original' wgtFUN is implemented")
|
|
75
|
+
|
|
76
|
+
return CovComedResult(cov, center, weights)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Example usage
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
# Example data matrix (with non-singular covariance matrix)
|
|
82
|
+
X = np.random.rand(100, 3) # 100 samples, 3 features
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
result = covComed(X)
|
|
86
|
+
print("Covariance Matrix:", result.cov)
|
|
87
|
+
print("Center:", result.center)
|
|
88
|
+
print("Weights:", result.weights)
|
|
89
|
+
except LinAlgError as e:
|
|
90
|
+
print("Error:", e)
|
|
@@ -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,7 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: robustbase
|
|
3
|
-
Version: 3.
|
|
4
|
-
Summary: A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR)
|
|
3
|
+
Version: 3.1.1
|
|
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
|
|
7
7
|
Author-email: dky.united@gmail.com
|
|
@@ -13,22 +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
|
-
Requires-Dist:
|
|
24
|
+
Requires-Dist: scipy>=1.13.1
|
|
27
25
|
Provides-Extra: dev
|
|
28
26
|
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
29
27
|
Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
|
|
30
28
|
Requires-Dist: coverage>=5.0; extra == "dev"
|
|
31
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
|
|
32
44
|
|
|
33
45
|
[](https://pepy.tech/project/robustbase)
|
|
34
46
|
[](https://pepy.tech/project/robustbase/month)
|
|
@@ -100,6 +112,24 @@ x = [1, 2, 3, 4, 5]
|
|
|
100
112
|
res = iqr(x)
|
|
101
113
|
```
|
|
102
114
|
|
|
115
|
+
* **Co-Median Location and Scatter "Covariance" Estimator**
|
|
116
|
+
* Compute the multivariate "Comedian" covariance, a robust measure of multivariate location and scatter. Read More
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from robustbase.stats import covComed
|
|
120
|
+
|
|
121
|
+
# Example data matrix
|
|
122
|
+
X = np.random.rand(100, 3)
|
|
123
|
+
|
|
124
|
+
# Compute the Co-Median covariance estimator
|
|
125
|
+
result = covComed(X)
|
|
126
|
+
|
|
127
|
+
# Access the components of the result
|
|
128
|
+
print("Covariance Matrix:", result.cov)
|
|
129
|
+
print("Center:", result.center)
|
|
130
|
+
print("Weights:", result.weights)
|
|
131
|
+
```
|
|
132
|
+
|
|
103
133
|
## Development Setup
|
|
104
134
|
|
|
105
135
|
For local development setup:
|
|
@@ -112,6 +142,10 @@ pip install -r requirements.txt -r requirements-dev.txt
|
|
|
112
142
|
|
|
113
143
|
## Recent Changes
|
|
114
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
|
+
|
|
115
149
|
### Version 3.0.0
|
|
116
150
|
- Changed the API's call
|
|
117
151
|
- Refactored the dir structure
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
LICENSE
|
|
2
2
|
MANIFEST.in
|
|
3
3
|
README.md
|
|
4
|
+
VERSION
|
|
4
5
|
requirements.txt
|
|
5
6
|
setup.py
|
|
6
7
|
robustbase/__init__.py
|
|
@@ -13,6 +14,7 @@ robustbase.egg-info/top_level.txt
|
|
|
13
14
|
robustbase/stats/Qn.py
|
|
14
15
|
robustbase/stats/Sn.py
|
|
15
16
|
robustbase/stats/__init__.py
|
|
17
|
+
robustbase/stats/covComed.py
|
|
16
18
|
robustbase/stats/iqr.py
|
|
17
19
|
robustbase/stats/mad.py
|
|
18
20
|
robustbase/utils/__init__.py
|
|
@@ -20,6 +22,7 @@ robustbase/utils/mean.py
|
|
|
20
22
|
robustbase/utils/median.py
|
|
21
23
|
tests/test_Qn.py
|
|
22
24
|
tests/test_Sn.py
|
|
25
|
+
tests/test_covcomed.py
|
|
23
26
|
tests/test_import.py
|
|
24
27
|
tests/test_iqr.py
|
|
25
28
|
tests/test_mad.py
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
# Get the version from git tags
|
|
5
|
+
version = (
|
|
6
|
+
subprocess.run(
|
|
7
|
+
["git", "describe", "--tags"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
|
|
8
|
+
)
|
|
9
|
+
.stdout.decode("utf-8")
|
|
10
|
+
.strip()
|
|
11
|
+
)
|
|
12
|
+
|
|
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()
|
|
24
|
+
|
|
25
|
+
assert "-" not in version
|
|
26
|
+
assert "." in version
|
|
27
|
+
|
|
28
|
+
# Read the long description from the README file
|
|
29
|
+
with open('README.md', encoding='utf-8') as f:
|
|
30
|
+
long_description = f.read()
|
|
31
|
+
|
|
32
|
+
# Setup function
|
|
33
|
+
setup(
|
|
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,
|
|
40
|
+
long_description_content_type='text/markdown',
|
|
41
|
+
url='https://github.com/deepak7376/robustbase',
|
|
42
|
+
author='Deepak Yadav',
|
|
43
|
+
author_email='dky.united@gmail.com',
|
|
44
|
+
license='MIT',
|
|
45
|
+
packages=find_packages(), # Automatically find packages
|
|
46
|
+
include_package_data=True,
|
|
47
|
+
project_urls={
|
|
48
|
+
'Source': 'https://github.com/deepak7376/robustbase',
|
|
49
|
+
'Tracker': 'https://github.com/deepak7376/robustbase/issues',
|
|
50
|
+
},
|
|
51
|
+
classifiers=[
|
|
52
|
+
'Development Status :: 3 - Alpha',
|
|
53
|
+
'Intended Audience :: Developers',
|
|
54
|
+
'License :: OSI Approved :: MIT License',
|
|
55
|
+
'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',
|
|
60
|
+
],
|
|
61
|
+
keywords='robust statistics robustness Sn Qn MAD IQR',
|
|
62
|
+
python_requires='>=3.10',
|
|
63
|
+
install_requires=[
|
|
64
|
+
'numpy>=1.18.0',
|
|
65
|
+
'scipy>=1.13.1',
|
|
66
|
+
],
|
|
67
|
+
extras_require={
|
|
68
|
+
'dev': [
|
|
69
|
+
'pytest>=6.0.0',
|
|
70
|
+
'pytest-cov>=2.10.0',
|
|
71
|
+
'coverage>=5.0',
|
|
72
|
+
'flake8>=3.8.0',
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
)
|
|
@@ -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!!!")
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
from robustbase.stats.covComed import covComed, CovComedResult
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_covcomed_basic():
|
|
7
|
+
np.random.seed(42)
|
|
8
|
+
X = np.random.rand(100, 3)
|
|
9
|
+
result = covComed(X)
|
|
10
|
+
|
|
11
|
+
assert isinstance(result, CovComedResult), \
|
|
12
|
+
"Result should be of type CovComedResult"
|
|
13
|
+
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
14
|
+
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
15
|
+
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_covcomed_reweight():
|
|
19
|
+
np.random.seed(42)
|
|
20
|
+
X = np.random.rand(100, 3)
|
|
21
|
+
result = covComed(X, reweight=True)
|
|
22
|
+
|
|
23
|
+
assert isinstance(result, CovComedResult), \
|
|
24
|
+
"Result should be of type CovComedResult"
|
|
25
|
+
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
26
|
+
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
27
|
+
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
28
|
+
assert np.any(result.weights == 0), \
|
|
29
|
+
"There should be some zero weights when reweighting"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_covcomed_custom_control():
|
|
33
|
+
np.random.seed(42)
|
|
34
|
+
X = np.random.rand(100, 3)
|
|
35
|
+
control = {'tolSolve': 1e-5, 'trace': True, 'wgtFUN': '01.original'}
|
|
36
|
+
result = covComed(X, n_iter=1, control=control)
|
|
37
|
+
|
|
38
|
+
assert isinstance(result, CovComedResult), \
|
|
39
|
+
"Result should be of type CovComedResult"
|
|
40
|
+
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
41
|
+
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
42
|
+
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
43
|
+
|
|
44
|
+
# def test_covcomed_no_iterations():
|
|
45
|
+
# np.random.seed(42)
|
|
46
|
+
# X = np.random.rand(100, 3)
|
|
47
|
+
# result = covComed(X, n_iter=0)
|
|
48
|
+
|
|
49
|
+
# assert isinstance(result, CovComedResult), \
|
|
50
|
+
# "Result should be of type CovComedResult"
|
|
51
|
+
# assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
52
|
+
# assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
53
|
+
# assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_covcomed_invalid_wgtfun():
|
|
57
|
+
np.random.seed(42)
|
|
58
|
+
X = np.random.rand(100, 3)
|
|
59
|
+
with pytest.raises(ValueError, match="Only '01.original' wgtFUN is implemented"):
|
|
60
|
+
covComed(X, wgt_fun="invalid")
|
|
61
|
+
|
|
62
|
+
# # Example with specific data
|
|
63
|
+
# def test_covcomed_specific_data():
|
|
64
|
+
# # Using the same example as in the description
|
|
65
|
+
# hbk_x = np.array([
|
|
66
|
+
# [1, 2, 3],
|
|
67
|
+
# [4, 5, 6],
|
|
68
|
+
# [7, 8, 9],
|
|
69
|
+
# # Add more rows if needed for testing
|
|
70
|
+
# ])
|
|
71
|
+
# with pytest.raises(LinAlgError, match="Covariance matrix is singular"):
|
|
72
|
+
# result = covComed(hbk_x)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
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'
|
robustbase-3.0.8/setup.py
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
import subprocess
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
|
-
# Get the version from git tags
|
|
6
|
-
version = (
|
|
7
|
-
subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE)
|
|
8
|
-
.stdout.decode("utf-8")
|
|
9
|
-
.strip()
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
if "-" in version:
|
|
13
|
-
v, i, s = version.split("-")
|
|
14
|
-
version = v + "+" + i + ".git." + s
|
|
15
|
-
|
|
16
|
-
assert "-" not in version
|
|
17
|
-
assert "." in version
|
|
18
|
-
|
|
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
|
-
# Read the long description from the README file
|
|
24
|
-
with open('README.md', encoding='utf-8') as f:
|
|
25
|
-
long_description = f.read()
|
|
26
|
-
|
|
27
|
-
# Setup function
|
|
28
|
-
setup(
|
|
29
|
-
name='robustbase',
|
|
30
|
-
version=version,
|
|
31
|
-
description='A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR)',
|
|
32
|
-
long_description=long_description,
|
|
33
|
-
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',
|
|
38
|
-
packages=find_packages(), # Automatically find packages
|
|
39
|
-
include_package_data=True,
|
|
40
|
-
project_urls={
|
|
41
|
-
'Source': 'https://github.com/deepak7376/robustbase',
|
|
42
|
-
'Tracker': 'https://github.com/deepak7376/robustbase/issues',
|
|
43
|
-
},
|
|
44
|
-
classifiers=[
|
|
45
|
-
'Development Status :: 3 - Alpha',
|
|
46
|
-
'Intended Audience :: Developers',
|
|
47
|
-
'License :: OSI Approved :: MIT License',
|
|
48
|
-
'Programming Language :: Python :: 3',
|
|
49
|
-
'Programming Language :: Python :: 3.6',
|
|
50
|
-
'Programming Language :: Python :: 3.7',
|
|
51
|
-
'Programming Language :: Python :: 3.8',
|
|
52
|
-
'Programming Language :: Python :: 3.9',
|
|
53
|
-
],
|
|
54
|
-
keywords='robust statistics robustness Sn Qn MAD IQR',
|
|
55
|
-
python_requires='>=3.0',
|
|
56
|
-
install_requires=[
|
|
57
|
-
'certifi>=2019.11.28',
|
|
58
|
-
'docutils>=0.15.2',
|
|
59
|
-
'numpy>=1.18.0',
|
|
60
|
-
'statistics>=1.0.3.5',
|
|
61
|
-
],
|
|
62
|
-
extras_require={
|
|
63
|
-
'dev': [
|
|
64
|
-
'pytest>=6.0.0',
|
|
65
|
-
'pytest-cov>=2.10.0',
|
|
66
|
-
'coverage>=5.0',
|
|
67
|
-
'flake8>=3.8.0',
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
)
|
|
@@ -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
|