lernen 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/README.md +534 -48
- data/Rakefile +26 -7
- data/Steepfile +14 -0
- data/examples/ripper_prism.rb +63 -0
- data/examples/uri_parse_regexp.rb +73 -0
- data/lib/lernen/algorithm/cex_processor/acex.rb +43 -0
- data/lib/lernen/algorithm/cex_processor/prefix_transformer_acex.rb +43 -0
- data/lib/lernen/algorithm/cex_processor.rb +115 -0
- data/lib/lernen/algorithm/kearns_vazirani/discrimination_tree.rb +207 -0
- data/lib/lernen/algorithm/kearns_vazirani/kearns_vazirani_learner.rb +100 -0
- data/lib/lernen/algorithm/kearns_vazirani.rb +44 -0
- data/lib/lernen/algorithm/kearns_vazirani_vpa/discrimination_tree_vpa.rb +246 -0
- data/lib/lernen/algorithm/kearns_vazirani_vpa/kearns_vazirani_vpa_learner.rb +89 -0
- data/lib/lernen/algorithm/kearns_vazirani_vpa.rb +35 -0
- data/lib/lernen/algorithm/learner.rb +82 -0
- data/lib/lernen/algorithm/lsharp/lsharp_learner.rb +367 -0
- data/lib/lernen/algorithm/lsharp/observation_tree.rb +115 -0
- data/lib/lernen/algorithm/lsharp.rb +43 -0
- data/lib/lernen/algorithm/lstar/lstar_learner.rb +49 -0
- data/lib/lernen/algorithm/lstar/observation_table.rb +214 -0
- data/lib/lernen/algorithm/lstar.rb +49 -0
- data/lib/lernen/algorithm/procedural/atr_manager.rb +200 -0
- data/lib/lernen/algorithm/procedural/procedural_learner.rb +223 -0
- data/lib/lernen/algorithm/procedural/procedural_sul.rb +47 -0
- data/lib/lernen/algorithm/procedural/return_indices_acex.rb +58 -0
- data/lib/lernen/algorithm/procedural.rb +57 -0
- data/lib/lernen/algorithm.rb +19 -0
- data/lib/lernen/automaton/dfa.rb +204 -0
- data/lib/lernen/automaton/mealy.rb +108 -0
- data/lib/lernen/automaton/moore.rb +122 -0
- data/lib/lernen/automaton/moore_like.rb +83 -0
- data/lib/lernen/automaton/proc_util.rb +93 -0
- data/lib/lernen/automaton/spa.rb +368 -0
- data/lib/lernen/automaton/transition_system.rb +209 -0
- data/lib/lernen/automaton/vpa.rb +300 -0
- data/lib/lernen/automaton.rb +19 -493
- data/lib/lernen/equiv/combined_oracle.rb +57 -0
- data/lib/lernen/equiv/exhaustive_search_oracle.rb +60 -0
- data/lib/lernen/equiv/moore_like_simulator_oracle.rb +36 -0
- data/lib/lernen/equiv/oracle.rb +109 -0
- data/lib/lernen/equiv/random_walk_oracle.rb +69 -0
- data/lib/lernen/equiv/random_well_matched_word_oracle.rb +139 -0
- data/lib/lernen/equiv/random_word_oracle.rb +71 -0
- data/lib/lernen/equiv/spa_simulator_oracle.rb +39 -0
- data/lib/lernen/equiv/test_words_oracle.rb +42 -0
- data/lib/lernen/equiv/transition_system_simulator_oracle.rb +36 -0
- data/lib/lernen/equiv/vpa_simulator_oracle.rb +48 -0
- data/lib/lernen/equiv.rb +25 -0
- data/lib/lernen/graph.rb +215 -0
- data/lib/lernen/system/block_sul.rb +41 -0
- data/lib/lernen/system/moore_like_simulator.rb +45 -0
- data/lib/lernen/system/moore_like_sul.rb +33 -0
- data/lib/lernen/system/sul.rb +126 -0
- data/lib/lernen/system/transition_system_simulator.rb +40 -0
- data/lib/lernen/system.rb +72 -0
- data/lib/lernen/version.rb +2 -1
- data/lib/lernen.rb +284 -34
- data/rbs_collection.lock.yaml +16 -0
- data/rbs_collection.yaml +14 -0
- data/renovate.json +6 -0
- data/sig/generated/lernen/algorithm/cex_processor/acex.rbs +30 -0
- data/sig/generated/lernen/algorithm/cex_processor/prefix_transformer_acex.rbs +27 -0
- data/sig/generated/lernen/algorithm/cex_processor.rbs +59 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani/discrimination_tree.rbs +68 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani/kearns_vazirani_learner.rbs +51 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani.rbs +32 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani_vpa/discrimination_tree_vpa.rbs +73 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani_vpa/kearns_vazirani_vpa_learner.rbs +51 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani_vpa.rbs +20 -0
- data/sig/generated/lernen/algorithm/learner.rbs +53 -0
- data/sig/generated/lernen/algorithm/lsharp/lsharp_learner.rbs +103 -0
- data/sig/generated/lernen/algorithm/lsharp/observation_tree.rbs +53 -0
- data/sig/generated/lernen/algorithm/lsharp.rbs +38 -0
- data/sig/generated/lernen/algorithm/lstar/lstar_learner.rbs +38 -0
- data/sig/generated/lernen/algorithm/lstar/observation_table.rbs +79 -0
- data/sig/generated/lernen/algorithm/lstar.rbs +37 -0
- data/sig/generated/lernen/algorithm/procedural/atr_manager.rbs +80 -0
- data/sig/generated/lernen/algorithm/procedural/procedural_learner.rbs +79 -0
- data/sig/generated/lernen/algorithm/procedural/procedural_sul.rbs +36 -0
- data/sig/generated/lernen/algorithm/procedural/return_indices_acex.rbs +33 -0
- data/sig/generated/lernen/algorithm/procedural.rbs +27 -0
- data/sig/generated/lernen/algorithm.rbs +10 -0
- data/sig/generated/lernen/automaton/dfa.rbs +93 -0
- data/sig/generated/lernen/automaton/mealy.rbs +61 -0
- data/sig/generated/lernen/automaton/moore.rbs +69 -0
- data/sig/generated/lernen/automaton/moore_like.rbs +63 -0
- data/sig/generated/lernen/automaton/proc_util.rbs +38 -0
- data/sig/generated/lernen/automaton/spa.rbs +125 -0
- data/sig/generated/lernen/automaton/transition_system.rbs +108 -0
- data/sig/generated/lernen/automaton/vpa.rbs +109 -0
- data/sig/generated/lernen/automaton.rbs +15 -0
- data/sig/generated/lernen/equiv/combined_oracle.rbs +27 -0
- data/sig/generated/lernen/equiv/exhaustive_search_oracle.rbs +38 -0
- data/sig/generated/lernen/equiv/moore_like_simulator_oracle.rbs +27 -0
- data/sig/generated/lernen/equiv/oracle.rbs +75 -0
- data/sig/generated/lernen/equiv/random_walk_oracle.rbs +41 -0
- data/sig/generated/lernen/equiv/random_well_matched_word_oracle.rbs +70 -0
- data/sig/generated/lernen/equiv/random_word_oracle.rbs +45 -0
- data/sig/generated/lernen/equiv/spa_simulator_oracle.rbs +30 -0
- data/sig/generated/lernen/equiv/test_words_oracle.rbs +20 -0
- data/sig/generated/lernen/equiv/transition_system_simulator_oracle.rbs +27 -0
- data/sig/generated/lernen/equiv/vpa_simulator_oracle.rbs +33 -0
- data/sig/generated/lernen/equiv.rbs +11 -0
- data/sig/generated/lernen/graph.rbs +80 -0
- data/sig/generated/lernen/system/block_sul.rbs +29 -0
- data/sig/generated/lernen/system/moore_like_simulator.rbs +31 -0
- data/sig/generated/lernen/system/moore_like_sul.rbs +28 -0
- data/sig/generated/lernen/system/sul.rbs +87 -0
- data/sig/generated/lernen/system/transition_system_simulator.rbs +28 -0
- data/sig/generated/lernen/system.rbs +62 -0
- data/sig/generated/lernen/version.rbs +6 -0
- data/sig/generated/lernen.rbs +214 -0
- data/sig-test/generated/test/example_test.rbs +14 -0
- data/sig-test/generated/test/lernen/algorithm/kearns_vazirani_test.rbs +16 -0
- data/sig-test/generated/test/lernen/algorithm/kearns_vazirani_vpa_test.rbs +10 -0
- data/sig-test/generated/test/lernen/algorithm/lsharp_test.rbs +16 -0
- data/sig-test/generated/test/lernen/algorithm/lstar_test.rbs +16 -0
- data/sig-test/generated/test/lernen/algorithm/procedural_test.rbs +10 -0
- data/sig-test/generated/test/lernen/automaton/dfa_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/mealy_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/moore_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/proc_util_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/spa_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/vpa_test.rbs +19 -0
- data/sig-test/generated/test/lernen/equiv/exhaustive_search_oracle_test.rbs +10 -0
- data/sig-test/generated/test/lernen/equiv/random_walk_oracle_test.rbs +10 -0
- data/sig-test/generated/test/lernen/equiv/random_word_oracle_test.rbs +10 -0
- data/sig-test/generated/test/lernen/system/block_sul_test.rbs +16 -0
- data/sig-test/generated/test/lernen/system/moore_like_simulator_test.rbs +16 -0
- data/sig-test/generated/test/lernen/system/transition_system_simulator_test.rbs +13 -0
- data/sig-test/generated/test/lernen/system_test.rbs +11 -0
- data/sig-test/generated/test/lernen_test.rbs +13 -0
- metadata +131 -11
- data/.yardopts +0 -3
- data/lib/lernen/cex_processor.rb +0 -92
- data/lib/lernen/kearns_vazirani.rb +0 -310
- data/lib/lernen/lsharp.rb +0 -344
- data/lib/lernen/lstar.rb +0 -170
- data/lib/lernen/oracle.rb +0 -119
- data/lib/lernen/sul.rb +0 -210
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/kearns_vazirani_vpa/discrimination_tree_vpa.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module KearnsVaziraniVPA
|
6
|
+
# DiscriminationTreeVPA is a extended version of discrimination tree for VPA.
|
7
|
+
#
|
8
|
+
# @rbs generic In -- Type for input alphabet
|
9
|
+
# @rbs generic Call -- Type for call alphabet
|
10
|
+
# @rbs generic Return -- Type for return alphabet
|
11
|
+
class DiscriminationTreeVPA[In, Call, Return]
|
12
|
+
type tree[In, Call, Return] = Node[In, Call, Return] | Leaf[In, Call, Return]
|
13
|
+
|
14
|
+
class Node[In, Call, Return] < Data
|
15
|
+
attr_reader access: Array[In | Call | Return]
|
16
|
+
attr_reader suffix: Array[In | Call | Return]
|
17
|
+
attr_reader branch: Hash[bool, tree[In, Call, Return]]
|
18
|
+
def self.[]: [In, Call, Return] (Array[In | Call | Return] access, Array[In | Call | Return] suffix, Hash[bool, tree[In, Call, Return]] branch) -> Node[In, Call, Return]
|
19
|
+
end
|
20
|
+
|
21
|
+
class Leaf[In, Call, Return] < Data
|
22
|
+
attr_reader prefix: Array[In | Call | Return]
|
23
|
+
def self.[]: [In, Call, Return] (Array[In | Call | Return] prefix) -> Leaf[In, Call, Return]
|
24
|
+
end
|
25
|
+
|
26
|
+
@root: Node[In, Call, Return]
|
27
|
+
|
28
|
+
@path_hash: Hash[Array[In | Call | Return], Array[bool]]
|
29
|
+
|
30
|
+
@cex_processing: cex_processing_method
|
31
|
+
|
32
|
+
@sul: System::MooreLikeSUL[In | Call | Return, bool]
|
33
|
+
|
34
|
+
@return_alphabet: Array[Return]
|
35
|
+
|
36
|
+
@call_alphabet: Array[Call]
|
37
|
+
|
38
|
+
@alphabet: Array[In]
|
39
|
+
|
40
|
+
# : (
|
41
|
+
# Array[In] alphabet,
|
42
|
+
# Array[Call] call_alphabet,
|
43
|
+
# Array[Return] return_alphabet,
|
44
|
+
# System::MooreLikeSUL[In | Call | Return, bool] sul,
|
45
|
+
# cex: Array[In],
|
46
|
+
# cex_processing: cex_processing_method
|
47
|
+
# ) -> void
|
48
|
+
def initialize: (Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet, System::MooreLikeSUL[In | Call | Return, bool] sul, cex: Array[In], cex_processing: cex_processing_method) -> void
|
49
|
+
|
50
|
+
# Constructs a hypothesis automaton from this discrimination tree.
|
51
|
+
#
|
52
|
+
# : () -> [Automaton::VPA[In, Call, Return], Hash[Integer, Array[In | Call | Return]]]
|
53
|
+
def build_hypothesis: () -> [ Automaton::VPA[In, Call, Return], Hash[Integer, Array[In | Call | Return]] ]
|
54
|
+
|
55
|
+
# Update this classification tree by the given `cex`.
|
56
|
+
#
|
57
|
+
# : (
|
58
|
+
# Array[In | Call | Return] cex,
|
59
|
+
# Automaton::VPA[In, Call, Return] hypothesis,
|
60
|
+
# Hash[Integer, Array[In | Call | Return]] state_to_prefix
|
61
|
+
# ) -> void
|
62
|
+
def refine_hypothesis: (Array[In | Call | Return] cex, Automaton::VPA[In, Call, Return] hypothesis, Hash[Integer, Array[In | Call | Return]] state_to_prefix) -> void
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# Returns a prefix discriminated by `word`.
|
67
|
+
#
|
68
|
+
# : (Array[In | Call | Return] word) -> Array[In | Call | Return]
|
69
|
+
def sift: (Array[In | Call | Return] word) -> Array[In | Call | Return]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/kearns_vazirani_vpa/kearns_vazirani_vpa_learner.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module KearnsVaziraniVPA
|
6
|
+
# KearnzVaziraniVPALearner is an implementation of Kearnz-Vazirani algorithm for VPA.
|
7
|
+
#
|
8
|
+
# The idea behind this implementation is described by [Isberner (2015) "Foundations
|
9
|
+
# of Active Automata Learning: An Algorithmic Overview"](https://eldorado.tu-dortmund.de/handle/2003/34282).
|
10
|
+
#
|
11
|
+
# @rbs generic In -- Type for input alphabet
|
12
|
+
# @rbs generic Call -- Type for call alphabet
|
13
|
+
# @rbs generic Return -- Type for return alphabet
|
14
|
+
class KearnsVaziraniVPALearner[In, Call, Return] < Learner[In | Call | Return, bool]
|
15
|
+
@alphabet: Array[In]
|
16
|
+
|
17
|
+
@call_alphabet: Array[Call]
|
18
|
+
|
19
|
+
@return_alphabet: Array[Return]
|
20
|
+
|
21
|
+
@sul: System::MooreLikeSUL[In | Call | Return, bool]
|
22
|
+
|
23
|
+
@oracle: Equiv::Oracle[In | Call | Return, bool]
|
24
|
+
|
25
|
+
@cex_processing: cex_processing_method
|
26
|
+
|
27
|
+
@tree: DiscriminationTreeVPA[In, Call, Return] | nil
|
28
|
+
|
29
|
+
# : (
|
30
|
+
# Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet,
|
31
|
+
# System::MooreLikeSUL[In | Call | Return, bool] sul,
|
32
|
+
# ?cex_processing: cex_processing_method
|
33
|
+
# ) -> void
|
34
|
+
def initialize: (Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet, System::MooreLikeSUL[In | Call | Return, bool] sul, ?cex_processing: cex_processing_method) -> void
|
35
|
+
|
36
|
+
# @rbs override
|
37
|
+
def build_hypothesis: ...
|
38
|
+
|
39
|
+
# @rbs override
|
40
|
+
def refine_hypothesis: ...
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Constructs the first hypothesis VPA.
|
45
|
+
#
|
46
|
+
# : () -> Automaton::VPA[In, Call, Return]
|
47
|
+
def build_first_hypothesis: () -> Automaton::VPA[In, Call, Return]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/kearns_vazirani_vpa.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
# KearnzVaziraniVPA provides an implementation of Kearnz-Vazirani algorithm for VPA.
|
6
|
+
#
|
7
|
+
# The idea behind this implementation is described by [Isberner (2015) "Foundations
|
8
|
+
# of Active Automata Learning: An Algorithmic Overview"](https://eldorado.tu-dortmund.de/handle/2003/34282).
|
9
|
+
module KearnsVaziraniVPA
|
10
|
+
# Runs Kearns-Vazirani algorithm for VPA and returns an inferred VPA.
|
11
|
+
#
|
12
|
+
# : [In, Call, Return] (
|
13
|
+
# Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet,
|
14
|
+
# System::MooreLikeSUL[In | Call | Return, bool] sul, Equiv::Oracle[In | Call | Return, bool] oracle,
|
15
|
+
# ?cex_processing: cex_processing_method, ?max_learning_rounds: Integer | nil
|
16
|
+
# ) -> Automaton::VPA[In, Call, Return]
|
17
|
+
def self.learn: [In, Call, Return] (Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet, System::MooreLikeSUL[In | Call | Return, bool] sul, Equiv::Oracle[In | Call | Return, bool] oracle, ?cex_processing: cex_processing_method, ?max_learning_rounds: Integer | nil) -> Automaton::VPA[In, Call, Return]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/learner.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
# Learner is an abstraction of implementations of learning algorithms.
|
6
|
+
#
|
7
|
+
# Note that this class is *abstract*. We should implement the following method:
|
8
|
+
#
|
9
|
+
# - `#oracle`
|
10
|
+
# - `#refine(cex, hypothesis, state_to_prefix)`
|
11
|
+
# - `#build_hypothesis`
|
12
|
+
#
|
13
|
+
# @rbs generic In -- Type for input alphabet
|
14
|
+
# @rbs generic Out -- Type for output values
|
15
|
+
class Learner[In, Out]
|
16
|
+
# Runs the learning algorithm and returns an inferred automaton.
|
17
|
+
#
|
18
|
+
# `max_learning_rounds` is a parameter for specifying the maximum number of iterations for learning.
|
19
|
+
# When `max_learning_rounds: nil` is specified, it means the algorithm only stops if the equivalent
|
20
|
+
# hypothesis is found.
|
21
|
+
#
|
22
|
+
# : (
|
23
|
+
# Equiv::Oracle[In, Out] oracle,
|
24
|
+
# ?max_learning_rounds: Integer | nil
|
25
|
+
# ) -> Automaton::TransitionSystem[untyped, In, Out]
|
26
|
+
def learn: (Equiv::Oracle[In, Out] oracle, ?max_learning_rounds: Integer | nil) -> Automaton::TransitionSystem[untyped, In, Out]
|
27
|
+
|
28
|
+
# Adds the given `input` to the alphabet.
|
29
|
+
#
|
30
|
+
# In the default, this method raises `TypeError` as the learner does not support
|
31
|
+
# adding an input character to the alphabet.
|
32
|
+
#
|
33
|
+
# : (In input) -> void
|
34
|
+
def add_alphabet: (In input) -> void
|
35
|
+
|
36
|
+
# Refine the learning hypothesis by the given counterexample.
|
37
|
+
#
|
38
|
+
# This is an abstract method.
|
39
|
+
#
|
40
|
+
# : (
|
41
|
+
# Array[In] cex,
|
42
|
+
# Automaton::TransitionSystem[untyped, In, Out] hypothesis,
|
43
|
+
# Hash[Integer, Array[In]] state_to_prefix
|
44
|
+
# ) -> void
|
45
|
+
def refine_hypothesis: (Array[In] cex, Automaton::TransitionSystem[untyped, In, Out] hypothesis, Hash[Integer, Array[In]] state_to_prefix) -> void
|
46
|
+
|
47
|
+
# This is an abstract method.
|
48
|
+
# r
|
49
|
+
# : () -> [Automaton::TransitionSystem[untyped, In, Out], Hash[Integer, Array[In]]]
|
50
|
+
def build_hypothesis: () -> [ Automaton::TransitionSystem[untyped, In, Out], Hash[Integer, Array[In]] ]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/lsharp/lsharp_learner.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module LSharp
|
6
|
+
# LSharpLearner is an implementation of L# algorithm.
|
7
|
+
#
|
8
|
+
# L# is introduced by [Vaandrager et al. (2022) "A New Approach for Active
|
9
|
+
# Automata Learning Based on Apartness"](https://link.springer.com/chapter/10.1007/978-3-030-99524-9_12).
|
10
|
+
#
|
11
|
+
# @rbs generic In -- Type for input alphabet
|
12
|
+
# @rbs generic Out -- Type for output values
|
13
|
+
class LSharpLearner[In, Out] < Learner[In, Out]
|
14
|
+
@incomplete_basis: Array[Array[In]]
|
15
|
+
|
16
|
+
@frontier: Hash[Array[In], Array[Array[In]]]
|
17
|
+
|
18
|
+
@basis: Array[Array[In]]
|
19
|
+
|
20
|
+
@witness_cache: Hash[[ Array[In], Array[In] ], Array[In]]
|
21
|
+
|
22
|
+
@tree: ObservationTree[In, Out]
|
23
|
+
|
24
|
+
@automaton_type: :dfa | :mealy | :moore
|
25
|
+
|
26
|
+
@oracle: Equiv::Oracle[In, Out]
|
27
|
+
|
28
|
+
@sul: System::SUL[In, Out]
|
29
|
+
|
30
|
+
@alphabet: Array[In]
|
31
|
+
|
32
|
+
# : (
|
33
|
+
# Array[In] alphabet,
|
34
|
+
# System::SUL[In, Out] sul,
|
35
|
+
# automaton_type: :dfa | :mealy | :moore,
|
36
|
+
# ) -> void
|
37
|
+
def initialize: (Array[In] alphabet, System::SUL[In, Out] sul, automaton_type: :dfa | :mealy | :moore) -> void
|
38
|
+
|
39
|
+
# @rbs override
|
40
|
+
def build_hypothesis: ...
|
41
|
+
|
42
|
+
# @rbs override
|
43
|
+
def refine_hypothesis: ...
|
44
|
+
|
45
|
+
# @rbs override
|
46
|
+
def add_alphabet: ...
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Checks apartness on the current observation tree between the given two nodes.
|
51
|
+
# It returns the witness suffix if they are apart. If it is not, it returns `nil`.
|
52
|
+
#
|
53
|
+
# : (
|
54
|
+
# ObservationTree::Node[In, Out] node1,
|
55
|
+
# ObservationTree::Node[In, Out] node2
|
56
|
+
# ) -> (Array[In] | nil)
|
57
|
+
def check_apartness: (ObservationTree::Node[In, Out] node1, ObservationTree::Node[In, Out] node2) -> (Array[In] | nil)
|
58
|
+
|
59
|
+
# Computes the witness suffix of apartness between the given two basis prefixes.
|
60
|
+
#
|
61
|
+
# : (
|
62
|
+
# Array[In] prefix1,
|
63
|
+
# Array[In] prefix2
|
64
|
+
# ) -> Array[In]
|
65
|
+
def compute_witness: (Array[In] prefix1, Array[In] prefix2) -> Array[In]
|
66
|
+
|
67
|
+
# : (Array[In] prefix) -> void
|
68
|
+
def add_basis: (Array[In] prefix) -> void
|
69
|
+
|
70
|
+
# : (Array[In] border) -> void
|
71
|
+
def add_frontier: (Array[In] border) -> void
|
72
|
+
|
73
|
+
# : () -> void
|
74
|
+
def update_frontier: () -> void
|
75
|
+
|
76
|
+
# : () -> [Automaton::TransitionSystem[Integer, In, Out], Hash[Integer, Array[In]]]
|
77
|
+
def build_hypothesis_internal: () -> [ Automaton::TransitionSystem[Integer, In, Out], Hash[Integer, Array[In]] ]
|
78
|
+
|
79
|
+
# : (
|
80
|
+
# Automaton::TransitionSystem[Integer, In, Out] hypothesis,
|
81
|
+
# Hash[Integer, Array[In]] state_to_prefix
|
82
|
+
# ) -> (Array[In] | nil)
|
83
|
+
def check_consistency: (Automaton::TransitionSystem[Integer, In, Out] hypothesis, Hash[Integer, Array[In]] state_to_prefix) -> (Array[In] | nil)
|
84
|
+
|
85
|
+
# : () -> bool
|
86
|
+
def promotion: () -> bool
|
87
|
+
|
88
|
+
# : () -> bool
|
89
|
+
def completion: () -> bool
|
90
|
+
|
91
|
+
# : () -> bool
|
92
|
+
def identification: () -> bool
|
93
|
+
|
94
|
+
# : (
|
95
|
+
# Array[In] cex,
|
96
|
+
# Automaton::TransitionSystem[Integer, In, Out] hypothesis,
|
97
|
+
# Hash[Integer, Array[In]] state_to_prefix,
|
98
|
+
# ) -> void
|
99
|
+
def process_cex: (Array[In] cex, Automaton::TransitionSystem[Integer, In, Out] hypothesis, Hash[Integer, Array[In]] state_to_prefix) -> void
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/lsharp/observation_tree.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module LSharp
|
6
|
+
# ObservationTree is an implementation of observation tree data structure.
|
7
|
+
#
|
8
|
+
# This data structure is used for L# algorithm.
|
9
|
+
#
|
10
|
+
# @rbs generic In -- Type for input alphabet
|
11
|
+
# @rbs generic Out -- Type for output values
|
12
|
+
class ObservationTree[In, Out]
|
13
|
+
class Node[In, Out] < Data
|
14
|
+
attr_reader output: Out | nil
|
15
|
+
attr_reader branch: Hash[In, Node[In, Out]]
|
16
|
+
def self.[]: [In, Out] (Out output, Hash[In, Node[In, Out]] branch) -> Node[In, Out]
|
17
|
+
end
|
18
|
+
|
19
|
+
@sul: System::SUL[In, Out]
|
20
|
+
|
21
|
+
@automaton_type: :dfa | :mealy | :moore
|
22
|
+
|
23
|
+
@root: Node[In, Out]
|
24
|
+
|
25
|
+
# : (
|
26
|
+
# System::SUL[In, Out] sul,
|
27
|
+
# automaton_type: :dfa | :mealy | :moore
|
28
|
+
# ) -> void
|
29
|
+
def initialize: (System::SUL[In, Out] sul, automaton_type: :dfa | :mealy | :moore) -> void
|
30
|
+
|
31
|
+
attr_reader root: Node[In, Out]
|
32
|
+
|
33
|
+
# Returns a node for the given word.
|
34
|
+
# When the word (or its subword) is not observed, it returns `nil` instead.
|
35
|
+
#
|
36
|
+
# : (Array[In] word) -> (Node[In, Out] | nil)
|
37
|
+
def []: (Array[In] word) -> (Node[In, Out] | nil)
|
38
|
+
|
39
|
+
# Returns an output sequence for the given word if it is observed.
|
40
|
+
# If it is not, it returns `nil` instead.
|
41
|
+
#
|
42
|
+
# : (Array[In] word) -> (Array[Out] | nil)
|
43
|
+
def observed_query: (Array[In] word) -> (Array[Out] | nil)
|
44
|
+
|
45
|
+
# Returns an output sequence for the given word.
|
46
|
+
# When the word is observed, it runs actual query over `sul`.
|
47
|
+
#
|
48
|
+
# : (Array[In] word) -> Array[Out]
|
49
|
+
def query: (Array[In] word) -> Array[Out]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/lsharp.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
# LSharp provides an implementation of L# algorithm.
|
6
|
+
#
|
7
|
+
# L# is introduced by [Vaandrager et al. (2022) "A New Approach for Active
|
8
|
+
# Automata Learning Based on Apartness"](https://link.springer.com/chapter/10.1007/978-3-030-99524-9_12).
|
9
|
+
module LSharp
|
10
|
+
# Runs the L# algorithm and returns an inferred automaton.
|
11
|
+
#
|
12
|
+
# : [In] (
|
13
|
+
# Array[In] alphabet,
|
14
|
+
# System::SUL[In, bool] sul,
|
15
|
+
# Equiv::Oracle[In, bool] oracle,
|
16
|
+
# automaton_type: :dfa,
|
17
|
+
# ?max_learning_rounds: Integer | nil
|
18
|
+
# ) -> Automaton::DFA[In]
|
19
|
+
# : [In, Out] (
|
20
|
+
# Array[In] alphabet,
|
21
|
+
# System::SUL[In, Out] sul,
|
22
|
+
# Equiv::Oracle[In, Out] oracle,
|
23
|
+
# automaton_type: :mealy,
|
24
|
+
# ?max_learning_rounds: Integer | nil
|
25
|
+
# ) -> Automaton::Mealy[In, Out]
|
26
|
+
# : [In, Out] (
|
27
|
+
# Array[In] alphabet,
|
28
|
+
# System::SUL[In, Out] sul,
|
29
|
+
# Equiv::Oracle[In, Out] oracle,
|
30
|
+
# automaton_type: :moore,
|
31
|
+
# ?max_learning_rounds: Integer | nil
|
32
|
+
# ) -> Automaton::Moore[In, Out]
|
33
|
+
def self.learn: [In] (Array[In] alphabet, System::SUL[In, bool] sul, Equiv::Oracle[In, bool] oracle, automaton_type: :dfa, ?max_learning_rounds: Integer | nil) -> Automaton::DFA[In]
|
34
|
+
| [In, Out] (Array[In] alphabet, System::SUL[In, Out] sul, Equiv::Oracle[In, Out] oracle, automaton_type: :mealy, ?max_learning_rounds: Integer | nil) -> Automaton::Mealy[In, Out]
|
35
|
+
| [In, Out] (Array[In] alphabet, System::SUL[In, Out] sul, Equiv::Oracle[In, Out] oracle, automaton_type: :moore, ?max_learning_rounds: Integer | nil) -> Automaton::Moore[In, Out]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/lstar/lstar_learner.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module LStar
|
6
|
+
# LStarLearner is an implementation of Angluin's L* algorithm.
|
7
|
+
#
|
8
|
+
# Angluin's L* is introduced by [Angluin (1987) "Learning Regular Sets from
|
9
|
+
# Queries and Counterexamples"](https://dl.acm.org/doi/10.1016/0890-5401%2887%2990052-6).
|
10
|
+
#
|
11
|
+
# @rbs generic In -- Type for input alphabet
|
12
|
+
# @rbs generic Out -- Type for output values
|
13
|
+
class LStarLearner[In, Out] < Learner[In, Out]
|
14
|
+
@alphabet: Array[In]
|
15
|
+
|
16
|
+
@oracle: Equiv::Oracle[In, Out]
|
17
|
+
|
18
|
+
@table: ObservationTable[In, Out]
|
19
|
+
|
20
|
+
# : (
|
21
|
+
# Array[In] alphabet, System::SUL[In, Out] sul,
|
22
|
+
# automaton_type: :dfa | :moore | :mealy,
|
23
|
+
# ?cex_processing: cex_processing_method | nil
|
24
|
+
# ) -> void
|
25
|
+
def initialize: (Array[In] alphabet, System::SUL[In, Out] sul, automaton_type: :dfa | :moore | :mealy, ?cex_processing: cex_processing_method | nil) -> void
|
26
|
+
|
27
|
+
# @rbs override
|
28
|
+
def build_hypothesis: ...
|
29
|
+
|
30
|
+
# @rbs override
|
31
|
+
def refine_hypothesis: ...
|
32
|
+
|
33
|
+
# @rbs override
|
34
|
+
def add_alphabet: ...
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/lstar/observation_table.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module LStar
|
6
|
+
# ObservationTable is an implementation of observation tabel data structure.
|
7
|
+
#
|
8
|
+
# This data structure is used for Angluin's L* algorithm.
|
9
|
+
#
|
10
|
+
# @rbs generic In -- Type for input alphabet
|
11
|
+
# @rbs generic Out -- Type for output values
|
12
|
+
class ObservationTable[In, Out]
|
13
|
+
@table: Hash[Array[In], Array[Out]]
|
14
|
+
|
15
|
+
@suffixes: Array[Array[In]]
|
16
|
+
|
17
|
+
@prefixes: Array[Array[In]]
|
18
|
+
|
19
|
+
@cex_processing: cex_processing_method | nil
|
20
|
+
|
21
|
+
@automaton_type: Automaton::transition_system_type
|
22
|
+
|
23
|
+
@sul: System::SUL[In, Out]
|
24
|
+
|
25
|
+
@alphabet: Array[In]
|
26
|
+
|
27
|
+
# : (
|
28
|
+
# Array[In] alphabet,
|
29
|
+
# System::SUL[In, Out] sul,
|
30
|
+
# automaton_type: :dfa | :moore | :mealy,
|
31
|
+
# cex_processing: cex_processing_method | nil
|
32
|
+
# ) -> void
|
33
|
+
def initialize: (Array[In] alphabet, System::SUL[In, Out] sul, automaton_type: :dfa | :moore | :mealy, cex_processing: cex_processing_method | nil) -> void
|
34
|
+
|
35
|
+
# Constructs a hypothesis automaton from this observation table.
|
36
|
+
#
|
37
|
+
# : () -> [Automaton::TransitionSystem[Integer, In, Out], Hash[Integer, Array[In]]]
|
38
|
+
def build_hypothesis: () -> [ Automaton::TransitionSystem[Integer, In, Out], Hash[Integer, Array[In]] ]
|
39
|
+
|
40
|
+
# Updates this observation table by the given `cex`.
|
41
|
+
#
|
42
|
+
# : (
|
43
|
+
# Array[In] cex,
|
44
|
+
# Automaton::TransitionSystem[Integer, In, Out] hypothesis,
|
45
|
+
# Hash[Integer, Array[In]] state_to_prefix
|
46
|
+
# ) -> void
|
47
|
+
def refine_hypothesis: (Array[In] cex, Automaton::TransitionSystem[Integer, In, Out] hypothesis, Hash[Integer, Array[In]] state_to_prefix) -> void
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Finds new prefixes to close.
|
52
|
+
#
|
53
|
+
# : () -> (Array[Array[In]] | nil)
|
54
|
+
def find_prefixes_to_close: () -> (Array[Array[In]] | nil)
|
55
|
+
|
56
|
+
# Checks consistency and returns a new suffix to add if this observation table
|
57
|
+
# is inconsistent.
|
58
|
+
#
|
59
|
+
# : () -> (Array[In] | nil)
|
60
|
+
def check_consistency: () -> (Array[In] | nil)
|
61
|
+
|
62
|
+
# Updates rows of this observation table.
|
63
|
+
#
|
64
|
+
# : () -> void
|
65
|
+
def update_table: () -> void
|
66
|
+
|
67
|
+
# Updates the row for the given `prefix` of this observation table.
|
68
|
+
#
|
69
|
+
# : (Array[In] prefix) -> void
|
70
|
+
def update_table_row: (Array[In] prefix) -> void
|
71
|
+
|
72
|
+
# Update this table to be consistent and closed.
|
73
|
+
#
|
74
|
+
# : () -> void
|
75
|
+
def make_consistent_and_closed: () -> void
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/lstar.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
# LStar provides an implementation of Angluin's L* algorithm.
|
6
|
+
#
|
7
|
+
# Angluin's L* is introduced by [Angluin (1987) "Learning Regular Sets from
|
8
|
+
# Queries and Counterexamples"](https://dl.acm.org/doi/10.1016/0890-5401%2887%2990052-6).
|
9
|
+
module LStar
|
10
|
+
# Runs Angluin's L* algorithm and returns an inferred automaton.
|
11
|
+
#
|
12
|
+
# `cex_processing` is used for determining a method of counterexample processing.
|
13
|
+
# In additional to predefined `cex_processing_method`, we can specify `nil` as `cex_processing`.
|
14
|
+
# When `cex_processing: nil` is specified, it uses the original counterexample processing
|
15
|
+
# described in the Angluin paper.
|
16
|
+
#
|
17
|
+
# : [In] (
|
18
|
+
# Array[In] alphabet, System::SUL[In, bool] sul, Equiv::Oracle[In, bool] oracle,
|
19
|
+
# automaton_type: :dfa,
|
20
|
+
# ?cex_processing: cex_processing_method | nil, ?max_learning_rounds: Integer | nil
|
21
|
+
# ) -> Automaton::DFA[In]
|
22
|
+
# : [In, Out] (
|
23
|
+
# Array[In] alphabet, System::SUL[In, Out] sul, Equiv::Oracle[In, Out] oracle,
|
24
|
+
# automaton_type: :mealy,
|
25
|
+
# ?cex_processing: cex_processing_method | nil, ?max_learning_rounds: Integer | nil
|
26
|
+
# ) -> Automaton::Mealy[In, Out]
|
27
|
+
# : [In, Out] (
|
28
|
+
# Array[In] alphabet, System::SUL[In, Out] sul, Equiv::Oracle[In, Out] oracle,
|
29
|
+
# automaton_type: :moore,
|
30
|
+
# ?cex_processing: cex_processing_method | nil, ?max_learning_rounds: Integer | nil
|
31
|
+
# ) -> Automaton::Moore[In, Out]
|
32
|
+
def self.learn: [In] (Array[In] alphabet, System::SUL[In, bool] sul, Equiv::Oracle[In, bool] oracle, automaton_type: :dfa, ?cex_processing: cex_processing_method | nil, ?max_learning_rounds: Integer | nil) -> Automaton::DFA[In]
|
33
|
+
| [In, Out] (Array[In] alphabet, System::SUL[In, Out] sul, Equiv::Oracle[In, Out] oracle, automaton_type: :mealy, ?cex_processing: cex_processing_method | nil, ?max_learning_rounds: Integer | nil) -> Automaton::Mealy[In, Out]
|
34
|
+
| [In, Out] (Array[In] alphabet, System::SUL[In, Out] sul, Equiv::Oracle[In, Out] oracle, automaton_type: :moore, ?cex_processing: cex_processing_method | nil, ?max_learning_rounds: Integer | nil) -> Automaton::Moore[In, Out]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/procedural/atr_manager.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module Procedural
|
6
|
+
# ATRManager is a collection to manage access, terminating, and return sequences.
|
7
|
+
#
|
8
|
+
# @rbs generic In -- Type for input alphabet
|
9
|
+
# @rbs generic Call -- Type for call alphabet
|
10
|
+
# @rbs generic Return -- Type for return alphabet
|
11
|
+
class ATRManager[In, Call, Return]
|
12
|
+
@scan_procs: bool
|
13
|
+
|
14
|
+
@return_input: Return
|
15
|
+
|
16
|
+
@call_alphabet_set: Set[Call]
|
17
|
+
|
18
|
+
@alphabet: Array[In]
|
19
|
+
|
20
|
+
@proc_to_return_sequence: Hash[Call, Array[In | Call | Return]]
|
21
|
+
|
22
|
+
@proc_to_terminating_sequence: Hash[Call, Array[In | Call | Return]]
|
23
|
+
|
24
|
+
@proc_to_access_sequence: Hash[Call, Array[In | Call | Return]]
|
25
|
+
|
26
|
+
# : (
|
27
|
+
# Array[In] alphabet,
|
28
|
+
# Array[Call] call_alphabet,
|
29
|
+
# Return return_input,
|
30
|
+
# ?scan_procs: bool
|
31
|
+
# ) -> void
|
32
|
+
def initialize: (Array[In] alphabet, Array[Call] call_alphabet, Return return_input, ?scan_procs: bool) -> void
|
33
|
+
|
34
|
+
attr_reader proc_to_access_sequence: Hash[Call, Array[In | Call | Return]]
|
35
|
+
|
36
|
+
attr_reader proc_to_terminating_sequence: Hash[Call, Array[In | Call | Return]]
|
37
|
+
|
38
|
+
attr_reader proc_to_return_sequence: Hash[Call, Array[In | Call | Return]]
|
39
|
+
|
40
|
+
# : (Array[In | Call | Return] cex) -> Array[Call]
|
41
|
+
def scan_positive_cex: (Array[In | Call | Return] cex) -> Array[Call]
|
42
|
+
|
43
|
+
# : (
|
44
|
+
# Hash[Call, Automaton::DFA[In | Call]] procs,
|
45
|
+
# Hash[Call, Hash[Integer, Array[In | Call]]] proc_to_state_to_prefix
|
46
|
+
# ) -> void
|
47
|
+
def scan_procs: (Hash[Call, Automaton::DFA[In | Call]] procs, Hash[Call, Hash[Integer, Array[In | Call]]] proc_to_state_to_prefix) -> void
|
48
|
+
|
49
|
+
# : (Call proc, Array[In | Call] word) -> Array[In | Call | Return]
|
50
|
+
def embed: (Call proc, Array[In | Call] word) -> Array[In | Call | Return]
|
51
|
+
|
52
|
+
# : [In, Call, Return] (Array[In | Call] word) -> Array[In | Call | Return]
|
53
|
+
def expand: [In, Call, Return] (Array[In | Call] word) -> Array[In | Call | Return]
|
54
|
+
|
55
|
+
# : [In, Call, Return] (Array[In | Call] word) -> Array[In | Call | Return]
|
56
|
+
def project: [In, Call, Return] (Array[In | Call] word) -> Array[In | Call | Return]
|
57
|
+
|
58
|
+
# : (Array[In | Call | Return] word, Integer index) -> Integer
|
59
|
+
def find_call_index: (Array[In | Call | Return] word, Integer index) -> Integer
|
60
|
+
|
61
|
+
# : (Array[In | Call | Return] word, Integer index) -> Integer
|
62
|
+
def find_return_index: (Array[In | Call | Return] word, Integer index) -> Integer
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# : (Array[In | Call | Return] cex) -> Array[Call]
|
67
|
+
def extract_potential_terminating_sequences: (Array[In | Call | Return] cex) -> Array[Call]
|
68
|
+
|
69
|
+
# : (Array[In | Call | Return] cex) -> void
|
70
|
+
def extract_potential_access_and_return_sequences: (Array[In | Call | Return] cex) -> void
|
71
|
+
|
72
|
+
# : (Array[In | Call | Return] word) -> Array[In | Call | Return]
|
73
|
+
def minify_well_matched: (Array[In | Call | Return] word) -> Array[In | Call | Return]
|
74
|
+
|
75
|
+
# : (Hash[Call, Array[In | Call | Return]]) -> void
|
76
|
+
def optimize_sequences: (Hash[Call, Array[In | Call | Return]]) -> void
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|