Skip to content

phepy.detector

IdentityScorer

IdentityScorer(detector: OutOfDistributionDetector)

Bases: OutOfDistributionScorer

Source code in phepy/detector.py
def __init__(self, detector: OutOfDistributionDetector) -> IdentityScorer:
    super().__init__(detector)

calibrate

calibrate(
    X_valid: np.ndarray, Y_valid: np.ndarray
) -> IdentityScorer
Source code in phepy/detector.py
def calibrate(
    self, X_valid: np.ndarray, Y_valid: np.ndarray
) -> IdentityScorer:
    return self

predict

predict(X_test: np.ndarray) -> np.ndarray
Source code in phepy/detector.py
def predict(self, X_test: np.ndarray) -> np.ndarray:
    S_test = self.detector.predict(X_test)

    return (
        S_test
        if type(self.detector).low_score_is_low_confidence()
        else 1.0 - S_test
    )

OutOfDistributionDetector

Bases: abc.ABC

fit abstractmethod

fit(
    X_train: np.ndarray, Y_train: np.ndarray
) -> OutOfDistributionDetector
Source code in phepy/detector.py
@abc.abstractmethod
def fit(
    self, X_train: np.ndarray, Y_train: np.ndarray
) -> OutOfDistributionDetector:
    pass

low_score_is_low_confidence abstractmethod staticmethod

low_score_is_low_confidence() -> bool
Source code in phepy/detector.py
@staticmethod
@abc.abstractmethod
def low_score_is_low_confidence() -> bool:
    pass

predict abstractmethod

predict(X_test: np.ndarray) -> np.ndarray
Source code in phepy/detector.py
@abc.abstractmethod
def predict(self, X_test: np.ndarray) -> np.ndarray:
    pass

OutOfDistributionScorer

OutOfDistributionScorer(
    detector: OutOfDistributionDetector,
)

Bases: abc.ABC

Source code in phepy/detector.py
@abc.abstractmethod
def __init__(
    self, detector: OutOfDistributionDetector
) -> OutOfDistributionScorer:
    self.__detector = detector

calibrate abstractmethod

calibrate(
    X_valid: np.ndarray, Y_valid: np.ndarray
) -> OutOfDistributionScorer
Source code in phepy/detector.py
@abc.abstractmethod
def calibrate(
    self, X_valid: np.ndarray, Y_valid: np.ndarray
) -> OutOfDistributionScorer:
    pass

detector property

predict abstractmethod

predict(X_test: np.ndarray) -> np.ndarray

Predict the confidence scores for several test data inputs.

PARAMETER DESCRIPTION
X_test

numpy array of shape N_SAMPLES x N_FEATURES

TYPE: np.ndarray

RETURNS DESCRIPTION
np.ndarray

The array confidence scores of shape N_SAMPLES

Source code in phepy/detector.py
@abc.abstractmethod
def predict(self, X_test: np.ndarray) -> np.ndarray:
    """Predict the confidence scores for several test data inputs.

    Args:
      X_test:
        numpy array of shape `N_SAMPLES x N_FEATURES`

    Returns:
      The array confidence scores of shape `N_SAMPLES`
    """
    pass

PercentileScorer

PercentileScorer(detector: OutOfDistributionDetector)

Bases: OutOfDistributionScorer

Source code in phepy/detector.py
def __init__(
    self, detector: OutOfDistributionDetector
) -> PercentileScorer:
    super().__init__(detector)

calibrate

calibrate(
    X_valid: np.ndarray, Y_valid: np.ndarray
) -> PercentileScorer
Source code in phepy/detector.py
def calibrate(
    self, X_valid: np.ndarray, Y_valid: np.ndarray
) -> PercentileScorer:
    self.__S_valid = np.sort(self.detector.predict(X_valid))

    return self

predict

predict(X_test: np.ndarray) -> np.ndarray
Source code in phepy/detector.py
def predict(self, X_test: np.ndarray) -> np.ndarray:
    S_test = np.searchsorted(
        self.__S_valid,
        self.detector.predict(X_test),
    ) / len(self.__S_valid)

    return (
        S_test
        if type(self.detector).low_score_is_low_confidence()
        else 1.0 - S_test
    )