示例#1
0
    def test_user_model_simulate_response(self):
        """Test the simulate_response function."""
        self._user_model._user_state.time_budget = 0.5
        cluster_id = 3
        quality = 2.0
        document = interest_evolution.IEvVideo(doc_id=1,
                                               features=np.ones((20, )),
                                               cluster_id=cluster_id,
                                               video_length=1,
                                               quality=quality)
        responses = self._user_model.simulate_response([document])

        self.assertEqual(responses[0].cluster_id, 3)
        self.assertEqual(responses[0].quality, quality)
        # The clicked is true since our choice model wil select the first document.
        self.assertEqual(responses[0].clicked, True)
        # The watch time is 0.5 because time_budget < video_length and
        # time_budget = 0.5.
        self.assertEqual(responses[0].watch_time, 0.5)
示例#2
0
    def test_user_model_update_state(self):
        """Test the update_state function."""
        self._user_model._user_state.time_budget = 0.5
        self._user_model._user_state.user_quality_factor = 0.3
        self._user_model._user_state.document_quality_factor = 0.7
        self._user_model._user_state.user_update_alpha = 1

        cluster_id = 3
        quality = 3.0
        document = interest_evolution.IEvVideo(doc_id=1,
                                               features=np.ones((20, )),
                                               cluster_id=cluster_id,
                                               video_length=1,
                                               quality=quality)
        response = interest_evolution.IEvResponse(clicked=True, watch_time=0.3)
        self._user_model.update_state([document], [response])

        # The expected_utility is 2 (the score of the choice model), the document
        # quality is 3.0, the user_quality_factor = 0.3 and document_quality_factor
        # = 0.7, so received_utility = 0.3 * 2 * 0.7 * 3 = 2.7. Besides,
        # user_update_alpha = 1 so the final time budget is
        # 0.5 - 0.3 + 1 * 0.3 * 2.7 = 1.01.
        self.assertAlmostEqual(self._user_model._user_state.time_budget, 1.01)