Class: Likes::Engines::BestIntersectionSize

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(person, likes_of, liked, intersections_factory = Intersections) ⇒ BestIntersectionSize

Creates new instance of BestIntersectionSize engine

Parameters:

  • person (Person#==)

    The person to provide recommendations for

  • likes_of (Hash<Person, Array<Item>>)

    Input data in form of map person => [item]

  • liked (Hash<Item, Array<Person>>)

    Input data in form of map item => [person]

  • intersections_factory (Factory<Intersections>#new(Person)) (defaults to: Intersections)

    Knows how to find best intersection candidates



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

#solveArray<Item>

Solves the problem and returns recommendation list

Returns:

  • (Array<Item>)

    Returns list of recommended items



46
47
48
# File 'lib/likes/engines/best_intersection_size.rb', line 46

def solve
  solution_candidate(intersections.next_people_with_similar_tastes)
end