Exemplo n.º 1
0
    def evaluate(self, bi, wallet_distribution_type, sample_seed_set, ss_time):
        eva_start_time = time.time()
        ini = Initialization(self.dataset_name, self.product_name, wallet_distribution_type)

        seed_cost_dict = ini.constructSeedCostDict(self.seed_cost_option)
        graph_dict = ini.constructGraphDict(self.cascade_model)
        product_list = ini.constructProductList()[0]
        num_product = len(product_list)
        wallet_dict = ini.constructWalletDict()
        total_cost = sum(seed_cost_dict[k][i] for i in seed_cost_dict[0] for k in range(num_product))
        total_budget = round(total_cost / 2 ** bi, 4)

        eva = Evaluation(graph_dict, product_list, wallet_dict)
        print('@ evaluation @ ' + self.new_dataset_name + '_' + self.cascade_model + '_' + self.seed_cost_option +
              '\t' + self.model_name +
              '\t' + wallet_distribution_type + '_' + self.new_product_name + '_bi' + str(bi))
        sample_pnn_k = [0.0 for _ in range(num_product)]
        seed_diffusion_dict_k = {(k, s): 0 for k in range(num_product) for s in sample_seed_set[k]}

        for _ in range(self.eva_monte_carlo):
            pnn_k_list, seed_diffusion_dict = eva.getSeedSetProfit(sample_seed_set)
            sample_pnn_k = [(pnn_k + sample_pnn_k) for pnn_k, sample_pnn_k in zip(pnn_k_list, sample_pnn_k)]
            for seed_diffusion_flag in seed_diffusion_dict:
                seed_diffusion_dict_k[seed_diffusion_flag] += seed_diffusion_dict[seed_diffusion_flag]
        sample_pnn_k = [round(sample_pnn_k / self.eva_monte_carlo, 4) for sample_pnn_k in sample_pnn_k]
        sample_pro_k = [round(sample_pnn_k[k] * product_list[k][0], 4) for k in range(num_product)]
        sample_sn_k = [len(sample_sn_k) for sample_sn_k in sample_seed_set]
        sample_bud_k = [round(sum(seed_cost_dict[k][i] for i in sample_seed_set[k]), 4) for k in range(num_product)]
        sample_bud = round(sum(sample_bud_k), 4)
        sample_pro = round(sum(sample_pro_k), 4)
        seed_diffusion_list = [(seed_diffusion_flag, round(seed_diffusion_dict_k[seed_diffusion_flag] / self.eva_monte_carlo, 4)) for seed_diffusion_flag in seed_diffusion_dict_k]
        seed_diffusion_list = [(round(sd_item[1] * product_list[sd_item[0][0]][0], 4), sd_item[0], sd_item[1]) for sd_item in seed_diffusion_list]
        seed_diffusion_list = sorted(seed_diffusion_list, reverse=True)

        result = [sample_pro, sample_bud, sample_sn_k, sample_pnn_k, sample_pro_k, sample_bud_k, sample_seed_set]
        print('eva_time = ' + str(round(time.time() - eva_start_time, 2)) + 'sec')
        print(result)
        print('------------------------------------------')

        path0 = 'result/' + self.new_dataset_name + '_' + self.cascade_model + '_' + self.seed_cost_option
        if not os.path.isdir(path0):
            os.mkdir(path0)
        path = path0 + '/' + wallet_distribution_type + '_' + self.new_product_name + '_bi' + str(bi)
        if not os.path.isdir(path):
            os.mkdir(path)
        result_name = path + '/' + self.model_name + '.txt'

        fw = open(result_name, 'w')
        fw.write(self.new_dataset_name + '_' + self.cascade_model + '_' + self.seed_cost_option + '\t' +
                 self.model_name + '\t' +
                 wallet_distribution_type + '_' + self.new_product_name + '_bi' + str(bi) + '\n' +
                 'budget_limit = ' + str(total_budget) + '\n' +
                 'time = ' + str(ss_time) + '\n\n' +
                 'profit = ' + str(sample_pro) + '\n' +
                 'budget = ' + str(sample_bud) + '\n')
        fw.write('\nprofit_ratio = ')
        for kk in range(num_product):
            fw.write(str(sample_pro_k[kk]) + '\t')
        fw.write('\nbudget_ratio = ')
        for kk in range(num_product):
            fw.write(str(sample_bud_k[kk]) + '\t')
        fw.write('\nseed_number = ')
        for kk in range(num_product):
            fw.write(str(sample_sn_k[kk]) + '\t')
        fw.write('\ncustomer_number = ')
        for kk in range(num_product):
            fw.write(str(sample_pnn_k[kk]) + '\t')
        fw.write('\n\n')

        fw.write(str(sample_seed_set))
        for sd_item in seed_diffusion_list:
            fw.write('\n' + str(sd_item[1]) + '\t' + str(sd_item[0]) + '\t' + str(sd_item[2]))
        fw.close()
