distance_measures 0.0.0 → 0.0.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{distance_measures}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["reddavis"]
12
- s.date = %q{2010-01-25}
12
+ s.date = %q{2010-01-26}
13
13
  s.description = %q{A bundle of distance measures}
14
14
  s.email = %q{reddavis@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -57,4 +57,12 @@ module DistanceMeasures
57
57
 
58
58
  unions
59
59
  end
60
+
61
+ private
62
+
63
+ # Checks if we're dealing with NaN's and will return 0.0 unless
64
+ # handle NaN's is set to false
65
+ def handle_nan(result)
66
+ result.nan? ? 0.0 : result
67
+ end
60
68
  end
@@ -4,6 +4,6 @@ module DistanceMeasures
4
4
  dot_product = self.dot_product(other)
5
5
  normalization = self.euclidean_normalize * other.euclidean_normalize
6
6
 
7
- dot_product / normalization
7
+ handle_nan(dot_product / normalization)
8
8
  end
9
9
  end
@@ -2,6 +2,8 @@
2
2
  module DistanceMeasures
3
3
  def tanimoto_coefficient(other)
4
4
  dot = self.dot_product(other).to_f
5
- dot / (self.sum_of_squares + other.sum_of_squares - dot).to_f
5
+ result = dot / (self.sum_of_squares + other.sum_of_squares - dot).to_f
6
+
7
+ handle_nan(result)
6
8
  end
7
9
  end
@@ -12,12 +12,20 @@ describe "DistanceMeasures" do
12
12
  it "should return 1.0" do
13
13
  array.cosine_similarity(array).should > 0.99
14
14
  end
15
+
16
+ it "should handle NaN's" do
17
+ [0.0, 0.0].cosine_similarity([0.0, 0.0]).nan?.should be_false
18
+ end
15
19
  end
16
20
 
17
21
  describe "Tanimoto Coefficient" do
18
22
  it "should return 1.0" do
19
23
  array.tanimoto_coefficient(array).should == 1.0
20
24
  end
25
+
26
+ it "should handle NaN's" do
27
+ [0.0, 0.0].tanimoto_coefficient([0.0, 0.0]).nan?.should be_false
28
+ end
21
29
  end
22
30
 
23
31
  describe "Sum of Squares" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distance_measures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - reddavis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-25 00:00:00 +00:00
12
+ date: 2010-01-26 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency