\Drupal\strata\Anomaly Series

A run of observations of one measurement, and the statistics a detector asks of it.

The median and the median absolute deviation are used rather than the mean and the standard deviation. The series a detector watches is a site's own history, and a site's history contains the very spikes the detector exists to find - a mean and a standard deviation computed over a window containing one large spike are both dragged toward it, which raises the threshold enough for the next spike to look ordinary. The median absolute deviation is not moved by a minority of outliers, so yesterday's incident does not hide today's.

The 1.4826 scale factor makes the deviation comparable to a standard deviation for normally distributed data, so a threshold expressed in sigma means roughly what a reader expects.

Summary

Methods
Properties
Constants
__construct
count
isEstablished
median
deviation
score
latest
history
mean
No public properties found
SCALE
MIN_OBSERVATIONS
No protected methods found
No protected properties found
No protected constants found
medianOf
sorted
values
No private constants found

Constant

SCALE

SCALE = 1.4826

Scales the median absolute deviation onto the standard-deviation scale.

MIN_OBSERVATIONS

MIN_OBSERVATIONS = 8

Fewest observations before a deviation is meaningful.

Under this a series has no shape to depart from, and a detector says so rather than reporting that the first value it ever saw is unusual.

Properties

$sorted

$sorted : list

The observations, sorted ascending.

Type

array<int, float> —

$values

$values : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(list  $values = []) : mixed

Constructs a series.

Parameters

list $values

The observations, in any order.

Returns

mixed —

count()

count() : int

How many observations the series holds.

Returns

int —

The count.

isEstablished()

isEstablished(int  $minimum = \self::MIN_OBSERVATIONS) : bool

Whether the series is long enough to have a shape.

Parameters

int $minimum

Fewest observations to accept.

Returns

bool —

TRUE when a deviation can be computed meaningfully.

median()

median() : float

The middle observation.

Returns

float —

The median, or 0.0 for an empty series.

deviation()

deviation() : float

The median absolute deviation, scaled onto the standard-deviation scale.

Returns

float —

The deviation, or 0.0 when every observation is identical.

score()

score(float  $value) : float

How far a value sits from the middle, in deviations.

A series whose observations are all identical has no deviation, so any different value is infinitely unusual by the arithmetic. That is not useful, so the distance is expressed against the median instead: a value double the median scores 1.0 rather than infinity.

Parameters

float $value

The observation to score.

Returns

float —

Signed deviations from the median.

latest()

latest() : float|null

The most recent observation.

Returns

float|null —

The last value passed in, or NULL for an empty series.

history()

history() : self

The series without its most recent observation.

A detector scores the newest value against the history BEFORE it, so the value being judged does not shift the baseline it is judged against.

Returns

self —

The earlier observations.

mean()

mean() : float

The mean, for a report that wants one alongside the median.

Returns

float —

The mean, or 0.0 for an empty series.

medianOf()

medianOf(list  $sorted) : float

The middle value of an already-sorted list.

Parameters

list $sorted

Ascending values.

Returns

float —

The median, or 0.0 for an empty list.