Exemplo n.º 2
0
    def evaluate(self, bi, wallet_key, sample_seed_set, ss_time):
        ss_time = 0.001 if ss_time == 0.0 else ss_time
        eva_start_time = time.time()
        ini = Initialization(self.data_key, self.prod_key, self.cas_key, wallet_key)

        seed_cost_dict = ini.constructSeedCostDict()
        graph_dict = ini.constructGraphDict()
        product_list = ini.constructProductList()[0]
        num_product = len(product_list)
        wallet_dict = ini.constructWalletDict()
        total_cost = sum(seed_cost_dict[i] for i in seed_cost_dict)
        total_budget = round(total_cost / 2 ** bi, 4)

        eva = Evaluation(graph_dict, product_list, wallet_dict)
        print('@ evaluation @ ' + self.data_name + '_' + self.cas_name +
              '\t' + self.model_name +
              '\t' + wallet_distribution_type_dict[wallet_key] + '_' + self.prod_name + '_bi' + str(bi))

        for times in range(self.times):
            model_name = self.model_name + '_' + str(times) if self.times == 10 else self.model_name

            sample_pnn_k, seed_diffusion_dict_k = eva.getSeedSetProfit(sample_seed_set)
            sample_pro_k = [round(sample_pnn_k[k] * product_list[k][0], 4) for k in range(num_product)]
            sample_sn_k = [len(sample_sn_k) for sample_sn_k in sample_seed_set]
            sample_bud_k = [round(sum(seed_cost_dict[i] for i in sample_seed_set[k]), 4) for k in range(num_product)]
            sample_bud = round(sum(sample_bud_k), 4)
            sample_pro = round(sum(sample_pro_k), 4)
            seed_diffusion_list = [(seed_diffusion_flag, seed_diffusion_dict_k[seed_diffusion_flag]) for seed_diffusion_flag in seed_diffusion_dict_k]
            seed_diffusion_list = [(round(sd_item[1] * product_list[sd_item[0][0]][0], 4), sd_item[0], sd_item[1]) for sd_item in seed_diffusion_list]
            seed_diffusion_list = sorted(seed_diffusion_list, reverse=True)

            result = [sample_pro, sample_bud, sample_sn_k, sample_pnn_k, sample_pro_k, sample_bud_k, sample_seed_set]
            print('eva_time = ' + str(round(time.time() - eva_start_time, 2)) + 'sec')
            print(result)
            print('------------------------------------------')

            path0 = 'result/' + self.data_name + '_' + self.cas_name
            if not os.path.isdir(path0):
                os.mkdir(path0)
            path = path0 + '/' + wallet_distribution_type_dict[wallet_key] + '_' + self.prod_name + '_bi' + str(bi)
            if not os.path.isdir(path):
                os.mkdir(path)
            result_name = path + '/' + model_name + '.txt'

            fw = open(result_name, 'w')
            fw.write(self.data_name + '_' + self.cas_name + '\t' +
                     model_name + '\t' +
                     wallet_distribution_type_dict[wallet_key] + '_' + self.prod_name + '_bi' + str(bi) + '\n' +
                     'budget_limit = ' + str(total_budget) + '\n' +
                     'time = ' + str(ss_time) + '\n\n' +
                     'profit = ' + str(sample_pro) + '\n' +
                     'budget = ' + str(sample_bud) + '\n')
            fw.write('\nprofit_ratio = ')
            for kk in range(num_product):
                fw.write(str(sample_pro_k[kk]) + '\t')
            fw.write('\nbudget_ratio = ')
            for kk in range(num_product):
                fw.write(str(sample_bud_k[kk]) + '\t')
            fw.write('\nseed_number = ')
            for kk in range(num_product):
                fw.write(str(sample_sn_k[kk]) + '\t')
            fw.write('\ncustomer_number = ')
            for kk in range(num_product):
                fw.write(str(sample_pnn_k[kk]) + '\t')
            fw.write('\n\n')

            fw.write(str(sample_seed_set))
            for sd_item in seed_diffusion_list:
                fw.write('\n' + str(sd_item[1]) + '\t' + str(sd_item[0]) + '\t' + str(sd_item[2]))
            fw.close()
Exemplo n.º 3
0
dataset_name = 'email' * (data_setting == 1) + 'dnc_email' * (data_setting == 2) + \
               'email_Eu_core' * (data_setting == 3) + 'NetHEPT' * (data_setting == 4)
new_dataset_name = 'email' * (data_setting == 1) + 'dnc' * (data_setting == 2) + \
                   'Eu' * (data_setting == 3) + 'Net' * (data_setting == 4)
seed_cost_option = 'dp' * (sc_option == 1) + 'd' * (sc_option == 2) + 'p' * (
    sc_option == 3)
cascade_model = 'ic' * (cm == 1) + 'wc' * (cm == 2)
product_name = 'item_lphc' * (prod_setting == 1) + 'item_hplc' * (prod_setting
                                                                  == 2)
new_product_name = 'lphc' * (prod_setting == 1) + 'hplc' * (prod_setting == 2)
wallet_distribution_type = 'm50e25' * (wd == 1) + 'm99e96' * (
    wd == 2) + 'm66e34' * (wd == 3)

