measurable 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +4 -1
- data/README.md +1 -10
- data/lib/measurable/chebyshev.rb +7 -10
- data/lib/measurable/cosine.rb +16 -17
- data/lib/measurable/euclidean.rb +15 -18
- data/lib/measurable/hamming.rb +7 -8
- data/lib/measurable/haversine.rb +10 -11
- data/lib/measurable/jaccard.rb +14 -21
- data/lib/measurable/kullback_leibler.rb +5 -5
- data/lib/measurable/levenshtein.rb +5 -6
- data/lib/measurable/maxmin.rb +7 -8
- data/lib/measurable/minkowski.rb +7 -8
- data/lib/measurable/tanimoto.rb +7 -8
- data/lib/measurable/version.rb +1 -1
- data/measurable.gemspec +1 -2
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78f3ee18bb4decc88988138f4a27c967d3ae56a1
|
4
|
+
data.tar.gz: c623b11567f78a13197f91ccc2bbf5ca19dd2f01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb1ea8f5d14c7526955427e96d4232758b6ec94772acf5b51fdc142a4d039c3d95f83d162196431fac663b67cb90dca7e8c5c8543a8eb611d65997086d5466dc
|
7
|
+
data.tar.gz: 981fb532fd55a2ed1b371009fa869afeb1776096952f93f085631739c874be38a78dbd0acb16d6f4550a826e910abcc3f5474bc3166dd928b92b5da071e8d186
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -62,16 +62,7 @@ Most of the methods accept arbitrary enumerable objects instead of Arrays. For e
|
|
62
62
|
|
63
63
|
## Documentation
|
64
64
|
|
65
|
-
|
66
|
-
to install the [Fivefish
|
67
|
-
generator](https://github.com/ged/rdoc-generator-fivefish) (`gem install
|
68
|
-
rdoc-generator-fivefish`) and run the following command:
|
69
|
-
|
70
|
-
```bash
|
71
|
-
rake rdoc
|
72
|
-
```
|
73
|
-
|
74
|
-
If there's something wrong with an explanation or if there's information missing, please open an issue or send a pull request.
|
65
|
+
The documentation is hosted on [rubydoc](http://www.rubydoc.info/github/agarie/measurable).
|
75
66
|
|
76
67
|
## License
|
77
68
|
|
data/lib/measurable/chebyshev.rb
CHANGED
@@ -4,16 +4,13 @@ module Measurable
|
|
4
4
|
# call-seq:
|
5
5
|
# chebyshev(u, v) -> Float
|
6
6
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# * *Raises* :
|
15
|
-
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
16
|
-
#
|
7
|
+
# Arguments:
|
8
|
+
# - +u+ -> An array of Numeric objects.
|
9
|
+
# - +v+ -> An array of Numeric objects.
|
10
|
+
# Returns:
|
11
|
+
# - The L-infinite distance between +u+ and +v+.
|
12
|
+
# Raises:
|
13
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
17
14
|
def chebyshev(u, v)
|
18
15
|
# TODO: Change this to a more specific, custom-made exception.
|
19
16
|
raise ArgumentError if u.size != v.size
|
data/lib/measurable/cosine.rb
CHANGED
@@ -10,14 +10,14 @@ module Measurable
|
|
10
10
|
#
|
11
11
|
# See: http://en.wikipedia.org/wiki/Cosine_similarity
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
13
|
+
# Arguments:
|
14
|
+
# - +u+ -> An array of Numeric objects.
|
15
|
+
# - +v+ -> An array of Numeric objects.
|
16
|
+
# Returns:
|
17
|
+
# - The normalized dot product of +u+ and +v+, that is, the angle between
|
18
|
+
# them in the n-dimensional space.
|
19
|
+
# Raises:
|
20
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
21
21
|
#
|
22
22
|
def cosine_similarity(u, v)
|
23
23
|
# TODO: Change this to a more specific, custom-made exception.
|
@@ -35,15 +35,14 @@ module Measurable
|
|
35
35
|
#
|
36
36
|
# See: http://en.wikipedia.org/wiki/Cosine_similarity
|
37
37
|
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
38
|
+
# Arguments:
|
39
|
+
# - +u+ -> An array of Numeric objects.
|
40
|
+
# - +v+ -> An array of Numeric objects.
|
41
|
+
# Returns:
|
42
|
+
# - The normalized dot product of +u+ and +v+, that is, the angle between
|
43
|
+
# them in the n-dimensional space.
|
44
|
+
# Raises:
|
45
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
47
46
|
def cosine_distance(u, v)
|
48
47
|
# TODO: Change this to a more specific, custom-made exception.
|
49
48
|
raise ArgumentError if u.size != v.size
|
data/lib/measurable/euclidean.rb
CHANGED
@@ -11,15 +11,13 @@ module Measurable
|
|
11
11
|
#
|
12
12
|
# See: http://en.wikipedia.org/wiki/Euclidean_distance#N_dimensions
|
13
13
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
22
|
-
#
|
14
|
+
# Arguments:
|
15
|
+
# - +u+ -> An array of Numeric objects.
|
16
|
+
# - +v+ -> (Optional) An array of Numeric objects.
|
17
|
+
# Returns:
|
18
|
+
# - The euclidean norm of +u+ or the euclidean distance between +u+ and +v+.
|
19
|
+
# Raises:
|
20
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
23
21
|
def euclidean(u, v = nil)
|
24
22
|
Math.sqrt(self.euclidean_squared(u, v))
|
25
23
|
end
|
@@ -38,15 +36,14 @@ module Measurable
|
|
38
36
|
#
|
39
37
|
# See: http://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
40
38
|
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
39
|
+
# Arguments:
|
40
|
+
# - +u+ -> An array of Numeric objects.
|
41
|
+
# - +v+ -> (Optional) An array of Numeric objects.
|
42
|
+
# Returns:
|
43
|
+
# - The squared value of the euclidean norm of +u+ or of the euclidean
|
44
|
+
# distance between +u+ and +v+.
|
45
|
+
# Raises:
|
46
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
50
47
|
def euclidean_squared(u, v = nil)
|
51
48
|
# If the second argument is nil, the method should return the norm of
|
52
49
|
# vector u. For this, we need the distance between u and the origin.
|
data/lib/measurable/hamming.rb
CHANGED
@@ -10,14 +10,13 @@ module Measurable
|
|
10
10
|
#
|
11
11
|
# See: http://en.wikipedia.org/wiki/Hamming_distance
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
13
|
+
# Arguments:
|
14
|
+
# - +s1+ -> A String.
|
15
|
+
# - +s2+ -> A String with the same size of +s1+.
|
16
|
+
# Returns:
|
17
|
+
# - The number of characters in which +s1+ and +s2+ differ.
|
18
|
+
# Raises:
|
19
|
+
# - +ArgumentError+ -> The sizes of +s1+ and +s2+ don't match.
|
21
20
|
def hamming(s1, s2)
|
22
21
|
# TODO: Change this to a more specific, custom-made exception.
|
23
22
|
raise ArgumentError if s1.size != s2.size
|
data/lib/measurable/haversine.rb
CHANGED
@@ -37,17 +37,16 @@ module Measurable
|
|
37
37
|
# - http://en.wikipedia.org/wiki/Haversine_formula
|
38
38
|
# - http://en.wikipedia.org/wiki/Great-circle_distance
|
39
39
|
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
40
|
+
# Arguments:
|
41
|
+
# - +u+ -> An array of Numeric objects.
|
42
|
+
# - +v+ -> An array of Numeric objects.
|
43
|
+
# - +unit+ -> (Optional) A Symbol representing the unit of measure. Available
|
44
|
+
# options are +:miles+, +:feet+, +:km+ and +:meters+.
|
45
|
+
# Returns:
|
46
|
+
# - The great circle distance between +u+ and +v+.
|
47
|
+
# Raises:
|
48
|
+
# - +ArgumentError+ -> The size of +u+ and +v+ must be 2.
|
49
|
+
# - +ArgumentError+ -> +unit+ must be a Symbol.
|
51
50
|
def haversine(u, v, unit = :meters)
|
52
51
|
# TODO: Create better exceptions.
|
53
52
|
raise ArgumentError if u.size != 2 || v.size != 2
|
data/lib/measurable/jaccard.rb
CHANGED
@@ -11,25 +11,19 @@ module Measurable
|
|
11
11
|
# cardinality of set x.
|
12
12
|
#
|
13
13
|
# For example:
|
14
|
-
# jaccard_index([1, 0
|
14
|
+
# jaccard_index([1, 0], [1]) == 0.5
|
15
15
|
#
|
16
16
|
# Because |intersection| = |(1)| = 1 and |union| = |(0, 1)| = 2.
|
17
17
|
#
|
18
18
|
# See: http://en.wikipedia.org/wiki/Jaccard_coefficient
|
19
19
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# * *Raises* :
|
27
|
-
# - +ArgumentError+ -> The size of the input arrays doesn't match.
|
28
|
-
#
|
20
|
+
# Arguments:
|
21
|
+
# - +u+ -> Array.
|
22
|
+
# - +v+ -> Array.
|
23
|
+
# Returns:
|
24
|
+
# - Float value representing the Jaccard similarity coefficient between
|
25
|
+
# +u+ and +v+.
|
29
26
|
def jaccard_index(u, v)
|
30
|
-
# TODO: Change this to a more specific, custom-made exception.
|
31
|
-
raise ArgumentError if u.size != v.size
|
32
|
-
|
33
27
|
intersection = u & v
|
34
28
|
union = u | v
|
35
29
|
intersection.length.to_f / union.length
|
@@ -48,14 +42,13 @@ module Measurable
|
|
48
42
|
# - Coincidence axiom: jaccard(u, v) == 0 if u == v
|
49
43
|
# - Triangular inequality: jaccard(u, v) <= jaccard(u, w) + jaccard(w, v)
|
50
44
|
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
45
|
+
# Arguments:
|
46
|
+
# - +u+ -> Array.
|
47
|
+
# - +v+ -> Array.
|
48
|
+
# Returns:
|
49
|
+
# - Float value representing the dissimilarity between +u+ and +v+.
|
50
|
+
# Raises:
|
51
|
+
# - +ArgumentError+ -> The size of the input arrays doesn't match.
|
59
52
|
def jaccard(u, v)
|
60
53
|
1 - jaccard_index(u, v)
|
61
54
|
end
|
@@ -20,11 +20,11 @@ module Measurable
|
|
20
20
|
# - Christopher D. Manning and Hinrich Schütze. Foundations of Statistical
|
21
21
|
# Natural Language Processing.
|
22
22
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
23
|
+
# Arguments:
|
24
|
+
# - +p+ -> A probability distribution represented by a n-element Array.
|
25
|
+
# - +q+ -> A probability distribution represented by a n-element Array.
|
26
|
+
# Returns:
|
27
|
+
# - A measure of the difference between the probability distributions p and q.
|
28
28
|
def kullback_leibler(p, q)
|
29
29
|
# TODO: Change this to a more specific, custom-made exception.
|
30
30
|
raise ArgumentError if p.size != q.size
|
@@ -18,12 +18,11 @@ module Measurable
|
|
18
18
|
#
|
19
19
|
# See: http://en.wikipedia.org/wiki/Levenshtein_distance
|
20
20
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# +u+ and +v+.
|
21
|
+
# Arguments:
|
22
|
+
# - +u+ -> Array or String.
|
23
|
+
# - +v+ -> Array or String.
|
24
|
+
# Returns:
|
25
|
+
# - Integer value representing the Levenshtein distance between +u+ and +v+.
|
27
26
|
#
|
28
27
|
def levenshtein(u, v)
|
29
28
|
return 0 if u == v
|
data/lib/measurable/maxmin.rb
CHANGED
@@ -12,14 +12,13 @@ module Measurable
|
|
12
12
|
#
|
13
13
|
# See: http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=05156398
|
14
14
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
15
|
+
# Arguments:
|
16
|
+
# - +u+ -> An array of Numeric objects.
|
17
|
+
# - +v+ -> An array of Numeric objects.
|
18
|
+
# Returns:
|
19
|
+
# - Similarity between +u+ and +v+.
|
20
|
+
# Raises:
|
21
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
23
22
|
def maxmin(u, v)
|
24
23
|
# TODO: Change this to a more specific, custom-made exception.
|
25
24
|
raise ArgumentError if u.size != v.size
|
data/lib/measurable/minkowski.rb
CHANGED
@@ -7,14 +7,13 @@ module Measurable
|
|
7
7
|
# Calculate the sum of the absolute value of the differences between each
|
8
8
|
# coordinate of +u+ and +v+.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
10
|
+
# Arguments:
|
11
|
+
# - +u+ -> An array of Numeric objects.
|
12
|
+
# - +v+ -> An array of Numeric objects.
|
13
|
+
# Returns:
|
14
|
+
# - The Minkowski (or L1) distance between +u+ and +v+.
|
15
|
+
# Raises:
|
16
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
18
17
|
def minkowski(u, v)
|
19
18
|
# TODO: Change this to a more specific, custom-made exception.
|
20
19
|
raise ArgumentError if u.size != v.size
|
data/lib/measurable/tanimoto.rb
CHANGED
@@ -15,14 +15,13 @@ module Measurable
|
|
15
15
|
#
|
16
16
|
# See: # http://en.wikipedia.org/wiki/Jaccard_index#Tanimoto.27s_Definitions_of_Similarity_and_Distance
|
17
17
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
18
|
+
# Arguments:
|
19
|
+
# - +u+ -> An array of Numeric objects.
|
20
|
+
# - +v+ -> An array of Numeric objects.
|
21
|
+
# Returns:
|
22
|
+
# - A measure of the similarity between +u+ and +v+.
|
23
|
+
# Raises:
|
24
|
+
# - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
|
26
25
|
def tanimoto(u, v)
|
27
26
|
# TODO: Change this to a more specific, custom-made exception.
|
28
27
|
raise ArgumentError if u.size != v.size
|
data/lib/measurable/version.rb
CHANGED
data/measurable.gemspec
CHANGED
@@ -26,6 +26,5 @@ Gem::Specification.new do |gem|
|
|
26
26
|
gem.add_development_dependency 'bundler'
|
27
27
|
gem.add_development_dependency 'rake', '~> 10.1'
|
28
28
|
gem.add_development_dependency 'rdoc', '~> 4.1'
|
29
|
-
gem.add_development_dependency 'rspec', '~> 2
|
30
|
-
gem.add_development_dependency 'rdoc-generator-fivefish'
|
29
|
+
gem.add_development_dependency 'rspec', '~> 3.2'
|
31
30
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Agarie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,28 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2
|
61
|
+
version: '3.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rdoc-generator-fivefish
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
68
|
+
version: '3.2'
|
83
69
|
description: A Ruby gem with a lot of distance measures for your projects.
|
84
70
|
email: carlos.agarie@gmail.com
|
85
71
|
executables: []
|
@@ -140,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
126
|
version: '0'
|
141
127
|
requirements: []
|
142
128
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.4.5
|
144
130
|
signing_key:
|
145
131
|
specification_version: 4
|
146
132
|
summary: A Ruby gem with a lot of distance measures for your projects.
|