distance_measures 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/distance_measures.gemspec +27 -28
- data/lib/distance_measures.rb +1 -0
- data/lib/distance_measures/haversine.rb +46 -0
- metadata +14 -7
- data/.gitignore +0 -23
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/distance_measures.gemspec
CHANGED
@@ -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
|
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.
|
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-
|
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
|
-
|
18
|
+
"README.rdoc"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".document",
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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.
|
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
|
-
|
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::
|
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"])
|
data/lib/distance_measures.rb
CHANGED
@@ -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
|
-
-
|
9
|
-
version: 0.0.
|
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-
|
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
|
-
|
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.
|
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