chemotools 0.0.17__tar.gz → 0.0.19__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.
Files changed (44) hide show
  1. {chemotools-0.0.17 → chemotools-0.0.19}/PKG-INFO +5 -1
  2. {chemotools-0.0.17 → chemotools-0.0.19}/README.md +4 -0
  3. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/air_pls.py +27 -18
  4. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/constant_baseline_correction.py +2 -2
  5. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/cubic_spline_correction.py +2 -2
  6. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/linear_correction.py +2 -2
  7. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/non_negative.py +2 -2
  8. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/polynomial_correction.py +2 -2
  9. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/subtract_reference.py +2 -2
  10. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/derivative/norris_william.py +2 -2
  11. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/derivative/savitzky_golay.py +2 -2
  12. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scale/index_scaler.py +2 -2
  13. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scale/min_max_scaler.py +2 -2
  14. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scale/norm_scaler.py +2 -2
  15. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scatter/multiplicative_scatter_correction.py +2 -2
  16. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scatter/standard_normal_variate.py +2 -2
  17. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/smooth/mean_filter.py +2 -2
  18. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/smooth/median_filter.py +2 -2
  19. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/smooth/savitzky_golay_filter.py +2 -2
  20. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/smooth/whittaker_smooth.py +24 -14
  21. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/variable_selection/range_cut.py +2 -2
  22. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools.egg-info/PKG-INFO +5 -1
  23. {chemotools-0.0.17 → chemotools-0.0.19}/tests/test_functionality.py +2 -2
  24. {chemotools-0.0.17 → chemotools-0.0.19}/LICENSE +0 -0
  25. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/__init__.py +0 -0
  26. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/baseline/__init__.py +0 -0
  27. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/derivative/__init__.py +0 -0
  28. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scale/__init__.py +0 -0
  29. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scatter/__init__.py +0 -0
  30. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/scatter/extended_multiplicative_scatter_correction.py +0 -0
  31. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/smooth/__init__.py +0 -0
  32. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/utils/__init__.py +0 -0
  33. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/utils/check_inputs.py +0 -0
  34. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools/variable_selection/__init__.py +0 -0
  35. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools.egg-info/SOURCES.txt +0 -0
  36. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools.egg-info/dependency_links.txt +0 -0
  37. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools.egg-info/requires.txt +0 -0
  38. {chemotools-0.0.17 → chemotools-0.0.19}/chemotools.egg-info/top_level.txt +0 -0
  39. {chemotools-0.0.17 → chemotools-0.0.19}/pyproject.toml +0 -0
  40. {chemotools-0.0.17 → chemotools-0.0.19}/setup.cfg +0 -0
  41. {chemotools-0.0.17 → chemotools-0.0.19}/setup.py +0 -0
  42. {chemotools-0.0.17 → chemotools-0.0.19}/tests/__init__.py +0 -0
  43. {chemotools-0.0.17 → chemotools-0.0.19}/tests/fixtures.py +0 -0
  44. {chemotools-0.0.17 → chemotools-0.0.19}/tests/test_sklearn_compliance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chemotools
3
- Version: 0.0.17
3
+ Version: 0.0.19
4
4
  Summary: Package to integrate chemometrics in scikit-learn pipelines
5
5
  Home-page: https://github.com/paucablop/chemotools
6
6
  Author: Pau Cabaneros Lopez
@@ -13,10 +13,14 @@ Requires-Python: >=3.9
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
 
