Beispiel #1
0
def main():
    # env = SinEnvironment(bo_param2model_param_dic=bo_param2model_param_dic, result_filename=result_filename,
    #                      output_dir=output_dir,
    #                      reload=reload)
    env = OneDimGaussianEnvironment(bo_param2model_param_dic=bo_param2model_param_dic, result_filename=result_filename,
                                    output_dir=output_dir,
                                    reload=reload)

    agent = GMRF_BO(bo_param_list, env, GAMMA=GAMMA, GAMMA0=GAMMA0, GAMMA_Y=GAMMA_Y, ALPHA=ALPHA,
                    is_edge_normalized=IS_EDGE_NORMALIZED, gt_available=True, n_early_stopping=N_EARLY_STOPPING,
                    burnin=BURNIN,
                    normalize_output=NORMALIZE_OUTPUT, update_hyperparam_func=UPDATE_HYPERPARAM_FUNC,
                    initial_k=INITIAL_K, initial_theta=INITIAL_THETA, acquisition_func=ACQUISITION_FUNC,
                    acquisition_param_dic=ACQUISITION_PARAM_DIC)
    #
    # agent = GP_BO(bo_param_list, env, gt_available=True, my_kernel=kernel, burnin=BURNIN,
    #               normalize_output=NORMALIZE_OUTPUT, acquisition_func=ACQUISITION_FUNC,
    #               acquisition_param_dic=ACQUISITION_PARAM_DIC)

    # for i in tqdm(range(n_iter)):
    for i in range(n_iter):
        try:
            flg = agent.learn()
            agent.plot(output_dir=output_dir)
            agent.save_mu_sigma_csv()

            if flg == False:
                print("Early Stopping!!!")
                print(agent.bestX)
                print(agent.bestT)
                break

        except KeyboardInterrupt:
            print("Learnig process was forced to stop!")
            break

    plot_1dim(agent.point_info_manager.T_seq, 'reward.png')
Beispiel #2
0
                initial_k=INITIAL_K, initial_theta=INITIAL_THETA, acquisition_func=ACQUISITION_FUNC,
                acquisition_param_dic=ACQUISITION_PARAM_DIC, n_ctr=n_total_exp)

# for i in tqdm(range(n_iter)):

agent.save_mu_sigma_csv(outfn=mu_sigma_fn, point_info_fn=point_fn)
agent.plot_click_distribution(output_dir)
# agent.learn_from_clicks()

for i in range(n_iter):
    try:
        flg = agent.learn_from_clicks()
        # agent.sample_randomly()
        agent.plot_click_distribution(output_dir)

        if flg == False:
            print("Early Stopping!!!")
            print(agent.bestX)
            print(agent.bestT)
            break

    except KeyboardInterrupt:
        print("Learnig process was forced to stop!")
        # print(agent.X)
        # print(agent.Treal)
        break

plot_1dim([agent.total_clicked_ratio_list, agent.randomly_total_clicked_ratio_list], 'total_clicked_ratio_list.png')
print(agent.total_clicked_ratio_list)
print(agent.randomly_total_clicked_ratio_list)
Beispiel #3
0
def test(ACQUISITION_FUNC):
    # ### temporary ###
    if os.path.exists(OUTPUT_DIR):
        shutil.rmtree(OUTPUT_DIR)
    ##################

    print('GAMMA: ', GAMMA)
    print('GAMMA_Y: ', GAMMA_Y)
    print('GAMMA0:', GAMMA0)

    mkdir_if_not_exist(OUTPUT_DIR)
    param_names = sorted(
        [x.replace('.csv', '') for x in os.listdir(PARAMETER_DIR)])

    bo_param2model_param_dic = {}
    bo_param_list = []
    for param_name in param_names:  # param_name is a param file's name
        param_df = pd.read_csv(
            os.path.join(PARAMETER_DIR, param_name + '.csv'),
            dtype=str)  #makes index column type str instead of float

        # always read the column of the same name as the file name -- param_name
        bo_param_list.append(param_df[param_name].values)
        # param_df has a column of its csv file name, e.g. "x"
        # and this column is set as the index column
        param_df.set_index(param_name, inplace=True)
        # dict: param_file name -> column dict (the column with the name "bo_"+param_file name)
        # column dict: index column element -> cell value #index column is type str
        bo_param2model_param_dic[param_name] = param_df.to_dict()['bo_' +
                                                                  param_name]

        # bo_param_list is a list of every "bo_" column in all the param files of param_names
        # print("bo_param_list", bo_param_list)


#    env = SinEnvironment(bo_param2model_param_dic=bo_param2model_param_dic,
#                         result_filename=RESULT_FILENAME,
#                         output_dir=OUTPUT_DIR,
#                         reload=RELOAD)

    env = OneDimGaussianEnvironment(
        bo_param2model_param_dic=bo_param2model_param_dic,
        result_filename=RESULT_FILENAME,
        output_dir=OUTPUT_DIR,
        reload=RELOAD)

    #    agent = GMRF_BO(bo_param_list, env, GAMMA=GAMMA, GAMMA0=GAMMA0, GAMMA_Y=GAMMA_Y, ALPHA=ALPHA,
    #                     is_edge_normalized=IS_EDGE_NORMALIZED,
    #                     gt_available=True,
    #                     n_early_stopping=N_EARLY_STOPPING,
    #                     burnin=BURNIN,
    #                     normalize_output=NORMALIZE_OUTPUT,
    #                     update_hyperparam_func=UPDATE_HYPERPARAM_FUNC,
    #                     initial_k=INITIAL_K,
    #                     initial_theta=INITIAL_THETA,
    #                     acquisition_func=ACQUISITION_FUNC,
    #                     acquisition_param_dic=ACQUISITION_PARAM_DIC)

    agent = GP_BO(bo_param_list,
                  env,
                  gt_available=True,
                  my_kernel=kernel,
                  burnin=BURNIN,
                  normalize_output=NORMALIZE_OUTPUT,
                  acquisition_func=ACQUISITION_FUNC,
                  acquisition_param_dic=ACQUISITION_PARAM_DIC)

    nIter = 200
    for i in range(nIter):
        flg = agent.learn(drop=True if i < nIter - 1 else False)
        agent.plot(output_dir=OUTPUT_DIR)
        agent.save_mu_sigma_csv()
        if flg == False:
            print("Early Stopping!!!")
            print("bestX =", agent.bestX)
            print("bestT =", agent.bestT)
            break
    plot_1dim(agent.point_info_manager.T_seq, 'reward.png')
    subprocess.call([
        "./convert_pngs2gif.sh demo_%s_iter_%d_eps_%f.gif" %
        (ACQUISITION_FUNC, nIter, ACQUISITION_PARAM_DIC["eps"])
    ],
                    shell=True)
    os.system("mv ./output/*.gif ./")