morphological_metrics 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.autotest +30 -30
- data/.minitest.rb +3 -3
- data/.travis.yml +10 -10
- data/Gemfile +0 -0
- data/Gemfile.lock +0 -0
- data/History.txt +6 -6
- data/Manifest.txt +27 -27
- data/README.rdoc +66 -65
- data/ROADMAP.txt +63 -63
- data/Rakefile +33 -32
- data/bin/mm +3 -3
- data/lib/mm.rb +10 -10
- data/lib/mm/deltas.rb +34 -35
- data/lib/mm/metric.rb +191 -180
- data/lib/mm/pairs.rb +12 -12
- data/lib/mm/ratio.rb +156 -145
- data/lib/mm/scaling.rb +30 -30
- data/lib/mm/search.rb +81 -81
- data/lib/shortcuts.yml +49 -49
- data/test/helpers.rb +22 -19
- data/test/mm/test_metric.rb +168 -160
- data/test/mm/test_mm.rb +6 -5
- data/test/mm/test_pairs.rb +27 -24
- data/test/mm/test_ratio.rb +139 -130
- data/test/mm/test_search.rb +89 -83
- metadata +8 -16
- data/.gemtest +0 -0
data/lib/shortcuts.yml
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
:olm:
|
2
|
-
:ordered: true
|
3
|
-
:pair: :linear
|
4
|
-
:scale: :none
|
5
|
-
:intra_delta: :abs
|
6
|
-
:inter_delta: :abs
|
7
|
-
:ocm:
|
8
|
-
:ordered: true
|
9
|
-
:pair: :combinatorial
|
10
|
-
:scale: :none
|
11
|
-
:intra_delta: :abs
|
12
|
-
:inter_delta: :abs
|
13
|
-
:ulm:
|
14
|
-
:ordered: false
|
15
|
-
:pair: :linear
|
16
|
-
:scale: :none
|
17
|
-
:intra_delta: :abs
|
18
|
-
:inter_delta: :mean
|
19
|
-
:ucm:
|
20
|
-
:ordered: false
|
21
|
-
:pair: :combinatorial
|
22
|
-
:scale: :none
|
23
|
-
:intra_delta: :abs
|
24
|
-
:inter_delta: :mean
|
25
|
-
:old:
|
26
|
-
:ordered: true
|
27
|
-
:pair: :linear
|
28
|
-
:scale: :none
|
29
|
-
:intra_delta: :direction
|
30
|
-
:inter_delta: :abs
|
31
|
-
:ocd:
|
32
|
-
:ordered: true
|
33
|
-
:pair: :combinatorial
|
34
|
-
:scale: :none
|
35
|
-
:intra_delta: :direction
|
36
|
-
:inter_delta: :abs
|
37
|
-
:uld:
|
38
|
-
:ordered: false
|
39
|
-
:pair: :linear
|
40
|
-
:scale: :none
|
41
|
-
:intra_delta: :direction
|
42
|
-
:inter_delta: :mean
|
43
|
-
:ucd:
|
44
|
-
:ordered: false
|
45
|
-
:pair: :combinatorial
|
46
|
-
:scale: :none
|
47
|
-
:intra_delta: :direction
|
48
|
-
:inter_delta: :mean
|
49
|
-
|
1
|
+
:olm:
|
2
|
+
:ordered: true
|
3
|
+
:pair: :linear
|
4
|
+
:scale: :none
|
5
|
+
:intra_delta: :abs
|
6
|
+
:inter_delta: :abs
|
7
|
+
:ocm:
|
8
|
+
:ordered: true
|
9
|
+
:pair: :combinatorial
|
10
|
+
:scale: :none
|
11
|
+
:intra_delta: :abs
|
12
|
+
:inter_delta: :abs
|
13
|
+
:ulm:
|
14
|
+
:ordered: false
|
15
|
+
:pair: :linear
|
16
|
+
:scale: :none
|
17
|
+
:intra_delta: :abs
|
18
|
+
:inter_delta: :mean
|
19
|
+
:ucm:
|
20
|
+
:ordered: false
|
21
|
+
:pair: :combinatorial
|
22
|
+
:scale: :none
|
23
|
+
:intra_delta: :abs
|
24
|
+
:inter_delta: :mean
|
25
|
+
:old:
|
26
|
+
:ordered: true
|
27
|
+
:pair: :linear
|
28
|
+
:scale: :none
|
29
|
+
:intra_delta: :direction
|
30
|
+
:inter_delta: :abs
|
31
|
+
:ocd:
|
32
|
+
:ordered: true
|
33
|
+
:pair: :combinatorial
|
34
|
+
:scale: :none
|
35
|
+
:intra_delta: :direction
|
36
|
+
:inter_delta: :abs
|
37
|
+
:uld:
|
38
|
+
:ordered: false
|
39
|
+
:pair: :linear
|
40
|
+
:scale: :none
|
41
|
+
:intra_delta: :direction
|
42
|
+
:inter_delta: :mean
|
43
|
+
:ucd:
|
44
|
+
:ordered: false
|
45
|
+
:pair: :combinatorial
|
46
|
+
:scale: :none
|
47
|
+
:intra_delta: :direction
|
48
|
+
:inter_delta: :mean
|
49
|
+
|
data/test/helpers.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
-
module TestHelpers
|
2
|
-
# Asserts that each item in exp matches each item in act
|
3
|
-
def assert_nested_in_delta exp, act, delta = 0.001, msg = nil
|
4
|
-
exp.zip(act) do |x|
|
5
|
-
if block_given?
|
6
|
-
yield x, delta, msg
|
7
|
-
else
|
8
|
-
assert_in_delta(*x, delta, msg)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# Asserts that nested values 2-deep are within a certain delta
|
14
|
-
def assert_nested_in_delta_2_deep *args
|
15
|
-
assert_nested_in_delta(*args) do |x, delta, msg|
|
16
|
-
x[0].zip(x[1]) do |y|
|
17
|
-
assert_in_delta(*y, delta, msg)
|
18
|
-
end
|
19
|
-
|
1
|
+
module TestHelpers
|
2
|
+
# Asserts that each item in exp matches each item in act
|
3
|
+
def assert_nested_in_delta exp, act, delta = 0.001, msg = nil
|
4
|
+
exp.zip(act) do |x|
|
5
|
+
if block_given?
|
6
|
+
yield x, delta, msg
|
7
|
+
else
|
8
|
+
assert_in_delta(*x, delta, msg)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Asserts that nested values 2-deep are within a certain delta
|
14
|
+
def assert_nested_in_delta_2_deep *args
|
15
|
+
assert_nested_in_delta(*args) do |x, delta, msg|
|
16
|
+
x[0].zip(x[1]) do |y|
|
17
|
+
assert_in_delta(*y, delta, msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/test/mm/test_metric.rb
CHANGED
@@ -1,160 +1,168 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
|
3
|
-
require 'mm/metric'
|
4
|
-
|
5
|
-
class TestMM < Minitest::Test; end
|
6
|
-
|
7
|
-
class TestMM::TestMetric < Minitest::Test
|
8
|
-
def setup
|
9
|
-
@ordered ||= true
|
10
|
-
@pair ||= :linear
|
11
|
-
@scale ||= :none
|
12
|
-
@intra_delta ||= :abs
|
13
|
-
@inter_delta ||= :abs
|
14
|
-
@metric = MM::Metric.new(ordered: @ordered, pair: @pair, scale: @scale, intra_delta: @intra_delta, inter_delta: @inter_delta)
|
15
|
-
|
16
|
-
# Setting up the sample vectors for many of the examples
|
17
|
-
@v1 = [1, 6, 2, 5, 11]
|
18
|
-
@v2 = [3, 15, 13, 2, 9]
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_creates_new_metric
|
22
|
-
assert @metric.is_a? MM::Metric
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_metric_responds_to_call
|
26
|
-
assert_respond_to @metric, :call
|
27
|
-
end
|
28
|
-
|
29
|
-
class TestGetPairs < self
|
30
|
-
class TestLinearPairs < self
|
31
|
-
def test_gets_linear_pairs
|
32
|
-
exp = [
|
33
|
-
[[1, 6], [6, 2], [2, 5], [5, 11]],
|
34
|
-
[[3, 15], [15, 13], [13, 2], [2, 9]]
|
35
|
-
]
|
36
|
-
assert_equal exp, @metric.send(:get_pairs, @v1, @v2)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class TestCombinatorialPairs < self
|
41
|
-
def setup
|
42
|
-
@pair = :combinatorial
|
43
|
-
super
|
44
|
-
end
|
45
|
-
def test_gets_combinatorial_pairs
|
46
|
-
exp = [
|
47
|
-
[[1, 6], [1, 2], [1, 5], [1, 11], [6, 2], [6, 5],
|
48
|
-
[6, 11], [2, 5], [2, 11], [5, 11]],
|
49
|
-
[[3, 15], [3, 13], [3, 2], [3, 9], [15, 13], [15, 2],
|
50
|
-
[15, 9], [13, 2], [13, 9], [2, 9]]
|
51
|
-
]
|
52
|
-
assert_equal exp, @metric.send(:get_pairs, @v1, @v2)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class TestDeltas < self
|
58
|
-
class TestIntraDelta < self
|
59
|
-
def test_gets_intra_delta
|
60
|
-
pairs = [
|
61
|
-
[[1, 6], [6, 2], [2, 5], [5, 11]],
|
62
|
-
[[3, 15], [15, 13], [13, 2], [2, 9]]
|
63
|
-
]
|
64
|
-
exp = [
|
65
|
-
[5, 4, 3, 6],
|
66
|
-
[12, 2, 11, 7]
|
67
|
-
]
|
68
|
-
assert_equal exp, @metric.send(:intra_delta, pairs)
|
69
|
-
end
|
70
|
-
def test_intra_delta_proc
|
71
|
-
@metric.intra_delta = ->(*vp) {nil}
|
72
|
-
assert_instance_of Proc, @metric.instance_variable_get(:@intra_delta)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class TestInterDelta < self
|
77
|
-
def setup
|
78
|
-
super
|
79
|
-
@diffs = [
|
80
|
-
[5, 4, 3, 6],
|
81
|
-
[12, 2, 11, 7]
|
82
|
-
]
|
83
|
-
end
|
84
|
-
def test_gets_inter_delta_ordered
|
85
|
-
exp = 4.5
|
86
|
-
assert_equal exp, @metric.send(:inter_delta, @diffs)
|
87
|
-
end
|
88
|
-
def test_inter_delta_proc
|
89
|
-
@metric.inter_delta = ->(*diffs) {nil}
|
90
|
-
assert_instance_of Proc, @metric.instance_variable_get(:@inter_delta)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class TestScaling < self
|
96
|
-
def setup
|
97
|
-
super
|
98
|
-
@unscaled = [
|
99
|
-
[5, 4, 3, 6],
|
100
|
-
[12, 2, 11, 7]
|
101
|
-
]
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_assigns_scaling_proc
|
105
|
-
@metric.scale = ->(pairs) {}
|
106
|
-
scale = @metric.instance_variable_get :@scale
|
107
|
-
assert_equal Proc, scale.class
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_no_scaling
|
111
|
-
assert_equal @unscaled, @metric.send(:scale, @unscaled)
|
112
|
-
end
|
113
|
-
|
114
|
-
# TODO: This is a complicated test and I don't like it
|
115
|
-
def test_absolute_scaling
|
116
|
-
@metric.scale = :absolute
|
117
|
-
@exp = [
|
118
|
-
[0.417, 0.333, 0.25, 0.5],
|
119
|
-
[1.0, 0.167, 0.917, 0.583]
|
120
|
-
]
|
121
|
-
actual = @metric.send :scale, @unscaled
|
122
|
-
actual.each_with_index do |v, i|
|
123
|
-
v.each_with_index do |w, j|
|
124
|
-
assert_in_delta @exp[i][j], w, 0.001
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_relative_scaling
|
130
|
-
@metric.scale = :relative
|
131
|
-
@exp = [
|
132
|
-
[0.833, 0.667, 0.5, 1.0],
|
133
|
-
[1.0, 0.167, 0.917, 0.583]
|
134
|
-
]
|
135
|
-
actual = @metric.send :scale, @unscaled
|
136
|
-
actual.each_with_index do |v, i|
|
137
|
-
v.each_with_index do |w, j|
|
138
|
-
assert_in_delta @exp[i][j], w, 0.001
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
class TestMagnitudeMetric < self
|
145
|
-
# Definitions of expected results
|
146
|
-
@exp = {
|
147
|
-
:olm => {:scale_none => 4.5, :scale_absolute => 0.375},
|
148
|
-
:ocm => {:scale_none => 5.2, :scale_absolute => 0.4},
|
149
|
-
:ulm => {:scale_none => 3.5, :scale_absolute => 0.29167},
|
150
|
-
:ucm => {:scale_none => 2.4, :scale_absolute => 0.1846},
|
151
|
-
:old => {:scale_none => 0.25},
|
152
|
-
:ocd => {:scale_none => 0.4},
|
153
|
-
:uld => {:scale_none => 0.25},
|
154
|
-
:ucd => {:scale_none => 0.4}
|
155
|
-
}
|
156
|
-
|
157
|
-
@exp.each do |metric, expected|
|
158
|
-
expected.each do |scaling, e|
|
159
|
-
define_method "test_#{metric}_#{scaling}" do
|
160
|
-
m = ::MM::Metric.
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require 'mm/metric'
|
4
|
+
|
5
|
+
class TestMM < Minitest::Test; end
|
6
|
+
|
7
|
+
class TestMM::TestMetric < Minitest::Test
|
8
|
+
def setup
|
9
|
+
@ordered ||= true
|
10
|
+
@pair ||= :linear
|
11
|
+
@scale ||= :none
|
12
|
+
@intra_delta ||= :abs
|
13
|
+
@inter_delta ||= :abs
|
14
|
+
@metric = MM::Metric.new(ordered: @ordered, pair: @pair, scale: @scale, intra_delta: @intra_delta, inter_delta: @inter_delta)
|
15
|
+
|
16
|
+
# Setting up the sample vectors for many of the examples
|
17
|
+
@v1 = [1, 6, 2, 5, 11]
|
18
|
+
@v2 = [3, 15, 13, 2, 9]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_creates_new_metric
|
22
|
+
assert @metric.is_a? MM::Metric
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_metric_responds_to_call
|
26
|
+
assert_respond_to @metric, :call
|
27
|
+
end
|
28
|
+
|
29
|
+
class TestGetPairs < self
|
30
|
+
class TestLinearPairs < self
|
31
|
+
def test_gets_linear_pairs
|
32
|
+
exp = [
|
33
|
+
[[1, 6], [6, 2], [2, 5], [5, 11]],
|
34
|
+
[[3, 15], [15, 13], [13, 2], [2, 9]]
|
35
|
+
]
|
36
|
+
assert_equal exp, @metric.send(:get_pairs, @v1, @v2)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class TestCombinatorialPairs < self
|
41
|
+
def setup
|
42
|
+
@pair = :combinatorial
|
43
|
+
super
|
44
|
+
end
|
45
|
+
def test_gets_combinatorial_pairs
|
46
|
+
exp = [
|
47
|
+
[[1, 6], [1, 2], [1, 5], [1, 11], [6, 2], [6, 5],
|
48
|
+
[6, 11], [2, 5], [2, 11], [5, 11]],
|
49
|
+
[[3, 15], [3, 13], [3, 2], [3, 9], [15, 13], [15, 2],
|
50
|
+
[15, 9], [13, 2], [13, 9], [2, 9]]
|
51
|
+
]
|
52
|
+
assert_equal exp, @metric.send(:get_pairs, @v1, @v2)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class TestDeltas < self
|
58
|
+
class TestIntraDelta < self
|
59
|
+
def test_gets_intra_delta
|
60
|
+
pairs = [
|
61
|
+
[[1, 6], [6, 2], [2, 5], [5, 11]],
|
62
|
+
[[3, 15], [15, 13], [13, 2], [2, 9]]
|
63
|
+
]
|
64
|
+
exp = [
|
65
|
+
[5, 4, 3, 6],
|
66
|
+
[12, 2, 11, 7]
|
67
|
+
]
|
68
|
+
assert_equal exp, @metric.send(:intra_delta, pairs)
|
69
|
+
end
|
70
|
+
def test_intra_delta_proc
|
71
|
+
@metric.intra_delta = ->(*vp) {nil}
|
72
|
+
assert_instance_of Proc, @metric.instance_variable_get(:@intra_delta)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class TestInterDelta < self
|
77
|
+
def setup
|
78
|
+
super
|
79
|
+
@diffs = [
|
80
|
+
[5, 4, 3, 6],
|
81
|
+
[12, 2, 11, 7]
|
82
|
+
]
|
83
|
+
end
|
84
|
+
def test_gets_inter_delta_ordered
|
85
|
+
exp = 4.5
|
86
|
+
assert_equal exp, @metric.send(:inter_delta, @diffs)
|
87
|
+
end
|
88
|
+
def test_inter_delta_proc
|
89
|
+
@metric.inter_delta = ->(*diffs) {nil}
|
90
|
+
assert_instance_of Proc, @metric.instance_variable_get(:@inter_delta)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class TestScaling < self
|
96
|
+
def setup
|
97
|
+
super
|
98
|
+
@unscaled = [
|
99
|
+
[5, 4, 3, 6],
|
100
|
+
[12, 2, 11, 7]
|
101
|
+
]
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_assigns_scaling_proc
|
105
|
+
@metric.scale = ->(pairs) {}
|
106
|
+
scale = @metric.instance_variable_get :@scale
|
107
|
+
assert_equal Proc, scale.class
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_no_scaling
|
111
|
+
assert_equal @unscaled, @metric.send(:scale, @unscaled)
|
112
|
+
end
|
113
|
+
|
114
|
+
# TODO: This is a complicated test and I don't like it
|
115
|
+
def test_absolute_scaling
|
116
|
+
@metric.scale = :absolute
|
117
|
+
@exp = [
|
118
|
+
[0.417, 0.333, 0.25, 0.5],
|
119
|
+
[1.0, 0.167, 0.917, 0.583]
|
120
|
+
]
|
121
|
+
actual = @metric.send :scale, @unscaled
|
122
|
+
actual.each_with_index do |v, i|
|
123
|
+
v.each_with_index do |w, j|
|
124
|
+
assert_in_delta @exp[i][j], w, 0.001
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_relative_scaling
|
130
|
+
@metric.scale = :relative
|
131
|
+
@exp = [
|
132
|
+
[0.833, 0.667, 0.5, 1.0],
|
133
|
+
[1.0, 0.167, 0.917, 0.583]
|
134
|
+
]
|
135
|
+
actual = @metric.send :scale, @unscaled
|
136
|
+
actual.each_with_index do |v, i|
|
137
|
+
v.each_with_index do |w, j|
|
138
|
+
assert_in_delta @exp[i][j], w, 0.001
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
class TestMagnitudeMetric < self
|
145
|
+
# Definitions of expected results
|
146
|
+
@exp = {
|
147
|
+
:olm => {:scale_none => 4.5, :scale_absolute => 0.375},
|
148
|
+
:ocm => {:scale_none => 5.2, :scale_absolute => 0.4},
|
149
|
+
:ulm => {:scale_none => 3.5, :scale_absolute => 0.29167},
|
150
|
+
:ucm => {:scale_none => 2.4, :scale_absolute => 0.1846},
|
151
|
+
:old => {:scale_none => 0.25},
|
152
|
+
:ocd => {:scale_none => 0.4},
|
153
|
+
:uld => {:scale_none => 0.25},
|
154
|
+
:ucd => {:scale_none => 0.4}
|
155
|
+
}
|
156
|
+
|
157
|
+
@exp.each do |metric, expected|
|
158
|
+
expected.each do |scaling, e|
|
159
|
+
define_method "test_#{metric}_#{scaling}" do
|
160
|
+
m = ::MM::Metric.send(metric)
|
161
|
+
m.scale = /_(.*)$/.match(scaling)[1].to_sym
|
162
|
+
assert_in_delta e, m.call(@v1, @v2), 0.001
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|