# OPTICS algorithm

__: Algorithm for finding density based clusters in spatial data__

**Short description**Machine learning and data mining |
---|

**Ordering points to identify the clustering structure** (**OPTICS**) is an algorithm for finding density-based^{[1]} clusters in spatial data. It was presented by Mihael Ankerst, Markus M. Breunig, Hans-Peter Kriegel and Jörg Sander.^{[2]}
Its basic idea is similar to DBSCAN,^{[3]} but it addresses one of DBSCAN's major weaknesses: the problem of detecting meaningful clusters in data of varying density. To do so, the points of the database are (linearly) ordered such that spatially closest points become neighbors in the ordering. Additionally, a special distance is stored for each point that represents the density that must be accepted for a cluster so that both points belong to the same cluster. This is represented as a dendrogram.

## Basic idea

Like DBSCAN, OPTICS requires two parameters: ε, which describes the maximum distance (radius) to consider, and MinPts, describing the number of points required to form a cluster. A point p is a *core point* if at least MinPts points are found within its ε-neighborhood [math]\displaystyle{ N_\varepsilon(p) }[/math] (including point p itself). In contrast to DBSCAN, OPTICS also considers points that are part of a more densely packed cluster, so each point is assigned a *core distance* that describes the distance to the MinPtsth closest point:

- [math]\displaystyle{ \text{core-dist}_\mathit{\varepsilon,MinPts}(p)= \begin{cases} \text{UNDEFINED} & \text{if } |N_\varepsilon(p)| \lt \mathit{MinPts}\\ \mathit{MinPts}\text{-th smallest distance in } N_\varepsilon(p) & \text{otherwise} \end{cases} }[/math]

The *reachability-distance* of another point o from a point p is either the distance between o and p, or the core distance of p, whichever is bigger:

- [math]\displaystyle{ \text{reachability-dist}_\mathit{\varepsilon,MinPts}(o,p) = \begin{cases} \text{UNDEFINED} & \text{if } |N_\varepsilon(p)| \lt \mathit{MinPts}\\ \max(\text{core-dist}_\mathit{\varepsilon,MinPts}(p), \text{dist}(p,o)) & \text{otherwise} \end{cases} }[/math]

If p and o are nearest neighbors, this is the [math]\displaystyle{ \varepsilon' \lt \varepsilon }[/math] we need to assume to have p and o belong to the same cluster.

Both core-distance and reachability-distance are undefined if no sufficiently dense cluster (w.r.t. ε) is available. Given a sufficiently large ε, this never happens, but then every ε-neighborhood query returns the entire database, resulting in [math]\displaystyle{ O(n^2) }[/math] runtime. Hence, the ε parameter is required to cut off the density of clusters that are no longer interesting, and to speed up the algorithm.

The parameter ε is, strictly speaking, not necessary. It can simply be set to the maximum possible value. When a spatial index is available, however, it does play a practical role with regards to complexity. OPTICS abstracts from DBSCAN by removing this parameter, at least to the extent of only having to give the maximum value.

## Pseudocode

The basic approach of OPTICS is similar to DBSCAN, but instead of maintaining known, but so far unprocessed cluster members in a set, they are maintained in a priority queue (e.g. using an indexed heap).

functionOPTICS(DB, ε, MinPts)isfor eachpoint p of DBdop.reachability-distance = UNDEFINEDfor eachunprocessed point p of DBdoN = getNeighbors(p, ε) mark p as processed output p to the ordered listifcore-distance(p, ε, MinPts) != UNDEFINEDthenSeeds = empty priority queue update(N, p, Seeds, ε, MinPts)for eachnext q in SeedsdoN' = getNeighbors(q, ε) mark q as processed output q to the ordered listifcore-distance(q, ε, MinPts) != UNDEFINEDdoupdate(N', q, Seeds, ε, MinPts)

In update(), the priority queue Seeds is updated with the [math]\displaystyle{ \varepsilon }[/math]-neighborhood of [math]\displaystyle{ p }[/math] and [math]\displaystyle{ q }[/math], respectively:

functionupdate(N, p, Seeds, ε, MinPts)iscoredist = core-distance(p, ε, MinPts)for eacho in Nifo is not processedthennew-reach-dist = max(coredist, dist(p,o))ifo.reachability-distance == UNDEFINEDthen// o is not in Seeds o.reachability-distance = new-reach-dist Seeds.insert(o, new-reach-dist)else// o in Seeds, check for improvementifnew-reach-dist < o.reachability-distancetheno.reachability-distance = new-reach-dist Seeds.move-up(o, new-reach-dist)

