예제 #1
0
파일: run.py 프로젝트: Limmen/gym-idsgame
def run_experiment(configpath: str, random_seed: int, noconfig: bool):
    """
    Runs one experiment and saves results and plots

    :param configpath: path to configfile
    :param noconfig: whether to override config
    :return: (train_csv_path, eval_csv_path)
    """
    if configpath is not None and not noconfig:
        if not os.path.exists(args.configpath):
            write_default_config()
        config = util.read_config(args.configpath)
    else:
        config = default_config()
    time_str = str(time.time())
    util.create_artefact_dirs(config.output_dir, random_seed)
    logger = util.setup_logger("maximal_attack_vs_reinforce-v9",
                               config.output_dir + "/results/logs/" +
                               str(random_seed) + "/",
                               time_str=time_str)
    config.pg_agent_config.save_dir = default_output_dir(
    ) + "/results/data/" + str(random_seed) + "/"
    config.pg_agent_config.video_dir = default_output_dir(
    ) + "/results/videos/" + str(random_seed) + "/"
    config.pg_agent_config.gif_dir = default_output_dir(
    ) + "/results/gifs/" + str(random_seed) + "/"
    config.pg_agent_config.tensorboard_dir = default_output_dir() + "/results/tensorboard/" \
                                                       + str(random_seed) + "/"
    config.logger = logger
    config.pg_agent_config.logger = logger
    config.pg_agent_config.random_seed = random_seed
    config.random_seed = random_seed
    config.pg_agent_config.to_csv(config.output_dir +
                                  "/results/hyperparameters/" +
                                  str(random_seed) + "/" + time_str + ".csv")
    train_csv_path = ""
    eval_csv_path = ""
    if config.hp_tuning:
        hp_tuning.hype_grid(config)
    else:
        train_result, eval_result = Runner.run(config)
        if len(train_result.avg_episode_steps) > 0 and len(
                eval_result.avg_episode_steps) > 0:
            train_csv_path = config.output_dir + "/results/data/" + str(
                random_seed) + "/" + time_str + "_train" + ".csv"
            train_result.to_csv(train_csv_path)
            eval_csv_path = config.output_dir + "/results/data/" + str(
                random_seed) + "/" + time_str + "_eval" + ".csv"
            eval_result.to_csv(eval_csv_path)
            plot_csv(config, eval_csv_path, train_csv_path, random_seed)

    return train_csv_path, eval_csv_path
예제 #2
0
def run_experiment(configpath: str, random_seed: int, noconfig: bool):
    """
    Runs one experiment and saves results and plots

    :param config: experiment configuration
    :param noconfig: whether to override config
    :return: (train_csv_path, eval_csv_path)
    """
    if configpath is not None and not noconfig:
        if not os.path.exists(configpath):
            write_default_config()
        config = util.read_config(configpath)
    else:
        config = default_config()
    time_str = str(time.time())
    util.create_artefact_dirs(config.output_dir, random_seed)
    logger = util.setup_logger("tabular_q_learning_vs_tabular_q_learning-v0",
                               config.output_dir + "/results/logs/" +
                               str(random_seed) + "/",
                               time_str=time_str)
    config.q_agent_config.save_dir = default_output_dir(
    ) + "/results/data/" + str(random_seed) + "/"
    config.q_agent_config.video_dir = default_output_dir(
    ) + "/results/videos/" + str(random_seed) + "/"
    config.q_agent_config.gif_dir = default_output_dir(
    ) + "/results/gifs/" + str(random_seed) + "/"
    config.logger = logger
    config.q_agent_config.logger = logger
    config.q_agent_config.random_seed = random_seed
    config.random_seed = random_seed
    config.q_agent_config.to_csv(config.output_dir +
                                 "/results/hyperparameters/" +
                                 str(random_seed) + "/" + time_str + ".csv")
    train_result, eval_result = Runner.run(config)
    train_csv_path = ""
    eval_csv_path = ""
    if len(train_result.avg_episode_steps) > 0 and len(
            eval_result.avg_episode_steps) > 0:
        train_csv_path = config.output_dir + "/results/data/" + str(
            random_seed) + "/" + time_str + "_train" + ".csv"
        train_result.to_csv(train_csv_path)
        eval_csv_path = config.output_dir + "/results/data/" + str(
            random_seed) + "/" + time_str + "_eval" + ".csv"
        eval_result.to_csv(eval_csv_path)
        plot_csv(config, eval_csv_path, train_csv_path, random_seed)

    return train_csv_path, eval_csv_path
