Class: Bparity::Formal::ActiveLearner
- Inherits:
-
Object
- Object
- Bparity::Formal::ActiveLearner
- Defined in:
- lib/bparity/formal/lts.rb
Instance Method Summary collapse
-
#initialize(factory:, state_projection:, operations:, state_limit: 500) ⇒ ActiveLearner
constructor
A new instance of ActiveLearner.
- #learn ⇒ Object
Constructor Details
#initialize(factory:, state_projection:, operations:, state_limit: 500) ⇒ ActiveLearner
Returns a new instance of ActiveLearner.
92 93 94 95 96 97 |
# File 'lib/bparity/formal/lts.rb', line 92 def initialize(factory:, state_projection:, operations:, state_limit: 500) @factory = factory @state_projection = state_projection @operations = operations @state_limit = state_limit end |
Instance Method Details
#learn ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/bparity/formal/lts.rb', line 99 def learn initial_subject = @factory.call initial_label = state_label(initial_subject) paths = { initial_label => [] } queue = [initial_label] transitions = [] queries = 0 until queue.empty? from = queue.shift @operations.each do |name, operation| subject = replay(paths.fetch(from)) output = observe(subject, operation) queries += 1 target = state_label(subject) transitions << Transition.new(from:, input: name, output:, to: target) next if paths.key?(target) return learned(initial_label, transitions, false, queries) if paths.length >= @state_limit paths[target] = paths.fetch(from) + [name] queue << target end end learned(initial_label, transitions, true, queries) end |