takuti / flurs

:ocean: FluRS: A Python library for streaming recommendation algorithms
https://flurs.readthedocs.io/
MIT License
108 stars 17 forks source link

Disallow to build fature-based recommender from empty vector #12

Closed takuti closed 2 years ago

takuti commented 2 years ago

Originally, user, item, and contextual features were initialized with a dummy element np.array([0.]) to avoid errors associated with empty array manipulation. This workaround added unnecessary dimensions to the input vectors and caused a failure in a simple case like:

  recommender = FMRecommender(p=3)
  recommender.initialize()

  user = User(0)  # -> dummy user feature: np.array([0.])
  recommender.register(user)

  item = Item(0)  # -> dummy item feature: np.array([0.])
  recommender.register(item)

  # Eventually, the num of dimensions of a feature vector corresponding
  # to the event is # 5 (1 user dummy + 1 item dummy + 3 contextual),
  # which differs from `p=3`.
  event = Event(user, item, context=np.array([0, 4, 0]))
  recommender.update(event)  # -> FAILED

Fix #10