measurable 0.0.5 → 0.0.11

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.
@@ -0,0 +1,46 @@
1
+ describe "Kullback-Leibler" do
2
+ before :all do
3
+ @p = [0.10, 0.15, 0.35, 0.25, 0.15]
4
+ @q = [0.09, 0.13, 0.39, 0.22, 0.17]
5
+ @uniform = [0.20, 0.20, 0.20, 0.20, 0.20]
6
+ end
7
+
8
+ context "Divergence" do
9
+ it "accepts two arguments" do
10
+ expect { Measurable.kullback_leibler(@p, @q) }.to_not raise_error
11
+ expect { Measurable.kullback_leibler(@p, @q, []) }.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it "shouldn't work with vectors of different length" do
15
+ expect { Measurable.kullback_leibler(@p, [0.50, 0.50]) }.to raise_error(ArgumentError)
16
+ end
17
+
18
+ it "shouldn't be symmetric" do
19
+ Measurable.kullback_leibler(@p, @q).should_not == Measurable.kullback_leibler(@q, @p)
20
+ end
21
+
22
+ it "should increase with dissimilarity" do
23
+ Measurable.kullback_leibler(@p, @uniform).should > Measurable.kullback_leibler(@p, @q)
24
+ end
25
+
26
+ it "should return the correct value" do
27
+ Measurable.kullback_leibler(@p, @uniform).should be_within(TOLERANCE).of 0.0960320738
28
+ end
29
+
30
+ it "can be extended separately" do
31
+ klass = Class.new do
32
+ extend Measurable::KullbackLeibler
33
+ end
34
+
35
+ klass.kullback_leibler(@p, @q).should be_within(TOLERANCE).of 0.007310294
36
+ end
37
+
38
+ it "can be included separately" do
39
+ klass = Class.new do
40
+ include Measurable::KullbackLeibler
41
+ end
42
+
43
+ klass.new.kullback_leibler(@p, @q).should be_within(TOLERANCE).of 0.007310294
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,71 @@
1
+ describe Measurable::Levenshtein do
2
+
3
+ it "can be extended seperately" do
4
+ klass = Class.new do
5
+ extend Measurable::Levenshtein
6
+ end
7
+
8
+ klass.levenshtein("ab", "abc").should == 1
9
+ end
10
+
11
+ it "can be included seperately" do
12
+ klass = Class.new do
13
+ include Measurable::Levenshtein
14
+ end
15
+
16
+ klass.new.levenshtein("ab", "abc").should == 1
17
+ end
18
+
19
+ context "strings" do
20
+
21
+ it "handles empty" do
22
+ Measurable.levenshtein("", "").should == 0
23
+ Measurable.levenshtein("", "abcd").should == 4
24
+ Measurable.levenshtein("abcd", "").should == 4
25
+ end
26
+
27
+ it "should not count equality" do
28
+ Measurable.levenshtein("aa", "aa").should == 0
29
+ end
30
+
31
+ it "should count deletion" do
32
+ Measurable.levenshtein("ab", "a").should == 1
33
+ end
34
+
35
+ it "should count insertion" do
36
+ Measurable.levenshtein("ab", "abc").should == 1
37
+ end
38
+
39
+ it "should count substitution" do
40
+ Measurable.levenshtein("aa", "ab").should == 1
41
+ end
42
+
43
+ end
44
+
45
+ context "arrays" do
46
+
47
+ it "handles empty" do
48
+ Measurable.levenshtein([], []).should == 0
49
+ Measurable.levenshtein([], %w[ a b c d ]).should == 4
50
+ Measurable.levenshtein(%w[ a b c d ], []).should == 4
51
+ end
52
+
53
+ it "should not count equality" do
54
+ Measurable.levenshtein(%w[ a ], %w[ a ]).should == 0
55
+ end
56
+
57
+ it "should count deletion" do
58
+ Measurable.levenshtein(%w[ a b ], %w[ a ]).should == 1
59
+ end
60
+
61
+ it "should count insertion" do
62
+ Measurable.levenshtein(%w[ a b ], %w[ a b c ]).should == 1
63
+ end
64
+
65
+ it "should count substitution" do
66
+ Measurable.levenshtein(%w[ a a ], %w[ a b ]).should == 1
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -25,6 +25,25 @@ describe "Max-min distance" do
25
25
  end
