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,63 +0,0 @@
1
- require 'test/unit'
2
- require 'stamina/errors'
3
- require 'stamina/stamina_test'
4
- require 'stamina/scoring'
5
- module Stamina
6
- class ScoringTest < StaminaTest
7
-
8
- def assert_almost_equal(x, y)
9
- assert (x.to_f - y.to_f).abs <= 0.0001
10
- end
11
-
12
- def test_scoring_on_exact
13
- learned, reference = "11010", "11010"
14
- scoring = Scoring.scoring(learned, reference)
15
-
16
- # It looks like a Scoring object
17
- assert scoring.respond_to?(:false_positive)
18
- assert scoring.respond_to?(:recall)
19
-
20
- # four measures are ok
21
- assert_equal 3, scoring.true_positive
22
- assert_equal 2, scoring.true_negative
23
- assert_equal 0, scoring.false_positive
24
- assert_equal 0, scoring.false_negative
25
-
26
- # precision and recall are ok
27
- assert_equal (3.0 / (3.0 + 0.0)), scoring.precision
28
- assert_equal (3.0 / (3.0 + 0.0)), scoring.recall
29
-
30
- # sensitivity and specificity are ok
31
- assert_equal (3.0 / (3.0 + 0.0)), scoring.sensitivity
32
- assert_equal (3.0 / (3.0 + 0.0)), scoring.specificity
33
-
34
- #
35
- assert_equal 1.0, scoring.accuracy
36
- assert_equal 1.0, scoring.bcr
37
- assert_equal 1.0, scoring.f_measure
38
- assert_equal 1.0, scoring.hbcr
39
- end
40
-
41
- def test_on_wikipedia_example
42
- hash = {
43
- :true_positive => 2,
44
- :false_positive => 18,
45
- :true_negative => 182,
46
- :false_negative => 1
47
- }
48
- hash.extend(Scoring)
49
- assert_equal (2.0 / (2 + 18)), hash.positive_predictive_value
50
- assert_equal (182.0 / (1 + 182)), hash.negative_predictive_value
51
- assert_equal (2.0 / (2 + 1)), hash.sensitivity
52
- assert_equal (182.0 / (18 + 182)), hash.specificity
53
- assert_equal (18.0 / (18 + 182)), hash.false_positive_rate
54
- assert_equal (1.0 / (2 + 1)), hash.false_negative_rate
55
- #
56
- assert_almost_equal (1.0 - hash.specificity), hash.false_positive_rate
57
- assert_almost_equal (1.0 - hash.sensitivity), hash.false_negative_rate
58
- assert_almost_equal hash.sensitivity / (1.0 - hash.specificity), hash.positive_likelihood
59
- assert_almost_equal (1.0 - hash.sensitivity) / hash.specificity, hash.negative_likelihood
60
- end
61
-
62
- end # class ScoringTest
63
- end # module Stamina
@@ -1,16 +0,0 @@
1
- digraph small_dfa {
2
- graph [rankdir="LR"];
3
- node [shape="circle"];
4
- zz [label="" width=0.01 height=0.01];
5
- 0 [shape=doublecircle label="s0"];
6
- 1 [label="s1"];
7
- 2 [shape=doublecircle label="s2"];
8
- 3 [label="s3"];
9
- 0 -> 1 [label="e0/a"]
10
- 1 -> 2 [label="e1/b"]
11
- 1 -> 3 [label="e2/a"]
12
- 3 -> 2 [label="e3/b"]
13
- 2 -> 0 [label="e4/c"]
14
- 1 -> 1 [label="e5/c"]
15
- zz -> 3 [label=""]
16
- }
Binary file
@@ -1,18 +0,0 @@
1
- digraph small_nfa {
2
- graph [rankdir="LR"];
3
- node [shape="circle"];
4
- zz [label="" width=0.01 height=0.01];
5
- 0 [shape=doublecircle label="s0"];
6
- 1 [label="s1"];
7
- 2 [shape=doublecircle label="s2"];
8
- 3 [label="s3"];
9
- 0 -> 1 [label="e0/a"]
10
- 1 -> 1 [label="e1/nil"]
11
- 1 -> 2 [label="e2/b"]
12
- 1 -> 3 [label="e3/b"]
13
- 2 -> 3 [label="e4/c"]
14
- 3 -> 0 [label="e5/a"]
15
- 2 -> 1 [label="e6/nil"]
16
- zz -> 0 [label=""]
17
- zz -> 3 [label=""]
18
- }
Binary file
@@ -1,80 +0,0 @@
1
- require 'test/unit'
2
- require 'stamina'
3
- module Stamina
4
-
5
- #
6
- # Main test class for stamina. By default this test installs default example
7
- # automata on setup.
8
- #
9
- # In particular, it installs the following automata:
10
- # - @small_dfa: a small deterministic automaton whose picture can be found in
11
- # small_dfa.gif
12
- # - @small_nfa: a small non deterministic automaton whose picture can be found
13
- # in small_nfa.gif
14
- #
15
- # Moreover, is also provides the following helpers:
16
- # - @examples is an array containing all created automata.
17
- # - @dfa_examples is an array containing deterministic automaton only.
18
- # - @nfa_examples is an array containing non-deterministic automaton only.
19
- #
20
- class StaminaTest < Test::Unit::TestCase
21
-
22
- def load_adl_automaton(file, resolver)
23
- Stamina::ADL.parse_automaton_file(File.expand_path("../#{file}", resolver))
24
- end
25
-
26
- # Creates a small automaton for the sake of simple tests
27
- def setup
28
- @small_dfa = Automaton.new do
29
- s0, s1, s2, s3 = add_n_states(4)
30
- s3.initial!
31
- s0.accepting!
32
- s2.accepting!
33
- connect(s0, s1, 'a')
34
- connect(s1, s2, 'b')
35
- connect(s1, s3, 'a')
36
- connect(s3, s2, 'b')
37
- connect(s2, s0, 'c')
38
- connect(s1, s1, 'c')
39
- end
40
-
41
- @small_nfa = Automaton.new do
42
- s0, s1, s2, s3 = add_n_states(4)
43
- s0.initial!
44
- s3.initial!
45
- s0.accepting!
46
- s2.accepting!
47
- connect(s0, s1, 'a')
48
- connect(s1, s1, nil)
49
- connect(s1, s2, 'b')
50
- connect(s1, s3, 'b')
51
- connect(s2, s3, 'c')
52
- connect(s3, s0, 'a')
53
- connect(s2, s1, nil)
54
- end
55
-
56
- @examples = [@small_dfa, @small_nfa]
57
- @dfa_examples = [@small_dfa]
58
- @nfa_examples = [@small_nfa]
59
- end
60
-
61
- # Tests the validity of examples
62
- def test_validity_of_examples
63
- @dfa_examples.each do |e|
64
- assert_equal(true, e.deterministic?)
65
- end
66
- @nfa_examples.each do |e|
67
- assert_equal(false, e.deterministic?)
68
- end
69
- end
70
-
71
- def assert_not_equivalent(expected, dfa)
72
- assert !expected.complete.equivalent?(dfa.complete)
73
- end
74
-
75
- def assert_equivalent(expected, dfa)
76
- assert expected.complete.equivalent?(dfa.complete)
77
- end
78
-
79
- end # class StaminaTest
80
- end # module Stamina
@@ -1,65 +0,0 @@
1
- require 'stamina'
2
- require 'stamina/utils/decorate'
3
- require 'stamina/stamina_test'
4
- require 'test/unit'
5
- module Stamina
6
- module Utils
7
- class DecorateTest < ::Stamina::StaminaTest
8
-
9
- module Reachability
10
- def suppremum(d0, d1) d0 || d1; end
11
- def propagate(deco, edge) deco; end
12
- end
13
-
14
- module Depth
15
- def suppremum(d0, d1) (d0 < d1 ? d0 : d1) end
16
- def propagate(deco, edge) deco+1; end
17
- end
18
-
19
- module ShortPrefix
20
- def suppremum(d0, d1)
21
- return d0 if d1.nil?
22
- return d1 if d0.nil?
23
- d0.size <= d1.size ? d0 : d1
24
- end
25
- def propagate(deco, edge)
26
- deco.dup << edge.symbol
27
- end
28
- end
29
-
30
- def test_reachability_on_small_dfa
31
- algo = Stamina::Utils::Decorate.new(:reachable)
32
- algo.set_suppremum {|d0,d1| d0 || d1 }
33
- algo.set_propagate {|deco,edge| deco }
34
- algo.execute(@small_dfa, false, true)
35
- assert_equal @small_dfa.states.select {|s| s[:reachable]==true}, @small_dfa.states
36
-
37
- algo = Stamina::Utils::Decorate.new(:reachable)
38
- algo.extend(Reachability)
39
- algo.execute(@small_dfa, false, true)
40
- assert_equal @small_dfa.states.select {|s| s[:reachable]==true}, @small_dfa.states
41
- end
42
-
43
- def test_depth_on_small_dfa
44
- algo = Stamina::Utils::Decorate.new(:depth)
45
- algo.extend(Depth)
46
- algo.execute(@small_dfa, 1000000, 0)
47
- assert_equal 0, @small_dfa.ith_state(3)[:depth]
48
- assert_equal 1, @small_dfa.ith_state(2)[:depth]
49
- assert_equal 2, @small_dfa.ith_state(0)[:depth]
50
- assert_equal 3, @small_dfa.ith_state(1)[:depth]
51
- end
52
-
53
- def test_depth_on_small_dfa
54
- algo = Stamina::Utils::Decorate.new(:short_prefix)
55
- algo.extend(ShortPrefix)
56
- algo.execute(@small_dfa, nil, [])
57
- assert_equal [], @small_dfa.ith_state(3)[:short_prefix]
58
- assert_equal ['b'], @small_dfa.ith_state(2)[:short_prefix]
59
- assert_equal ['b', 'c'], @small_dfa.ith_state(0)[:short_prefix]
60
- assert_equal ['b', 'c', 'a'], @small_dfa.ith_state(1)[:short_prefix]
61
- end
62
-
63
- end
64
- end
65
- end
data/test/test_all.rb DELETED
@@ -1,7 +0,0 @@
1
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
2
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'test')
4
- test_files = Dir['**/*_test.rb']
5
- test_files.each { |file|
6
- require(file)
7
- }