Exemplo n.º 1
0
    def test_evaluation(self):
        """tests the evaluation method of the pointrobot trainer"""

        trainer = PointrobotTrainer(self.policy,
                                    self.env,
                                    self.params,
                                    test_env=self.test_env)

        trainer.evaluate()
Exemplo n.º 2
0
    def test_training(self):
        """sanity check of the training method."""

        self.params["trainer"]["max_steps"] = 1e4

        trainer = PointrobotTrainer(self.policy,
                                    self.env,
                                    self.params,
                                    test_env=self.test_env)

        trainer.train()
Exemplo n.º 3
0
    # getting random hyperparams according to the ranges and placing them into params.
    params = get_random_params(params)

    # setting up logdir for the current hyperparams:
    logdir = os.path.join('results', 'hyperparam_tuning', str(run))
    os.makedirs(logdir)
    params["trainer"]["logdir"] = logdir

    # write the actual hyperparams into a file:
    info_file = os.path.join(logdir, "params.txt")
    export_params(params, info_file)

    #Initialize the environment
    env = gym.make(
        params["env"]["name"],
        params=params,
    )
    test_env = gym.make(params["env"]["name"], params=params)

    # deleting the previous checkpoints:
    ckp_files = glob.glob(os.path.join(params["trainer"]["model_dir"], "*"))
    for f in ckp_files:
        os.remove(f)

    # initialize the agent:
    policy = DDPG(env=env, params=params)

    # initialize the trainer:
    trainer = PointrobotTrainer(policy, env, params, test_env=test_env)

    trainer.train()
Exemplo n.º 4
0
 def test_pointrobot_trainer_init(self):
     """tests the __init__() function of the pointrobot trainer"""
     trainer = PointrobotTrainer(self.policy,
                                 self.env,
                                 self.params,
                                 test_env=self.test_env)
    params = set_up_benchmark_params(params, key)
    params["trainer"]["logdir"] = os.path.join(params["trainer"]["logdir"],
                                               key)

    #Initialize the environment
    env = gym.make(
        params["env"]["name"],
        params=params,
    )
    test_env = gym.make(params["env"]["name"], params=params)

    # initialize the agent:
    policy = DDPG(env=env, params=params)

    # initialize the trainer:
    trainer = PointrobotTrainer(policy, env, params, test_env=test_env)

    avg_test_return, success_rate, ratio_straight_lines, success_rate_straight_line, success_rate_no_straight_line = trainer.evaluate(
    )

    # writing the results into a log file.
    results_path = os.path.join(params["trainer"]["logdir"], "results.txt")
    with open(results_path, 'a') as f:
        f.write("model_dir: {}".format(params["trainer"]["model_dir"]) + "\n")
        f.write("WS_level: {}".format(params["env"]["WS_level"]) + "\n")
        f.write("num_obj_max: {}".format(params["env"]["num_obj_max"]) + "\n")
        f.write("avg_test_return: {}".format(avg_test_return) + "\n")
        f.write("success_rate: {}".format(success_rate) + "\n")
        f.write("ratio_straight_lines: {}".format(ratio_straight_lines) + "\n")
        f.write("success_rate_straight_line: {}".format(
            success_rate_straight_line) + "\n")