chemotools 0.1.4__tar.gz → 0.1.6__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.
- {chemotools-0.1.4 → chemotools-0.1.6}/PKG-INFO +18 -15
- {chemotools-0.1.4 → chemotools-0.1.6}/README.md +2 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/augmentation/__init__.py +10 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/augmentation/baseline_shift.py +23 -15
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/augmentation/exponential_noise.py +24 -15
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/augmentation/index_shift.py +24 -15
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/augmentation/normal_noise.py +24 -14
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/augmentation/spectrum_scale.py +24 -15
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/augmentation/uniform_noise.py +26 -14
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/__init__.py +13 -1
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_air_pls.py +16 -14
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_ar_pls.py +17 -17
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_constant_baseline_correction.py +19 -16
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_cubic_spline_correction.py +17 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_linear_correction.py +18 -10
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_non_negative.py +14 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_polynomial_correction.py +19 -11
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/baseline/_subtract_reference.py +17 -9
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/__init__.py +2 -0
- chemotools-0.1.6/chemotools/datasets/_base.py +122 -0
- chemotools-0.1.6/chemotools/derivative/__init__.py +4 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/derivative/_norris_william.py +14 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/derivative/_savitzky_golay.py +25 -21
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/feature_selection/__init__.py +2 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/feature_selection/_index_selector.py +18 -17
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/feature_selection/_range_cut.py +12 -7
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scale/__init__.py +2 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scale/_min_max_scaler.py +14 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scale/_norm_scaler.py +14 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scale/_point_scaler.py +18 -10
- chemotools-0.1.6/chemotools/scatter/__init__.py +13 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scatter/_extended_multiplicative_scatter_correction.py +18 -19
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scatter/_multiplicative_scatter_correction.py +18 -10
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scatter/_robust_normal_variate.py +14 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/scatter/_standard_normal_variate.py +14 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/smooth/__init__.py +3 -1
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/smooth/_mean_filter.py +14 -8
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/smooth/_median_filter.py +31 -9
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/smooth/_savitzky_golay_filter.py +20 -9
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/smooth/_whittaker_smooth.py +20 -11
- chemotools-0.1.6/pyproject.toml +38 -0
- chemotools-0.1.4/chemotools/datasets/_base.py +0 -69
- chemotools-0.1.4/chemotools/derivative/__init__.py +0 -2
- chemotools-0.1.4/chemotools/scatter/__init__.py +0 -4
- chemotools-0.1.4/chemotools/utils/check_inputs.py +0 -14
- chemotools-0.1.4/chemotools.egg-info/PKG-INFO +0 -102
- chemotools-0.1.4/chemotools.egg-info/SOURCES.txt +0 -65
- chemotools-0.1.4/chemotools.egg-info/dependency_links.txt +0 -1
- chemotools-0.1.4/chemotools.egg-info/requires.txt +0 -4
- chemotools-0.1.4/chemotools.egg-info/top_level.txt +0 -2
- chemotools-0.1.4/pyproject.toml +0 -6
- chemotools-0.1.4/setup.cfg +0 -4
- chemotools-0.1.4/setup.py +0 -36
- chemotools-0.1.4/tests/__init__.py +0 -0
- chemotools-0.1.4/tests/fixtures.py +0 -89
- chemotools-0.1.4/tests/test_datasets.py +0 -43
- chemotools-0.1.4/tests/test_functionality.py +0 -763
- chemotools-0.1.4/tests/test_sklearn_compliance.py +0 -277
- {chemotools-0.1.4 → chemotools-0.1.6}/LICENSE +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/__init__.py +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/data/__init__.py +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/data/coffee_labels.csv +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/data/coffee_spectra.csv +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/data/fermentation_hplc.csv +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/data/fermentation_spectra.csv +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/data/train_hplc.csv +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/datasets/data/train_spectra.csv +0 -0
- {chemotools-0.1.4 → chemotools-0.1.6}/chemotools/utils/__init__.py +0 -0
@@ -1,21 +1,22 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: chemotools
|
3
|
-
Version: 0.1.
|
4
|
-
Summary: Package
|
5
|
-
|
6
|
-
Author: Pau Cabaneros
|
7
|
-
|
8
|
-
Project-URL: Bug Tracker, https://github.com/paucablop/chemotools/issues/
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
3
|
+
Version: 0.1.6
|
4
|
+
Summary: chemotools: A Python Package that Integrates Chemometrics and scikit-learn
|
5
|
+
License: MIT
|
6
|
+
Author: Pau Cabaneros
|
7
|
+
Requires-Python: >=3.10,<4.0
|
10
8
|
Classifier: License :: OSI Approved :: MIT License
|
11
|
-
Classifier:
|
12
|
-
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
14
|
+
Requires-Dist: numpy (>=2.0.0,<3.0.0)
|
15
|
+
Requires-Dist: pandas (>=2.0.0,<3.0.0)
|
16
|
+
Requires-Dist: polars (>=1.17.0,<2.0.0)
|
17
|
+
Requires-Dist: pyarrow (>=18.0.0,<19.0.0)
|
18
|
+
Requires-Dist: scikit-learn (>=1.4.0,<2.0.0)
|
13
19
|
Description-Content-Type: text/markdown
|
14
|
-
License-File: LICENSE
|
15
|
-
Requires-Dist: numpy
|
16
|
-
Requires-Dist: pandas
|
17
|
-
Requires-Dist: scipy
|
18
|
-
Requires-Dist: scikit-learn
|
19
20
|
|
20
21
|

