pdist 0.0.1 → 0.0.2
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 +4 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab14b4afc32f4446b586db088d314b4e0a75bac
|
4
|
+
data.tar.gz: 38596c57ac1bd79f64cf24a47cee4e06c37ca23c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e5417f94da5b7247bddc96c61d1fd70bb106f1efb5f3a850c34b359b64d76c59ea97788611c31ad4adb716ce08f7b792f7600d78b482d133f8dacf5a984083f
|
7
|
+
data.tar.gz: 6bbb082ee9a403f7db62ac373e7dbb9cb593a02cb970a575135c7a909ad595205334354f1bb0af06f172ee57a70e6cf4556252d8a389b3befc329b6257108a48
|
data/lib/pdist.rb
CHANGED
@@ -12,7 +12,7 @@ class PDist
|
|
12
12
|
return difference_abs
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.
|
15
|
+
def self.deviation(original, permutation)
|
16
16
|
s = distances(original, permutation).inject(:+)
|
17
17
|
n = permutation.length
|
18
18
|
if n % 2 == 0
|
@@ -23,7 +23,7 @@ class PDist
|
|
23
23
|
return score
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.
|
26
|
+
def self.square(original, permutation)
|
27
27
|
sq_dists = []
|
28
28
|
distances(original, permutation).each{|d| sq_dists << d**2}
|
29
29
|
s = sq_dists.inject(:+)
|
@@ -45,21 +45,11 @@ class PDist
|
|
45
45
|
return hds.inject(:+)
|
46
46
|
end
|
47
47
|
|
48
|
-
def self.
|
48
|
+
def self.hamming(original, permutation) # generalized hamming distance
|
49
49
|
ham_dist(original, permutation).to_f / permutation.length.to_f # normalize by dividing by the max score, which == number of objects
|
50
50
|
end
|
51
51
|
|
52
|
-
def self.
|
53
|
-
pos_1 = permutation.index(original[0]) # position of the first object of original order in permutation
|
54
|
-
if original[0] != permutation[0]
|
55
|
-
new_a = [permutation[pos_1..-1], permutation[0..pos_1-1]].flatten # re-order the permutation to get first object at front
|
56
|
-
else
|
57
|
-
new_a = permutation # running the if above for a permutation with 1 at front results in duplicates
|
58
|
-
end
|
59
|
-
return (ham_dist(original, new_a) + pos_1).to_f / (2 * (permutation.length - 1)).to_f # no need to take away 1 from pos_1 as the index in ruby is position - 1
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.r_dist(original, permutation) # reverse R distance (since higher scores = bad)
|
52
|
+
def self.rdist(original, permutation) # reverse R distance (since higher scores = bad)
|
63
53
|
x = 0
|
64
54
|
r = []
|
65
55
|
n = permutation.length
|