Class: Lernen::Equiv::RandomWellMatchedWordOracle

Inherits:
Oracle
  • Object
show all
Defined in:
lib/lernen/equiv/random_well_matched_word_oracle.rb

Overview

RandomWellMatchedWordOracle provides an implementation of equivalence query that finds a counterexample by using random well-matched word generation.

This takes three important parameters:

  • ‘max_words` (default: `100`): It is a limit of number of random words.

    If random words is generated and tried up to this value and no counterexample
    is found, it returns `nil` finally.
    
  • ‘min_word_size` (default: `2`): It is the minimal size of randomly generated word.

    It should be greater than `0`.
    
  • ‘max_word_size` (default: `30`): It is the maximal size of randomly generated word.

    It should be greater than or equal to `min_word_size`.
    
  • ‘call_prob` (default: `0.1`): It is a probability to generate call and return subwords.

  • ‘initial_proc` (default `nil`): It is the initial proc character.

    If it is specified, the generated words must be started with it.
    

Instance Attribute Summary

Attributes inherited from Oracle

#sul

Instance Method Summary collapse

Methods inherited from Oracle

#+, #stats

Constructor Details

#initialize(alphabet, call_alphabet, return_alphabet, sul, max_words: 100, min_word_size: 2, max_word_size: 30, call_prob: 0.5, initial_proc: nil, random: Random) ⇒ RandomWellMatchedWordOracle

: (

  Array[In] alphabet,
  Array[Call] call_alphabet,
  Array[Return] return_alphabet,
  System::SUL[In | Call | Return, Out] sul,
  ?max_words: Integer,
  ?min_word_size: Integer,
  ?max_word_size: Integer,
  ?call_prob: Float,
  ?initial_proc: Call | nil,
  ?random: Random
) -> void


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lernen/equiv/random_well_matched_word_oracle.rb', line 49

def initialize(
  alphabet,
  call_alphabet,
  return_alphabet,
  sul,
  max_words: 100,
  min_word_size: 2,
  max_word_size: 30,
  call_prob: 0.5,
  initial_proc: nil,
  random: Random
)
  super(sul)

  @alphabet = alphabet
  @call_alphabet = call_alphabet
  @return_alphabet = return_alphabet
  @max_words = max_words
  @min_word_size = min_word_size
  @max_word_size = max_word_size
  @call_prob = call_prob
  @initial_proc = initial_proc
  @random = random
end

Instance Method Details

#find_cex(hypothesis) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/lernen/equiv/random_well_matched_word_oracle.rb', line 75

def find_cex(hypothesis)
  super

  @max_words.times do
    reset_internal(hypothesis)

    word = generate_word
    word.each_with_index do |input, index|
      hypothesis_output, sul_output = step_internal(hypothesis, input)

      if hypothesis_output != sul_output # steep:ignore
        @sul.shutdown
        return word[0..index]
      end
    end
  end

  nil
end