def test_step(self): # Create a simple user slate_size = 2 user_model = iev.IEvUserModel( slate_size, choice_model_ctor=choice_model.MultinomialLogitChoiceModel, response_model_ctor=iev.IEvResponse) # Create a candidate_set with 5 items num_candidates = 5 document_sampler = iev.IEvVideoSampler() ievsim = environment.Environment(user_model, document_sampler, num_candidates, slate_size) # Create agent action_space = spaces.MultiDiscrete(num_candidates * np.ones((slate_size,))) agent = random_agent.RandomAgent(action_space, random_seed=0) # This agent doesn't use the previous user response observation, documents = ievsim.reset() slate = agent.step(1, dict(user=observation, doc=documents)) self.assertAllEqual(slate, [2, 0])
def test_slate_indices_and_length(self): # Initialize agent slate_size = 2 num_candidates = 100 action_space = spaces.MultiDiscrete(num_candidates * np.ones((slate_size,))) user_model = iev.IEvUserModel( slate_size, choice_model_ctor=choice_model.MultinomialLogitChoiceModel, response_model_ctor=iev.IEvResponse) agent = random_agent.RandomAgent(action_space, random_seed=0) # Create a set of documents document_sampler = iev.IEvVideoSampler() ievenv = environment.Environment(user_model, document_sampler, num_candidates, slate_size) # Test that slate indices in correct range and length is correct observation, documents = ievenv.reset() slate = agent.step(1, dict(user=observation, doc=documents)) self.assertLen(slate, slate_size) self.assertAllInSet(slate, range(num_candidates))
def iev_document_sampler_creator(env_ctx): return iev.IEvVideoSampler(doc_ctor=SingleClusterIEvVideo, seed=env_ctx["seed"])