26
26
 
27
27
  it "shouldn't work with vectors of different length" do
28
- expect { Measurable.maxmin(@u, [1, 3, 5, 7]) }.to raise_error
28
+ expect { Measurable.maxmin(@u, [1, 3, 5, 7]) }.to raise_error(ArgumentError)
29
29
  end
30
- end
30
+
31
+ it "can be extended separately" do
32
+ klass = Class.new do
33
+ extend Measurable::Maxmin
34
+ end
35
+ x = klass.maxmin(@u, @v)
36
+
37
+ x.should be_within(TOLERANCE).of(0.9523809523)
38
+ end
39
+
40
+ it "can be included separately" do
41
+ klass = Class.new do
42
+ include Measurable::Maxmin
43
+ end
44
+ x = klass.new.maxmin(@u, @v)
45
+
46
+ x.should be_within(TOLERANCE).of(0.9523809523)
47
+ end
48
+
49
+ end
@@ -0,0 +1,44 @@
1
+ describe "Minkowski" do
2
+
3
+ before :all do
4
+ @u = [1, 3, 6]
5
+ @v = [1, 4, 7]
6
+ @w = [4, 5, 6]
7
+ end
8
+
9
+ context "Distance" do
10
+ it "accepts two arguments" do
11
+ expect { Measurable.minkowski(@u, @v) }.to_not raise_error
12
+ expect { Measurable.minkowski(@u, @v, @w) }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it "should be symmetric" do
16
+ Measurable.minkowski(@u, @v).should == Measurable.minkowski(@v, @u)
17
+ end
18
+
19
+ it "should return the correct value" do
20
+ Measurable.minkowski(@u, @u).should == 0
21
+ Measurable.minkowski(@u, @v).should == 2
22
+ end
23
+
24
+ it "shouldn't work with vectors of different length" do
25
+ expect { Measurable.minkowski(@u, [2, 2, 2, 2]) }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "can be extended separately" do
29
+ klass = Class.new do
30
+ extend Measurable::Minkowski
31
+ end
32
+
33
+ klass.minkowski(@u, @u).should == 0
34
+ end
35
+
36
+ it "can be included separately" do
37
+ klass = Class.new do
38
+ include Measurable::Minkowski
39
+ end
40
+
41
+ klass.new.minkowski(@u, @u).should == 0
42
+ end
43
+ end
44
+ end
@@ -3,4 +3,4 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
4
  require 'measurable'
5
5
 
6
- TOLERANCE = 10e-9
6
+ TOLERANCE = 10e-9
@@ -21,10 +21,30 @@ describe "Tanimoto distance" do
21
21
  it "should return the correct value" do
22
22
  x = Measurable.tanimoto(@u, @v)
23
23
 
24
- x.should be_within(TOLERANCE).of(-Math.log2(2.0 / 3.0))
24
+ x.should be_within(TOLERANCE).of(-Math.log2(1.0 / 2.0))
25
25
  end
26
26
 
27
27
  it "shouldn't work with vectors of different length" do
28
- expect { Measurable.tanimoto(@u, [1, 3, 5, 7]) }.to raise_error
28
+ expect { Measurable.tanimoto(@u, [1, 3, 5, 7]) }.to raise_error(ArgumentError)
29
29
  end
30
- end
30
+
31
+ it "can be extended separately" do
32
+ klass = Class.new do
33
+ extend Measurable::Tanimoto
34
+ end
35
+
36
+ x = klass.tanimoto(@u, @v)
37
+
38
+ x.should be_within(TOLERANCE).of(-Math.log2(1.0 / 2.0))
39
+ end
40
+
41
+ it "can be included separately" do
42
+ klass = Class.new do
43
+ include Measurable::Tanimoto
44
+ end
45
+
46
+ x = klass.new.tanimoto(@u, @v)
47
+
48
+ x.should be_within(TOLERANCE).of(-Math.log2(1.0 / 2.0))
49
+ end
50
+ end
metadata CHANGED
@@ -1,114 +1,144 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measurable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Agarie
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-24 00:00:00.000000000 Z
11
+ date: 2020-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0.9'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0.9'
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 6.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 6.0.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 2.9.0
61
+ version: '3.2'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 2.9.0
68
+ version: '3.2'
55
69
  description: A Ruby gem with a lot of distance measures for your projects.
