code: def evaluate(self, test_events):
          
          for i, e in enumerate(test_events):
              self.__validate(e)
  
              # target items (all or unobserved depending on a detaset)
              unobserved = set(self.item_buffer)
              if not self.repeat:
                  unobserved -= self.rec.users[e.user.index]['known_items']
  
              # item i interacted by user u must be in the recommendation candidate
              # even if it is a new item
              unobserved.add(e.item.index)
  
              candidates = np.asarray(list(unobserved))
  
              # make top-{at} recommendation for the 1001 items
              start = time.clock()
              recos, scores = self.__recommend(e, candidates)
              recommend_time = (time.clock() - start)
  
              rank = np.where(recos == e.item.index)[0][0]
  
              # Step 2: update the model with the observed event
              self.rec.users[e.user.index]['known_items'].add(e.item.index)
              start = time.clock()
              self.rec.update(e)
              update_time = (time.clock() - start)
  
              self.item_buffer.append(e.item.index)
  
              # (top-1 score, where the correct item is ranked, rec time, update time)
              yield scores[0], rank, recommend_time, update_time
docs: Iterate recommend/update procedure and compute incremental recall.
  
          Args:
              test_events (list of Event): Positive test events.
  
          Returns:
              list of tuples: (rank, recommend time, update time)