def check_lambda_by_profit(cam_data, cam_data_length, cam_r, cam_base_ctr, dsp_budget, volume, dsp_l, cam_v, para, algo):
    # init
    cost = 0
    profit = 0
    budget_run_out = False
    cam_data_index = arbitrage_rtb_test.init_cam_data_index(cam_data)
    cam_vc = cam_v.copy()  # we will change cam_vc when one campaign runs out of data
    data_run_out = arbitrage_rtb_test.check_data_ran_out(cam_data_index, cam_data_length, cam_vc, volume)

    # start simulation
    while (not data_run_out) and (not budget_run_out):
        cam = arbitrage_rtb_test.sample_cam(cam_vc)
        yzp = arbitrage_rtb_test.next_cam_data(cam_data, cam_data_index, cam_data_length, cam)
        if yzp == -1:
            print cam_data_length
            print cam_data_index
        clk = yzp[0]
        mp = yzp[1]
        pctr = yzp[2]
        r = cam_r[cam]
        bid = arbitrage_rtb_test.bidding(r / config.cpc_payoff_ratio, cam_base_ctr[cam], r, dsp_l, pctr, algo, para)
        if bid > mp:  # win auction
            cost += mp
            if algo == "lin" or algo == "ortb":
                profit += clk  # these two algorithms care about clicks
            else:
                profit += clk * r - mp * 1.0E-3  # not cpm counting

        budget_run_out = (cost >= dsp_budget)
        data_run_out = arbitrage_rtb_test.check_data_ran_out(cam_data_index, cam_data_length, cam_vc, volume)
    return -profit
def estimate_mu_sigma(cam_data, cam_data_length, cam_r, cam_base_ctr, dsp_budget, volume, dsp_l, cam_v,
                      algo_one_para, algo):
    cam_mu = {}
    cam_sigma = {}  # standard deviation
    para = algo_one_para[algo]
    for cam in cam_data:
        data = cam_data[cam]
        length = cam_data_length[cam]
        profit_margins = []
        index = 0
        for process in range(config.e_step_mu_process_num):
            cost = 0
            profit = 0
            for i in range(min(volume, len(data))):
                yzp = data[index]
                index = (index + 1) % length  # rotation
                clk = yzp[0]
                mp = yzp[1]
                pctr = yzp[2]
                r = cam_r[cam]

                # bid = 0
                # if algo == "sam":
                #     bid = arbitrage_rtb_test.bidding_sam(pctr, r, dsp_l, para)
                # elif algo == "lin":
                #     bid = arbitrage_rtb_test.bidding_lin(pctr, cam_base_ctr[cam], para)
                # elif algo == "ortb":
                #     bid = arbitrage_rtb_test.bidding_ortb(pctr, cam_base_ctr[cam], r, dsp_l, para)
                # else:
                #     print "e-step portfolio algorithm name error"

                bid = arbitrage_rtb_test.bidding(r / config.cpc_payoff_ratio, cam_base_ctr[cam], r, dsp_l, pctr, algo, para)

                if bid > mp:  # win auction
                    cost += mp * 1.0E-3 # should have the same unit
                    profit += clk * r - mp * 1.0E-3  # not cpm counting
                if cost >= dsp_budget:
                    break
            profit_margin = profit / max(cost, 0.1) # avoid zero division
            profit_margins.append(profit_margin)
        cam_mu[cam] = numpy.mean(profit_margins)
        cam_sigma[cam] = numpy.std(profit_margins)
    return cam_mu, cam_sigma
Esempio n. 3
0
def get_market_price_up_value(cam_data, cam_r, cam_original_ecpc, cam_original_ctr,
                              dsp_l, algo, para):
    up_value = 0.
    num = 0
    for cam in cam_data:
        data = cam_data[cam]
        original_ecpc = cam_original_ecpc[cam]
        original_ctr = cam_original_ctr[cam]
        r = cam_r[cam]
        for yzp in data:
            clk = yzp[0]
            mp = yzp[1]
            pctr = yzp[2]
            bid = arbitrage_rtb_test.bidding(original_ecpc, original_ctr, r, dsp_l, pctr, algo, para)
            if bid > mp:
                up_value += (bid - mp) * 0.5
            num += 1
    up_value /= num
    return up_value
def get_market_price_up_value(cam_data, cam_r, cam_original_ecpc,
                              cam_original_ctr, dsp_l, algo, para):
    up_value = 0.
    num = 0
    for cam in cam_data:
        data = cam_data[cam]
        original_ecpc = cam_original_ecpc[cam]
        original_ctr = cam_original_ctr[cam]
        r = cam_r[cam]
        for yzp in data:
            clk = yzp[0]
            mp = yzp[1]
            pctr = yzp[2]
            bid = arbitrage_rtb_test.bidding(original_ecpc, original_ctr, r,
                                             dsp_l, pctr, algo, para)
            if bid > mp:
                up_value += (bid - mp) * 0.5
            num += 1
    up_value /= num
    return up_value
def check_lambda_by_profit(cam_data, cam_data_length, cam_r, cam_base_ctr,
                           dsp_budget, volume, dsp_l, cam_v, para, algo):
    # init
    cost = 0
    profit = 0
    budget_run_out = False
    cam_data_index = arbitrage_rtb_test.init_cam_data_index(cam_data)
    cam_vc = cam_v.copy(
    )  # we will change cam_vc when one campaign runs out of data
    data_run_out = arbitrage_rtb_test.check_data_ran_out(
        cam_data_index, cam_data_length, cam_vc, volume)

    # start simulation
    while (not data_run_out) and (not budget_run_out):
        cam = arbitrage_rtb_test.sample_cam(cam_vc)
        yzp = arbitrage_rtb_test.next_cam_data(cam_data, cam_data_index,
                                               cam_data_length, cam)
        if yzp == -1:
            print cam_data_length
            print cam_data_index
        clk = yzp[0]
        mp = yzp[1]
        pctr = yzp[2]
        r = cam_r[cam]
        bid = arbitrage_rtb_test.bidding(r / config.cpc_payoff_ratio,
                                         cam_base_ctr[cam], r, dsp_l, pctr,
                                         algo, para)
        if bid > mp:  # win auction
            cost += mp
            if algo == "lin" or algo == "ortb":
                profit += clk  # these two algorithms care about clicks
            else:
                profit += clk * r - mp * 1.0E-3  # not cpm counting

        budget_run_out = (cost >= dsp_budget)
        data_run_out = arbitrage_rtb_test.check_data_ran_out(
            cam_data_index, cam_data_length, cam_vc, volume)
    return -profit