stamina 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +22 -5
- data/LICENCE.md +2 -2
- data/bin/stamina +1 -7
- data/lib/stamina.rb +10 -19
- metadata +54 -333
- data/.gemtest +0 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -37
- data/Manifest.txt +0 -16
- data/README.md +0 -78
- data/Rakefile +0 -23
- data/example/adl/automaton.adl +0 -49
- data/example/adl/sample.adl +0 -53
- data/example/basic/characteristic_sample.adl +0 -32
- data/example/basic/target.adl +0 -9
- data/example/competition/31_test.adl +0 -1500
- data/example/competition/31_training.adl +0 -1759
- data/lib/stamina/abbadingo.rb +0 -2
- data/lib/stamina/abbadingo/random_dfa.rb +0 -48
- data/lib/stamina/abbadingo/random_sample.rb +0 -146
- data/lib/stamina/adl.rb +0 -298
- data/lib/stamina/automaton.rb +0 -1263
- data/lib/stamina/automaton/complete.rb +0 -36
- data/lib/stamina/automaton/equivalence.rb +0 -55
- data/lib/stamina/automaton/metrics.rb +0 -78
- data/lib/stamina/automaton/minimize.rb +0 -25
- data/lib/stamina/automaton/minimize/hopcroft.rb +0 -116
- data/lib/stamina/automaton/minimize/pitchies.rb +0 -64
- data/lib/stamina/automaton/strip.rb +0 -16
- data/lib/stamina/automaton/walking.rb +0 -363
- data/lib/stamina/classifier.rb +0 -52
- data/lib/stamina/command.rb +0 -45
- data/lib/stamina/command/abbadingo_dfa.rb +0 -81
- data/lib/stamina/command/abbadingo_samples.rb +0 -40
- data/lib/stamina/command/adl2dot.rb +0 -71
- data/lib/stamina/command/classify.rb +0 -48
- data/lib/stamina/command/help.rb +0 -27
- data/lib/stamina/command/infer.rb +0 -141
- data/lib/stamina/command/metrics.rb +0 -51
- data/lib/stamina/command/robustness.rb +0 -22
- data/lib/stamina/command/score.rb +0 -35
- data/lib/stamina/errors.rb +0 -23
- data/lib/stamina/ext/math.rb +0 -20
- data/lib/stamina/induction/blue_fringe.rb +0 -265
- data/lib/stamina/induction/commons.rb +0 -156
- data/lib/stamina/induction/rpni.rb +0 -186
- data/lib/stamina/induction/union_find.rb +0 -377
- data/lib/stamina/input_string.rb +0 -123
- data/lib/stamina/loader.rb +0 -1
- data/lib/stamina/markable.rb +0 -42
- data/lib/stamina/sample.rb +0 -267
- data/lib/stamina/scoring.rb +0 -213
- data/lib/stamina/utils.rb +0 -1
- data/lib/stamina/utils/decorate.rb +0 -81
- data/lib/stamina/version.rb +0 -14
- data/stamina.gemspec +0 -191
- data/stamina.noespec +0 -32
- data/tasks/debug_mail.rake +0 -78
- data/tasks/debug_mail.txt +0 -13
- data/tasks/gem.rake +0 -68
- data/tasks/spec_test.rake +0 -79
- data/tasks/unit_test.rake +0 -77
- data/tasks/yard.rake +0 -51
- data/test/stamina/abbadingo/random_dfa_test.rb +0 -16
- data/test/stamina/abbadingo/random_sample_test.rb +0 -78
- data/test/stamina/adl_test.rb +0 -516
- data/test/stamina/automaton/classifier_test.rb +0 -259
- data/test/stamina/automaton/complete_test.rb +0 -58
- data/test/stamina/automaton/equivalence_test.rb +0 -120
- data/test/stamina/automaton/metrics_test.rb +0 -36
- data/test/stamina/automaton/minimize/hopcroft_test.rb +0 -15
- data/test/stamina/automaton/minimize/minimize_test.rb +0 -55
- data/test/stamina/automaton/minimize/pitchies_test.rb +0 -15
- data/test/stamina/automaton/minimize/rice_edu_10.adl +0 -16
- data/test/stamina/automaton/minimize/rice_edu_10.min.adl +0 -13
- data/test/stamina/automaton/minimize/rice_edu_13.adl +0 -13
- data/test/stamina/automaton/minimize/rice_edu_13.min.adl +0 -7
- data/test/stamina/automaton/minimize/should_strip_1.adl +0 -8
- data/test/stamina/automaton/minimize/should_strip_1.min.adl +0 -6
- data/test/stamina/automaton/minimize/unknown_1.adl +0 -16
- data/test/stamina/automaton/minimize/unknown_1.min.adl +0 -12
- data/test/stamina/automaton/strip_test.rb +0 -36
- data/test/stamina/automaton/to_dot_test.rb +0 -64
- data/test/stamina/automaton/walking/dfa_delta_test.rb +0 -39
- data/test/stamina/automaton/walking_test.rb +0 -206
- data/test/stamina/automaton_additional_test.rb +0 -190
- data/test/stamina/automaton_test.rb +0 -1104
- data/test/stamina/exit.rb +0 -3
- data/test/stamina/induction/blue_fringe_test.rb +0 -83
- data/test/stamina/induction/induction_test.rb +0 -70
- data/test/stamina/induction/redblue_mergesamestatebug_expected.adl +0 -19
- data/test/stamina/induction/redblue_mergesamestatebug_pta.dot +0 -64
- data/test/stamina/induction/redblue_mergesamestatebug_sample.adl +0 -9
- data/test/stamina/induction/redblue_universal_expected.adl +0 -4
- data/test/stamina/induction/redblue_universal_sample.adl +0 -5
- data/test/stamina/induction/rpni_inria_expected.adl +0 -7
- data/test/stamina/induction/rpni_inria_sample.adl +0 -9
- data/test/stamina/induction/rpni_test.rb +0 -129
- data/test/stamina/induction/rpni_test_pta.dot +0 -22
- data/test/stamina/induction/rpni_universal_expected.adl +0 -4
- data/test/stamina/induction/rpni_universal_sample.adl +0 -4
- data/test/stamina/induction/union_find_test.rb +0 -124
- data/test/stamina/input_string_test.rb +0 -323
- data/test/stamina/markable_test.rb +0 -70
- data/test/stamina/randdfa.adl +0 -66
- data/test/stamina/sample.adl +0 -4
- data/test/stamina/sample_classify_test.rb +0 -149
- data/test/stamina/sample_test.rb +0 -290
- data/test/stamina/scoring_test.rb +0 -63
- data/test/stamina/small_dfa.dot +0 -16
- data/test/stamina/small_dfa.gif +0 -0
- data/test/stamina/small_nfa.dot +0 -18
- data/test/stamina/small_nfa.gif +0 -0
- data/test/stamina/stamina_test.rb +0 -80
- data/test/stamina/utils/decorate_test.rb +0 -65
- 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
|
data/test/stamina/small_dfa.dot
DELETED
@@ -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
|
-
}
|
data/test/stamina/small_dfa.gif
DELETED
Binary file
|
data/test/stamina/small_nfa.dot
DELETED
@@ -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
|
-
}
|
data/test/stamina/small_nfa.gif
DELETED
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