16
+ ![chemotools](assets/images/logo_5.png)
17
+
18
+
16
19
  [![pypi](https://img.shields.io/pypi/v/chemotools)](https://pypi.org/project/chemotools)
17
20
  [![pypi](https://img.shields.io/pypi/pyversions/chemotools)](https://pypi.org/project/chemotools)
18
21
  [![pypi](https://img.shields.io/pypi/l/chemotools)](https://github.com/paucablop/chemotools/blob/main/LICENSE)
19
22
  [![codecov](https://codecov.io/github/paucablop/chemotools/branch/main/graph/badge.svg?token=D7JUJM89LN)](https://codecov.io/github/paucablop/chemotools)
23
+ [![Downloads](https://static.pepy.tech/badge/chemotools)](https://pepy.tech/project/chemotools)
20
24
 
21
25
  # __chemotools__
22
26
 
@@ -1,7 +1,11 @@
1
+ ![chemotools](assets/images/logo_5.png)
2
+
3
+
1
4
  [![pypi](https://img.shields.io/pypi/v/chemotools)](https://pypi.org/project/chemotools)
2
5
  [![pypi](https://img.shields.io/pypi/pyversions/chemotools)](https://pypi.org/project/chemotools)
3
6
  [![pypi](https://img.shields.io/pypi/l/chemotools)](https://github.com/paucablop/chemotools/blob/main/LICENSE)
4
7
  [![codecov](https://codecov.io/github/paucablop/chemotools/branch/main/graph/badge.svg?token=D7JUJM89LN)](https://codecov.io/github/paucablop/chemotools)
8
+ [![Downloads](https://static.pepy.tech/badge/chemotools)](https://pepy.tech/project/chemotools)
5
9
 
6
10
  # __chemotools__
7
11
 
@@ -1,13 +1,21 @@
1
1
  import logging
2
2
  import numpy as np
3
- from sklearn.base import BaseEstimator, TransformerMixin
3
+ from scipy.sparse import csc_matrix, eye, diags
4
+ from scipy.sparse.linalg import spsolve
5
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
4
6
  from sklearn.utils.validation import check_is_fitted
5
7
 
6
8
  from chemotools.utils.check_inputs import check_input
7
9
 
8
10
  logger = logging.getLogger(__name__)
9
11
 
10
- class AirPls(BaseEstimator, TransformerMixin):
12
+ # This code is adapted from the following source:
13
+ # Z.-M. Zhang, S. Chen, and Y.-Z. Liang,
14
+ # Baseline correction using adaptive iteratively reweighted penalized least squares.
15
+ # Analyst 135 (5), 1138-1146 (2010).P
16
+
17
+
18
+ class AirPls(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
11
19
  def __init__(
12
20
  self,
13
21
  nr_iterations: int = 15,
@@ -40,7 +48,9 @@ class AirPls(BaseEstimator, TransformerMixin):
40
48
 
41
49
  # Check that the number of features is the same as the fitted data
42
50
  if X_.shape[1] != self.n_features_in_:
43
- raise ValueError(f"Expected {self.n_features_in_} features but got {X_.shape[1]}")
51
+ raise ValueError(
52
+ f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
53
+ )
44
54
 
45
55
  # Calculate the air pls smooth
46
56
  for i, x in enumerate(X_):
@@ -49,15 +59,16 @@ class AirPls(BaseEstimator, TransformerMixin):
49
59
  return X_.reshape(-1, 1) if X_.ndim == 1 else X_
50
60
 
51
61
  def _calculate_whittaker_smooth(self, x, w):
52
- x = np.asarray(x)
53
- n = len(x)
54
- D = np.diff(np.eye(n), self.polynomial_order)
62
+ X = np.matrix(x)
63
+ m = X.size
64
+ E = eye(m, format="csc")
55
65
  for i in range(self.polynomial_order):
56
- W = np.diag(w) + 1e-8*np.eye(n)
57
- Z = W + self.lam * np.dot(D, D.T)
58
- z = np.linalg.solve(Z, w * x)
59
- w = np.sqrt(np.maximum(z, 0))
60
- return z
66
+ E = E[1:] - E[:-1]
67
+ W = diags(w, 0, shape=(m, m))
68
+ A = csc_matrix(W + (self.lam * E.T * E))
69
+ B = csc_matrix(W * X.T)
70
+ background = spsolve(A, B)
71
+ return np.array(background)
61
72
 
62
73
  def _calculate_air_pls(self, x):
63
74
  m = x.shape[0]
@@ -66,16 +77,16 @@ class AirPls(BaseEstimator, TransformerMixin):
66
77
  for i in range(1, self.nr_iterations):
67
78
  z = self._calculate_whittaker_smooth(x, w)
68
79
  d = x - z
69
- dssn = np.abs(d[d<0].sum())
80
+ dssn = np.abs(d[d < 0].sum())
70
81
 
71
- if dssn < 0.001 * np.abs(x).sum():
82
+ if dssn < 0.001 * np.abs(x).sum():
72
83
  break
73
-
84
+
74
85
  if i == self.nr_iterations - 1:
75
86
  break
76
87
 
77
- w[d>=0]=0
78
- w[d<0] = np.exp(i * np.abs(d[d < 0]) / dssn)
88
+ w[d >= 0] = 0
89
+ w[d < 0] = np.exp(i * np.abs(d[d < 0]) / dssn)
79
90
 
80
91
  negative_d = d[d < 0]
81
92
  if negative_d.size > 0:
@@ -84,5 +95,3 @@ class AirPls(BaseEstimator, TransformerMixin):
84
95
  w[-1] = w[0]
85
96
 
86
97
  return z
87
-
88
-
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class ConstantBaselineCorrection(BaseEstimator, TransformerMixin):
8
+ class ConstantBaselineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(
10
10
  self, wavenumbers: np.ndarray = None, start: int = 0, end: int = 1
11
11
  ) -> None:
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
2
  from scipy.interpolate import CubicSpline
3
- from sklearn.base import BaseEstimator, TransformerMixin
3
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
4
4
  from sklearn.utils.validation import check_is_fitted
5
5
 
6
6
  from chemotools.utils.check_inputs import check_input
7
7
 
8
- class CubicSplineCorrection(BaseEstimator, TransformerMixin):
8
+ class CubicSplineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(self, indices: np.ndarray = None) -> None:
10
10
  self.indices = indices
11
11
 
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class LinearCorrection(BaseEstimator, TransformerMixin):
8
+ class LinearCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
 
10
10
  def _drift_correct_spectrum(self, x: np.ndarray) -> np.ndarray:
11
11
 
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
8
 
9
- class NonNegative(BaseEstimator, TransformerMixin):
9
+ class NonNegative(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
10
  def __init__(self, mode: str = "zero"):
11
11
  self.mode = mode
12
12
 
@@ -1,10 +1,10 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
- class PolynomialCorrection(BaseEstimator, TransformerMixin):
7
+ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
8
8
  def __init__(self, order: int = 1, indices: list = None) -> None:
9
9
  self.order = order
10
10
  self.indices = indices
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class SubtractReference(BaseEstimator, TransformerMixin):
8
+ class SubtractReference(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(
10
10
  self,
11
11
  reference: np.ndarray = None,
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
2
  from scipy.ndimage import convolve1d
3
- from sklearn.base import BaseEstimator, TransformerMixin
3
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
4
4
  from sklearn.utils.validation import check_is_fitted
5
5
 
6
6
  from chemotools.utils.check_inputs import check_input
7
7
 
8
8
 
9
- class NorrisWilliams(BaseEstimator, TransformerMixin):
9
+ class NorrisWilliams(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
10
  def __init__(
11
11
  self,
12
12
  window_size: int = 5,
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
2
  from scipy.signal import savgol_filter
3
- from sklearn.base import BaseEstimator, TransformerMixin
3
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
4
4
  from sklearn.utils.validation import check_is_fitted
5
5
 
6
6
  from chemotools.utils.check_inputs import check_input
7
7
 
8
8
 
9
- class SavitzkyGolay(BaseEstimator, TransformerMixin):
9
+ class SavitzkyGolay(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
10
  def __init__(
11
11
  self, window_size: int = 3, polynomial_order: int = 1, derivate_order: int = 1, mode: str = "nearest"
12
12
  ) -> None:
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class IndexScaler(BaseEstimator, TransformerMixin):
8
+ class IndexScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(self, index: int = 0):
10
10
  self.index = index
11
11
 
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class MinMaxScaler(BaseEstimator, TransformerMixin):
8
+ class MinMaxScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(self, norm: str = 'max'):
10
10
  self.norm = norm
11
11
 
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class NormScaler(BaseEstimator, TransformerMixin):
8
+ class NormScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(self, l_norm: int = 2):
10
10
  self.l_norm = l_norm
11
11
 
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class MultiplicativeScatterCorrection(BaseEstimator, TransformerMixin):
8
+ class MultiplicativeScatterCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(
10
10
  self,
11
11
  reference: np.ndarray = None,
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class StandardNormalVariate(BaseEstimator, TransformerMixin):
8
+ class StandardNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def fit(self, X: np.ndarray, y=None) -> "StandardNormalVariate":
10
10
  # Check that X is a 2D array and has only finite values
11
11
  X = check_input(X)
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
2
  from scipy.ndimage import uniform_filter1d
3
- from sklearn.base import BaseEstimator, TransformerMixin
3
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
4
4
  from sklearn.utils.validation import check_is_fitted
5
5
 
6
6
  from chemotools.utils.check_inputs import check_input
7
7
 
8
8
 
9
- class MeanFilter(BaseEstimator, TransformerMixin):
9
+ class MeanFilter(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
10
  def __init__(self, window_size: int = 3, mode='nearest') -> None:
11
11
  self.window_size = window_size
12
12
  self.mode = mode
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
2
  from scipy.ndimage import median_filter
3
- from sklearn.base import BaseEstimator, TransformerMixin
3
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
4
4
  from sklearn.utils.validation import check_is_fitted
5
5
 
6
6
  from chemotools.utils.check_inputs import check_input
7
7
 
8
8
 
9
- class MedianFilter(BaseEstimator, TransformerMixin):
9
+ class MedianFilter(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
10
  def __init__(self, window_size: int = 3, mode: str = 'nearest') -> None:
11
11
  self.window_size = window_size
12
12
  self.mode = mode
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
2
  from scipy.signal import savgol_filter
3
- from sklearn.base import BaseEstimator, TransformerMixin
3
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
4
4
  from sklearn.utils.validation import check_is_fitted
5
5
 
6
6
  from chemotools.utils.check_inputs import check_input
7
7
 
8
8
 
9
- class SavitzkyGolayFilter(BaseEstimator, TransformerMixin):
9
+ class SavitzkyGolayFilter(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
10
  def __init__(
11
11
  self, window_size: int = 3, polynomial_order: int = 1, mode: str = "nearest"
12
12
  ) -> None:
@@ -1,11 +1,18 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from scipy.sparse import csc_matrix, eye, diags
3
+ from scipy.sparse.linalg import spsolve
4
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
5
  from sklearn.utils.validation import check_is_fitted
4
6
 
5
7
  from chemotools.utils.check_inputs import check_input
6
8
 
9
+ # This code is adapted from the following source:
10
+ # Z.-M. Zhang, S. Chen, and Y.-Z. Liang,
11
+ # Baseline correction using adaptive iteratively reweighted penalized least squares.
12
+ # Analyst 135 (5), 1138-1146 (2010).
7
13
 
8
- class WhittakerSmooth(BaseEstimator, TransformerMixin):
14
+
15
+ class WhittakerSmooth(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
16
  def __init__(
10
17
  self,
11
18
  lam: float = 1e2,
@@ -36,22 +43,25 @@ class WhittakerSmooth(BaseEstimator, TransformerMixin):
36
43
 
37
44
  # Check that the number of features is the same as the fitted data
38
45
  if X_.shape[1] != self.n_features_in_:
39
- raise ValueError(f"Expected {self.n_features_in_} features but got {X_.shape[1]}")
46
+ raise ValueError(
47
+ f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
48
+ )
40
49
 
41
50
  # Calculate the whittaker smooth
42
51
  for i, x in enumerate(X_):
43
52
  X_[i] = self._calculate_whittaker_smooth(x)
44
-
53
+
45
54
  return X_.reshape(-1, 1) if X_.ndim == 1 else X_
46
55
 
47
56
  def _calculate_whittaker_smooth(self, x):
48
- x = np.asarray(x)
49
- n = len(x)
50
- D = np.diff(np.eye(n), self.differences)
51
- w = np.ones(n)
52
- for i in range(self.differences+1):
53
- W = np.diag(w) + 1e-8*np.eye(n)
54
- Z = W + self.lam * np.dot(D, D.T)
55
- z = np.linalg.solve(Z, w * x)
56
- w = np.sqrt(np.maximum(z, 0))
57
- return z
57
+ X = np.matrix(x)
58
+ m = X.size
59
+ E = eye(m, format="csc")
60
+ w = np.ones(m)
61
+ for i in range(self.differences):
62
+ E = E[1:] - E[:-1]
63
+ W = diags(w, 0, shape=(m, m))
64
+ A = csc_matrix(W + (self.lam * E.T * E))
65
+ B = csc_matrix(W * X.T)
66
+ background = spsolve(A, B)
67
+ return np.array(background)
@@ -1,11 +1,11 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin
2
+ from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
3
3
  from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
7
 
8
- class RangeCut(BaseEstimator, TransformerMixin):
8
+ class RangeCut(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  def __init__(
10
10
  self,
11
11
  wavenumbers: np.ndarray = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chemotools
3
- Version: 0.0.17
3
+ Version: 0.0.19
4
4
  Summary: Package to integrate chemometrics in scikit-learn pipelines
5
5
  Home-page: https://github.com/paucablop/chemotools
6
6
  Author: Pau Cabaneros Lopez
@@ -13,10 +13,14 @@ Requires-Python: >=3.9
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
15
 
16
+ ![chemotools](assets/images/logo_5.png)
17
+
18
+
16
19
  [![pypi](https://img.shields.io/pypi/v/chemotools)](https://pypi.org/project/chemotools)
17
20
  [![pypi](https://img.shields.io/pypi/pyversions/chemotools)](https://pypi.org/project/chemotools)
18
21
  [![pypi](https://img.shields.io/pypi/l/chemotools)](https://github.com/paucablop/chemotools/blob/main/LICENSE)
19
22
  [![codecov](https://codecov.io/github/paucablop/chemotools/branch/main/graph/badge.svg?token=D7JUJM89LN)](https://codecov.io/github/paucablop/chemotools)
23
+ [![Downloads](https://static.pepy.tech/badge/chemotools)](https://pepy.tech/project/chemotools)
20
24
 
21
25
  # __chemotools__
22
26
 
@@ -25,7 +25,7 @@ def test_air_pls(spectrum, reference_airpls):
25
25
  spectrum_corrected = air_pls.fit_transform(spectrum)
26
26
 
27
27
  # Assert
28
- assert np.allclose(spectrum_corrected[0], reference_airpls[0], atol=1e-8)
28
+ assert np.allclose(spectrum_corrected[0], reference_airpls[0], atol=1e-7)
29
29
 
30
30
  def test_constant_baseline_correction():
31
31
  # Arrange
@@ -356,4 +356,4 @@ def test_whitakker_smooth(spectrum, reference_whitakker):
356
356
  spectrum_corrected = whitakker_smooth.fit_transform(spectrum)
357
357
 
358
358
  # Assert
359
- assert np.allclose(spectrum_corrected[0], reference_whitakker[0], atol=1e-2)
359
+ assert np.allclose(spectrum_corrected[0], reference_whitakker[0], atol=1e-8)
File without changes
File without changes
File without changes
File without changes