Esempio n. 1
0
def main(_seed, _run, env):
    torch.manual_seed(_seed)

    train_env, test_env = build_env(**env['train']), build_env(**env['test'])
    input_shape = train_env.observation_space.shape
    num_actions = test_env.action_space.n

    agent_params = DeepQAgentParams()
    add_params(params=agent_params, prefix='agent')
    add_params(params=agent_params.optimizer_params, prefix='opt')
    add_epsilon_params(params=agent_params)

    agent_params.sacred_run = _run
    agent_params.train_env = train_env
    agent_params.test_envs.append(test_env)

    online_q_net = build_net(input_shape=input_shape, num_actions=num_actions)
    target_q_net = build_net(input_shape=input_shape, num_actions=num_actions)
    agent_params.online_q_net = online_q_net
    agent_params.target_q_net = target_q_net

    agent_params.obs_filter = batch_fn

    agent = agent_params.make_agent()
    agent.run()
Esempio n. 2
0
def main(_seed, _run, env):
    torch.manual_seed(_seed)

    train_envs, (kg_entities, _, num_node_feats,
                 num_edge_feats) = build_envs(**env['train'])
    num_entities = len(kg_entities)
    train_env = SampleEnv(train_envs)

    test_envs, _ = build_envs(**env['test'])

    input_shape = train_env.observation_space.shape
    num_actions = train_env.action_space.n

    agent_params = DeepQAgentParams()
    add_params(params=agent_params, prefix='agent')
    add_params(params=agent_params.optimizer_params, prefix='opt')
    add_epsilon_params(params=agent_params)
    add_stopping_params(params=agent_params)

    agent_params.sacred_run = _run
    agent_params.train_env = train_env
    agent_params.test_envs = test_envs

    agent_params.obs_filter = GraphEnv.batch_observations

    online_q_net = build_net(input_shape=input_shape,
                             num_actions=num_actions,
                             num_entities=num_entities,
                             num_node_feats=num_node_feats,
                             num_edge_feats=num_edge_feats)
    target_q_net = build_net(input_shape=input_shape,
                             num_actions=num_actions,
                             num_entities=num_entities,
                             num_node_feats=num_node_feats,
                             num_edge_feats=num_edge_feats)
    agent_params.online_q_net = online_q_net
    agent_params.target_q_net = target_q_net

    agent = agent_params.make_agent()
    agent.run()