Skip to content

Commit

Permalink
fix: adjust factor
Browse files Browse the repository at this point in the history
Signed-off-by: Avik Basu <[email protected]>
  • Loading branch information
ab93 committed Apr 23, 2024
1 parent 9ad6d8d commit eed9ad4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions numalogic/models/threshold/_median.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,29 @@ class MaxPercentileThreshold(BaseThresholdModel):
min_threshold: Value to be used if threshold is less than this
"""

__slots__ = ("_max_percentile", "_min_thresh", "_thresh", "_is_fitted", "_adjust_threshold")
__slots__ = (
"_max_percentile",
"_min_thresh",
"_thresh",
"_is_fitted",
"_adjust_threshold",
"_adjust_factor",
)

def __init__(
self,
max_inlier_percentile: float = 96.0,
min_threshold: float = 1e-4,
adjust_threshold: bool = False,
adjust_factor: float = 3.0,
):
super().__init__()
self._max_percentile = max_inlier_percentile
self._min_thresh = min_threshold
self._thresh = None
self._is_fitted = False
self._adjust_threshold = adjust_threshold
self._adjust_factor = adjust_factor

@property
def threshold(self):
Expand All @@ -53,13 +62,15 @@ def fit(self, x: npt.NDArray[float]) -> Self:

if self._adjust_threshold:
for idx, _ in enumerate(self._thresh):
if self._thresh[idx] / self._min_thresh < 1e-2:
ratio = self._thresh[idx] / self._min_thresh

Check warning on line 65 in numalogic/models/threshold/_median.py

View check run for this annotation

Codecov / codecov/patch

numalogic/models/threshold/_median.py#L65

Added line #L65 was not covered by tests
if ratio < 1e-2:
LOGGER.info(

Check warning on line 67 in numalogic/models/threshold/_median.py

View check run for this annotation

Codecov / codecov/patch

numalogic/models/threshold/_median.py#L67

Added line #L67 was not covered by tests
"Min threshold is less than 1e-2 times the "
"threshold for column %s; Using mean instead.",
"Min threshold ratio: %s is less than 1e-2 times the "
"threshold for column %s;",
ratio,
idx,
)
self._thresh[idx] = np.mean(x[:, idx]) + (3 * np.std(x[:, idx]))
self._thresh[idx] = self._min_thresh * self._adjust_factor

Check warning on line 73 in numalogic/models/threshold/_median.py

View check run for this annotation

Codecov / codecov/patch

numalogic/models/threshold/_median.py#L73

Added line #L73 was not covered by tests

self._thresh[self._thresh < self._min_thresh] = self._min_thresh
self._is_fitted = True
Expand Down

0 comments on commit eed9ad4

Please sign in to comment.