milia.anomaly.models.ecod#

ECOD: empirical-CDF tail probabilities, summed over dimensions.

Functions

tails(train, X)

Left and right empirical tail probabilities of new rows under the training columns.

Classes

ECOD([contamination])

Parameter-free detector from per-dimension empirical CDFs (Li et al., 2023, IEEE TKDE).

ECODConfig(*[, name, kind, space, contamination])

Validated hyperparameters of the ECOD detector.

milia.anomaly.models.ecod.tails(train, X)#

Left and right empirical tail probabilities of new rows under the training columns.

Parameters:
  • train (ndarray) – Training data, each column sorted ascending.

  • X (ndarray) – Rows to evaluate.

Return type:

tuple[ndarray, ndarray]

Returns:

(left, right) arrays of the shape of X, clipped below at 1 / (n + 1) so an extreme point never takes log(0).

Examples

>>> left, right = tails(np.array([[1.0], [2.0], [3.0], [4.0]]), np.array([[2.0]]))
>>> float(left[0, 0]), float(right[0, 0])
(0.5, 0.5)
class milia.anomaly.models.ecod.ECOD(contamination=0.1)#

Bases: BaseDetector

Parameter-free detector from per-dimension empirical CDFs (Li et al., 2023, IEEE TKDE).

Per dimension, the smaller of the left and right tail probabilities is kept, and its negative logarithm is summed across dimensions. Implemented from the paper rather than through pyod.

Parameters:

contamination (float) – Expected share of outliers, used for the default threshold.

Examples

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> train, cal = rng.normal(size=(200, 2)), rng.normal(size=(100, 2))
>>> model = ECOD().fit(train).calibrate(cal, alpha=0.1)
>>> model.flag(np.array([[0.0, 0.0], [8.0, 8.0]])).tolist()
[False, True]
class milia.anomaly.models.ecod.ECODConfig(*, name='ecod', kind='detector', space=None, contamination=0.1)#

Bases: BaseModelConfig

Validated hyperparameters of the ECOD detector.

Fields mirror ECOD’s constructor; space is the default Optuna search space. Build the detector with make("detector", "ecod", ...) or ECOD(**config.params()).

Examples

>>> ECODConfig().name
'ecod'