def create_D_function(camp, max_bid): large_storage_media = "/media/onetbssd/rlb/" src = "ipinyou" obj_type = "clk" clk_vp = 1 # N = 10000 N = 500 c0 = 1 / 8 gamma = 1 overwrite = False if src == "ipinyou": camps = config.ipinyou_camps_to_test data_path = config.ipinyouPath max_market_price = config.ipinyou_max_market_price camp_info = config.get_camp_info(camp, src) aution_in_file = data_path + camp + "/test.theta.txt" opt_obj = Opt_Obj(obj_type, int(clk_vp * camp_info["cost_train"] / camp_info["clk_train"])) B = int(camp_info["cost_train"] / camp_info["imp_train"] * c0 * N) large_storage_folder = large_storage_media + src + "/" + camp + "/bid-model/" if not os.path.exists(large_storage_folder): os.makedirs(large_storage_folder) env = BidEnv(camp_info, aution_in_file) agent = bidding_agent_rtb_rl_dp_tabular() agent.init(env, camp_info, opt_obj, gamma) setting = "{}, camp={}, algo={}, N={}, c0={}" \ .format(src, camp, "rlb_rl_fa", N, c0) bid_log_path = config.projectPath + "bid-log/{}.txt".format(setting) # Approximating D(t,b) function m_pdf = calc_m_pdf(camp_info["price_counter_train"]) D_function_path = large_storage_folder + "rlb_dnb_gamma={}_N={}_{}.txt".format(gamma, N, obj_type) print("D_function_path = " + D_function_path) if (not os.path.isfile(D_function_path)) or overwrite: # print("START: Approximating V function by dynamic programming... ") agent.calc_Dnb(N, B, max_market_price, m_pdf, D_function_path) # print("END: Approximating V function by dynamic programming.") else: agent.load_Dnb(N,B,D_function_path) X, Y = agent.run_and_output_datasets(bid_log_path, N, c0, max_bid, delimiter=" ", save_log=False) # Then train a NN using the Dnd function NN_model_path = large_storage_folder + "fa_dnb_gamma={}_N={}_{}.pickle".format(gamma, N, obj_type) NN_model_txt_path = large_storage_folder + "fa_dnb_gamma={}_N={}_{}.txt".format(gamma, N, obj_type) return agent, src, N, D_function_path, large_storage_folder, NN_model_path, NN_model_txt_path, opt_obj, camp_info, X, Y
dim = 2 net_type = "nn" src = "ipinyou" camp = "1458" if len(_argv) == 2: camp = _argv[1] obj_type = "clk" clk_vp = 1 N = 5000 tag = src + "_" + camp + "_" + model + "_" + net_type + "_N={}_{}".format( N, obj_type) + "_" + getTime() if src == "ipinyou": data_path = config.ipinyouPath camp_info = config.get_camp_info(camp, src) elif src == 'vlion': data_path = config.vlionPath camp_info = config.get_camp_info(camp, src) elif src == "yoyi": data_path = config.yoyiPath camp_info = config.get_camp_info(camp, src) opt_obj = Opt_Obj( obj_type, int(clk_vp * camp_info["cost_train"] / camp_info["clk_train"])) avg_theta = camp_info["clk_train"] / camp_info["imp_train"] if obj_type == "profit": avg_theta *= opt_obj.clk_v b_bound = 800
if model == "dnb": dim = 2 net_type = "nn" src = "ipinyou" camp = "1458" if len(_argv) == 2: camp = _argv[1] obj_type = "clk" clk_vp = 1 N = 5000 tag = src + "_" + camp + "_" + model + "_" + net_type + "_N={}_{}".format(N, obj_type) + "_" + getTime() if src == "ipinyou": data_path = config.ipinyouPath camp_info = config.get_camp_info(camp, src) elif src == 'vlion': data_path = config.vlionPath camp_info = config.get_camp_info(camp, src) elif src == "yoyi": data_path = config.yoyiPath camp_info = config.get_camp_info(camp, src) opt_obj = Opt_Obj(obj_type, int(clk_vp * camp_info["cost_train"] / camp_info["clk_train"])) avg_theta = camp_info["clk_train"] / camp_info["imp_train"] if obj_type == "profit": avg_theta *= opt_obj.clk_v b_bound = 800 n_bound = 50 max_train_round = 500
# Generate testing and training datasets for target campaing. camp_to_test = config.ipinyou_camps_to_test[0] camp_to_test_file = data_path + camp_to_test + "/test.theta.txt" training_filename, testing_filename, len_training, len_testing = generate_training_and_evaluation_files_for_target_camp( camp_to_test_file, 0.8) T_shoots_list = [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1] #T_shoots_list = [.1] T_shoots_list = np.array(T_shoots_list) T_shoots_list = T_shoots_list * len_training T_shoots_list = T_shoots_list.astype(int) for T_shoots_learning_size in T_shoots_list: for camp in camps: camp_info = config.get_camp_info(camp, src) aution_in_file = data_path + camp + "/test.theta.txt" opt_obj = Opt_Obj( obj_type, int(clk_vp * camp_info["cost_train"] / camp_info["clk_train"])) B = int(camp_info["cost_train"] / camp_info["imp_train"] * c0 * N) large_storage_media = "/media/onetbssd/rlb/" # Create log file folder location. if not os.path.exists(config.projectPath + "bid-log"): os.makedirs(config.projectPath + "bid-log") # Create training merged set: train_camps = []