robustbase 3.0.8__tar.gz → 3.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.
- {robustbase-3.0.8/robustbase.egg-info → robustbase-3.1.0}/PKG-INFO +21 -2
- {robustbase-3.0.8 → robustbase-3.1.0}/README.md +18 -0
- robustbase-3.1.0/requirements.txt +4 -0
- robustbase-3.1.0/robustbase/stats/__init__.py +5 -0
- robustbase-3.1.0/robustbase/stats/covComed.py +76 -0
- {robustbase-3.0.8 → robustbase-3.1.0/robustbase.egg-info}/PKG-INFO +21 -2
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase.egg-info/SOURCES.txt +2 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase.egg-info/requires.txt +1 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/setup.py +2 -1
- robustbase-3.1.0/tests/test_covcomed.py +66 -0
- robustbase-3.0.8/requirements.txt +0 -4
- robustbase-3.0.8/robustbase/stats/__init__.py +0 -4
- {robustbase-3.0.8 → robustbase-3.1.0}/LICENSE +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/MANIFEST.in +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/__init__.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/stats/Qn.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/stats/Sn.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/stats/iqr.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/stats/mad.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/utils/__init__.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/utils/mean.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/utils/median.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase/version.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase.egg-info/dependency_links.txt +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/robustbase.egg-info/top_level.txt +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/setup.cfg +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/tests/test_Qn.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/tests/test_Sn.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/tests/test_import.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/tests/test_iqr.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/tests/test_mad.py +0 -0
- {robustbase-3.0.8 → robustbase-3.1.0}/tests/test_median.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: robustbase
|
|
3
|
-
Version: 3.0
|
|
4
|
-
Summary: A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR)
|
|
3
|
+
Version: 3.1.0
|
|
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
|
|
@@ -23,6 +23,7 @@ License-File: LICENSE
|
|
|
23
23
|
Requires-Dist: certifi>=2019.11.28
|
|
24
24
|
Requires-Dist: docutils>=0.15.2
|
|
25
25
|
Requires-Dist: numpy>=1.18.0
|
|
26
|
+
Requires-Dist: scipy>=1.13.1
|
|
26
27
|
Requires-Dist: statistics>=1.0.3.5
|
|
27
28
|
Provides-Extra: dev
|
|
28
29
|
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
@@ -100,6 +101,24 @@ x = [1, 2, 3, 4, 5]
|
|
|
100
101
|
res = iqr(x)
|
|
101
102
|
```
|
|
102
103
|
|
|
104
|
+
* **Co-Median Location and Scatter "Covariance" Estimator**
|
|
105
|
+
* Compute the multivariate "Comedian" covariance, a robust measure of multivariate location and scatter. Read More
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from robustbase.stats import covComed
|
|
109
|
+
|
|
110
|
+
# Example data matrix
|
|
111
|
+
X = np.random.rand(100, 3)
|
|
112
|
+
|
|
113
|
+
# Compute the Co-Median covariance estimator
|
|
114
|
+
result = covComed(X)
|
|
115
|
+
|
|
116
|
+
# Access the components of the result
|
|
117
|
+
print("Covariance Matrix:", result.cov)
|
|
118
|
+
print("Center:", result.center)
|
|
119
|
+
print("Weights:", result.weights)
|
|
120
|
+
```
|
|
121
|
+
|
|
103
122
|
## Development Setup
|
|
104
123
|
|
|
105
124
|
For local development setup:
|
|
@@ -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:
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
def covComed(X, n_iter=2, reweight=False, tol_solve=1e-7, trace=False, wgt_fun="01.original", control=None):
|
|
9
|
+
if control is None:
|
|
10
|
+
control = {}
|
|
11
|
+
|
|
12
|
+
# Default control values
|
|
13
|
+
control_defaults = {
|
|
14
|
+
'tolSolve': tol_solve,
|
|
15
|
+
'trace': trace,
|
|
16
|
+
'wgtFUN': wgt_fun
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Update control with any additional parameters provided
|
|
20
|
+
control.update(control_defaults)
|
|
21
|
+
|
|
22
|
+
# Initial center and covariance
|
|
23
|
+
center = np.median(X, axis=0)
|
|
24
|
+
cov = np.cov(X, rowvar=False)
|
|
25
|
+
|
|
26
|
+
for i in range(n_iter):
|
|
27
|
+
# Check if covariance matrix is singular
|
|
28
|
+
if np.linalg.matrix_rank(cov) < cov.shape[0]:
|
|
29
|
+
raise LinAlgError("Covariance matrix is singular. Cannot proceed with computations.")
|
|
30
|
+
|
|
31
|
+
# Compute Mahalanobis distances
|
|
32
|
+
inv_cov = solve(cov, np.eye(cov.shape[0]), assume_a='pos')
|
|
33
|
+
dists = np.array([mahalanobis(x, center, inv_cov) for x in X])
|
|
34
|
+
|
|
35
|
+
if control['trace']:
|
|
36
|
+
print(f"Iteration {i}: center={center}, cov={cov}")
|
|
37
|
+
|
|
38
|
+
# Compute weights
|
|
39
|
+
if wgt_fun == "01.original":
|
|
40
|
+
weights = (dists <= 1).astype(int)
|
|
41
|
+
else:
|
|
42
|
+
raise ValueError("Only '01.original' wgtFUN is implemented")
|
|
43
|
+
|
|
44
|
+
# Update center and covariance with weights
|
|
45
|
+
if np.sum(weights) == 0:
|
|
46
|
+
break
|
|
47
|
+
|
|
48
|
+
center = np.average(X, axis=0, weights=weights)
|
|
49
|
+
cov = np.cov(X.T, aweights=weights)
|
|
50
|
+
|
|
51
|
+
# Final reweighting step
|
|
52
|
+
if reweight:
|
|
53
|
+
if np.linalg.matrix_rank(cov) < cov.shape[0]:
|
|
54
|
+
raise LinAlgError("Covariance matrix is singular. Cannot proceed with computations.")
|
|
55
|
+
|
|
56
|
+
inv_cov = solve(cov, np.eye(cov.shape[0]), assume_a='pos')
|
|
57
|
+
dists = np.array([mahalanobis(x, center, inv_cov) for x in X])
|
|
58
|
+
if wgt_fun == "01.original":
|
|
59
|
+
weights = (dists <= 1).astype(int)
|
|
60
|
+
else:
|
|
61
|
+
raise ValueError("Only '01.original' wgtFUN is implemented")
|
|
62
|
+
|
|
63
|
+
return CovComedResult(cov, center, weights)
|
|
64
|
+
|
|
65
|
+
# Example usage
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
# Example data matrix (with non-singular covariance matrix)
|
|
68
|
+
X = np.random.rand(100, 3) # 100 samples, 3 features
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
result = covComed(X)
|
|
72
|
+
print("Covariance Matrix:", result.cov)
|
|
73
|
+
print("Center:", result.center)
|
|
74
|
+
print("Weights:", result.weights)
|
|
75
|
+
except LinAlgError as e:
|
|
76
|
+
print("Error:", e)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: robustbase
|
|
3
|
-
Version: 3.0
|
|
4
|
-
Summary: A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR)
|
|
3
|
+
Version: 3.1.0
|
|
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
|
|
@@ -23,6 +23,7 @@ License-File: LICENSE
|
|
|
23
23
|
Requires-Dist: certifi>=2019.11.28
|
|
24
24
|
Requires-Dist: docutils>=0.15.2
|
|
25
25
|
Requires-Dist: numpy>=1.18.0
|
|
26
|
+
Requires-Dist: scipy>=1.13.1
|
|
26
27
|
Requires-Dist: statistics>=1.0.3.5
|
|
27
28
|
Provides-Extra: dev
|
|
28
29
|
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
@@ -100,6 +101,24 @@ x = [1, 2, 3, 4, 5]
|
|
|
100
101
|
res = iqr(x)
|
|
101
102
|
```
|
|
102
103
|
|
|
104
|
+
* **Co-Median Location and Scatter "Covariance" Estimator**
|
|
105
|
+
* Compute the multivariate "Comedian" covariance, a robust measure of multivariate location and scatter. Read More
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from robustbase.stats import covComed
|
|
109
|
+
|
|
110
|
+
# Example data matrix
|
|
111
|
+
X = np.random.rand(100, 3)
|
|
112
|
+
|
|
113
|
+
# Compute the Co-Median covariance estimator
|
|
114
|
+
result = covComed(X)
|
|
115
|
+
|
|
116
|
+
# Access the components of the result
|
|
117
|
+
print("Covariance Matrix:", result.cov)
|
|
118
|
+
print("Center:", result.center)
|
|
119
|
+
print("Weights:", result.weights)
|
|
120
|
+
```
|
|
121
|
+
|
|
103
122
|
## Development Setup
|
|
104
123
|
|
|
105
124
|
For local development setup:
|
|
@@ -13,6 +13,7 @@ robustbase.egg-info/top_level.txt
|
|
|
13
13
|
robustbase/stats/Qn.py
|
|
14
14
|
robustbase/stats/Sn.py
|
|
15
15
|
robustbase/stats/__init__.py
|
|
16
|
+
robustbase/stats/covComed.py
|
|
16
17
|
robustbase/stats/iqr.py
|
|
17
18
|
robustbase/stats/mad.py
|
|
18
19
|
robustbase/utils/__init__.py
|
|
@@ -20,6 +21,7 @@ robustbase/utils/mean.py
|
|
|
20
21
|
robustbase/utils/median.py
|
|
21
22
|
tests/test_Qn.py
|
|
22
23
|
tests/test_Sn.py
|
|
24
|
+
tests/test_covcomed.py
|
|
23
25
|
tests/test_import.py
|
|
24
26
|
tests/test_iqr.py
|
|
25
27
|
tests/test_mad.py
|
|
@@ -28,7 +28,7 @@ with open('README.md', encoding='utf-8') as f:
|
|
|
28
28
|
setup(
|
|
29
29
|
name='robustbase',
|
|
30
30
|
version=version,
|
|
31
|
-
description='A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR)',
|
|
31
|
+
description='A Python Based Library to Calculate Estimators (Sn, Qn, MAD, IQR, covComed)',
|
|
32
32
|
long_description=long_description,
|
|
33
33
|
long_description_content_type='text/markdown',
|
|
34
34
|
url='https://github.com/deepak7376/robustbase',
|
|
@@ -57,6 +57,7 @@ setup(
|
|
|
57
57
|
'certifi>=2019.11.28',
|
|
58
58
|
'docutils>=0.15.2',
|
|
59
59
|
'numpy>=1.18.0',
|
|
60
|
+
'scipy>=1.13.1',
|
|
60
61
|
'statistics>=1.0.3.5',
|
|
61
62
|
],
|
|
62
63
|
extras_require={
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
from robustbase.stats.covComed import covComed, CovComedResult
|
|
4
|
+
|
|
5
|
+
def test_covcomed_basic():
|
|
6
|
+
np.random.seed(42)
|
|
7
|
+
X = np.random.rand(100, 3)
|
|
8
|
+
result = covComed(X)
|
|
9
|
+
|
|
10
|
+
assert isinstance(result, CovComedResult), "Result should be of type CovComedResult"
|
|
11
|
+
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
12
|
+
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
13
|
+
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
14
|
+
|
|
15
|
+
def test_covcomed_reweight():
|
|
16
|
+
np.random.seed(42)
|
|
17
|
+
X = np.random.rand(100, 3)
|
|
18
|
+
result = covComed(X, reweight=True)
|
|
19
|
+
|
|
20
|
+
assert isinstance(result, CovComedResult), "Result should be of type CovComedResult"
|
|
21
|
+
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
22
|
+
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
23
|
+
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
24
|
+
assert np.any(result.weights == 0), "There should be some zero weights when reweighting"
|
|
25
|
+
|
|
26
|
+
def test_covcomed_custom_control():
|
|
27
|
+
np.random.seed(42)
|
|
28
|
+
X = np.random.rand(100, 3)
|
|
29
|
+
control = {'tolSolve': 1e-5, 'trace': True, 'wgtFUN': '01.original'}
|
|
30
|
+
result = covComed(X, n_iter=1, control=control)
|
|
31
|
+
|
|
32
|
+
assert isinstance(result, CovComedResult), "Result should be of type CovComedResult"
|
|
33
|
+
assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
34
|
+
assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
35
|
+
assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
36
|
+
|
|
37
|
+
# def test_covcomed_no_iterations():
|
|
38
|
+
# np.random.seed(42)
|
|
39
|
+
# X = np.random.rand(100, 3)
|
|
40
|
+
# result = covComed(X, n_iter=0)
|
|
41
|
+
|
|
42
|
+
# assert isinstance(result, CovComedResult), "Result should be of type CovComedResult"
|
|
43
|
+
# assert result.cov.shape == (3, 3), "Covariance matrix should be 3x3"
|
|
44
|
+
# assert result.center.shape == (3,), "Center should be a 3-element vector"
|
|
45
|
+
# assert len(result.weights) == 100, "Weights should have 100 elements"
|
|
46
|
+
|
|
47
|
+
def test_covcomed_invalid_wgtfun():
|
|
48
|
+
np.random.seed(42)
|
|
49
|
+
X = np.random.rand(100, 3)
|
|
50
|
+
with pytest.raises(ValueError, match="Only '01.original' wgtFUN is implemented"):
|
|
51
|
+
covComed(X, wgt_fun="invalid")
|
|
52
|
+
|
|
53
|
+
# # Example with specific data
|
|
54
|
+
# def test_covcomed_specific_data():
|
|
55
|
+
# # Using the same example as in the description
|
|
56
|
+
# hbk_x = np.array([
|
|
57
|
+
# [1, 2, 3],
|
|
58
|
+
# [4, 5, 6],
|
|
59
|
+
# [7, 8, 9],
|
|
60
|
+
# # Add more rows if needed for testing
|
|
61
|
+
# ])
|
|
62
|
+
# with pytest.raises(LinAlgError, match="Covariance matrix is singular"):
|
|
63
|
+
# result = covComed(hbk_x)
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
pytest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|