Class: Suggestor::Algorithms::EuclideanDistance
- Inherits:
-
Object
- Object
- Suggestor::Algorithms::EuclideanDistance
show all
- Includes:
- RecommendationAlgorithm
- Defined in:
- lib/suggestor/algorithms/euclidean_distance.rb
Overview
The closest they are, the more similar their tastes are. More info at:
http://en.wikipedia.org/wiki/Euclidean_metric
http://en.wikipedia.org/wiki/Distance_correlation
Instance Attribute Summary
#collection
Instance Method Summary
collapse
#initialize, #no_shared_items_between?, #recommented_related_items_for, #shared_items_between, #similar_items_to
Instance Method Details
#inverse_of_sum_of_squares_between(first, second) ⇒ Object
32
33
34
|
# File 'lib/suggestor/algorithms/euclidean_distance.rb', line 32
def inverse_of_sum_of_squares_between(first, second)
1/(1+sum_squares_of_shared_items_between(first, second))
end
|
#similarity_score_between(first, second) ⇒ Object
27
28
29
30
|
# File 'lib/suggestor/algorithms/euclidean_distance.rb', line 27
def similarity_score_between(first, second)
return 0.0 if no_shared_items_between?(first, second)
inverse_of_sum_of_squares_between(first, second)
end
|
#sum_squares_of_shared_items_between(first, second) ⇒ Object
36
37
38
39
40
|
# File 'lib/suggestor/algorithms/euclidean_distance.rb', line 36
def sum_squares_of_shared_items_between(first, second)
shared_items_between(first, second).inject(0.0) do |sum, item|
sum + (values_for(first)[item] - values_for(second)[item])**2
end
end
|