diff --git a/docs/source/api_reference/detectors.md b/docs/source/api_reference/detectors.md index c2716b9..bef9dc3 100644 --- a/docs/source/api_reference/detectors.md +++ b/docs/source/api_reference/detectors.md @@ -140,7 +140,7 @@ The {mod}`frouros.detectors` module contains drift detection algorithms. BhattacharyyaDistance EMD HellingerDistance - HistogramIntersection + HINormalizedComplement JS KL MMD diff --git a/docs/source/images/detectors.png b/docs/source/images/detectors.png index 52eba2e..46e89ae 100644 Binary files a/docs/source/images/detectors.png and b/docs/source/images/detectors.png differ diff --git a/frouros/detectors/data_drift/__init__.py b/frouros/detectors/data_drift/__init__.py index dc50b27..44ddda7 100644 --- a/frouros/detectors/data_drift/__init__.py +++ b/frouros/detectors/data_drift/__init__.py @@ -6,7 +6,7 @@ CVMTest, EMD, HellingerDistance, - HistogramIntersection, + HINormalizedComplement, JS, KL, KSTest, @@ -23,7 +23,7 @@ "CVMTest", "EMD", "HellingerDistance", - "HistogramIntersection", + "HINormalizedComplement", "IncrementalKSTest", "JS", "KL", diff --git a/frouros/detectors/data_drift/batch/__init__.py b/frouros/detectors/data_drift/batch/__init__.py index 96137b6..695eec6 100644 --- a/frouros/detectors/data_drift/batch/__init__.py +++ b/frouros/detectors/data_drift/batch/__init__.py @@ -4,7 +4,7 @@ BhattacharyyaDistance, EMD, HellingerDistance, - HistogramIntersection, + HINormalizedComplement, JS, KL, PSI, @@ -23,7 +23,7 @@ "CVMTest", "EMD", "HellingerDistance", - "HistogramIntersection", + "HINormalizedComplement", "JS", "KL", "KSTest", diff --git a/frouros/detectors/data_drift/batch/distance_based/__init__.py b/frouros/detectors/data_drift/batch/distance_based/__init__.py index 689a0fb..fe96d28 100644 --- a/frouros/detectors/data_drift/batch/distance_based/__init__.py +++ b/frouros/detectors/data_drift/batch/distance_based/__init__.py @@ -3,7 +3,7 @@ from .bhattacharyya_distance import BhattacharyyaDistance from .emd import EMD from .hellinger_distance import HellingerDistance -from .histogram_intersection import HistogramIntersection +from .hi_normalized_complement import HINormalizedComplement from .js import JS from .kl import KL from .psi import PSI @@ -13,7 +13,7 @@ "BhattacharyyaDistance", "EMD", "HellingerDistance", - "HistogramIntersection", + "HINormalizedComplement", "JS", "KL", "PSI", diff --git a/frouros/detectors/data_drift/batch/distance_based/histogram_intersection.py b/frouros/detectors/data_drift/batch/distance_based/hi_normalized_complement.py similarity index 75% rename from frouros/detectors/data_drift/batch/distance_based/histogram_intersection.py rename to frouros/detectors/data_drift/batch/distance_based/hi_normalized_complement.py index 8e1756c..a5a0903 100644 --- a/frouros/detectors/data_drift/batch/distance_based/histogram_intersection.py +++ b/frouros/detectors/data_drift/batch/distance_based/hi_normalized_complement.py @@ -1,4 +1,4 @@ -"""Histogram intersection module.""" +"""HI (Histogram intersection) normalized complement module.""" from typing import List, Optional, Union @@ -10,8 +10,8 @@ ) -class HistogramIntersection(DistanceBinsBasedBase): - """Histogram intersection [swain1991color]_ detector. +class HINormalizedComplement(DistanceBinsBasedBase): + """HI (Histogram intersection) normalized complement [swain1991color]_ detector. :References: @@ -33,7 +33,7 @@ def __init__( :type callbacks: Optional[Union[Callback, List[Callback]]] """ super().__init__( - statistical_method=self._histogram_intersection, + statistical_method=self._hi_normalized_complement, statistical_kwargs={ "num_bins": num_bins, }, @@ -46,13 +46,13 @@ def _distance_measure_bins( X_ref: np.ndarray, # noqa: N803 X: np.ndarray, # noqa: N803 ) -> float: - no_intersection = self._histogram_intersection( + intersection_normalized_complement = self._hi_normalized_complement( X=X_ref, Y=X, num_bins=self.num_bins ) - return no_intersection + return intersection_normalized_complement @staticmethod - def _histogram_intersection( + def _hi_normalized_complement( X: np.ndarray, # noqa: N803 Y: np.ndarray, *, @@ -68,6 +68,6 @@ def _histogram_intersection( X_hist = X_hist / X.shape[0] # noqa: N806 Y_hist, _ = np.histogram(Y, bins=num_bins, range=hist_range) # noqa: N806 Y_hist = Y_hist / Y.shape[0] # noqa: N806 - no_intersection = 1 - np.sum(np.minimum(X_hist, Y_hist)) + intersection_normalized_complement = 1 - np.sum(np.minimum(X_hist, Y_hist)) - return no_intersection + return intersection_normalized_complement diff --git a/frouros/tests/integration/test_callback.py b/frouros/tests/integration/test_callback.py index 0232a8f..d4224e1 100644 --- a/frouros/tests/integration/test_callback.py +++ b/frouros/tests/integration/test_callback.py @@ -35,7 +35,7 @@ CVMTest, EMD, HellingerDistance, - HistogramIntersection, + HINormalizedComplement, JS, KL, KSTest, @@ -52,7 +52,7 @@ (BhattacharyyaDistance, 0.55516059, 0.0), (EMD, 3.85346006, 0.0), (HellingerDistance, 0.74509099, 0.0), - (HistogramIntersection, 0.78, 0.0), + (HINormalizedComplement, 0.78, 0.0), (JS, 0.67010107, 0.0), (KL, np.inf, 0.0), (MMD, 0.71529206, 0.0), diff --git a/frouros/tests/integration/test_data_drift.py b/frouros/tests/integration/test_data_drift.py index 5d40279..6921192 100644 --- a/frouros/tests/integration/test_data_drift.py +++ b/frouros/tests/integration/test_data_drift.py @@ -10,7 +10,7 @@ BhattacharyyaDistance, EMD, HellingerDistance, - HistogramIntersection, + HINormalizedComplement, PSI, JS, KL, @@ -61,7 +61,7 @@ def test_batch_distance_based_categorical( (EMD(), 3.85346006), (JS(), 0.67010107), (KL(), np.inf), - (HistogramIntersection(), 0.78), + (HINormalizedComplement(), 0.78), ], ) def test_batch_distance_based_univariate( diff --git a/images/detectors.png b/images/detectors.png index 52eba2e..46e89ae 100644 Binary files a/images/detectors.png and b/images/detectors.png differ