similar 0.0.3 → 0.0.4

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. data/lib/similar/version.rb +1 -1
  2. data/lib/similar.rb +3 -12
  3. metadata +1 -1
@@ -1,3 +1,3 @@
1
1
  module Similar
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/similar.rb CHANGED
@@ -43,22 +43,13 @@ module Similar
43
43
  num / den.to_f
44
44
  end
45
45
 
46
+ # Calculate the distance between two Arrays of values.
47
+ #
48
+ # Distance is inverted, so higher values are better.
46
49
  def self.euclidean_distance(a, b)
47
-
48
- # Add up the squares of all the differences
49
- # sum_of_squares = sum(
50
- # [pow(prefs[person1][item]-prefs[person2][item],2)
51
-
52
- # for item in prefs[person1] if item in prefs[person2]])
53
-
54
- # return 1/(1+sum_of_squares)
55
-
56
50
  # sum, of the squares of the differences...
57
51
  sum = a.zip(b).map { |x, y| ( (x - y) ** 2) }.inject(:+)
58
-
59
52
  1 / (1+ sum)
60
- # sum_1_sq = a.inject(0) { |sum, c| sum + c ** 2 }
61
- # sum_2_sq = b.inject(0) { |sum, c| sum + c ** 2 }
62
53
  end
63
54
 
64
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: similar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: