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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pdist.rb +7 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60af35948ee406fc8869882d08b86638d9d451ae
4
- data.tar.gz: b03e2749c3e332d2348e9d960fbcb944be1195ce
3
+ metadata.gz: 55a92e4315831c4dbcf6d6f82234c3866c0e2e3d
4
+ data.tar.gz: 4d302000e4f0b641f00ac5ca203a234aa9e4b636
5
5
  SHA512:
6
- metadata.gz: cde3314e504ce289b30b271e584aef46a9026a8281e69469b4e5786ba769092d649aa2170028bbd2d0ea2b499f09332e0026aecc89a1a89a90869f906f380a71
7
- data.tar.gz: bebfc1d120e68ecd67a93b736fdc7276eac1e8e3c958887efee64893cc848993fbc77cddb5662617000727b23c9ae91eac1ecd1147e1cfe98d531490b0a971fc
6
+ metadata.gz: aa1bd2577a5da537d5204c3d07c4c79a79403eaae915c468f0b8dc40c24026097e76829d31d8c9b1bb31cc10843dc86cc74932484cfeebf7b488e93117d85508
7
+ data.tar.gz: c029ec2faedefb7f1f501a9fb2c61ca51753d91da446fc87bada34d04b26c26107e6b71c7b740fd5ca5b3cbdfea3591cc9eecd6ad79ce77721bd68b2b95da707
@@ -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 == original[x]
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] == permutation[y+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 |original_x| # for each of the objects in original...
81
- y = 0
82
- n.times do # ... iterate over both original and permutation
83
- if original_x < original[y] && permutation[x] > permutation[y] # every time object y comes before object x in permutation, where it comes after in original...
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.5
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-05-01 00:00:00.000000000 Z
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'