Skip to content

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

Angle-Based Outlier Detection (ABOD)

Identify points with unusually little variation in directions to other observations. Angle-based information can be useful where distances alone lose contrast in high-dimensional spaces.

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 points with unusually little variation in directions to other observations. Angle-based information can be useful where distances alone lose contrast in high-dimensional spaces.

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

Pairwise weighted-angle calculations at each anchor, optionally restricted to nearest neighbors.

Assumptions

The weighting is part of the definition; variance of plain cosine similarities is a related but different score. Exact pair enumeration can be expensive. Feature scaling changes angles and must be chosen deliberately.

Formula / computational definition

For anchor xx and pairs a,ba,b, form weighted angle terms gx(a,b)=((a−x)T(b−x))/(∥a−x∥2∥b−x∥2)g_x(a,b)=((a-x)^T(b-x))/(\|a-x\|^2\|b-x\|^2) and summarize their variance. Low variance indicates an outlying anchor. Exact ABOD uses many pairs; FastABOD restricts computation to a neighborhood.

Parameters and notation

Learned or fitted quantities: Reference geometry and angle-variance scores. User-set hyperparameters/design choices: Choose exact or approximate mode, neighbor count, and treatment of duplicates. 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

Compare ranking stability as neighbor count grows, runtime, and performance under irrelevant dimensions. Inspect the scoring convention because implementations may invert the variance so larger stored values mean more anomalous.

Example application

Rank unusual directions in high-dimensional feature vectors. 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 provides ABOD. R can implement the weighted pairwise terms directly or bridge to Python. The component example calculates variance for one anchor and explicitly retains the original low-variance-is-anomalous direction.

Component: ABOD weighted-angle variance for one anchor. 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 — ABOD weighted-angle variance for one anchor. · needs numpy

import numpy as np
V=np.array([[1.,0.],[0.,1.],[2.,1.]]); values=[]
for i in range(3):
    for j in range(i+1,3): values.append(V[i]@V[j]/((V[i]@V[i])*(V[j]@V[j])))
result=np.var(values) # population variance; low means more outlying
print(result)
R

Component demo, not a trained model — ABOD weighted-angle variance for one anchor.

V=rbind(c(1,0),c(0,1),c(2,1)); pairs=combn(1:3,2)
v=apply(pairs,2,function(p) sum(V[p[1],]*V[p[2],])/(sum(V[p[1],]^2)*sum(V[p[2],]^2)))
result=mean((v-mean(v))^2)
print(result)

Sources

From the CodeSplash reference, entry UCL052.