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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef813e1fecb8d7f5a5a19cf70018b3965ea34790
4
- data.tar.gz: 23489086e5091bff9a868e6d167cd2b77210b030
3
+ metadata.gz: 78f3ee18bb4decc88988138f4a27c967d3ae56a1
4
+ data.tar.gz: c623b11567f78a13197f91ccc2bbf5ca19dd2f01
5
5
  SHA512:
6
- metadata.gz: ea90a56d0a5dc4062b45aa8acd8536e9eb2032287d4f04080130f826aaf9bfe88ee0245899dfe5a0188f48768d690e05d9639c3e2dbefed4ba7323157775912a
7
- data.tar.gz: 195c6eb734ef6b2183ceece52dc68bd68cbb316de0e26127dde3e152195ce435845b52fe965ca47546f47fa6c325cc67d065311213648a41c7bf90d0563345aa
6
+ metadata.gz: cb1ea8f5d14c7526955427e96d4232758b6ec94772acf5b51fdc142a4d039c3d95f83d162196431fac663b67cb90dca7e8c5c8543a8eb611d65997086d5466dc
7
+ data.tar.gz: 981fb532fd55a2ed1b371009fa869afeb1776096952f93f085631739c874be38a78dbd0acb16d6f4550a826e910abcc3f5474bc3166dd928b92b5da071e8d186
@@ -1,3 +1,6 @@
1
- === 18th May, 2014 -- Version 0.0.8
1
+ 0.0.9 -- 16th April, 2015
2
+ * Removed unnecessary argument length check from jaccard_index.
3
+ * Host documentation on rubydoc.info.
2
4
 
5
+ 0.0.8 -- 18th May, 2014
3
6
  * Added Kullback-Leibler divergence.
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
- `RDoc` syntax is used to document the project. To build it locally, you'll need
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
 
@@ -4,16 +4,13 @@ module Measurable
4
4
  # call-seq:
5
5
  # chebyshev(u, v) -> Float
6
6
  #
7
- #
8
- #
9
- # * *Arguments* :
10
- # - +u+ -> An array of Numeric objects.
11
- # - +v+ -> An array of Numeric objects.
12
- # * *Returns* :
13
- # - The L-infinite distance between +u+ and +v+.
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
@@ -10,14 +10,14 @@ module Measurable
10
10
  #
11
11
  # See: http://en.wikipedia.org/wiki/Cosine_similarity
12
12
  #
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.
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
- # * *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.
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
@@ -11,15 +11,13 @@ module Measurable
11
11
  #
12
12
  # See: http://en.wikipedia.org/wiki/Euclidean_distance#N_dimensions
13
13
  #
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
19
- # +v+.
20
- # * *Raises* :
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
- # * *Arguments* :
42
- # - +u+ -> An array of Numeric objects.
43
- # - +v+ -> (Optional) An array of Numeric objects.
44
- # * *Returns* :
45
- # - The squared value of the euclidean norm of +u+ or of the euclidean
46
- # distance between +u+ and +v+.
47
- # * *Raises* :
48
- # - +ArgumentError+ -> The sizes of +u+ and +v+ don't match.
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.
@@ -10,14 +10,13 @@ module Measurable
10
10
  #
11
11
  # See: http://en.wikipedia.org/wiki/Hamming_distance
12
12
  #
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.
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
@@ -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
- # * *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.
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
@@ -11,25 +11,19 @@ module Measurable
11
11
  # cardinality of set x.
12
12
  #
13
13
  # For example:
14
- # jaccard_index([1, 0, 1], [1, 1, 1]) == 0.5
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
- # * *Arguments* :
21
- # - +u+ -> Array.
22
- # - +v+ -> Array.
23
- # * *Returns* :
24
- # - Float value representing the Jaccard similarity coefficient between
25
- # +u+ and +v+.
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
- # * *Arguments* :
52
- # - +u+ -> Array.
53
- # - +v+ -> Array.
54
- # * *Returns* :
55
- # - Float value representing the dissimilarity between +u+ and +v+.
56
- # * *Raises* :
57
- # - +ArgumentError+ -> The size of the input arrays doesn't match.
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
- # * *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.
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
- # * *Arguments* :
22
- # - +u+ -> Array or String.
23
- # - +v+ -> Array or String.
24
- # * *Returns* :
25
- # - Integer value representing the Levenshtein distance between
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
@@ -12,14 +12,13 @@ module Measurable
12
12
  #
13
13
  # See: http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=05156398
14
14
  #
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.
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
@@ -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
- # * *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.
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
@@ -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
- # * *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.
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
@@ -1,3 +1,3 @@
1
1
  module Measurable
2
- VERSION = "0.0.8" # :nodoc:
2
+ VERSION = "0.0.9" # :nodoc:
3
3
  end
@@ -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.1'
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.8
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: 2014-05-18 00:00:00.000000000 Z
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.1'
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.1'
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.2.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.