distance_measures 0.0.5 → 0.0.6

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.
@@ -26,6 +26,8 @@ A bunch of distance measures that extend Array.
26
26
 
27
27
  a.tanimoto_coefficient(b)
28
28
 
29
+ a.haversine_distance(b)
30
+
29
31
  This may or may not be the complete list, best thing is to check the source code.
30
32
 
31
33
  There are also a couple bonus methods:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -1,60 +1,59 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{distance_measures}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
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-09-11}
12
+ s.date = %q{2010-12-29}
13
13
  s.description = %q{A bundle of distance measures with C extensions for the slow bits}
14
14
  s.email = %q{reddavis@gmail.com}
15
15
  s.extensions = ["ext/core/extconf.rb", "ext/euclidean_distance/extconf.rb"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE",
18
- "README.rdoc"
18
+ "README.rdoc"
19
19
  ]
20
20
  s.files = [
21
21
  ".document",
22
- ".gitignore",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "distance_measures.gemspec",
28
- "ext/19_fix/19_fix.c",
29
- "ext/core/core.c",
30
- "ext/core/extconf.rb",
31
- "ext/euclidean_distance/euclidean_distance.c",
32
- "ext/euclidean_distance/extconf.rb",
33
- "lib/distance_measures.rb",
34
- "lib/distance_measures/core.bundle",
35
- "lib/distance_measures/cosine_similarity.rb",
36
- "lib/distance_measures/euclidean_distance.bundle",
37
- "lib/distance_measures/jaccard.rb",
38
- "lib/distance_measures/tanimoto_coefficient.rb",
39
- "spec/distance_measures_spec.rb",
40
- "spec/spec.opts",
41
- "spec/spec_helper.rb"
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "distance_measures.gemspec",
27
+ "ext/19_fix/19_fix.c",
28
+ "ext/core/core.c",
29
+ "ext/core/extconf.rb",
30
+ "ext/euclidean_distance/euclidean_distance.c",
31
+ "ext/euclidean_distance/extconf.rb",
32
+ "lib/distance_measures.rb",
33
+ "lib/distance_measures/core.bundle",
34
+ "lib/distance_measures/cosine_similarity.rb",
35
+ "lib/distance_measures/euclidean_distance.bundle",
36
+ "lib/distance_measures/haversine.rb",
37
+ "lib/distance_measures/jaccard.rb",
38
+ "lib/distance_measures/tanimoto_coefficient.rb",
39
+ "spec/distance_measures_spec.rb",
40
+ "spec/spec.opts",
41
+ "spec/spec_helper.rb"
42
42
  ]