ini = Initialization(dataset_name, product_name, wallet_distribution_type)
seed_cost_dict = ini.constructSeedCostDict(seed_cost_option)
wallet_dict = ini.constructWalletDict()
num_node = len(wallet_dict)
graph_dict = ini.constructGraphDict(cascade_model)
product_list, product_weight_list = ini.constructProductList()

ssmioa_model = SeedSelectionMIOA(graph_dict, seed_cost_dict, product_list,
                                 product_weight_list)
seed_mioa_dict = [{} for _ in range(num_product)]
mioa_dict = ssmioa_model.generateMIOA()
if epw_flag:
    mioa_dict = ssmioa_model.updateMIOAEPW(mioa_dict)
celf_heap = [(round((sum(mioa_dict[k][i][j][0]
                         for j in mioa_dict[k][i]) * product_list[k][0]) *
                    (1.0 if epw_flag else product_weight_list[k]), 4), k, i, 0)
             for k in range(num_product) for i in mioa_dict[k]]
heap.heapify_max(celf_heap)
Exemplo n.º 4
0
    def evaluate(self, bi, wallet_distribution_type, sample_seed_set, ss_time):
        eva_start_time = time.time()
        ini = Initialization(self.dataset_name, self.product_name, wallet_distribution_type)

        seed_cost_dict = ini.constructSeedCostDict(self.seed_cost_option)
        graph_dict = ini.constructGraphDict(self.cascade_model)
        product_list = ini.constructProductList()[0]
        num_product = len(product_list)
        wallet_dict = ini.constructWalletDict()
        total_cost = sum(seed_cost_dict[k][i] for i in seed_cost_dict[0] for k in range(num_product))
        total_budget = round(total_cost / 2 ** bi, 4)

        eva = Evaluation(graph_dict, product_list, wallet_dict)
        print('@ ' + self.model_name + ' evaluation @ dataset_name = ' + self.dataset_name + '_' + self.cascade_model + ', product_name = ' + self.product_name +
              ', seed_cost_option = ' + self.seed_cost_option + ', wd = ' + wallet_distribution_type)
        sample_pro_k, sample_pnn_k = [0.0 for _ in range(num_product)], [0 for _ in range(num_product)]

        for _ in range(self.eva_monte_carlo):
            pro_k_list, pnn_k_list = eva.getSeedSetProfit(sample_seed_set)
            sample_pro_k = [(pro_k + sample_pro_k) for pro_k, sample_pro_k in zip(pro_k_list, sample_pro_k)]
            sample_pnn_k = [(pnn_k + sample_pnn_k) for pnn_k, sample_pnn_k in zip(pnn_k_list, sample_pnn_k)]
        sample_pro_k = [round(sample_pro_k / self.eva_monte_carlo, 4) for sample_pro_k in sample_pro_k]
        sample_pnn_k = [round(sample_pnn_k / self.eva_monte_carlo, 4) for sample_pnn_k in sample_pnn_k]
        sample_bud_k = [round(sum(seed_cost_dict[sample_seed_set.index(sample_bud_k)][i] for i in sample_bud_k), 4) for sample_bud_k in sample_seed_set]
        sample_sn_k = [len(sample_sn_k) for sample_sn_k in sample_seed_set]
        sample_pro = round(sum(sample_pro_k), 4)
        sample_bud = round(sum(sample_bud_k), 4)

        result = [sample_pro, sample_bud, sample_sn_k, sample_pnn_k, sample_pro_k, sample_bud_k, sample_seed_set]
        print('eva_time = ' + str(round(time.time() - eva_start_time, 2)) + 'sec')
        print(result)
        print('------------------------------------------')

        path = 'result/' + self.model_name + '_' + wallet_distribution_type
        if not os.path.isdir(path):
            os.mkdir(path)
        fw = open(path + '/' + self.dataset_name + '_' + self.cascade_model + '_' + self.product_name + '_' + self.seed_cost_option +
                  '_ds' * self.diff_seed_option + '_bi' + str(bi) + '.txt', 'w')
        fw.write(self.model_name + ', ' + wallet_distribution_type + ', ' + self.dataset_name + '_' + self.cascade_model + ', ' + self.product_name +
                 ', seed_cost_option = ' + self.seed_cost_option + '\n\n' +
                 'total_budget = ' + str(total_budget) + '\n' +
                 'profit = ' + str(sample_pro) + '\n' +
                 'budget = ' + str(sample_bud) + '\n' +
                 'time = ' + str(ss_time) + '\n')
        fw.write('\nprofit_ratio =')
        for kk in range(num_product):
            fw.write(' ' + str(sample_pro_k[kk]))
        fw.write('\nbudget_ratio =')
        for kk in range(num_product):
            fw.write(' ' + str(sample_bud_k[kk]))
        fw.write('\nseed_number =')
        for kk in range(num_product):
            fw.write(' ' + str(sample_sn_k[kk]))
        fw.write('\ncustomer_number =')
        for kk in range(num_product):
            fw.write(' ' + str(sample_pnn_k[kk]))
        fw.write('\n\n')

        for r in result:
            # -- pro, bud, sn_k, pnn_k, pro_k, bud_k, seed_set --
            fw.write(str(r) + '\t')
        fw.close()