Class: Likes::Engines::BestRelativeIntersectionSize
- Inherits:
-
Object
- Object
- Likes::Engines::BestRelativeIntersectionSize
- Defined in:
- lib/likes/engines/best_relative_intersection_size.rb
Overview
Job: Understands which items could be recommended
Calculates relative intersection sizes to all other person likings and chooses maximum. This is Jaccard Similarity of Sets algorithm implementation
Relative intersection size = intersection size / union size
Worst approximation of execution time:
Given K = how much likes target person has, in reasonable situations it is not very big number. But in theory can be as high as P
Given P = how much distinct items we have
Given N = how much distinct people we have
Complexity: O(NK) * O(hash operations ~ log N + log P)
Defined Under Namespace
Classes: RelativeIntersectionsFactory, RelativeSizeTransform
Instance Method Summary collapse
-
#initialize(person, likes_of, liked) ⇒ BestRelativeIntersectionSize
constructor
Creates new instance of BestRelativeIntersectionSize engine.
-
#solve ⇒ Array<Item>
Solves the problem and returns recommendation list.
Constructor Details
#initialize(person, likes_of, liked) ⇒ BestRelativeIntersectionSize
Creates new instance of BestRelativeIntersectionSize engine
36 37 38 39 40 41 42 43 |
# File 'lib/likes/engines/best_relative_intersection_size.rb', line 36 def initialize(person, likes_of, liked) @delegatee = BestIntersectionSize.new( person, likes_of, liked, RelativeIntersectionsFactory.new(likes_of) ) end |
Instance Method Details
#solve ⇒ Array<Item>
Solves the problem and returns recommendation list
48 49 50 |
# File 'lib/likes/engines/best_relative_intersection_size.rb', line 48 def solve delegatee.solve end |