measurable 0.0.9 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -5
- data/History.txt +5 -0
- data/README.md +1 -1
- data/lib/measurable/jaccard.rb +10 -6
- data/lib/measurable/version.rb +1 -1
- data/measurable.gemspec +2 -2
- data/spec/chebyshev_spec.rb +4 -4
- data/spec/jaccard_spec.rb +15 -15
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ea2c713d50fac6bd342f46e18eb9ed8267ff65cfdbf6f1ee75c70bcc92d5b1c
|
4
|
+
data.tar.gz: fa3c04483562118a4d875edce0d8afbcac5cf3ee5fa29e8b5b8d04b374058b73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46aa4474a64b5b9e7e5c3ee53adf7804d618941528d0722e0bdff82e5010dc9f978d553ea5c7779d7917f26a9bc0e0f4c993bd74653d7f81b698abc9aabbcf9d
|
7
|
+
data.tar.gz: 9eaf669fef73e90a7dc4196939634f42c54f21471301c4913b9b46155feaf59a0755f88bf325a373d1242653fbe19e7f6d06fb4405e411a5e1aeef596a0b8713
|
data/.travis.yml
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
0.0.11 -- 22th June, 2020
|
2
|
+
* Updated rake & rdoc
|
3
|
+
* Updated Travis CI config
|
4
|
+
* ... honestly, just getting back to this repository
|
5
|
+
|
1
6
|
0.0.9 -- 16th April, 2015
|
2
7
|
* Removed unnecessary argument length check from jaccard_index.
|
3
8
|
* Host documentation on rubydoc.info.
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ NMatrix. Thank you, [@reddavis][reddavis]. :)
|
|
15
15
|
|
16
16
|
`gem install measurable`
|
17
17
|
|
18
|
-
|
18
|
+
I test this gem (via Travis CI) on Ruby MRI 2.5, 2.6 and 2.7.
|
19
19
|
|
20
20
|
## Available distance measures
|
21
21
|
|
data/lib/measurable/jaccard.rb
CHANGED
@@ -29,18 +29,20 @@ module Measurable
|
|
29
29
|
intersection.length.to_f / union.length
|
30
30
|
end
|
31
31
|
|
32
|
+
alias_method :jaccard, :jaccard_index
|
33
|
+
|
32
34
|
# call-seq:
|
33
|
-
#
|
35
|
+
# jaccard_dissimilarity(u, v) -> Float
|
34
36
|
#
|
35
37
|
# The jaccard distance is a measure of dissimilarity between two sets. It is
|
36
38
|
# calculated as:
|
37
39
|
# jaccard_distance = 1 - jaccard_index
|
38
40
|
#
|
39
41
|
# This is a proper metric, i.e. the following conditions hold:
|
40
|
-
# - Symmetry:
|
41
|
-
# - Non-negative:
|
42
|
-
# - Coincidence axiom:
|
43
|
-
# - Triangular inequality:
|
42
|
+
# - Symmetry: jaccard_dissimilarity(u, v) == jaccard(v, u)
|
43
|
+
# - Non-negative: jaccard_dissimilarity(u, v) >= 0
|
44
|
+
# - Coincidence axiom: jaccard_dissimilarity(u, v) == 0 if u == v
|
45
|
+
# - Triangular inequality: jaccard_dissimilarity(u, v) <= jaccard(u, w) + jaccard(w, v)
|
44
46
|
#
|
45
47
|
# Arguments:
|
46
48
|
# - +u+ -> Array.
|
@@ -49,10 +51,12 @@ module Measurable
|
|
49
51
|
# - Float value representing the dissimilarity between +u+ and +v+.
|
50
52
|
# Raises:
|
51
53
|
# - +ArgumentError+ -> The size of the input arrays doesn't match.
|
52
|
-
def
|
54
|
+
def jaccard_dissimilarity(u, v)
|
53
55
|
1 - jaccard_index(u, v)
|
54
56
|
end
|
55
57
|
|
58
|
+
alias_method :jaccard_distance, :jaccard_dissimilarity
|
59
|
+
|
56
60
|
extend Measurable::Jaccard
|
57
61
|
end
|
58
62
|
end
|
data/lib/measurable/version.rb
CHANGED
data/measurable.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.required_ruby_version = '>= 1.9.3'
|
25
25
|
|
26
26
|
gem.add_development_dependency 'bundler'
|
27
|
-
gem.add_development_dependency 'rake', '
|
28
|
-
gem.add_development_dependency 'rdoc', '
|
27
|
+
gem.add_development_dependency 'rake', '>= 12.3.3'
|
28
|
+
gem.add_development_dependency 'rdoc', '>= 6.0.0'
|
29
29
|
gem.add_development_dependency 'rspec', '~> 3.2'
|
30
30
|
end
|
data/spec/chebyshev_spec.rb
CHANGED
@@ -15,12 +15,12 @@ describe "Chebyshev distance" do
|
|
15
15
|
x = Measurable.chebyshev(@u, @v)
|
16
16
|
y = Measurable.chebyshev(@v, @u)
|
17
17
|
|
18
|
-
x.
|
18
|
+
expect(x).to be_within(TOLERANCE).of(y)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return the correct value" do
|
22
22
|
x = Measurable.chebyshev(@u, @v)
|
23
|
-
x.
|
23
|
+
expect(x).to be_within(TOLERANCE).of(3.1)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "shouldn't work with vectors of different length" do
|
@@ -33,7 +33,7 @@ describe "Chebyshev distance" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
x = klass.chebyshev(@u, @v)
|
36
|
-
x.
|
36
|
+
expect(x).to be_within(TOLERANCE).of(3.1)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "can be included separately" do
|
@@ -42,7 +42,7 @@ describe "Chebyshev distance" do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
x = klass.new.chebyshev(@u, @v)
|
45
|
-
x.
|
45
|
+
expect(x).to be_within(TOLERANCE).of(3.1)
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
data/spec/jaccard_spec.rb
CHANGED
@@ -16,17 +16,17 @@ describe "Jaccard" do
|
|
16
16
|
x = Measurable.jaccard_index(@u, @v)
|
17
17
|
y = Measurable.jaccard_index(@v, @u)
|
18
18
|
|
19
|
-
x.
|
19
|
+
expect(x).to be_within(TOLERANCE).of(y)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should return the correct value" do
|
23
23
|
x = Measurable.jaccard_index(@u, @v)
|
24
24
|
|
25
|
-
x.
|
25
|
+
expect(x).to be_within(TOLERANCE).of(1.0 / 2.0)
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
29
|
-
expect { Measurable.jaccard_index(@u, [1, 2, 3, 4]) }.
|
28
|
+
it "should work with vectors of different length" do
|
29
|
+
expect { Measurable.jaccard_index(@u, [1, 2, 3, 4]) }.to_not raise_error
|
30
30
|
end
|
31
31
|
|
32
32
|
it "can be extended separately" do
|
@@ -36,7 +36,7 @@ describe "Jaccard" do
|
|
36
36
|
|
37
37
|
x = klass.jaccard_index(@u, @v)
|
38
38
|
|
39
|
-
x.
|
39
|
+
expect(x).to be_within(TOLERANCE).of(1.0 / 2.0)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "can be included separately" do
|
@@ -46,7 +46,7 @@ describe "Jaccard" do
|
|
46
46
|
|
47
47
|
x = klass.new.jaccard_index(@u, @v)
|
48
48
|
|
49
|
-
x.
|
49
|
+
expect(x).to be_within(TOLERANCE).of(1.0 / 2.0)
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
@@ -59,25 +59,25 @@ describe "Jaccard" do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "accepts two arguments" do
|
62
|
-
expect { Measurable.
|
63
|
-
expect { Measurable.
|
62
|
+
expect { Measurable.jaccard_dissimilarity(@u, @v) }.to_not raise_error
|
63
|
+
expect { Measurable.jaccard_dissimilarity(@u, @v, @w) }.to raise_error(ArgumentError)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should be symmetric" do
|
67
|
-
x = Measurable.
|
68
|
-
y = Measurable.
|
67
|
+
x = Measurable.jaccard_dissimilarity(@u, @v)
|
68
|
+
y = Measurable.jaccard_dissimilarity(@v, @u)
|
69
69
|
|
70
|
-
x.
|
70
|
+
expect(x).to be_within(TOLERANCE).of(y)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should return the correct value" do
|
74
|
-
x = Measurable.
|
74
|
+
x = Measurable.jaccard_dissimilarity(@u, @v)
|
75
75
|
|
76
|
-
x.
|
76
|
+
expect(x).to be_within(TOLERANCE).of(1.0 / 2.0)
|
77
77
|
end
|
78
78
|
|
79
|
-
it "
|
80
|
-
expect { Measurable.
|
79
|
+
it "should work with vectors of different length" do
|
80
|
+
expect { Measurable.jaccard_dissimilarity(@u, [1, 2, 3, 4]) }.to_not raise_error
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: measurable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
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:
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
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:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 6.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 6.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,7 +110,7 @@ homepage: http://github.com/agarie/measurable
|
|
110
110
|
licenses:
|
111
111
|
- MIT
|
112
112
|
metadata: {}
|
113
|
-
post_install_message:
|
113
|
+
post_install_message:
|
114
114
|
rdoc_options: []
|
115
115
|
require_paths:
|
116
116
|
- lib
|
@@ -125,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
|
-
|
129
|
-
|
130
|
-
signing_key:
|
128
|
+
rubygems_version: 3.1.2
|
129
|
+
signing_key:
|
131
130
|
specification_version: 4
|
132
131
|
summary: A Ruby gem with a lot of distance measures for your projects.
|
133
132
|
test_files:
|