43
43
  s.homepage = %q{http://github.com/reddavis/distance_measure}
44
- s.rdoc_options = ["--charset=UTF-8"]
45
44
  s.require_paths = ["lib"]
46
- s.rubygems_version = %q{1.3.6}
45
+ s.rubygems_version = %q{1.3.7}
47
46
  s.summary = %q{A bundle of distance measures with C extensions for the slow bits}
48
47
  s.test_files = [
49
48
  "spec/distance_measures_spec.rb",
50
- "spec/spec_helper.rb"
49
+ "spec/spec_helper.rb"
51
50
  ]
52
51
 
53
52
  if s.respond_to? :specification_version then
54
53
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
54
  s.specification_version = 3
56
55
 
57
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
57
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
59
58
  else
60
59
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
@@ -5,6 +5,7 @@ require 'distance_measures/euclidean_distance'
5
5
  require 'distance_measures/tanimoto_coefficient'
6
6
  require 'distance_measures/core'
7
7
  require 'distance_measures/jaccard'
8
+ require 'distance_measures/haversine'
8
9
 
9
10
  class Array
10
11
  include DistanceMeasures
@@ -0,0 +1,46 @@
1
+ #
2
+ # Notes:
3
+ #
4
+ # translated into Ruby based on information contained in:
5
+ # http://mathforum.org/library/drmath/view/51879.html Doctors Rick and Peterson - 4/20/99
6
+ # http://www.movable-type.co.uk/scripts/latlong.html
7
+ # http://en.wikipedia.org/wiki/Haversine_formula
8
+ #
9
+ # This formula can compute accurate distances between two points given latitude and longitude, even for
10
+ # short distances.
11
+
12
+ module DistanceMeasures
13
+
14
+ # PI = 3.1415926535
15
+ RAD_PER_DEG = 0.017453293 # PI/180
16
+
17
+ R_MILES = 3956 # radius of the great circle in miles
18
+ R_KM = 6371 # radius in kilometers...some algorithms use 6367
19
+
20
+ # the great circle distance d will be in whatever units R is in
21
+ R = {
22
+ :miles => R_MILES,
23
+ :km => R_KM,
24
+ :feet => R_MILES * 5282,
25
+ :meters => R_KM * 1000
26
+ }
27
+
28
+ def haversine_distance(other, um = :meters)
29
+ dlon = other[1] - self[1]
30
+ dlat = other[0] - self[0]
31
+
32
+ dlon_rad = dlon * RAD_PER_DEG
33
+ dlat_rad = dlat * RAD_PER_DEG
34
+
35
+ lat1_rad = self[0] * RAD_PER_DEG
36
+ lon1_rad = self[1] * RAD_PER_DEG
37
+
38
+ lat2_rad = other[0] * RAD_PER_DEG
39
+ lon2_rad = other[1] * RAD_PER_DEG
40
+
41
+ a = (Math.sin(dlat_rad/2))**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * (Math.sin(dlon_rad/2))**2
42
+ c = 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1-a))
43
+
44
+ R[um] * c
45
+ end
46
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distance_measures
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 5
9
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - reddavis
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-11 00:00:00 +01:00
18
+ date: 2010-12-29 00:00:00 +00:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 13
27
30
  segments:
28
31
  - 1
29
32
  - 2
@@ -43,7 +46,6 @@ extra_rdoc_files:
43
46
  - README.rdoc
44
47
  files:
45
48
  - .document
46
- - .gitignore
47
49
  - LICENSE
48
50
  - README.rdoc
49
51
  - Rakefile
@@ -58,6 +60,7 @@ files:
58
60
  - lib/distance_measures/core.bundle
59
61
  - lib/distance_measures/cosine_similarity.rb
60
62
  - lib/distance_measures/euclidean_distance.bundle
63
+ - lib/distance_measures/haversine.rb
61
64
  - lib/distance_measures/jaccard.rb
62
65
  - lib/distance_measures/tanimoto_coefficient.rb
63
66
  - spec/distance_measures_spec.rb
@@ -68,28 +71,32 @@ homepage: http://github.com/reddavis/distance_measure
68
71
  licenses: []
69
72
 
70
73
  post_install_message:
71
- rdoc_options:
72
- - --charset=UTF-8
74
+ rdoc_options: []
75
+
73
76
  require_paths:
74
77
  - lib
75
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
76
80
  requirements:
77
81
  - - ">="
78
82
  - !ruby/object:Gem::Version
83
+ hash: 3
79
84
  segments:
80
85
  - 0
81
86
  version: "0"
82
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
83
89
  requirements:
84
90
  - - ">="
85
91
  - !ruby/object:Gem::Version
92
+ hash: 3
86
93
  segments:
87
94
  - 0
88
95
  version: "0"
89
96
  requirements: []
90
97
 
91
98
  rubyforge_project:
92
- rubygems_version: 1.3.6
99
+ rubygems_version: 1.3.7
93
100
  signing_key:
94
101
  specification_version: 3
95
102
  summary: A bundle of distance measures with C extensions for the slow bits
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- tmp/*
21
- benchmarks/*
22
-
23
- ## PROJECT::SPECIFIC