OPTICS hence outputs the points in a particular ordering, annotated with their smallest reachability distance (in the original algorithm, the core distance is also exported, but this is not required for further processing).

## Extracting the clusters

Using a *reachability-plot* (a special kind of dendrogram), the hierarchical structure of the clusters can be obtained easily. It is a 2D plot, with the ordering of the points as processed by OPTICS on the x-axis and the reachability distance on the y-axis. Since points belonging to a cluster have a low reachability distance to their nearest neighbor, the clusters show up as valleys in the reachability plot. The deeper the valley, the denser the cluster.

The image above illustrates this concept. In its upper left area, a synthetic example data set is shown. The upper right part visualizes the spanning tree produced by OPTICS, and the lower part shows the reachability plot as computed by OPTICS. Colors in this plot are labels, and not computed by the algorithm; but it is well visible how the valleys in the plot correspond to the clusters in above data set. The yellow points in this image are considered noise, and no valley is found in their reachability plot. They are usually not assigned to clusters, except the omnipresent "all data" cluster in a hierarchical result.

Extracting clusters from this plot can be done manually by selecting ranges on the x-axis after visual inspection, by selecting a threshold on the y-axis (the result is then similar to a DBSCAN clustering result with the same [math]\displaystyle{ \varepsilon }[/math] and minPts parameters; here a value of 0.1 may yield good results), or by different algorithms that try to detect the valleys by steepness, knee detection, or local maxima. A range of the plot beginning with a steep descent and ending with a steep ascent is considered a valley, and corresponds to a contiguous area of high density. Additional care must be taken to the last points in a valley to assign them to the inner or outer cluster, this can be achieved by considering the predecessor.^{[4]} Clusterings obtained this way usually are hierarchical, and cannot be achieved by a single DBSCAN run.

## Complexity

Like DBSCAN, OPTICS processes each point once, and performs one [math]\displaystyle{ \varepsilon }[/math]-neighborhood query during this processing. Given a spatial index that grants a neighborhood query in [math]\displaystyle{ O(\log n) }[/math] runtime, an overall runtime of [math]\displaystyle{ O(n \cdot \log n) }[/math] is obtained. The worst case however is [math]\displaystyle{ O(n^2) }[/math], as with DBSCAN. The authors of the original OPTICS paper report an actual constant slowdown factor of 1.6 compared to DBSCAN. Note that the value of [math]\displaystyle{ \varepsilon }[/math] might heavily influence the cost of the algorithm, since a value too large might raise the cost of a neighborhood query to linear complexity.

In particular, choosing [math]\displaystyle{ \varepsilon \gt \max_{x,y} d(x,y) }[/math] (larger than the maximum distance in the data set) is possible, but leads to quadratic complexity, since every neighborhood query returns the full data set. Even when no spatial index is available, this comes at additional cost in managing the heap. Therefore, [math]\displaystyle{ \varepsilon }[/math] should be chosen appropriately for the data set.

## Extensions

OPTICS-OF^{[5]} is an outlier detection algorithm based on OPTICS. The main use is the extraction of outliers from an existing run of OPTICS at low cost compared to using a different outlier detection method. The better known version LOF is based on the same concepts.

DeLi-Clu,^{[6]} Density-Link-Clustering combines ideas from single-linkage clustering and OPTICS, eliminating the [math]\displaystyle{ \varepsilon }[/math] parameter and offering performance improvements over OPTICS.

HiSC^{[7]} is a hierarchical subspace clustering (axis-parallel) method based on OPTICS.

HiCO^{[8]} is a hierarchical correlation clustering algorithm based on OPTICS.

DiSH^{[9]} is an improvement over HiSC that can find more complex hierarchies.

FOPTICS^{[10]} is a faster implementation using random projections.

HDBSCAN*^{[11]} is based on a refinement of DBSCAN, excluding border-points from the clusters and thus following more strictly the basic definition of density-levels by Hartigan.^{[12]}

## Availability

Java implementations of OPTICS, OPTICS-OF, DeLi-Clu, HiSC, HiCO and DiSH are available in the ELKI data mining framework (with index acceleration for several distance functions, and with automatic cluster extraction using the ξ extraction method). Other Java implementations include the Weka extension (no support for ξ cluster extraction).

The R package "dbscan" includes a C++ implementation of OPTICS (with both traditional dbscan-like and ξ cluster extraction) using a k-d tree for index acceleration for Euclidean distance only.

