anomaly_score_factory#

anomaly_score_factory(score: str | tuple[Callable, Callable] = 'mean')[source]#

Return anomaly score function and its initializer.

Parameters:
score: {“mean”, “mean_var”}, tuple[Callable, Callable], default=”mean”

Test statistic to use for anomaly detection.

  • “mean”: The CUSUM statistic for a change in mean (this is equivalent to a likelihood ratio test for a change in the mean of Gaussian data). For multivariate data, the sum of the CUSUM statistics for each dimension is used.

  • “mean_var”: The likelihood ratio test for a change in the mean and/or variance of Gaussian data. For multivariate data, the sum of the likelihood ratio statistics for each dimension is used.

  • If a tuple, it must contain two numba jitted functions:

    1. The first function is the scoring function, which takes five arguments:

      1. precomputed_params: The output of the second function.

      2. interval_starts: Start indices of the intervals to to test for anomalies within. 3. interval_ends: End indices of the intervals to to test for anomalies within. 4. anomaly_starts: Start indices of the anomalies. 5. anomaly_ends: End indices of the anomalies.

    For each interval_start, interval_end, anomaly_start and anomaly_end, the score should compare the data in [anomaly_start:anomaly_end+1] to the data in [interval_start:interval_end+1] that is not in [anomaly_start:anomaly_end+1].

    The overall and anomalous intervals must satisfy interval_start > anomaly_start <= anomaly_end <= interval_end.

    1. The second function is the initializer, which takes the data matrix as input and returns precomputed quantities that may speed up the score calculations. If not relevant, just return the data matrix.

Returns:
score_funcNumba jitted Callable

Score function.

init_score_funcNumba jitted Callable

Score function initializer.