# 自动机学习

自动机学习是一种机器学习技术，它通过主动查询系统并分析其响应，推断出系统的形式化状态机模型，例如确定性有限自动机（DFA）、Mealy机和寄存器自动机。该技术用于恢复软件和硬件组件的模型，以进行验证、测试和缺陷查找。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 主流设定是最小充分教师（MAT）框架，在该框架中，学习器通过两类查询与系统交互，直到学习到的模型与系统行为一致。<sup>[2](https://aqua.cs.tu-dortmund.de/storages/aqua-cs/r/Publications/Frohme2025Learnlib10Years_-_Learnlib__10_Years_Later.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 产生的模型 | 最常见的是Mealy机和DFA；可扩展到非确定性I/O自动机、寄存器自动机和定时模型<sup>[3](https://dl.acm.org/doi/10.1007/s10817-026-09758-9)</sup> |
| 核心框架 | MAT：成员查询加上以反例作答的等价查询<sup>[2](https://aqua.cs.tu-dortmund.de/storages/aqua-cs/r/Publications/Frohme2025Learnlib10Years_-_Learnlib__10_Years_Later.pdf)</sup> |
| L*查询成本 | \( O(k \cdot m \cdot n^{2}) \) 次成员查询，其中字母表大小为k，最长反例长度为m，自动机大小为n<sup>[4](https://tugraz.elsevierpure.com/ws/portalfiles/portal/77962395/3605360.pdf)</sup> |
| TTT查询成本 | O(n)次等价查询和 \( O(k \cdot n^{2} + n \log m) \) 次成员查询；在基准测试中平均比L*少用3.9倍的输入符号<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> |
| 实际规模限制 | 目前仅适用于输入少于约100个的情况，因为一致性测试成为瓶颈<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> |
| 实践中的等价性 | 由k-完备一致性测试（W方法、Wp、HSI、Hybrid-ADS）近似，其测试套件随\( \|I\|^k \)增长<sup>[5](https://link.springer.com/chapter/10.1007/978-3-031-57249-4_6)</sup> |
| 著名应用 | TLS实现、EMV银行卡、电信回归测试、嵌入式控制软件<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> |

## 工作原理

主动自动机学习通过一个等价关系\( \equiv_{H} \)来近似Nerode同余\( \equiv_{L} \)，后者关联导致相同行为的输入串，而\( \equiv_{L} \)精化\( \equiv_{H} \)；学习器通过识别到达相同状态的前缀来实现这一点。<sup>[6](https://proceedings.mlr.press/v21/steffen12a/steffen12a.pdf)</sup> 在MAT框架中，成员查询询问对输入序列\( \sigma \in I^{*} \)的输出，以系统的输出序列作答；等价查询询问假设机器H是否等价于未知机器M，回答是或给出反例\( \sigma \in I^{*} \)。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup>

Angluin的L*算法于1987年提出，从这样的教师那里学习任何正则集，其运行时间以最小DFA的状态数和所有反例的最大长度为变量，呈多项式增长。<sup>[7](https://doi.org/10.1016/0890-5401%2887%2990052-6)</sup> L*将查询结果记录在观察表中，这是用于识别正则语言的早期状态特征矩阵的改编版本。<sup>[8](https://people.cs.umu.se/drewes/biblio/ps-files/mat-survey.pdf)</sup> 在假设稳定后，等价预言机检查假设与系统是否等价，如果不等价，则返回一个反例，即不等价的见证，触发假设的精化。<sup>[2](https://aqua.cs.tu-dortmund.de/storages/aqua-cs/r/Publications/Frohme2025Learnlib10Years_-_Learnlib__10_Years_Later.pdf)</sup>

## 实施方法

实践者通过成员预言机将学习器连接到学习对象系统（SUL），在探索阶段构建暂定假设，然后在验证阶段使用等价预言机；两个阶段交替进行，直到找不到反例。<sup>[2](https://aqua.cs.tu-dortmund.de/storages/aqua-cs/r/Publications/Frohme2025Learnlib10Years_-_Learnlib__10_Years_Later.pdf)</sup> 学习器必须能够在查询之间将SUL重置到初始状态。<sup>[9](https://www.mbsd.cs.ru.nl/publications/papers/fvaan/LearningIOAs/paper.pdf)</sup> 对于带有数据值的系统，可以将映射器与推断出的Mealy机模型结合使用，带映射器的学习已在实践中应用。<sup>[6](https://proceedings.mlr.press/v21/steffen12a/steffen12a.pdf)</sup>

对于黑盒无法判定精确等价，因此等价查询由一致性测试近似。k-完备测试套件如W方法、Wp、HSI和Hybrid-ADS保证等价性，前提是SUL比假设最多多k个状态，但W方法套件随\( \|I\|^k \)增长，即使对于小的k也变得过于庞大。<sup>[5](https://link.springer.com/chapter/10.1007/978-3-031-57249-4_6)</sup> 如果假设有n个状态，SUL有n′个状态，且有k个输入，最坏情况需要覆盖所有k(n′ − n)种可能性的测试序列。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 标准工具包括基于Java的LearnLib、Python框架AALpy和用于寄存器自动机的RALib；libalf已不再积极维护。<sup>[10](https://link.springer.com/article/10.1007/s10009-026-00839-z)</sup>

## 起源

有限自动机学习的研究始于20世纪70年代，此后产生了广泛的学习模型、可学习性结果以及针对多类自动机的算法。<sup>[10](https://link.springer.com/article/10.1007/s10009-026-00839-z)</sup> 1956年针对该问题的一个算法是指数级的，而该问题被证明本质上是指数级的。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 1987年，[Dana Angluin](https://www.edgepedia.org/zh/dana-angluin)在《信息与计算》上发表了《从查询和反例学习正则集》，描述了L*和最小充分教师。<sup>[7](https://doi.org/10.1016/0890-5401%2887%2990052-6)</sup> 向学习真实系统模型的转变发生在人们观察到MAT框架可用于学习软件和硬件组件的黑盒模型，并用一致性测试工具近似等价查询之时。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup>

## 变体

主要算法变体的区别在于它们如何组织查询数据和处理反例，从而在查询复杂度上有所不同。L*需要\( O(k \cdot m \cdot n^{2}) \)次成员查询，并将反例的所有前缀添加到表中。<sup>[4](https://tugraz.elsevierpure.com/ws/portalfiles/portal/77962395/3605360.pdf)</sup> Rivest–Schapire算法将其减少到\( O(k \cdot n^{2} + n \log m) \)，使查询计数仅对数依赖于反例长度；Kearns–Vazirani算法用判别树代替观察表，其成员查询计数线性依赖于反例长度。<sup>[4](https://tugraz.elsevierpure.com/ws/portalfiles/portal/77962395/3605360.pdf)</sup> 一个相关的精化家族扩展表的列而不是行（与Maler和Pnueli相关）。<sup>[10](https://link.springer.com/article/10.1007/s10009-026-00839-z)</sup> TTT算法具有与Rivest–Schapire相同的最坏情况成员查询复杂度，需要O(n)次等价查询，在基准测试中使用的输入符号数平均为L*的1/3.9。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> ADT算法由Markus Theo Frohme于2019年在arXiv的一篇论文中提出，在自适应判别树中组织搜索，具有符号节点、重置节点和最终节点。<sup>[11](https://doi.org/10.48550/arxiv.1902.01139)</sup> L#算法由Frits Vaandrager及其同事于2021年在arXiv的一篇论文中提出，用分离性（一种构造性的不相等关系）的概念代替表，在概念上比TTT更简单，同时达到相同的结果。<sup>[12](https://doi.org/10.48550/arxiv.2107.05419)</sup>

模型类已扩展到DFA和Mealy机之外：L*的改编版本处理非确定性I/O自动机，<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 寄存器自动机捕获有限状态模型遗漏的数据参数之间的关系，<sup>[3](https://dl.acm.org/doi/10.1007/s10817-026-09758-9)</sup> 带定时器的Mealy机将学习扩展到时间行为。<sup>[13](https://ar5iv.labs.arxiv.org/html/2403.02019)</sup> 在RALib中实现的SLλ算法学习寄存器自动机，对于n个位置和t个转移，最多需要O(t²(2ⁿ)ⁿ⁺ᵐt²ᵐᵐ)次成员查询和O(t)次等价查询，与先前的寄存器自动机学习器SL*相比，成员查询最多减少一个数量级。<sup>[3](https://dl.acm.org/doi/10.1007/s10817-026-09758-9)</sup> 一篇论文提出了一种在黑盒环境中查询学习带定时器Mealy机的算法。<sup>[13](https://ar5iv.labs.arxiv.org/html/2403.02019)</sup> LearnLib已通过集成模型检查器LTSmin得到扩展，将其用作特殊形式的等价预言机，实现了黑盒检查。<sup>[2](https://aqua.cs.tu-dortmund.de/storages/aqua-cs/r/Publications/Frohme2025Learnlib10Years_-_Learnlib__10_Years_Later.pdf)</sup> 一种基于L#的算法主动学习用于不相交语言的小型分离DFA，应用包括学习网络不变式和上下文假设。<sup>[14](https://dl.acm.org/doi/10.1007/978-3-032-32526-6_13)</sup> 2025年的工作将MAT框架扩展到用于网络验证的符号NetKAT自动机。<sup>[15](https://www.tiferrei.com/files/pdf/research/2025-nkl.pdf)</sup>

## 应用

模型学习已应用于安全关键协议实现、遗留代码、智能卡、数据结构接口、嵌入式控制软件和神经网络策略。<sup>[5](https://link.springer.com/chapter/10.1007/978-3-031-57249-4_6)</sup> 在银行业，学习了荷兰和德国银行、MasterCard以及英国Visa借记卡的银行卡上EMV协议实现的模型，每张卡进行了855到1,696次成员查询和测试查询，产生的模型有4到8个状态。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 应用于TLS实现时，协议状态模糊测试在九个测试实现中的三个中发现了新的安全缺陷；学习到的Mealy机有6到16个状态，JSSE中一个在1.8.0.31版本中修复的缺陷通过重新学习确认已修复。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 工业用途包括西门子电信系统的回归测试和对沃尔沃技术线控制动系统需求的测试。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup>

## 局限与替代方案

大多数学习算法的成员查询随输入数量线性增长，随状态数量二次增长，一致性测试成为瓶颈；因此，模型学习目前只能应用于输入少于约100个的情况。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 当显式的逐状态表示变得庞大时，例如当模型单独捕获数据域的每个元素时，[可扩展性](https://www.edgepedia.org/zh/scalability)和状态空间爆炸是主要挑战。<sup>[10](https://link.springer.com/article/10.1007/s10009-026-00839-z)</sup> Mealy机形式化也限制了表达能力：为了学习TCP实现，必须消除时间相关行为和重传。<sup>[1](https://cacm.acm.org/research/model-learning/)</sup> 在理论方面，仅使用成员查询或仅使用等价查询无法在多项式时间内学习有限状态机。<sup>[10](https://link.springer.com/article/10.1007/s10009-026-00839-z)</sup>

主要的替代范式是被动自动机学习，它从固定数据集中推断自动机；从数据推断具有k个状态的DFA是NP完全的，RPNI算法从正迹构建前缀树接受器并合并状态，丢弃会生成负迹的合并。<sup>[16](https://ar5iv.labs.arxiv.org/html/2209.14031)</sup> 与有状态模糊测试相比，主动学习可以看作是一种受限的模糊测试形式，仅改变固定消息集的顺序，但其目标是推断被测系统的状态模型，而不仅仅是发现失败。<sup>[17](http://www.cs.ru.nl/%7Eerikpoll/papers/FCS2024.pdf)</sup>

## References

1. [Model Learning – Communications of the ACM](https://cacm.acm.org/research/model-learning/)
2. [LearnLib: 10 years later](https://aqua.cs.tu-dortmund.de/storages/aqua-cs/r/Publications/Frohme2025Learnlib10Years_-_Learnlib__10_Years_Later.pdf)
3. [SLλ: A Scalable Algorithm for Register Automata Learning](https://dl.acm.org/doi/10.1007/s10817-026-09758-9)
4. [Benchmarking Combinations of Learning and Testing Algorithms for Automata Learning](https://tugraz.elsevierpure.com/ws/portalfiles/portal/77962395/3605360.pdf)
5. [Small Test Suites for Active Automata Learning](https://link.springer.com/chapter/10.1007/978-3-031-57249-4_6)
6. [Active Automata Learning: From DFAs to Interface Programs and Beyond](https://proceedings.mlr.press/v21/steffen12a/steffen12a.pdf)
7. [Learning regular sets from queries and counterexamples (Information and Computation, 1987)](https://doi.org/10.1016/0890-5401%2887%2990052-6)
8. [MAT survey (Drewes et al.)](https://people.cs.umu.se/drewes/biblio/ps-files/mat-survey.pdf)
9. [Learning I/O Automata](https://www.mbsd.cs.ru.nl/publications/papers/fvaan/LearningIOAs/paper.pdf)
10. [A research agenda for active automata learning](https://link.springer.com/article/10.1007/s10009-026-00839-z)
11. [Frohme, Markus Theo (2019). Active Automata Learning with Adaptive Distinguishing Sequences. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1902.01139)
12. [Vaandrager, Frits and colleagues (2021). A New Approach for Active Automata Learning Based on Apartness. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2107.05419)
13. [Active Learning of Mealy Machines with Timers](https://ar5iv.labs.arxiv.org/html/2403.02019)
14. [An L# Based Algorithm for Active Learning of Minimal Separating Automata](https://dl.acm.org/doi/10.1007/978-3-032-32526-6_13)
15. [Active Learning of Symbolic NetKAT Automata](https://www.tiferrei.com/files/pdf/research/2025-nkl.pdf)
16. [Active vs. Passive: A Comparison of Automata Learning Paradigms for Network Protocols](https://ar5iv.labs.arxiv.org/html/2209.14031)
17. [Uses of Active and Passive Learning in Stateful Fuzzing](http://www.cs.ru.nl/%7Eerikpoll/papers/FCS2024.pdf)

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

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/automata-learning

English original: https://www.edgepedia.org/automata-learning
