Skip to content

Clustering, density estimation, and anomaly detection · Anomaly detection · UCL062 · Algorithm

Stochastic Outlier Selection (SOS)

Identify observations that receive little probabilistic affinity from other observations. An observation is unusual when few others regard it as a plausible neighbor, even if its outgoing neighborhood appears ordinary.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through discover.knn_outlier. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Identify observations that receive little probabilistic affinity from other observations. An observation is unusual when few others regard it as a plausible neighbor, even if its outgoing neighborhood appears ordinary.

Question / hypotheses

Which observations deviate from the chosen reference notion of normality, and at what operational alert rate? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.

Architecture / computational structure

Per-row entropy-matched affinities and a no-selection probability product.

Assumptions

The product's probability interpretation is internal to the stochastic-selection model, not a calibrated real-world anomaly probability. Dense affinity matrices have quadratic cost, and distance quality remains critical.

Formula / computational definition

Construct row-normalized affinities pij∝exp⁡(−βidij2)p_{ij}\propto\exp(-\beta_i d_{ij}^2) with zero self-affinity and bandwidth βi\beta_i chosen to match a target perplexity. The score is sj=∏i≠j(1−pij)s_j=\prod_{i\ne j}(1-p_{ij}), the probability of receiving no selections under the model's independence construction. Compute products through sums of logarithms for stability.

Parameters and notation

Learned or fitted quantities: Local affinity bandwidths and incoming-selection scores. User-set hyperparameters/design choices: Set perplexity, distance, bandwidth-search tolerance, and numerical clipping. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.

Fitting, fine-tuning, and adaptation

Neural fine-tuning is not applicable to this classical detector. Refit the reference model when its population changes, then recalibrate an alert threshold on a separate normal holdout. Tune sensitivity without using final-test anomaly labels repeatedly.

How to use and calibrate

Inspect incoming affinities, sensitivity to perplexity, ranking stability, and false-alarm behavior on independent reference observations. Compare with local density methods on uneven-density groups.

Example application

Find points receiving unusually little incoming neighbor affinity. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.

Interpretation / pitfalls

Watch out

The reported result is conditional on the representation and objective. An alert is a screening result, not a diagnosis or a calibrated posterior probability. Evaluate both ranking and the decision threshold.

Python and R code examples

PyOD supplies SOS. R can implement entropy-matched affinities and the log-product score or bridge to Python. The paired component computes the final no-selection product from a supplied valid affinity matrix.

Component: SOS no-incoming-selection score. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — SOS no-incoming-selection score. · needs numpy

import numpy as np
P=np.array([[0.,.8,.2],[.7,0.,.3],[.5,.5,0.]])
result=np.exp(np.log1p(-P).sum(0))
print(result)
R

Component demo, not a trained model — SOS no-incoming-selection score.

P=rbind(c(0,.8,.2),c(.7,0,.3),c(.5,.5,0))
result=exp(colSums(log1p(-P)))
print(result)

Sources

From the CodeSplash reference, entry UCL062.