Python implementations of OPTICS are available in the PyClustering library and in scikit-learn. HDBSCAN* is available in the hdbscan library.

## References

- ↑ Kriegel, Hans-Peter; Kröger, Peer; Sander, Jörg; Zimek, Arthur (May 2011). "Density-based clustering".
*Wiley Interdisciplinary Reviews: Data Mining and Knowledge Discovery***1**(3): 231–240. doi:10.1002/widm.30. https://portal.findresearcher.sdu.dk/da/publications/be8fe7b9-d5e2-415c-91bc-5ac6fa00994b. - ↑ "OPTICS: Ordering Points To Identify the Clustering Structure". ACM SIGMOD international conference on Management of data. ACM Press. 1999. pp. 49–60.
- ↑ Martin Ester (1996). "A density-based algorithm for discovering clusters in large spatial databases with noise". in Evangelos Simoudis. Proceedings of the Second International Conference on Knowledge Discovery and Data Mining (KDD-96). AAAI Press. pp. 226–231. ISBN 1-57735-004-9.
- ↑ Schubert, Erich; Gertz, Michael (2018-08-22). "Improving the Cluster Structure Extracted from OPTICS Plots". Lernen, Wissen, Daten, Analysen (LWDA 2018).
**CEUR-WS 2191**. pp. 318–329. http://ceur-ws.org/Vol-2191/paper37.pdf. - ↑ "OPTICS-OF: Identifying Local Outliers".
*Principles of Data Mining and Knowledge Discovery*. Lecture Notes in Computer Science.**1704**. Springer-Verlag. 1999. pp. 262–270. doi:10.1007/b72280. ISBN 978-3-540-66490-1. http://springerlink.metapress.com/content/76bx6413gqb4tvta/. - ↑ Achtert, Elke; Böhm, Christian; Kröger, Peer (2006). "Advances in Knowledge Discovery and Data Mining, 10th Pacific-Asia Conference, PAKDD 2006, Singapore, April 9-12, 2006, Proceedings". in Ng, Wee Keong; Kitsuregawa, Masaru; Li, Jianzhong et al..
**3918**. Springer. pp. 119–128. doi:10.1007/11731139_16. - ↑ Achtert, Elke; Böhm, Christian; Kriegel, Hans-Peter; Kröger, Peer; Müller-Gorman, Ina; Zimek, Arthur (2006). "Knowledge Discovery in Databases: PKDD 2006, 10th European Conference on Principles and Practice of Knowledge Discovery in Databases, Berlin, Germany, September 18-22, 2006, Proceedings". in Fürnkranz, Johannes; Scheffer, Tobias; Spiliopoulou, Myra.
**4213**. Springer. pp. 446–453. doi:10.1007/11871637_42. - ↑ Achtert, E.; Böhm, C.; Kröger, P.; Zimek, A. (2006). "Mining Hierarchies of Correlation Clusters".
*18th International Conference on Scientific and Statistical Database Management (SSDBM'06)*. pp. 119–128. doi:10.1109/SSDBM.2006.35. ISBN 978-0-7695-2590-7. - ↑ Achtert, Elke; Böhm, Christian; Kriegel, Hans-Peter; Kröger, Peer; Müller-Gorman, Ina; Zimek, Arthur (2007). "Advances in Databases: Concepts, Systems and Applications, 12th International Conference on Database Systems for Advanced Applications, DASFAA 2007, Bangkok, Thailand, April 9-12, 2007, Proceedings". in Ramamohanarao, Kotagiri; Krishna, P. Radha; Mohania, Mukesh K. et al..
**4443**. Springer. pp. 152–163. doi:10.1007/978-3-540-71703-4_15. - ↑ Schneider, Johannes; Vlachos, Michail (2013). "Fast parameterless density-based clustering via random projections".
*22nd ACM International Conference on Information and Knowledge Management(CIKM)*. - ↑ Campello, Ricardo J. G. B.; Moulavi, Davoud; Zimek, Arthur; Sander, Jörg (22 July 2015). "Hierarchical Density Estimates for Data Clustering, Visualization, and Outlier Detection".
*ACM Transactions on Knowledge Discovery from Data***10**(1): 1–51. doi:10.1145/2733381. - ↑ J.A. Hartigan (1975).
*Clustering algorithms*. John Wiley & Sons.

Original source: https://en.wikipedia.org/wiki/OPTICS algorithm.
Read more |