# OPTICS算法

OPTICS（Ordering Points To Identify the Clustering Structure，即“排序点以识别聚类结构”）是一种基于密度的聚类算法，它按可达距离对数据集的点进行排序，从而无需固定单一密度阈值或预设簇的数量，就能发现密度各异的簇。其动机来自一个观察：许多真实数据集具有内在的簇结构，无法用全局密度参数来刻画，因为要揭示数据空间不同区域的簇，可能需要非常不同的局部密度。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>

与k-means或DBSCAN不同，OPTICS不返回一个划分。它在原理上类似于针对无穷多个距离参数\( \varepsilon_{i} \leq \varepsilon \)（其中\( 0 \leq \varepsilon_{i} \leq \varepsilon \)）的扩展DBSCAN，但它不分配簇归属；它存储处理顺序，并且对每个对象只存两个值：核心距离和可达距离。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>其结果既可作为独立工具用来洞察数据集的分布，也可作为预处理步骤，供其他算法在检测到的簇上运行。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>

| 关键事实 | 值 |
|---|---|
| 输出 | 一个簇排序，加上每个点的两个值（核心距离、可达距离），可视化为可达性图<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup> |
| 原始发表 | Mihael Ankerst及同事，ACM SIGMOD 1999，SIGMOD Record 28(2):49–60<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup><sup> • </sup><sup>[2](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.compute_optics_graph.html)</sup> |
| 运行时间 | 无索引时为\( O(n^{2}) \)；使用基于树的空间索引时为\( O(n \log n) \)；直接网格访问时为O(n)；原始测试中约为DBSCAN运行时间的1.6倍<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup> |
| 参数敏感性 | 可达性图对ε和MinPts相当不敏感；这些值只需“足够大”即可<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup> |
| 簇提取 | 对排序做等价于DBSCAN的扫描，或使用ξ（陡峭度）方法<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup><sup> • </sup><sup>[3](https://elki-project.github.io/releases/current/doc/elki/clustering/optics/OPTICSXi.html)</sup> |
| 实现 | scikit-learn、ELKI、R dbscan（C++配合k-d树）<sup>[4](https://sklearn.org/stable/modules/generated/sklearn.cluster.OPTICS.html)</sup><sup> • </sup><sup>[5](https://search.r-project.org/CRAN/refmans/dbscan/html/optics.html)</sup> |

## 工作原理

DBSCAN使用密度的二值谓词，而OPTICS只保留minPts要求：一个点在半径r内至少有minPts个邻居时，在该半径下就是稠密的。OPTICS是一种贪心算法，它优先处理当前种子候选中可达距离最小的未处理点，当该点为核心点时扩展其邻域，并通过优先队列组织点。<sup>[6](https://ceur-ws.org/Vol-2191/paper37.pdf)</sup>

有两个值驱动排序。对象p的核心距离，是p与其ε邻域中某个对象之间的最小距离\( \varepsilon' \)，使得p相对于\( \varepsilon' \)成为核心对象；若不存在这样的对象，则核心距离未定义。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>p相对于o的可达距离，是使p从o直接密度可达的最小距离（前提是o为核心对象），且它不能小于o的核心距离。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>

由于点按最低可达距离顺序处理，稠密区域内的点获得较小的可达值，而跨入更稀疏区域时会产生跳变。因此，将可达距离对排序作图（即可达性图），就能以深浅不一的谷地揭示密度结构，而且这种可视化与数据集的维度无关。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>

## 具体做法

使用者选择两个输入：生成距离ε（常写作\( \varepsilon_{\max} \)）和minPts。为提升性能，OPTICS使用ε范围查询来寻找邻居。<sup>[7](https://dm.cs.tu-dortmund.de/mlbits/cluster-density-optics-intro/)</sup>\( \varepsilon_{\max} \)参数是所探索邻域半径的上界：足够大的上界可以在不截断所关注尺度的前提下启用索引加速，但如果设得太低，点可能具有未定义的可达距离，更大半径上的结构将无法体现。<sup>[6](https://ceur-ws.org/Vol-2191/paper37.pdf)</sup>

算法使用按最低可达距离排序的优先队列处理点。从当前核心对象直接密度可达的对象被插入种子列表OrderSeeds，并按可达距离排序；每一步选择可达距离最小的对象，插入由OrderSeeds::update(neighbors, CenterObject)管理。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup><sup> • </sup><sup>[7](https://dm.cs.tu-dortmund.de/mlbits/cluster-density-optics-intro/)</sup>

随后从排序中提取簇。对于任意\( \varepsilon' \leq \varepsilon \)，只需扫描簇排序，根据可达距离和核心距离分配归属，即可提取基于密度的聚类。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>在R dbscan包中，extractDBSCAN()复现DBSCAN在eps设为eps_cl时的结果；唯一区别是OPTICS无法分配某些边界点，而是将其报告为噪声。<sup>[5](https://search.r-project.org/CRAN/refmans/dbscan/html/optics.html)</sup>另一种方式是ξ（Xi）提取，它定义可达距离降至当前值的\( 1-\xi \)以下或升至\( 1+\xi \)以上的陡峭区域，然后构造以陡峭下降区开始、以匹配的陡峭上升区结束的谷地<sup>[3](https://elki-project.github.io/releases/current/doc/elki/clustering/optics/OPTICSXi.html)</sup>；对xi参数的一种解释是，它按相对簇密度的变化对簇分类。<sup>[5](https://search.r-project.org/CRAN/refmans/dbscan/html/optics.html)</sup>ELKI的实现增加了一个过滤器，从陡峭上升区中剪除在簇中没有前驱的元素，从而去除一类常见的伪影。<sup>[3](https://elki-project.github.io/releases/current/doc/elki/clustering/optics/OPTICSXi.html)</sup>

## 起源

OPTICS发表于1999年ACM SIGMOD数据管理国际会议论文集，刊于SIGMOD Record 28(2):49–60。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup><sup> • </sup><sup>[8](https://sigmodrecord.org/1999/06/25/optics-ordering-points-to-identify-the-clustering-structure/)</sup><sup> • </sup><sup>[2](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.compute_optics_graph.html)</sup>该论文指出了推动这项工作的三个普遍问题：输入参数难以确定；聚类算法对参数值非常敏感；高维真实数据集具有偏斜分布，单一的全局参数设置无法揭示。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>它的谱系是DBSCAN：OPTICS将DBSCAN的密度概念扩展到无穷多个距离参数，同时只保留minPts要求。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup><sup> • </sup><sup>[6](https://ceur-ws.org/Vol-2191/paper37.pdf)</sup>

## 变体

若干方法建立在OPTICS排序之上。DBSCAN和OPTICS的概念也被复用于离群点检测，即局部离群因子LOF及密切相关的OPTICS-OF离群因子。<sup>[6](https://ceur-ws.org/Vol-2191/paper37.pdf)</sup>FOP-OPTICS处理密度不均的数据集：它从增广簇排序中找到分界点，并用其可达距离作为对应簇的邻域eps。<sup>[9](https://sage.cnpereading.com/doi/10.3233/IDA-205497)</sup>Poptics是一种可扩展的并行OPTICS算法，利用OPTICS与Prim最小生成树算法之间的相似性。<sup>[10](https://psycnet.apa.org/doi/10.1145/2503210.2503255)</sup>sOPTICS是一种近似OPTICS变体，使用随机投影处理大规模或高维数据。<sup>[11](https://papers.nips.cc/paper_files/paper/2024/file/31421b112e5f7faf4fc577b74e45dab2-Paper-Conference.pdf)</sup>

## 应用

OPTICS可在scikit-learn中使用，其文档称它与DBSCAN密切相关：与DBSCAN不同，它为可变邻域半径保留簇层次结构，并且比scikit-learn当前实现的DBSCAN更适合用于大型数据集。<sup>[4](https://sklearn.org/stable/modules/generated/sklearn.cluster.OPTICS.html)</sup>此处的提取使用cluster_method='dbscan'或cluster_method='xi'。<sup>[4](https://sklearn.org/stable/modules/generated/sklearn.cluster.OPTICS.html)</sup>R dbscan包附带一个使用k-d树进行索引加速的C++实现，仅支持欧氏距离，支持两种提取方法。<sup>[5](https://search.r-project.org/CRAN/refmans/dbscan/html/optics.html)</sup>ELKI提供OPTICSXi提取。<sup>[3](https://elki-project.github.io/releases/current/doc/elki/clustering/optics/OPTICSXi.html)</sup>

可达性图一次编码了许多密度层级。像DBSCAN那样在某个eps处做水平切割，等于选定单一密度；ξ方法则沿着谷壁走，因此能抽出位于不同深度的簇，这是单一水平切割或单一DBSCAN eps无法捕捉的情形。<sup>[12](https://github.com/J-D-3/density-clustering)</sup>这就是为什么scikit-learn称OPTICS为可变邻域半径保留簇层次结构，而DBSCAN不具备这一点。<sup>[4](https://sklearn.org/stable/modules/generated/sklearn.cluster.OPTICS.html)</sup>

## 局限与替代方案

无索引支持时运行时间为\( O(n^{2}) \)；使用基于树的空间索引（如R*树、X树或M树）时降至\( O(n \log n) \)；若可通过网格直接访问邻域，则降至O(n)，因为网格中单次邻域查询代价为O(1)。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>在大量性能测试中，OPTICS的运行时间几乎恒为DBSCAN的1.6倍，两者都主要受ε邻域查询支配。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>已发表的比较在实际开销上存在差异：scikit-learn的实现预计算k近邻搜索且不使用堆，时间复杂度为\( O(n^{2}) \)。<sup>[4](https://sklearn.org/stable/modules/generated/sklearn.cluster.OPTICS.html)</sup>在可扩展性方面，SIGMOD 2018的一篇论文指出，当时所有现有实现的时间复杂度均为\( O(n^{2}) \)，并提出一种带保证的近似算法，在任意固定维度下以\( O(n \log n) \)运行，其线性空间索引支持以近最优代价进行簇分组查询。<sup>[13](https://dl.acm.org/doi/10.1145/3183713.3196922)</sup>

可达性图对ε和MinPts相当不敏感：粗略地说，这些值只需“足够大”，具体取值并不关键。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>较大的minPts会产生更平滑的图，因为ReachDist更频繁地等于CoreDist。<sup>[14](https://dm.cs.tu-dortmund.de/en/mlbits/cluster-density-optics-extraction/)</sup>由此有两点注意事项。第一，ε选得越小，越多对象可能具有未定义的可达距离，因此较低密度的簇可能不可见。<sup>[1](https://dl.acm.org/doi/10.1145/304181.304187)</sup>第二，当\( \mathrm{minPts} \leq 2 \)时，结果等价于单链接聚类。<sup>[14](https://dm.cs.tu-dortmund.de/en/mlbits/cluster-density-optics-extraction/)</sup>簇顺序并非完全确定，因为距离相同的点可能以任意顺序处理；不同运行可能产生不同结果，但它们仍对应高度相似的簇结构。<sup>[6](https://ceur-ws.org/Vol-2191/paper37.pdf)</sup>

## References

1. [OPTICS: Ordering Points To Identify the Clustering Structure (Ankerst, Breunig, Kriegel, Sander, ACM SIGMOD 1999)](https://dl.acm.org/doi/10.1145/304181.304187)
2. [compute_optics_graph, scikit-learn documentation](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.compute_optics_graph.html)
3. [OPTICSXi (ELKI documentation)](https://elki-project.github.io/releases/current/doc/elki/clustering/optics/OPTICSXi.html)
4. [OPTICS, scikit-learn 1.9.0 documentation](https://sklearn.org/stable/modules/generated/sklearn.cluster.OPTICS.html)
5. [R: Ordering Points to Identify the Clustering Structure (OPTICS), dbscan package](https://search.r-project.org/CRAN/refmans/dbscan/html/optics.html)
6. [Improving the Cluster Structure Extracted from OPTICS Plots (Schubert et al, 2018)](https://ceur-ws.org/Vol-2191/paper37.pdf)
7. [OPTICS Clustering – Lecture Notes (TU Dortmund)](https://dm.cs.tu-dortmund.de/mlbits/cluster-density-optics-intro/)
8. [OPTICS: Ordering Points To Identify the Clustering Structure – SIGMOD Record](https://sigmodrecord.org/1999/06/25/optics-ordering-points-to-identify-the-clustering-structure/)
9. [An improved OPTICS clustering algorithm for discovering clusters with uneven densities (FOP-OPTICS)](https://sage.cnpereading.com/doi/10.3233/IDA-205497)
10. [Scalable parallel OPTICS data clustering using graph algorithmic techniques (SC '13, Poptics)](https://psycnet.apa.org/doi/10.1145/2503210.2503255)
11. [Scalable DBSCAN with Random Projections (NeurIPS 2024)](https://papers.nips.cc/paper_files/paper/2024/file/31421b112e5f7faf4fc577b74e45dab2-Paper-Conference.pdf)
12. [J-D-3/density-clustering (Rust library with OPTICS, HDBSCAN*, sOPTICS/sHDBSCAN)](https://github.com/J-D-3/density-clustering)
13. [Fast Euclidean OPTICS with Bounded Precision in Low Dimensional Space (SIGMOD 2018)](https://dl.acm.org/doi/10.1145/3183713.3196922)
14. [Cluster Extraction from OPTICS – Lecture Notes (TU Dortmund)](https://dm.cs.tu-dortmund.de/en/mlbits/cluster-density-optics-extraction/)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Databases and data systems › Data mining, warehousing, and big data › Data mining algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/optics-algorithm

English original: https://www.edgepedia.org/optics-algorithm