|
21
22
|
|
@@ -25,6 +26,8 @@ Requires-Dist: scikit-learn
|
|
25
26
|
[](https://github.com/paucablop/chemotools/blob/main/LICENSE)
|
26
27
|
[](https://codecov.io/github/paucablop/chemotools)
|
27
28
|
[](https://pepy.tech/project/chemotools)
|
29
|
+
[](https://doi.org/10.21105/joss.06802)
|
30
|
+
|
28
31
|
|
29
32
|
# __chemotools__
|
30
33
|
|
@@ -6,6 +6,8 @@
|
|
6
6
|
[](https://github.com/paucablop/chemotools/blob/main/LICENSE)
|
7
7
|
[](https://codecov.io/github/paucablop/chemotools)
|
8
8
|
[](https://pepy.tech/project/chemotools)
|
9
|
+
[](https://doi.org/10.21105/joss.06802)
|
10
|
+
|
9
11
|
|
10
12
|
# __chemotools__
|
11
13
|
|
@@ -4,3 +4,13 @@ from .normal_noise import NormalNoise
|
|
4
4
|
from .index_shift import IndexShift
|
5
5
|
from .spectrum_scale import SpectrumScale
|
6
6
|
from .uniform_noise import UniformNoise
|
7
|
+
|
8
|
+
|
9
|
+
__all__ = [
|
10
|
+
"BaselineShift",
|
11
|
+
"ExponentialNoise",
|
12
|
+
"NormalNoise",
|
13
|
+
"IndexShift",
|
14
|
+
"SpectrumScale",
|
15
|
+
"UniformNoise",
|
16
|
+
]
|
@@ -1,11 +1,11 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
1
3
|
import numpy as np
|
2
4
|
from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
|
3
|
-
from sklearn.utils.validation import check_is_fitted
|
4
|
-
|
5
|
-
from chemotools.utils.check_inputs import check_input
|
5
|
+
from sklearn.utils.validation import check_is_fitted, validate_data
|
6
6
|
|
7
7
|
|
8
|
-
class BaselineShift(OneToOneFeatureMixin, BaseEstimator
|
8
|
+
class BaselineShift(TransformerMixin, OneToOneFeatureMixin, BaseEstimator):
|
9
9
|
"""
|
10
10
|
Adds a constant baseline to the data. The baseline is drawn from a one-sided
|
11
11
|
uniform distribution between 0 and 0 + scale.
|
@@ -17,7 +17,7 @@ class BaselineShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
17
17
|
|
18
18
|
random_state : int, default=None
|
19
19
|
The random state to use for the random number generator.
|
20
|
-
|
20
|
+
|
21
21
|
Attributes
|
22
22
|
----------
|
23
23
|
n_features_in_ : int
|
@@ -25,7 +25,7 @@ class BaselineShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
25
25
|
|
26
26
|
_is_fitted : bool
|
27
27
|
Whether the transformer has been fitted to data.
|
28
|
-
|
28
|
+
|
29
29
|
Methods
|
30
30
|
-------
|
31
31
|
fit(X, y=None)
|
@@ -35,15 +35,14 @@ class BaselineShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
35
35
|
Transform the input data by adding a baseline the spectrum.
|
36
36
|
"""
|
37
37
|
|
38
|
-
|
39
|
-
def __init__(self, scale: int = 0.0, random_state: int = None):
|
38
|
+
def __init__(self, scale: float = 0.0, random_state: Optional[int] = None):
|
40
39
|
self.scale = scale
|
41
40
|
self.random_state = random_state
|
42
41
|
|
43
42
|
def fit(self, X: np.ndarray, y=None) -> "BaselineShift":
|
44
43
|
"""
|
45
44
|
Fit the transformer to the input data.
|
46
|
-
|
45
|
+
|
47
46
|
Parameters
|
48
47
|
----------
|
49
48
|
X : np.ndarray of shape (n_samples, n_features)
|
@@ -58,8 +57,9 @@ class BaselineShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
58
57
|
The fitted transformer.
|
59
58
|
"""
|
60
59
|
# Check that X is a 2D array and has only finite values
|
61
|
-
X =
|
62
|
-
|
60
|
+
X = validate_data(
|
61
|
+
self, X, y="no_validation", ensure_2d=True, reset=True, dtype=np.float64
|
62
|
+
)
|
63
63
|
# Set the number of features
|
64
64
|
self.n_features_in_ = X.shape[1]
|
65
65
|
|
@@ -92,12 +92,21 @@ class BaselineShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
92
92
|
check_is_fitted(self, "_is_fitted")
|
93
93
|
|
94
94
|
# Check that X is a 2D array and has only finite values
|
95
|
-
|
96
|
-
|
95
|
+
X_ = validate_data(
|
96
|
+
self,
|
97
|
+
X,
|
98
|
+
y="no_validation",
|
99
|
+
ensure_2d=True,
|
100
|
+
copy=True,
|
101
|
+
reset=False,
|
102
|
+
dtype=np.float64,
|
103
|
+
)
|
97
104
|
|
98
105
|
# Check that the number of features is the same as the fitted data
|
99
106
|
if X_.shape[1] != self.n_features_in_:
|
100
|
-
raise ValueError(
|
107
|
+
raise ValueError(
|
108
|
+
f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
|
109
|
+
)
|
101
110
|
|
102
111
|
# Calculate the scaled spectrum
|
103
112
|
for i, x in enumerate(X_):
|
@@ -108,4 +117,3 @@ class BaselineShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
108
117
|
def _add_baseline(self, x) -> np.ndarray:
|
109
118
|
adding_factor = self._rng.uniform(low=0, high=self.scale)
|
110
119
|
return np.add(x, adding_factor)
|
111
|
-
|
@@ -1,11 +1,11 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
1
3
|
import numpy as np
|
2
4
|
from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
|
3
|
-
from sklearn.utils.validation import check_is_fitted
|
4
|
-
|
5
|
-
from chemotools.utils.check_inputs import check_input
|
5
|
+
from sklearn.utils.validation import check_is_fitted, validate_data
|
6
6
|
|
7
7
|
|
8
|
-
class ExponentialNoise(OneToOneFeatureMixin, BaseEstimator
|
8
|
+
class ExponentialNoise(TransformerMixin, OneToOneFeatureMixin, BaseEstimator):
|
9
9
|
"""
|
10
10
|
Add exponential noise to the input data.
|
11
11
|
|
@@ -16,7 +16,7 @@ class ExponentialNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
16
16
|
|
17
17
|
random_state : int, default=None
|
18
18
|
The random state to use for the random number generator.
|
19
|
-
|
19
|
+
|
20
20
|
Attributes
|
21
21
|
----------
|
22
22
|
n_features_in_ : int
|
@@ -24,7 +24,7 @@ class ExponentialNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
24
24
|
|
25
25
|
_is_fitted : bool
|
26
26
|
Whether the transformer has been fitted to data.
|
27
|
-
|
27
|
+
|
28
28
|
Methods
|
29
29
|
-------
|
30
30
|
fit(X, y=None)
|
@@ -34,15 +34,14 @@ class ExponentialNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
34
34
|
Transform the input data by adding random noise.
|
35
35
|
"""
|
36
36
|
|
37
|
-
|
38
|
-
def __init__(self, scale: float = 0.0, random_state: int = None):
|
37
|
+
def __init__(self, scale: float = 0.0, random_state: Optional[int] = None):
|
39
38
|
self.scale = scale
|
40
39
|
self.random_state = random_state
|
41
40
|
|
42
41
|
def fit(self, X: np.ndarray, y=None) -> "ExponentialNoise":
|
43
42
|
"""
|
44
43
|
Fit the transformer to the input data.
|
45
|
-
|
44
|
+
|
46
45
|
Parameters
|
47
46
|
----------
|
48
47
|
X : np.ndarray of shape (n_samples, n_features)
|
@@ -57,8 +56,9 @@ class ExponentialNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
57
56
|
The fitted transformer.
|
58
57
|
"""
|
59
58
|
# Check that X is a 2D array and has only finite values
|
60
|
-
X =
|
61
|
-
|
59
|
+
X = validate_data(
|
60
|
+
self, X, y="no_validation", ensure_2d=True, reset=True, dtype=np.float64
|
61
|
+
)
|
62
62
|
# Set the number of features
|
63
63
|
self.n_features_in_ = X.shape[1]
|
64
64
|
|
@@ -91,12 +91,21 @@ class ExponentialNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
91
91
|
check_is_fitted(self, "_is_fitted")
|
92
92
|
|
93
93
|
# Check that X is a 2D array and has only finite values
|
94
|
-
|
95
|
-
|
94
|
+
X_ = validate_data(
|
95
|
+
self,
|
96
|
+
X,
|
97
|
+
y="no_validation",
|
98
|
+
ensure_2d=True,
|
99
|
+
copy=True,
|
100
|
+
reset=False,
|
101
|
+
dtype=np.float64,
|
102
|
+
)
|
96
103
|
|
97
104
|
# Check that the number of features is the same as the fitted data
|
98
105
|
if X_.shape[1] != self.n_features_in_:
|
99
|
-
raise ValueError(
|
106
|
+
raise ValueError(
|
107
|
+
f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
|
108
|
+
)
|
100
109
|
|
101
110
|
# Calculate the standard exponential variate
|
102
111
|
for i, x in enumerate(X_):
|
@@ -105,4 +114,4 @@ class ExponentialNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
105
114
|
return X_.reshape(-1, 1) if X_.ndim == 1 else X_
|
106
115
|
|
107
116
|
def _add_random_noise(self, x) -> np.ndarray:
|
108
|
-
return x + self._rng.exponential(self.scale, size=x.shape)
|
117
|
+
return x + self._rng.exponential(self.scale, size=x.shape)
|
@@ -1,14 +1,14 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
1
3
|
import numpy as np
|
2
4
|
from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
|
3
|
-
from sklearn.utils.validation import check_is_fitted
|
4
|
-
|
5
|
-
from chemotools.utils.check_inputs import check_input
|
5
|
+
from sklearn.utils.validation import check_is_fitted, validate_data
|
6
6
|
|
7
7
|
|
8
|
-
class IndexShift(OneToOneFeatureMixin, BaseEstimator
|
8
|
+
class IndexShift(TransformerMixin, OneToOneFeatureMixin, BaseEstimator):
|
9
9
|
"""
|
10
10
|
Shift the spectrum a given number of indices between - shift and + shift drawn
|
11
|
-
from a discrete uniform distribution.
|
11
|
+
from a discrete uniform distribution.
|
12
12
|
|
13
13
|
Parameters
|
14
14
|
----------
|
@@ -17,7 +17,7 @@ class IndexShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
17
17
|
|
18
18
|
random_state : int, default=None
|
19
19
|
The random state to use for the random number generator.
|
20
|
-
|
20
|
+
|
21
21
|
Attributes
|
22
22
|
----------
|
23
23
|
n_features_in_ : int
|
@@ -25,7 +25,7 @@ class IndexShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
25
25
|
|
26
26
|
_is_fitted : bool
|
27
27
|
Whether the transformer has been fitted to data.
|
28
|
-
|
28
|
+
|
29
29
|
Methods
|
30
30
|
-------
|
31
31
|
fit(X, y=None)
|
@@ -35,15 +35,14 @@ class IndexShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
35
35
|
Transform the input data by shifting the spectrum.
|
36
36
|
"""
|
37
37
|
|
38
|
-
|
39
|
-
def __init__(self, shift: int = 0, random_state: int = None):
|
38
|
+
def __init__(self, shift: int = 0, random_state: Optional[int] = None):
|
40
39
|
self.shift = shift
|
41
40
|
self.random_state = random_state
|
42
41
|
|
43
42
|
def fit(self, X: np.ndarray, y=None) -> "IndexShift":
|
44
43
|
"""
|
45
44
|
Fit the transformer to the input data.
|
46
|
-
|
45
|
+
|
47
46
|
Parameters
|
48
47
|
----------
|
49
48
|
X : np.ndarray of shape (n_samples, n_features)
|
@@ -58,7 +57,9 @@ class IndexShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
58
57
|
The fitted transformer.
|
59
58
|
"""
|
60
59
|
# Check that X is a 2D array and has only finite values
|
61
|
-
X =
|
60
|
+
X = validate_data(
|
61
|
+
self, X, y="no_validation", ensure_2d=True, reset=True, dtype=np.float64
|
62
|
+
)
|
62
63
|
|
63
64
|
# Set the number of features
|
64
65
|
self.n_features_in_ = X.shape[1]
|
@@ -92,12 +93,21 @@ class IndexShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
92
93
|
check_is_fitted(self, "_is_fitted")
|
93
94
|
|
94
95
|
# Check that X is a 2D array and has only finite values
|
95
|
-
|
96
|
-
|
96
|
+
X_ = validate_data(
|
97
|
+
self,
|
98
|
+
X,
|
99
|
+
y="no_validation",
|
100
|
+
ensure_2d=True,
|
101
|
+
copy=True,
|
102
|
+
reset=False,
|
103
|
+
dtype=np.float64,
|
104
|
+
)
|
97
105
|
|
98
106
|
# Check that the number of features is the same as the fitted data
|
99
107
|
if X_.shape[1] != self.n_features_in_:
|
100
|
-
raise ValueError(
|
108
|
+
raise ValueError(
|
109
|
+
f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
|
110
|
+
)
|
101
111
|
|
102
112
|
# Calculate the standard normal variate
|
103
113
|
for i, x in enumerate(X_):
|
@@ -108,4 +118,3 @@ class IndexShift(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
108
118
|
def _shift_spectrum(self, x) -> np.ndarray:
|
109
119
|
shift_amount = self._rng.integers(-self.shift, self.shift, endpoint=True)
|
110
120
|
return np.roll(x, shift_amount)
|
111
|
-
|
@@ -1,11 +1,11 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
1
3
|
import numpy as np
|
2
4
|
from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
|
3
|
-
from sklearn.utils.validation import check_is_fitted
|
4
|
-
|
5
|
-
from chemotools.utils.check_inputs import check_input
|
5
|
+
from sklearn.utils.validation import check_is_fitted, validate_data
|
6
6
|
|
7
7
|
|
8
|
-
class NormalNoise(OneToOneFeatureMixin, BaseEstimator
|
8
|
+
class NormalNoise(TransformerMixin, OneToOneFeatureMixin, BaseEstimator):
|
9
9
|
"""
|
10
10
|
Add normal noise to the input data.
|
11
11
|
|
@@ -16,7 +16,7 @@ class NormalNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
16
16
|
|
17
17
|
random_state : int, default=None
|
18
18
|
The random state to use for the random number generator.
|
19
|
-
|
19
|
+
|
20
20
|
Attributes
|
21
21
|
----------
|
22
22
|
n_features_in_ : int
|
@@ -24,7 +24,7 @@ class NormalNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
24
24
|
|
25
25
|
_is_fitted : bool
|
26
26
|
Whether the transformer has been fitted to data.
|
27
|
-
|
27
|
+
|
28
28
|
Methods
|
29
29
|
-------
|
30
30
|
fit(X, y=None)
|
@@ -34,15 +34,14 @@ class NormalNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
34
34
|
Transform the input data by adding random noise.
|
35
35
|
"""
|
36
36
|
|
37
|
-
|
38
|
-
def __init__(self, scale: float = 0.0, random_state: int = None):
|
37
|
+
def __init__(self, scale: float = 0.0, random_state: Optional[int] = None):
|
39
38
|
self.scale = scale
|
40
39
|
self.random_state = random_state
|
41
40
|
|
42
41
|
def fit(self, X: np.ndarray, y=None) -> "NormalNoise":
|
43
42
|
"""
|
44
43
|
Fit the transformer to the input data.
|
45
|
-
|
44
|
+
|
46
45
|
Parameters
|
47
46
|
----------
|
48
47
|
X : np.ndarray of shape (n_samples, n_features)
|
@@ -57,7 +56,9 @@ class NormalNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
57
56
|
The fitted transformer.
|
58
57
|
"""
|
59
58
|
# Check that X is a 2D array and has only finite values
|
60
|
-
X =
|
59
|
+
X = validate_data(
|
60
|
+
self, X, y="no_validation", ensure_2d=True, reset=True, dtype=np.float64
|
61
|
+
)
|
61
62
|
|
62
63
|
# Set the number of features
|
63
64
|
self.n_features_in_ = X.shape[1]
|
@@ -91,12 +92,21 @@ class NormalNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
91
92
|
check_is_fitted(self, "_is_fitted")
|
92
93
|
|
93
94
|
# Check that X is a 2D array and has only finite values
|
94
|
-
|
95
|
-
|
95
|
+
X_ = validate_data(
|
96
|
+
self,
|
97
|
+
X,
|
98
|
+
y="no_validation",
|
99
|
+
ensure_2d=True,
|
100
|
+
copy=True,
|
101
|
+
reset=False,
|
102
|
+
dtype=np.float64,
|
103
|
+
)
|
96
104
|
|
97
105
|
# Check that the number of features is the same as the fitted data
|
98
106
|
if X_.shape[1] != self.n_features_in_:
|
99
|
-
raise ValueError(
|
107
|
+
raise ValueError(
|
108
|
+
f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
|
109
|
+
)
|
100
110
|
|
101
111
|
# Calculate the standard normal variate
|
102
112
|
for i, x in enumerate(X_):
|
@@ -105,4 +115,4 @@ class NormalNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
105
115
|
return X_.reshape(-1, 1) if X_.ndim == 1 else X_
|
106
116
|
|
107
117
|
def _add_random_noise(self, x) -> np.ndarray:
|
108
|
-
return x + self._rng.normal(0, self.scale, size=x.shape)
|
118
|
+
return x + self._rng.normal(0, self.scale, size=x.shape)
|
@@ -1,11 +1,11 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
1
3
|
import numpy as np
|
2
4
|
from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
|
3
|
-
from sklearn.utils.validation import check_is_fitted
|
4
|
-
|
5
|
-
from chemotools.utils.check_inputs import check_input
|
5
|
+
from sklearn.utils.validation import check_is_fitted, validate_data
|
6
6
|
|
7
7
|
|
8
|
-
class SpectrumScale(OneToOneFeatureMixin, BaseEstimator
|
8
|
+
class SpectrumScale(TransformerMixin, OneToOneFeatureMixin, BaseEstimator):
|
9
9
|
"""
|
10
10
|
Scales the data by a value drawn from the uniform distribution centered
|
11
11
|
around 1.0.
|
@@ -17,7 +17,7 @@ class SpectrumScale(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
17
17
|
|
18
18
|
random_state : int, default=None
|
19
19
|
The random state to use for the random number generator.
|
20
|
-
|
20
|
+
|
21
21
|
Attributes
|
22
22
|
----------
|
23
23
|
n_features_in_ : int
|
@@ -25,7 +25,7 @@ class SpectrumScale(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
25
25
|
|
26
26
|
_is_fitted : bool
|
27
27
|
Whether the transformer has been fitted to data.
|
28
|
-
|
28
|
+
|
29
29
|
Methods
|
30
30
|
-------
|
31
31
|
fit(X, y=None)
|
@@ -35,15 +35,14 @@ class SpectrumScale(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
35
35
|
Transform the input data by scaling the spectrum.
|
36
36
|
"""
|
37
37
|
|
38
|
-
|
39
|
-
def __init__(self, scale: int = 0.0, random_state: int = None):
|
38
|
+
def __init__(self, scale: float = 0.0, random_state: Optional[int] = None):
|
40
39
|
self.scale = scale
|
41
40
|
self.random_state = random_state
|
42
41
|
|
43
42
|
def fit(self, X: np.ndarray, y=None) -> "SpectrumScale":
|
44
43
|
"""
|
45
44
|
Fit the transformer to the input data.
|
46
|
-
|
45
|
+
|
47
46
|
Parameters
|
48
47
|
----------
|
49
48
|
X : np.ndarray of shape (n_samples, n_features)
|
@@ -58,7 +57,9 @@ class SpectrumScale(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
58
57
|
The fitted transformer.
|
59
58
|
"""
|
60
59
|
# Check that X is a 2D array and has only finite values
|
61
|
-
X =
|
60
|
+
X = validate_data(
|
61
|
+
self, X, y="no_validation", ensure_2d=True, reset=True, dtype=np.float64
|
62
|
+
)
|
62
63
|
|
63
64
|
# Set the number of features
|
64
65
|
self.n_features_in_ = X.shape[1]
|
@@ -92,12 +93,21 @@ class SpectrumScale(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
92
93
|
check_is_fitted(self, "_is_fitted")
|
93
94
|
|
94
95
|
# Check that X is a 2D array and has only finite values
|
95
|
-
|
96
|
-
|
96
|
+
X_ = validate_data(
|
97
|
+
self,
|
98
|
+
X,
|
99
|
+
y="no_validation",
|
100
|
+
ensure_2d=True,
|
101
|
+
copy=True,
|
102
|
+
reset=False,
|
103
|
+
dtype=np.float64,
|
104
|
+
)
|
97
105
|
|
98
106
|
# Check that the number of features is the same as the fitted data
|
99
107
|
if X_.shape[1] != self.n_features_in_:
|
100
|
-
raise ValueError(
|
108
|
+
raise ValueError(
|
109
|
+
f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
|
110
|
+
)
|
101
111
|
|
102
112
|
# Calculate the scaled spectrum
|
103
113
|
for i, x in enumerate(X_):
|
@@ -106,6 +116,5 @@ class SpectrumScale(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
106
116
|
return X_.reshape(-1, 1) if X_.ndim == 1 else X_
|
107
117
|
|
108
118
|
def _scale_spectrum(self, x) -> np.ndarray:
|
109
|
-
scaling_factor = self._rng.uniform(low=1-self.scale, high=1+self.scale)
|
119
|
+
scaling_factor = self._rng.uniform(low=1 - self.scale, high=1 + self.scale)
|
110
120
|
return np.multiply(x, scaling_factor)
|
111
|
-
|
@@ -1,11 +1,11 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
1
3
|
import numpy as np
|
2
4
|
from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
|
3
|
-
from sklearn.utils.validation import check_is_fitted
|
4
|
-
|
5
|
-
from chemotools.utils.check_inputs import check_input
|
5
|
+
from sklearn.utils.validation import check_is_fitted, validate_data
|
6
6
|
|
7
7
|
|
8
|
-
class UniformNoise(OneToOneFeatureMixin, BaseEstimator
|
8
|
+
class UniformNoise(TransformerMixin, OneToOneFeatureMixin, BaseEstimator):
|
9
9
|
"""
|
10
10
|
Add uniform noise to the input data.
|
11
11
|
|
@@ -19,7 +19,7 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
19
19
|
|
20
20
|
random_state : int, default=None
|
21
21
|
The random state to use for the random number generator.
|
22
|
-
|
22
|
+
|
23
23
|
Attributes
|
24
24
|
----------
|
25
25
|
n_features_in_ : int
|
@@ -27,7 +27,7 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
27
27
|
|
28
28
|
_is_fitted : bool
|
29
29
|
Whether the transformer has been fitted to data.
|
30
|
-
|
30
|
+
|
31
31
|
Methods
|
32
32
|
-------
|
33
33
|
fit(X, y=None)
|
@@ -37,8 +37,9 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
37
37
|
Transform the input data by adding random noise.
|
38
38
|
"""
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
def __init__(
|
41
|
+
self, min: float = 0.0, max: float = 0.0, random_state: Optional[int] = None
|
42
|
+
):
|
42
43
|
self.min = min
|
43
44
|
self.max = max
|
44
45
|
self.random_state = random_state
|
@@ -46,7 +47,7 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
46
47
|
def fit(self, X: np.ndarray, y=None) -> "UniformNoise":
|
47
48
|
"""
|
48
49
|
Fit the transformer to the input data.
|
49
|
-
|
50
|
+
|
50
51
|
Parameters
|
51
52
|
----------
|
52
53
|
X : np.ndarray of shape (n_samples, n_features)
|
@@ -61,7 +62,9 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
61
62
|
The fitted transformer.
|
62
63
|
"""
|
63
64
|
# Check that X is a 2D array and has only finite values
|
64
|
-
X =
|
65
|
+
X = validate_data(
|
66
|
+
self, X, y="no_validation", ensure_2d=True, reset=True, dtype=np.float64
|
67
|
+
)
|
65
68
|
|
66
69
|
# Set the number of features
|
67
70
|
self.n_features_in_ = X.shape[1]
|
@@ -95,12 +98,21 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
95
98
|
check_is_fitted(self, "_is_fitted")
|
96
99
|
|
97
100
|
# Check that X is a 2D array and has only finite values
|
98
|
-
|
99
|
-
|
101
|
+
X_ = validate_data(
|
102
|
+
self,
|
103
|
+
X,
|
104
|
+
y="no_validation",
|
105
|
+
ensure_2d=True,
|
106
|
+
copy=True,
|
107
|
+
reset=False,
|
108
|
+
dtype=np.float64,
|
109
|
+
)
|
100
110
|
|
101
111
|
# Check that the number of features is the same as the fitted data
|
102
112
|
if X_.shape[1] != self.n_features_in_:
|
103
|
-
raise ValueError(
|
113
|
+
raise ValueError(
|
114
|
+
f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
|
115
|
+
)
|
104
116
|
|
105
117
|
# Calculate the standard uniform variate
|
106
118
|
for i, x in enumerate(X_):
|
@@ -109,4 +121,4 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
|
|
109
121
|
return X_.reshape(-1, 1) if X_.ndim == 1 else X_
|
110
122
|
|
111
123
|
def _add_random_noise(self, x) -> np.ndarray:
|
112
|
-
return x + self._rng.uniform(self.min, self.max, size=x.shape)
|
124
|
+
return x + self._rng.uniform(self.min, self.max, size=x.shape)
|
@@ -5,4 +5,16 @@ from ._cubic_spline_correction import CubicSplineCorrection
|
|
5
5
|
from ._linear_correction import LinearCorrection
|
6
6
|
from ._non_negative import NonNegative
|
7
7
|
from ._polynomial_correction import PolynomialCorrection
|
8
|
-
from ._subtract_reference import SubtractReference
|
8
|
+
from ._subtract_reference import SubtractReference
|
9
|
+
|
10
|
+
|
11
|
+
__all__ = [
|
12
|
+
"AirPls",
|
13
|
+
"ArPls",
|
14
|
+
"ConstantBaselineCorrection",
|
15
|
+
"CubicSplineCorrection",
|
16
|
+
"LinearCorrection",
|
17
|
+
"NonNegative",
|
18
|
+
"PolynomialCorrection",
|
19
|
+
"SubtractReference",
|
20
|
+
]
|