pdist 0.0.5 → 1.0.0
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.
- checksums.yaml +4 -4
- data/lib/pdist.rb +7 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55a92e4315831c4dbcf6d6f82234c3866c0e2e3d
|
4
|
+
data.tar.gz: 4d302000e4f0b641f00ac5ca203a234aa9e4b636
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa1bd2577a5da537d5204c3d07c4c79a79403eaae915c468f0b8dc40c24026097e76829d31d8c9b1bb31cc10843dc86cc74932484cfeebf7b488e93117d85508
|
7
|
+
data.tar.gz: c029ec2faedefb7f1f501a9fb2c61ca51753d91da446fc87bada34d04b26c26107e6b71c7b740fd5ca5b3cbdfea3591cc9eecd6ad79ce77721bd68b2b95da707
|
data/lib/pdist.rb
CHANGED
@@ -38,9 +38,7 @@ class PDist
|
|
38
38
|
x = 0
|
39
39
|
hds = [] # hamming distances
|
40
40
|
permutation.each do |object| # hamming distances are 0 when object's have same index in original and permutation, and 1 when not
|
41
|
-
if object
|
42
|
-
hds << 0
|
43
|
-
else
|
41
|
+
if object != original[x]
|
44
42
|
hds << 1
|
45
43
|
end
|
46
44
|
x+=1
|
@@ -56,9 +54,7 @@ class PDist
|
|
56
54
|
n = permutation.length
|
57
55
|
(n - 1).times do
|
58
56
|
y = permutation.index(original[x])
|
59
|
-
if original[x+1]
|
60
|
-
r << 0
|
61
|
-
else
|
57
|
+
if original[x+1] != permutation[y+1]
|
62
58
|
r << 1
|
63
59
|
end
|
64
60
|
x+=1
|
@@ -73,21 +69,16 @@ class PDist
|
|
73
69
|
end
|
74
70
|
|
75
71
|
# Returns float of the kendall's tau distance between original and permutation, normalized between 0.0 and 1.0
|
76
|
-
def self.kendalls_tau(original, permutation)
|
72
|
+
def self.kendalls_tau(original, permutation) # TODO edit the if statement to work with any type of object
|
77
73
|
n = permutation.length
|
78
|
-
x = 0
|
79
74
|
kt = []
|
80
|
-
original.each do |
|
81
|
-
y
|
82
|
-
|
83
|
-
if
|
75
|
+
original.each do |x| # for each of the objects in original...
|
76
|
+
permutation.each do |y| # ... iterate over the objects in permutation
|
77
|
+
# every time object y comes before object x in permutation, where it comes after in original...
|
78
|
+
if original.index(x) < original.index(y) && permutation.index(x) > permutation.index(y)
|
84
79
|
kt << 1 # ... 1 is added
|
85
|
-
else
|
86
|
-
kt << 0
|
87
80
|
end
|
88
|
-
y+=1
|
89
81
|
end
|
90
|
-
x+=1
|
91
82
|
end
|
92
83
|
s = kt.inject(:+) # the number of pairwise adjacent permutations required to transform original into permutation
|
93
84
|
return 2 * (s.to_f / (n**2 - n).to_f) # normalized kendall's tau distance
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edward Chalstrey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Ruby gem to compare permutations using distance measures/metrics. github:
|
14
14
|
https://github.com/edwardchalstrey1/pdist'
|