stamina 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/CHANGELOG.md +22 -5
  2. data/LICENCE.md +2 -2
  3. data/bin/stamina +1 -7
  4. data/lib/stamina.rb +10 -19
  5. metadata +54 -333
  6. data/.gemtest +0 -0
  7. data/Gemfile +0 -2
  8. data/Gemfile.lock +0 -37
  9. data/Manifest.txt +0 -16
  10. data/README.md +0 -78
  11. data/Rakefile +0 -23
  12. data/example/adl/automaton.adl +0 -49
  13. data/example/adl/sample.adl +0 -53
  14. data/example/basic/characteristic_sample.adl +0 -32
  15. data/example/basic/target.adl +0 -9
  16. data/example/competition/31_test.adl +0 -1500
  17. data/example/competition/31_training.adl +0 -1759
  18. data/lib/stamina/abbadingo.rb +0 -2
  19. data/lib/stamina/abbadingo/random_dfa.rb +0 -48
  20. data/lib/stamina/abbadingo/random_sample.rb +0 -146
  21. data/lib/stamina/adl.rb +0 -298
  22. data/lib/stamina/automaton.rb +0 -1263
  23. data/lib/stamina/automaton/complete.rb +0 -36
  24. data/lib/stamina/automaton/equivalence.rb +0 -55
  25. data/lib/stamina/automaton/metrics.rb +0 -78
  26. data/lib/stamina/automaton/minimize.rb +0 -25
  27. data/lib/stamina/automaton/minimize/hopcroft.rb +0 -116
  28. data/lib/stamina/automaton/minimize/pitchies.rb +0 -64
  29. data/lib/stamina/automaton/strip.rb +0 -16
  30. data/lib/stamina/automaton/walking.rb +0 -363
  31. data/lib/stamina/classifier.rb +0 -52
  32. data/lib/stamina/command.rb +0 -45
  33. data/lib/stamina/command/abbadingo_dfa.rb +0 -81
  34. data/lib/stamina/command/abbadingo_samples.rb +0 -40
  35. data/lib/stamina/command/adl2dot.rb +0 -71
  36. data/lib/stamina/command/classify.rb +0 -48
  37. data/lib/stamina/command/help.rb +0 -27
  38. data/lib/stamina/command/infer.rb +0 -141
  39. data/lib/stamina/command/metrics.rb +0 -51
  40. data/lib/stamina/command/robustness.rb +0 -22
  41. data/lib/stamina/command/score.rb +0 -35
  42. data/lib/stamina/errors.rb +0 -23
  43. data/lib/stamina/ext/math.rb +0 -20
  44. data/lib/stamina/induction/blue_fringe.rb +0 -265
  45. data/lib/stamina/induction/commons.rb +0 -156
  46. data/lib/stamina/induction/rpni.rb +0 -186
  47. data/lib/stamina/induction/union_find.rb +0 -377
  48. data/lib/stamina/input_string.rb +0 -123
  49. data/lib/stamina/loader.rb +0 -1
  50. data/lib/stamina/markable.rb +0 -42
  51. data/lib/stamina/sample.rb +0 -267
  52. data/lib/stamina/scoring.rb +0 -213
  53. data/lib/stamina/utils.rb +0 -1
  54. data/lib/stamina/utils/decorate.rb +0 -81
  55. data/lib/stamina/version.rb +0 -14
  56. data/stamina.gemspec +0 -191
  57. data/stamina.noespec +0 -32
  58. data/tasks/debug_mail.rake +0 -78
  59. data/tasks/debug_mail.txt +0 -13
  60. data/tasks/gem.rake +0 -68
  61. data/tasks/spec_test.rake +0 -79
  62. data/tasks/unit_test.rake +0 -77
  63. data/tasks/yard.rake +0 -51
  64. data/test/stamina/abbadingo/random_dfa_test.rb +0 -16
  65. data/test/stamina/abbadingo/random_sample_test.rb +0 -78
  66. data/test/stamina/adl_test.rb +0 -516
  67. data/test/stamina/automaton/classifier_test.rb +0 -259
  68. data/test/stamina/automaton/complete_test.rb +0 -58
  69. data/test/stamina/automaton/equivalence_test.rb +0 -120
  70. data/test/stamina/automaton/metrics_test.rb +0 -36
  71. data/test/stamina/automaton/minimize/hopcroft_test.rb +0 -15
  72. data/test/stamina/automaton/minimize/minimize_test.rb +0 -55
  73. data/test/stamina/automaton/minimize/pitchies_test.rb +0 -15
  74. data/test/stamina/automaton/minimize/rice_edu_10.adl +0 -16
  75. data/test/stamina/automaton/minimize/rice_edu_10.min.adl +0 -13
  76. data/test/stamina/automaton/minimize/rice_edu_13.adl +0 -13
  77. data/test/stamina/automaton/minimize/rice_edu_13.min.adl +0 -7
  78. data/test/stamina/automaton/minimize/should_strip_1.adl +0 -8
  79. data/test/stamina/automaton/minimize/should_strip_1.min.adl +0 -6
  80. data/test/stamina/automaton/minimize/unknown_1.adl +0 -16
  81. data/test/stamina/automaton/minimize/unknown_1.min.adl +0 -12
  82. data/test/stamina/automaton/strip_test.rb +0 -36
  83. data/test/stamina/automaton/to_dot_test.rb +0 -64
  84. data/test/stamina/automaton/walking/dfa_delta_test.rb +0 -39
  85. data/test/stamina/automaton/walking_test.rb +0 -206
  86. data/test/stamina/automaton_additional_test.rb +0 -190
  87. data/test/stamina/automaton_test.rb +0 -1104
  88. data/test/stamina/exit.rb +0 -3
  89. data/test/stamina/induction/blue_fringe_test.rb +0 -83
  90. data/test/stamina/induction/induction_test.rb +0 -70
  91. data/test/stamina/induction/redblue_mergesamestatebug_expected.adl +0 -19
  92. data/test/stamina/induction/redblue_mergesamestatebug_pta.dot +0 -64
  93. data/test/stamina/induction/redblue_mergesamestatebug_sample.adl +0 -9
  94. data/test/stamina/induction/redblue_universal_expected.adl +0 -4
  95. data/test/stamina/induction/redblue_universal_sample.adl +0 -5
  96. data/test/stamina/induction/rpni_inria_expected.adl +0 -7
  97. data/test/stamina/induction/rpni_inria_sample.adl +0 -9
  98. data/test/stamina/induction/rpni_test.rb +0 -129
  99. data/test/stamina/induction/rpni_test_pta.dot +0 -22
  100. data/test/stamina/induction/rpni_universal_expected.adl +0 -4
  101. data/test/stamina/induction/rpni_universal_sample.adl +0 -4
  102. data/test/stamina/induction/union_find_test.rb +0 -124
  103. data/test/stamina/input_string_test.rb +0 -323
  104. data/test/stamina/markable_test.rb +0 -70
  105. data/test/stamina/randdfa.adl +0 -66
  106. data/test/stamina/sample.adl +0 -4
  107. data/test/stamina/sample_classify_test.rb +0 -149
  108. data/test/stamina/sample_test.rb +0 -290
  109. data/test/stamina/scoring_test.rb +0 -63
  110. data/test/stamina/small_dfa.dot +0 -16
  111. data/test/stamina/small_dfa.gif +0 -0
  112. data/test/stamina/small_nfa.dot +0 -18
  113. data/test/stamina/small_nfa.gif +0 -0
  114. data/test/stamina/stamina_test.rb +0 -80
  115. data/test/stamina/utils/decorate_test.rb +0 -65
  116. data/test/test_all.rb +0 -7
