Beispiel #1
0
    def test_MLE_rate_estimation(self):
        env_params = attention_allocation.Params()
        env_params.prior_incident_counts = (500, 500)
        env_params.n_attention_units = 5

        # pylint: disable=g-long-lambda
        agent_params = allocation_agents.MLEProbabilityMatchingAgentParams()

        agent_params.feature_selection_fn = lambda obs: allocation_agents._get_added_vector_features(
            obs, env_params.n_locations, keys=['incidents_seen'])
        agent_params.interval = 200
        agent_params.epsilon = 0

        env = attention_allocation.LocationAllocationEnv(env_params)
        agent = allocation_agents.MLEProbabilityMatchingAgent(
            action_space=env.action_space,
            reward_fn=lambda x: None,
            observation_space=env.observation_space,
            params=agent_params)
        seed = 0
        agent.rng.seed(seed)
        env.seed(seed)
        observation = env.reset()
        done = False
        steps = 200
        for _ in range(steps):
            action = agent.act(observation, done)
            observation, _, done, _ = env.step(action)

        self.assertTrue(
            np.all(
                np.isclose(list(agent.beliefs),
                           list(env_params.incident_rates),
                           atol=0.5)))
def mle_agent_epsilon_5_resource_all_dynamics():
    """Run experiments on a greedy-epsilon mle agent, epsilon=0.6, across dynamics."""
    dynamic_values_to_test = [0.0, 0.01, 0.05, 0.1, 0.15]
    experiment = _setup_experiment()
    experiment.agent_class = allocation_agents.MLEProbabilityMatchingAgent
    experiment.agent_params = allocation_agents.MLEProbabilityMatchingAgentParams(
    )
    experiment.agent_params.burn_steps = 25
    experiment.agent_params.epsilon = 0.5
    experiment.agent_params.window = 100

    reports_dict = {}

    for value in dynamic_values_to_test:
        experiment.env_params.dynamic_rate = value
        json_report = attention_allocation_experiment.run(experiment)
        report = json.loads(json_report)

        print('\n\nMLE Agent, 6 attention units, epsilon=0.5')
        _print_discovered_missed_incidents_report(value, report)
        output_filename = 'mle_epsilon.5_6units_%f.json' % value
        with open(os.path.join(FLAGS.output_dir, output_filename), 'w') as f:
            json.dump(report, f)

        reports_dict[value] = json_report
    return reports_dict
Beispiel #3
0
 def test_MLEProbabilityMatchingAgent_works(self):
     experiment = _setup_experiment()
     experiment.agent_class = allocation_agents.MLEProbabilityMatchingAgent
     experiment.agent_params = allocation_agents.MLEProbabilityMatchingAgentParams(
         burn_steps=25, window=100)
     result = attention_allocation_experiment.run(experiment)
     # Tests that the result is a valid json string.
     result = json.loads(result)