56
70
  email: carlos.agarie@gmail.com
57
71
  executables: []
58
72
  extensions: []
59
73
  extra_rdoc_files: []
60
74
  files:
61
- - .gitignore
62
- - .rspec
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".travis.yml"
63
78
  - Gemfile
64
- - Gemfile.lock
79
+ - History.txt
65
80
  - LICENSE
66
81
  - README.md
67
82
  - Rakefile
68
83
  - lib/measurable.rb
84
+ - lib/measurable/chebyshev.rb
69
85
  - lib/measurable/cosine.rb
70
86
  - lib/measurable/euclidean.rb
87
+ - lib/measurable/hamming.rb
71
88
  - lib/measurable/haversine.rb
72
89
  - lib/measurable/jaccard.rb
90
+ - lib/measurable/kullback_leibler.rb
91
+ - lib/measurable/levenshtein.rb
73
92
  - lib/measurable/maxmin.rb
93
+ - lib/measurable/minkowski.rb
74
94
  - lib/measurable/tanimoto.rb
75
95
  - lib/measurable/version.rb
76
96
  - measurable.gemspec
97
+ - spec/chebyshev_spec.rb
77
98
  - spec/cosine_spec.rb
78
99
  - spec/euclidean_spec.rb
100
+ - spec/hamming_spec.rb
79
101
  - spec/haversine_spec.rb
80
102
  - spec/jaccard_spec.rb
103
+ - spec/kullback_leibler_spec.rb
104
+ - spec/levenshtein_spec.rb
81
105
  - spec/maxmin_spec.rb
106
+ - spec/minkowski_spec.rb
82
107
  - spec/spec_helper.rb
83
108
  - spec/tanimoto_spec.rb
84
109
  homepage: http://github.com/agarie/measurable
85
- licenses: []
110
+ licenses:
111
+ - MIT
86
112
  metadata: {}
87
- post_install_message:
113
+ post_install_message:
88
114
  rdoc_options: []
89
115
  require_paths:
90
116
  - lib
91
117
  required_ruby_version: !ruby/object:Gem::Requirement
92
118
  requirements:
93
- - - '>='
119
+ - - ">="
94
120
  - !ruby/object:Gem::Version
95
121
  version: 1.9.3
96
122
  required_rubygems_version: !ruby/object:Gem::Requirement
97
123
  requirements:
98
- - - '>='
124
+ - - ">="
99
125
  - !ruby/object:Gem::Version
100
126
  version: '0'
101
127
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.0.3
104
- signing_key:
128
+ rubygems_version: 3.1.2
129
+ signing_key:
105
130
  specification_version: 4
106
131
  summary: A Ruby gem with a lot of distance measures for your projects.
107
132
  test_files:
133
+ - spec/chebyshev_spec.rb
108
134
  - spec/cosine_spec.rb
109
135
  - spec/euclidean_spec.rb
136
+ - spec/hamming_spec.rb
110
137
  - spec/haversine_spec.rb
111
138
  - spec/jaccard_spec.rb
139
+ - spec/kullback_leibler_spec.rb
140
+ - spec/levenshtein_spec.rb
112
141
  - spec/maxmin_spec.rb
142
+ - spec/minkowski_spec.rb
113
143
  - spec/spec_helper.rb
114
144
  - spec/tanimoto_spec.rb
@@ -1,27 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- measurable (0.0.5)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- diff-lcs (1.1.3)
10
- rake (0.9.2.2)
11
- rspec (2.9.0)
12
- rspec-core (~> 2.9.0)
13
- rspec-expectations (~> 2.9.0)
14
- rspec-mocks (~> 2.9.0)
15
- rspec-core (2.9.0)
16
- rspec-expectations (2.9.1)
17
- diff-lcs (~> 1.1.3)
18
- rspec-mocks (2.9.0)
19
-
20
- PLATFORMS
21
- ruby
22
-
23
- DEPENDENCIES
24
- bundler
25
- measurable!
26
- rake (~> 0.9)
27
- rspec (~> 2.9.0)