@@ -1,259 +0,0 @@
1
- require 'test/unit'
2
- require 'stamina/adl'
3
- require 'stamina/stamina_test'
4
- module Stamina
5
- class Automaton
6
- # Tests Classifier module, as to be installed on Automaton.
7
- class ClassifierTest < StaminaTest
8
-
9
- # Tests Classify#correctly_classified_by? is correct on valid sample against
10
- # small_dfa example
11
- def test_valid_sample_correctly_satified_by_small_dfa
12
- assert_equal(true, @small_dfa.correctly_classify?(Sample.new))
13
- sample = ADL::parse_sample <<-SAMPLE
14
- -
15
- + b
16
- + b c
17
- - b c a
18
- - b c a c
19
- - b c a c a
20
- - b c a a
21
- + b c a b
22
- + b c a b c a c b
23
- - z
24
- - b z
25
- SAMPLE
26
- assert_equal '01100001100', sample.signature
27
- assert_equal(true, @small_dfa.correctly_classify?(sample))
28
- assert_equal sample.signature, @small_dfa.signature(sample)
29
- end
30
-
31
- # Tests Classify#correctly_classified_by? is correct on invalid sample against
32
- # small_dfa example
33
- def test_invalid_sample_correctly_classified_by_small_dfa
34
- sample = ADL::parse_sample <<-SAMPLE
35
- -
36
- + b
37
- + b c
38
- - b c a
39
- # this one is reversed
40
- + b c a c
41
- - b c a c a
42
- - b c a a
43
- + b c a b
44
- + b c a b c a c b
45
- - z
46
- - b z
47
- SAMPLE
48
- assert_equal(false, @small_dfa.correctly_classify?(sample))
49
- assert_equal '01100001100', @small_dfa.signature(sample)
50
-
51
- sample = ADL::parse_sample <<-SAMPLE
52
- -
53
- + b
54
- + b c
55
- - b c a
56
- - b c a c
57
- - b c a c a
58
- - b c a a
59
- + b c a b
60
- + b c a b c a c b
61
- # this one is changed
62
- + z
63
- - b z
64
- SAMPLE
65
- assert_equal(false, @small_dfa.correctly_classify?(sample))
66
- assert_equal '01100001100', @small_dfa.signature(sample)
67
-
68
- sample = ADL::parse_sample <<-SAMPLE
69
- -
70
- + b
71
- + b c
72
- - b c a
73
- - b c a c
74
- - b c a c a
75
- - b c a a
76
- + b c a b
77
- # this one is changed
78
- - b c a b c a c b
79
- - z
80
- - b z
81
- SAMPLE
82
- assert_equal(false, @small_dfa.correctly_classify?(sample))
83
- assert_equal '01100001100', @small_dfa.signature(sample)
84
- end
85
-
86
- # Tests Classify#correctly_classify? is correct on valid sample against
87
- # small_nfa example
88
- def test_valid_sample_correctly_satified_by_small_nfa
89
- assert_equal(true, @small_nfa.correctly_classify?(Sample.new))
90
- sample = ADL::parse_sample <<-SAMPLE
91
- +
92
- + a
93
- - a a
94
- + a a b
95
- + a b
96
- + a b c a
97
- - a b c
98
- + a b b b b b b
99
- - a z
100
- - z
101
- SAMPLE
102
- assert_equal(true, @small_nfa.correctly_classify?(sample))
103
- assert_equal sample.signature, @small_nfa.signature(sample)
104
- end
105
-
106
- # Tests Classify#correctly_classify? is correct on invalid sample against
107
- # small_nfa example
108
- def test_invalid_sample_correctly_satified_by_small_nfa
109
- sample = ADL::parse_sample <<-SAMPLE
110
- # this one is changed
111
- -
112
- + a
113
- - a a
114
- + a a b
115
- + a b
116
- + a b c a
117
- - a b c
118
- + a b b b b b b
119
- - a z
120
- - z
121
- SAMPLE
122
- assert_equal(false, @small_nfa.correctly_classify?(sample))
123
- sample = ADL::parse_sample <<-SAMPLE
124
- +
125
- + a
126
- - a a
127
- + a a b
128
- # this one is changed
129
- - a b
130
- + a b c a
131
- - a b c
132
- + a b b b b b b
133
- - a z
134
- - z
135
- SAMPLE
136
- assert_equal(false, @small_nfa.correctly_classify?(sample))
137
- sample = ADL::parse_sample <<-SAMPLE
138
- +
139
- + a
140
- # this one is changed
141
- + a a
142
- + a a b
143
- + a b
144
- + a b c a
145
- - a b c
146
- + a b b b b b b
147
- - a z
148
- - z
149
- SAMPLE
150
- assert_equal(false, @small_nfa.correctly_classify?(sample))
151
- end
152
-
153
- def test_scoring_on_valid_sample
154
- sample = ADL::parse_sample <<-SAMPLE
155
- -
156
- + b
157
- + b c
158
- - b c a
159
- - b c a c
160
- - b c a c a
161
- - b c a a
162
- + b c a b
163
- + b c a b c a c b
164
- - z
165
- - b z
166
- SAMPLE
167
- measures = @small_dfa.scoring(sample)
168
- assert_equal(sample.positive_count, measures.true_positive)
169
- assert_equal(0, measures.false_positive)
170
- assert_equal(sample.negative_count, measures.true_negative)
171
- assert_equal(0, measures.false_negative)
172
- assert_equal(1.0, measures.precision)
173
- assert_equal(1.0, measures.recall)
174
- assert_equal(1.0, measures.sensitivity)
175
- assert_equal(1.0, measures.specificity)
176
- assert_equal(1.0, measures.accuracy)
177
- end
178
-
179
- def test_scoring_on_invalid_sample
180
- sample = ADL::parse_sample <<-SAMPLE
181
- +
182
- - b
183
- - b c
184
- + b c a
185
- + b c a c
186
- + b c a c a
187
- + b c a a
188
- - b c a b
189
- - b c a b c a c b
190
- + z
191
- + b z
192
- SAMPLE
193
- measures = @small_dfa.scoring(sample)
194
- assert_equal(0.0, measures.true_positive)
195
- assert_equal(sample.negative_count, measures.false_positive)
196
- assert_equal(0.0, measures.true_negative)
197
- assert_equal(sample.positive_count, measures.false_negative)
198
- assert_equal(0.0, measures.precision)
199
- assert_equal(0.0, measures.recall)
200
- assert_equal(0.0, measures.sensitivity)
201
- assert_equal(0.0, measures.specificity)
202
- assert_equal(0.0, measures.accuracy)
203
- end
204
-
205
- def test_scoring_with_positive_only
206
- sample = ADL::parse_sample <<-SAMPLE
207
- +
208
- + b
209
- + b c
210
- + b c a
211
- + b c a c
212
- + b c a c a
213
- + b c a a
214
- + b c a b
215
- + b c a b c a c b
216
- + z
217
- + b z
218
- SAMPLE
219
- measures = @small_dfa.scoring(sample)
220
- assert_equal(4.0, measures.true_positive)
221
- assert_equal(sample.size-sample.positive_count, measures.false_positive)
222
- assert_equal(0, measures.true_negative)
223
- assert_equal(sample.size-4.0, measures.false_negative)
224
- assert_equal(1.0, measures.precision)
225
- assert_equal(4.0/sample.size, measures.recall)
226
- assert_equal(4.0/sample.size, measures.sensitivity)
227
- #assert_equal(0.0/0.0, measures.specificity)
228
- assert_equal(4.0/sample.size, measures.accuracy)
229
- end
230
-
231
- def test_scoring_with_negative_only
232
- sample = ADL::parse_sample <<-SAMPLE
233
- -
234
- - b
235
- - b c
236
- - b c a
237
- - b c a c
238
- - b c a c a
239
- - b c a a
240
- - b c a b
241
- - b c a b c a c b
242
- - z
243
- - b z
244
- SAMPLE
245
- measures = @small_dfa.scoring(sample)
246
- assert_equal(0.0, measures.true_positive)
247
- assert_equal(4.0, measures.false_positive)
248
- assert_equal(sample.size-4.0, measures.true_negative)
249
- assert_equal(0.0, measures.false_negative)
250
- assert_equal(0.0, measures.precision)
251
- #assert_equal(0.0, measures.recall)
252
- #assert_equal(0.0, measures.sensitivity)
253
- assert_equal((sample.size-4.0)/sample.size, measures.specificity)
254
- assert_equal((sample.size-4.0)/sample.size, measures.accuracy)
255
- end
256
-
257
- end # class ClassifierTest
258
- end # class Automaton
259
- end # module Stamina
@@ -1,58 +0,0 @@
1
- require 'test/unit'
2
- require 'stamina/stamina_test'
3
- module Stamina
4
- class Automaton
5
- class CompleteTest < StaminaTest
6
-
7
- def test_on_not_complete
8
- x, y, z = nil, nil, nil
9
- dfa = Automaton.new(true) do |fa|
10
- fa.alphabet = ["a", "b"]
11
- x = fa.add_state(:initial => true, :accepting => true)
12
- y = fa.add_state(:initial => false, :accepting => false)
13
- fa.connect(0,1,'a')
14
- fa.connect(1,0,'b')
15
- end
16
-
17
- assert_equal false, dfa.complete?
18
- dfa.complete!
19
- assert_equal true, dfa.complete?
20
-
21
- assert_equal 3, dfa.state_count
22
- z = dfa.ith_state(2)
23
- assert_equal z, dfa.dfa_delta(x, "b")
24
- assert_equal y, dfa.dfa_delta(x, "a")
25
- assert_equal z, dfa.dfa_delta(y, "a")
26
- assert_equal x, dfa.dfa_delta(y, "b")
27
- end
28
-
29
- def test_on_complete
30
- dfa = Automaton.new(true) do |fa|
31
- fa.alphabet = ["a"]
32
- fa.add_state(:initial => true, :accepting => true)
33
- fa.add_state(:initial => false, :accepting => false)
34
- fa.connect(0,1,'a')
35
- fa.connect(1,0,'a')
36
- end
37
- assert_equal true, dfa.complete?
38
- dfa.complete!
39
- assert_equal 2, dfa.state_count
40
- end
41
-
42
- def test_it_has_a_non_touching_impl
43
- dfa = Automaton.new(true) do |fa|
44
- fa.alphabet = ["a", "b"]
45
- fa.add_state(:initial => true, :accepting => true)
46
- fa.add_state(:initial => false, :accepting => false)
47
- fa.connect(0,1,'a')
48
- fa.connect(1,0,'b')
49
- end
50
- c = dfa.complete
51
- assert_equal 2, dfa.state_count
52
- assert_equal 3, c.state_count
53
- end
54
-
55
- end # class CompleteTest
56
- end # class Automaton
57
- end # module Stamina
58
-
@@ -1,120 +0,0 @@
1
- require 'test/unit'
2
- require 'stamina/stamina_test'
3
- module Stamina
4
- class Automaton
5
- class EquivalenceTest < StaminaTest
6
-
7
- def test_equivalence_on_small_dfa
8
- assert_equal true, @small_dfa <=> @small_dfa
9
- end
10
-
11
- def test_equivalence_on_real_case
12
- dfa1 = Stamina::ADL.parse_automaton <<-EOF
13
- 3 5
14
- 0 true false
15
- 1 false false
16
- 2 false true
17
- 0 1 a
18
- 1 1 a
19
- 1 2 b
20
- 2 2 b
21
- 0 2 b
22
- EOF
23
- dfa2 = Stamina::ADL.parse_automaton <<-EOF
24
- 3 5
25
- 0 false true
26
- 1 true false
27
- 2 false false
28
- 0 0 b
29
- 1 2 a
30
- 1 0 b
31
- 2 2 a
32
- 2 0 b
33
- EOF
34
- dfa3 = Stamina::ADL.parse_automaton <<-EOF
35
- 3 5
36
- 0 false false
37
- 1 false true
38
- 2 true false
39
- 0 0 a
40
- 0 1 b
41
- 1 1 b
42
- 2 0 a
43
- 2 1 b
44
- EOF
45
- assert_equal true, dfa1 <=> dfa2
46
- assert_equal true, dfa2 <=> dfa1
47
- assert_equal true, dfa1 <=> dfa3
48
- assert_equal true, dfa3 <=> dfa1
49
- assert_equal true, dfa2 <=> dfa3
50
- assert_equal true, dfa3 <=> dfa2
51
- end
52
-
53
- def test_equivalence_does_not_change_the_automata
54
- dfa1 = Stamina::ADL.parse_automaton <<-EOF
55
- 1 1
56
- 0 true true
57
- 0 0 a
58
- EOF
59
- assert_not_nil dfa1.initial_state
60
- assert_equal true, dfa1 <=> dfa1
61
- assert_not_nil dfa1.initial_state
62
- end
63
-
64
- def test_non_equivalent_dfa_are_recognized_1
65
- dfa1 = Stamina::ADL.parse_automaton <<-EOF
66
- 3 5
67
- 0 true false
68
- 1 false false
69
- 2 false true
70
- 0 1 a
71
- 1 1 a
72
- 1 2 b
73
- 2 2 b
74
- 0 2 b
75
- EOF
76
- assert_equal false, @small_dfa <=> dfa1
77
- assert_equal false, dfa1 <=> @small_dfa
78
- end
79
-
80
- def test_non_equivalent_dfa_are_recognized_2
81
- dfa1 = Stamina::ADL.parse_automaton <<-EOF
82
- 5 4
83
- 0 true false
84
- 1 false false
85
- 2 false false
86
- 3 false false
87
- 4 false false
88
- 0 1 a
89
- 1 2 a
90
- 2 3 a
91
- 3 4 a
92
- EOF
93
- dfa2 = Stamina::ADL.parse_automaton <<-EOF
94
- 1 1
95
- 0 true true
96
- 0 0 a
97
- EOF
98
- assert_equal false, dfa2 <=> dfa1
99
- assert_not_nil dfa1.initial_state
100
- assert_not_nil dfa2.initial_state
101
- assert_equal false, dfa1 <=> dfa2
102
- end
103
-
104
- def test_equivalence_takes_care_of_state_flags
105
- dfa1 = Stamina::ADL.parse_automaton <<-EOF
106
- 1 0
107
- 0 true false
108
- EOF
109
- dfa2 = Stamina::ADL.parse_automaton <<-EOF
110
- 1 0
111
- 0 true true
112
- EOF
113
- assert_equal false, dfa1 <=> dfa2
114
- assert_equal false, dfa2 <=> dfa1
115
- end
116
-
117
- end # class EquivalenceTest
118
- end # class Automaton
119
- end # module Stamina
120
-
@@ -1,36 +0,0 @@
1
- require 'test/unit'
2
- require 'stamina/adl'
3
- require 'stamina/stamina_test'
4
- module Stamina
5
- class Automaton
6
- class MetricsTest < StaminaTest
7
-
8
- def test_alphabet_size
9
- assert_equal 3, @small_dfa.alphabet_size
10
- end
11
-
12
- def test_avg_degree
13
- assert_equal 6.to_f/4, @small_dfa.avg_degree
14
- end
15
-
16
- def test_avg_out_degree
17
- assert_equal 6.to_f/4, @small_dfa.avg_out_degree
18
- end
19
-
20
- def test_avg_in_degree
21
- assert_equal 6.to_f/4, @small_dfa.avg_in_degree
22
- end
23
-
24
- def test_accepting_ratio
25
- assert_equal 0.5, @small_dfa.accepting_ratio
26
- end
27
-
28
- def test_depth
29
- assert_equal 3, @small_dfa.depth
30
- assert_equal 2, @small_nfa.depth
31
- end
32
-
33
- end
34
- end
35
- end
36
-