# 约束聚类

约束聚类是一种机器学习方法，它在将数据划分为簇的同时满足用户提供的成对约束，从而使输出反映背景知识，而不仅仅是距离结构。两种标准的约束类型是必须连接（must-link），即两个点必须落在同一个簇中，以及不可连接（cannot-link），即它们必须落在不同的簇中。约束可以作为永远不能被打破的硬性要求来执行，也可以作为可能以一定代价被违反的软偏好来执行。与纯无监督聚类相比，这种引导将输出引向用户真正想要的分组，并且还可以通过对划分的搜索进行剪枝来减少运行时间。<sup>[1](https://wkiri.com/research/papers/wagstaff-constraints-00.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 约束词汇 | 必须连接（同簇）和不可连接（不同簇），于2000年随“约束聚类”这一名称一同引入<sup>[1](https://wkiri.com/research/papers/wagstaff-constraints-00.pdf)</sup> |
| 硬约束与软约束 | 硬约束必须被满足；软约束可以在不同程度上被违反<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup> |
| 硬执行的失效模式 | 如果某个点不存在合法的簇，COP-K均值返回空划分<sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup> |
| 计算成本 | 判定是否存在可行划分是NP完全的<sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup> |
| 精度收益 | 仅需10至100条约束即可在四个早期测试数据集中的三个上提升精度，同时降低运行时间<sup>[1](https://wkiri.com/research/papers/wagstaff-constraints-00.pdf)</sup> |
| 现代规模 | 整数规划方法可处理60,000个对象、100个簇和数百万条不可连接约束<sup>[5](https://doi.org/10.1287/ijoc.2023.0419)</sup> |
| 首个应用 | GPS数据中的车辆车道识别<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup> |

## 工作原理

一个约束集由必须连接对 \( C_{=} \) 和不可连接对 \( C_{\neq} \) 组成，目标是找到一个 \( K \) 个簇的划分，理想情况下满足 \( C_{=} \cup C_{\neq} \) 中的每一条约束。<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup> 由于必须连接具有传递性，实践者在聚类之前会对约束集取传递闭包：如果 \( d_i \) 必须连接到 \( d_j \)，而 \( d_j \) 不可连接到 \( d_k \)，那么 \( d_i \) 不可连接到 \( d_k \)。<sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup>

不同机制在约束如何触及目标函数上有所区别。硬执行，如COP-K均值中所采用的，限制每一步分配：一个点被分配到其最近的簇，除非这样做违反了某条约束，此时算法沿排好序的簇列表逐个向下查找，直到找到合法的归属。<sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup> PKM和CVQE等惩罚式表述则允许在满足约束会大幅恶化目标函数时忽略该约束，当约束含有噪声时，这比COP-K均值给出更好的结果。<sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup> 置信度表述为每条约束赋予一个0到1之间的实数权重，其中1表示硬约束；约束谱聚类可以编码这种置信度，并保证约束满足程度达到用户指定的下界。<sup>[6](https://www.cs.ucdavis.edu/~davidson/Publications/KDD10-DMKD12.pdf)</sup><sup> • </sup><sup>[7](https://people.eng.unimelb.edu.au/baileyj/papers/SDM16LCC.pdf)</sup>

可行性是硬执行的结构性限制。某些约束集对任何 \( K \) 都不存在可行划分，例如同一对点上同时施加必须连接和不可连接，而可行性可能依赖于 \( K \)：三条两两不可连接约束 \( C_{\neq}(x_1,x_2), C_{\neq}(x_2,x_3), C_{\neq}(x_1,x_3) \) 在 \( K = 3 \) 时可满足，但在 \( K = 2 \) 时不可满足。判定是否存在可行解是NP完全的，因此迭代算法不应试图在每次迭代时验证可行性；硬约束下的聚类等价于用 \( k \) 种颜色对不可连接图进行着色。<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup><sup> • </sup><sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup><sup> • </sup><sup>[8](https://www.arxiv.org/pdf/2603.27417)</sup>

## 实施方法

实践者的工作流程分为四个阶段。第一，获取约束：从已标注的条目中获取，其标签诱导出成对关系；或者通过查询预言机来获取，由预言机对指定的一对点回答必须连接或不可连接。<sup>[9](https://www.cs.utexas.edu/~ml/papers/semi-sdm-04.pdf)</sup> 约束如何选取与约束数量同样重要：在给定精度下，空间级传播通常需要的约束数量不到约束k均值的一半，<sup>[10](https://people.eecs.berkeley.edu/~klein/papers/constrained_clustering-ICML_2002.pdf)</sup> 主动选取的约束优于随机生成的约束，<sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup><sup> • </sup><sup>[9](https://www.cs.utexas.edu/~ml/papers/semi-sdm-04.pdf)</sup> 而主动查询能在较小的监督预算下带来显著的精度提升。第二，将约束集表示为图并在传递性下闭合，将必须连接的连通分量收缩为超节点，这是精确求解器中的标准步骤。<sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup><sup> • </sup><sup>[8](https://www.arxiv.org/pdf/2603.27417)</sup> 第三，运行所选算法。在COP-K均值中，循环为：初始化 \( k \) 个中心；将每个点分配到最近的、违反检查未触发的簇，如果不存在合法簇则返回空划分；将中心重新计算为已分配点的均值；迭代至收敛。<sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup> 第四，管理不可行性，例如切换到软约束方法。<sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup>

## 起源

约束聚类这一名称以及必须连接/不可连接词汇出现于Kiri L. Wagstaff和Claire Cardie于2000年发表的《Clustering with Instance-Level Constraints》一文中，该文还引入了COP-COBWEB算法，这是COBWEB的一个修改版本，倾向于满足所有成对约束。<sup>[1](https://wkiri.com/research/papers/wagstaff-constraints-00.pdf)</sup><sup> • </sup><sup>[11](https://germain-forestier.info/publis/guidedTour2020.pdf)</sup> 随后的论文《Constrained K-means Clustering with Background Knowledge》由Kiri L. Wagstaff及其同事于2001年发表，引入了COP-K均值。<sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup> 2002年，Dan Klein、Sepandar Kamvar和[Christopher D. Manning](https://www.edgepedia.org/zh/christopher-d-manning)引入了空间级约束，在特征空间中传播成对关系，其动机是观察到前两种算法在给定极少量约束时相比其无监督对应版本几乎没有改进。<sup>[10](https://people.eecs.berkeley.edu/~klein/papers/constrained_clustering-ICML_2002.pdf)</sup> 后来的里程碑包括Hongjing Zhang及其同事的深度约束聚类框架（2021年），<sup>[12](https://doi.org/10.1007/s10618-020-00734-4)</sup> Philipp Baumann和Dorit S. Hochbaum的PCCC整数规划算法（2024年），<sup>[5](https://doi.org/10.1287/ijoc.2023.0419)</sup> 以及Anri Patron及其同事的CODAC（2026年）。<sup>[13](https://doi.org/10.1007/s10618-026-01229-4)</sup>

## 变体

**硬约束划分方法。** COP-K均值是典型例子；后来的启发式方法如ICOP-K均值和CLC-K均值，其动机来自它的不可行中间解以及对数据点处理顺序的敏感性。<sup>[8](https://www.arxiv.org/pdf/2603.27417)</sup>

**软约束k均值。** PCK均值和MPCK均值将约束视为软惩罚而非不可违反的规则。<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup> PKM和CVQE选择性地忽略会严重损害目标函数的约束。<sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup>

**谱方法与精确方法。** 约束谱聚类编码约束置信度并从下方界定满足程度；<sup>[6](https://www.cs.ucdavis.edu/~davidson/Publications/KDD10-DMKD12.pdf)</sup> 一种谱正则化变体随对象和约束的数量扩展，并在多类问题中处理两种约束类型；<sup>[14](https://www.ee.columbia.edu/~zgli/papers/CVPR09_CCSR.pdf)</sup> 由逻辑组合构建的复杂约束可以在二次规划中表示为线性等式和不等式，对于合取约束，运行速度比当时最先进的约束谱方法快达1000倍。<sup>[15](https://people.cs.vt.edu/naren/papers/clust-complex-aaai13.pdf)</sup> PCCC在分配步骤使用整数规划，其独特之处在于在一个模型中混合硬约束和置信度加权的软约束。<sup>[5](https://doi.org/10.1287/ijoc.2023.0419)</sup> Kempe交换K均值从图着色中借用Kempe链交换，在改进分配的同时保持可行性。<sup>[8](https://www.arxiv.org/pdf/2603.27417)</sup>

**深度方法。** DCC框架学习与约束一致的表示，处理标准的同组/异组约束，以及来自连续值和高级领域知识的约束。<sup>[12](https://doi.org/10.1007/s10618-020-00734-4)</sup> SpherePair用有界于 \( [0, \pi] \) 的无锚角损失编码约束，消除了预先知道簇数的需要。<sup>[16](https://proceedings.neurips.cc/paper_files/paper/2025/file/a9cae5b74cfc8f71c39a4e646db819c2-Paper-Conference.pdf)</sup> CODAC将主动选取的约束集成到[深度表示学习](https://www.edgepedia.org/zh/deep-representation-learning)中。<sup>[13](https://doi.org/10.1007/s10618-026-01229-4)</sup>

## 应用

首个应用出现在2001年的COP-K均值论文中，是GPS数据中的车辆车道识别。<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup><sup> • </sup><sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup> 按发表数量计，最大的领域是文本数据分析，其中文档聚类吸引的工作最多，其次是生物、图像和视频数据分析。<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup>

## 局限与替代方案

硬执行有三种已记录的失效模式。可行性是NP完全的，因此贪心算法可能把自己逼入死角；COP-K均值通过返回空划分来应对，而它可能产生不可行的中间解，并且对处理顺序敏感。<sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup><sup> • </sup><sup>[3](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)</sup><sup> • </sup><sup>[8](https://www.arxiv.org/pdf/2603.27417)</sup> 随机生成的约束集可能有害：对于相当一部分此类约束集，性能比完全不使用约束还差，DCC通过学习满足约束同时仍能良好聚类的表示来缓解这一负面效应。<sup>[12](https://doi.org/10.1007/s10618-020-00734-4)</sup> 含噪声的约束更适合软方法，如PKM、CVQE、<sup>[4](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)</sup> COP-RF、<sup>[17](https://xiatian-zhu.github.io/papers/TNNLS15/ZhuLoyGong_TNNLS2015.pdf)</sup> 以及PCCC的置信度加权。<sup>[5](https://doi.org/10.1287/ijoc.2023.0419)</sup>

最接近的替代分支是约束距离度量学习，它学习一个度量，将必须连接对拉近并最大化不可连接距离，而不直接产生划分；该领域分为这一分支和约束划分方法。<sup>[2](https://link.springer.com/article/10.1007/s10462-024-11103-8)</sup> 近期工作利用大语言模型自动化约束获取，为不准确的生成约束添加置信度阈值和惩罚机制。<sup>[18](https://ojs.aaai.org/index.php/AAAI/article/view/39379)</sup>

## References

1. [Clustering with Instance-level Constraints (Wagstaff & Cardie, ICML 2000)](https://wkiri.com/research/papers/wagstaff-constraints-00.pdf)
2. [Semi-supervised constrained clustering: an in-depth overview, ranked taxonomy and future research directions (Artificial Intelligence Review, 2024)](https://link.springer.com/article/10.1007/s10462-024-11103-8)
3. [Constrained K-means Clustering with Background Knowledge (Wagstaff, Cardie, Rogers, Schroedl, ICML 2001)](https://wkiri.com/research/papers/wagstaff-kmeans-01.pdf)
4. [Intractability and Clustering with Constraints / Value, Cost, and Sharing (Davidson, ICML 2007)](https://www.cs.ucdavis.edu/~davidson/Publications/ICML2007.pdf)
5. [Philipp Baumann, Dorit S. Hochbaum (2024). An Algorithm for Clustering with Confidence-Based Must-Link and Cannot-Link Constraints. INFORMS journal on computing.](https://doi.org/10.1287/ijoc.2023.0419)
6. [On Constrained Spectral Clustering and Its Applications (Davidson et al.)](https://www.cs.ucdavis.edu/~davidson/Publications/KDD10-DMKD12.pdf)
7. [Lagrangian Constrained Clustering (SDM 2016)](https://people.eng.unimelb.edu.au/baileyj/papers/SDM16LCC.pdf)
8. [Kempe Swap K-Means for constrained clustering under rigid must-link and cannot-link constraints (arXiv preprint)](https://www.arxiv.org/pdf/2603.27417)
9. [Active Semi-Supervision for Pairwise Constrained Clustering (SDM 2004)](https://www.cs.utexas.edu/~ml/papers/semi-sdm-04.pdf)
10. [From Instance-level Constraints to Space-level Constraints: Making the Most of Prior Knowledge in Data Clustering (Klein et al., ICML 2002)](https://people.eecs.berkeley.edu/~klein/papers/constrained_clustering-ICML_2002.pdf)
11. [Constrained Clustering: Current and New Trends (guided tour survey, 2020)](https://germain-forestier.info/publis/guidedTour2020.pdf)
12. [Hongjing Zhang and colleagues (2021). A framework for deep constrained clustering. Data Mining and Knowledge Discovery.](https://doi.org/10.1007/s10618-020-00734-4)
13. [Anri Patron and colleagues (2026). CODAC: Constraint-based Deep Active Clustering. Data Mining and Knowledge Discovery.](https://doi.org/10.1007/s10618-026-01229-4)
14. [Constrained Clustering via Spectral Regularization (CVPR 2009)](https://www.ee.columbia.edu/~zgli/papers/CVPR09_CCSR.pdf)
15. [Clustering with Complex Constraints - Algorithms and Applications (AAAI 2013)](https://people.cs.vt.edu/naren/papers/clust-complex-aaai13.pdf)
16. [Angular Constraint Embedding via SpherePair Loss for Constrained Clustering (NeurIPS 2025)](https://proceedings.neurips.cc/paper_files/paper/2025/file/a9cae5b74cfc8f71c39a4e646db819c2-Paper-Conference.pdf)
17. [Constrained Clustering With Imperfect Oracles (COP-RF, TNNLS 2015)](https://xiatian-zhu.github.io/papers/TNNLS15/ZhuLoyGong_TNNLS2015.pdf)
18. [Optimized Algorithms for Text Clustering with LLM-Generated Constraints (AAAI)](https://ojs.aaai.org/index.php/AAAI/article/view/39379)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Supervised, unsupervised, and semi-supervised learning › Clustering algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/constrained-clustering

English original: https://www.edgepedia.org/constrained-clustering
