Class: Likes::Engines::BestIntersectionSize
- Inherits:
-
Object
- Object
- Likes::Engines::BestIntersectionSize
- Defined in:
- lib/likes/engines/best_intersection_size.rb
Overview
Job: Understands which items could be recommended
Calculates intersection sizes to all other person likings and chooses maximum
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 N = how much distinct people we have
Given P = how much distinct items we have
Complexity: O(NK) * O(hash operations ~ log N + log P)
Defined Under Namespace
Classes: Intersections, NullSizeTransform
Instance Method Summary collapse
-
#initialize(person, likes_of, liked, intersections_factory = Intersections) ⇒ BestIntersectionSize
constructor
Creates new instance of BestIntersectionSize engine.
-
#solve ⇒ Array<Item>
Solves the problem and returns recommendation list.
Constructor Details
#initialize(person, likes_of, liked, intersections_factory = Intersections) ⇒ BestIntersectionSize
Creates new instance of BestIntersectionSize engine
35 36 37 38 39 40 41 |
# File 'lib/likes/engines/best_intersection_size.rb', line 35 def initialize(person, likes_of, liked, intersections_factory=Intersections) @intersections = intersections_factory.build(person) @likes_of = likes_of @liked = liked @its_likes = likes_of.fetch(person) add_similar_tastes end |
Instance Method Details
#solve ⇒ Array<Item>
Solves the problem and returns recommendation list
46 47 48 |
# File 'lib/likes/engines/best_intersection_size.rb', line 46 def solve solution_candidate(intersections.next_people_with_similar_tastes) end |