예제 #3
0
파일: main.py 프로젝트: Limmen/idsgame
def setup_train(config: ClientConfig, random_seed):
    time_str = str(time.time())
    util.create_artefact_dirs(config.output_dir, random_seed)
    logger = util.setup_logger("tabular_q_vs_random_defense-v3",
                               config.output_dir + "/results/logs/" +
                               str(random_seed) + "/",
                               time_str=time_str)
    config.q_agent_config.save_dir = default_output_dir(
    ) + "/results/data/" + str(random_seed) + "/"
    config.q_agent_config.video_dir = default_output_dir(
    ) + "/results/videos/" + str(random_seed) + "/"
    config.q_agent_config.gif_dir = default_output_dir(
    ) + "/results/gifs/" + str(random_seed) + "/"
    # config.q_agent_config.dqn_config.tensorboard_dir = default_output_dir() + "/results/tensorboard/" \
    #                                                    + str(random_seed) + "/"
    config.logger = logger
    config.q_agent_config.logger = logger
    config.q_agent_config.random_seed = random_seed
    config.random_seed = random_seed
    config.q_agent_config.to_csv(config.output_dir +
                                 "/results/hyperparameters/" +
                                 str(random_seed) + "/" + time_str + ".csv")
    return time_str
예제 #4
0
                               attacker_cumulative_reward=df["attacker_cumulative_reward"],
                               defender_cumulative_reward=df["defender_cumulative_reward"],
                               log_frequency=config.simulation_config.log_frequency,
                               output_dir=config.output_dir, eval=False, sim=True)


# Program entrypoint
if __name__ == '__main__':
    args = util.parse_args(default_config_path())
    if args.configpath is not None:
        if not os.path.exists(args.configpath):
            write_default_config()
        config = util.read_config(args.configpath)
    else:
        config = default_config()
    time_str = str(time.time())
    util.create_artefact_dirs(config.output_dir)
    logger = util.setup_logger("idsgame-v0-random_vs_defend_minimal", config.output_dir + "/logs/",
                               time_str=time_str)
    config.logger = logger
    config.simulation_config.logger = logger
    config.simulation_config.to_csv(config.output_dir + "/hyperparameters/" + time_str + ".csv")
    result = Runner.run(config)
    if len(result.avg_episode_steps) > 0:
        csv_path = config.output_dir + "/data/" + time_str + "_simulation" + ".csv"
        result.to_csv(csv_path)
        plot_csv(config, csv_path)



예제 #5
0
    """
    return os.path.dirname(os.path.realpath(sys.argv[0]))


def default_output_dir() -> str:
    """
    :return: the default output dir
    """
    script_dir = get_script_path()
    return script_dir


# Program entrypoint
if __name__ == '__main__':
    random_seed = 0
    util.create_artefact_dirs(default_output_dir(), random_seed)
    pg_agent_config = PolicyGradientAgentConfig(
        gamma=1,
        alpha_attacker=0.0001,
        epsilon=1,
        render=False,
        alpha_defender=0.0001,
        eval_sleep=0.9,
        min_epsilon=0.01,
        eval_episodes=1000,
        train_log_frequency=1,
        epsilon_decay=0.9999,
        video=True,
        eval_log_frequency=500,
        video_fps=5,
        video_dir=default_output_dir() + "/results/videos",