Skip to content

Commit

Permalink
Merge pull request #158 from IFCA/fix-histogram-intersection-name
Browse files Browse the repository at this point in the history
Fix HistogramIntersection to HINormalizedComplement
  • Loading branch information
jaime-cespedes-sisniega authored Apr 10, 2023
2 parents 3279c10 + 8bcbab1 commit 3095f98
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/source/api_reference/detectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ The {mod}`frouros.detectors` module contains drift detection algorithms.
BhattacharyyaDistance
EMD
HellingerDistance
HistogramIntersection
HINormalizedComplement
JS
KL
MMD
Expand Down
Binary file modified docs/source/images/detectors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frouros/detectors/data_drift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CVMTest,
EMD,
HellingerDistance,
HistogramIntersection,
HINormalizedComplement,
JS,
KL,
KSTest,
Expand All @@ -23,7 +23,7 @@
"CVMTest",
"EMD",
"HellingerDistance",
"HistogramIntersection",
"HINormalizedComplement",
"IncrementalKSTest",
"JS",
"KL",
Expand Down
4 changes: 2 additions & 2 deletions frouros/detectors/data_drift/batch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
BhattacharyyaDistance,
EMD,
HellingerDistance,
HistogramIntersection,
HINormalizedComplement,
JS,
KL,
PSI,
Expand All @@ -23,7 +23,7 @@
"CVMTest",
"EMD",
"HellingerDistance",
"HistogramIntersection",
"HINormalizedComplement",
"JS",
"KL",
"KSTest",
Expand Down
4 changes: 2 additions & 2 deletions frouros/detectors/data_drift/batch/distance_based/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,7 +13,7 @@
"BhattacharyyaDistance",
"EMD",
"HellingerDistance",
"HistogramIntersection",
"HINormalizedComplement",
"JS",
"KL",
"PSI",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Histogram intersection module."""
"""HI (Histogram intersection) normalized complement module."""

from typing import List, Optional, Union

Expand All @@ -10,8 +10,8 @@
)


class HistogramIntersection(DistanceBinsBasedBase):
"""Histogram intersection [swain1991color]_ detector.
class HINormalizedComplement(DistanceBinsBasedBase):
"""HI (Histogram intersection) normalized complement [swain1991color]_ detector.
:References:
Expand All @@ -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,
},
Expand All @@ -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,
*,
Expand All @@ -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
4 changes: 2 additions & 2 deletions frouros/tests/integration/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
CVMTest,
EMD,
HellingerDistance,
HistogramIntersection,
HINormalizedComplement,
JS,
KL,
KSTest,
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions frouros/tests/integration/test_data_drift.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
BhattacharyyaDistance,
EMD,
HellingerDistance,
HistogramIntersection,
HINormalizedComplement,
PSI,
JS,
KL,
Expand Down Expand Up @@ -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(
Expand Down
Binary file modified images/detectors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3095f98

Please sign in to comment.