robustmodels 0.1.0__py3-none-any.whl
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.
- robustmodels/__init__.py +12 -0
- robustmodels/_validation.py +40 -0
- robustmodels/covariance.py +1191 -0
- robustmodels/location.py +241 -0
- robustmodels/scale.py +758 -0
- robustmodels-0.1.0.dist-info/METADATA +151 -0
- robustmodels-0.1.0.dist-info/RECORD +9 -0
- robustmodels-0.1.0.dist-info/WHEEL +4 -0
- robustmodels-0.1.0.dist-info/licenses/LICENSE +28 -0
robustmodels/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""robustmodels: robust statistics for Python."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
from . import covariance, location, scale
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
__version__ = version("robustmodels")
|
|
9
|
+
except PackageNotFoundError:
|
|
10
|
+
__version__ = "unknown"
|
|
11
|
+
|
|
12
|
+
__all__ = ["covariance", "location", "scale"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Checks for finite samples and estimator parameters."""
|
|
2
|
+
|
|
3
|
+
from numbers import Real
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def as_1d(x):
|
|
9
|
+
"""``x`` as a finite 1-D float array."""
|
|
10
|
+
x = np.atleast_1d(np.asarray(x, dtype=float))
|
|
11
|
+
if x.ndim != 1:
|
|
12
|
+
raise ValueError(f"expected a 1-D array, got shape {x.shape}")
|
|
13
|
+
if not np.isfinite(x).all():
|
|
14
|
+
raise ValueError("x contains NaN or infinite values")
|
|
15
|
+
return x
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def check_range(name, value, low, high, low_open=False, high_open=False):
|
|
19
|
+
"""Raise ``ValueError`` unless ``value`` lies in the interval ``[low, high]``."""
|
|
20
|
+
if not isinstance(value, Real):
|
|
21
|
+
raise ValueError(f"{name} must be a number, got {value!r}")
|
|
22
|
+
below = value <= low if low_open else value < low
|
|
23
|
+
above = value >= high if high_open else value > high
|
|
24
|
+
if not np.isfinite(value) or below or above:
|
|
25
|
+
interval = f"{'(' if low_open else '['}{low}, {high}{')' if high_open else ']'}"
|
|
26
|
+
raise ValueError(f"{name} must be in {interval}, got {value}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def check_count(name, value):
|
|
30
|
+
"""Require a positive integer for a trial or iteration count."""
|
|
31
|
+
if isinstance(value, (bool, np.bool_)) or not isinstance(value, (int, np.integer)):
|
|
32
|
+
raise ValueError(f"{name} must be a positive integer, got {value!r}")
|
|
33
|
+
if value < 1:
|
|
34
|
+
raise ValueError(f"{name} must be a positive integer, got {value!r}")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def check_option(name, value, options):
|
|
38
|
+
"""Raise ``ValueError`` unless ``value`` is one of ``options``."""
|
|
39
|
+
if value not in options:
|
|
40
|
+
raise ValueError(f"{name} must be one of {list(options)}, got {value!r}")
|