Пример #1
0
    linucb_regret_matrix = np.zeros((loop, iteration))
    linucb_error_matrix = np.zeros((loop, iteration))
    gob_regret_matrix = np.zeros((loop, iteration))
    gob_error_matrix = np.zeros((loop, iteration))

    for l in range(loop):
        print('loop/total_loop', l, loop)
        linucb_model = LINUCB(dimension, user_num, item_num, pool_size,
                              item_feature_matrix, user_feature_matrix,
                              true_payoffs, 0.25, delta, sigma, state)
        gob_model = GOB(dimension, user_num, item_num, pool_size,
                        item_feature_matrix, user_feature_matrix, true_payoffs,
                        true_adj, true_lap, 0.25, delta, sigma, b, state)

        linucb_regret, linucb_error, linucb_beta, linucb_x_norm, linucb_inst_regret, linucb_ucb, linucb_sum_x_norm, linucb_real_beta = linucb_model.run(
            user_seq, item_pool_seq, iteration)
        gob_regret, gob_error, gob_beta, gob_x_norm, gob_ucb, gob_sum_x_norm, gob_real_beta = gob_model.run(
            user_seq, item_pool_seq, iteration)

        linucb_regret_matrix[l], linucb_error_matrix[
            l] = linucb_regret, linucb_error
        gob_regret_matrix[l], gob_error_matrix[l] = gob_regret, gob_error

    linucb_regret = np.mean(linucb_regret_matrix, axis=0)
    linucb_error = np.mean(linucb_error_matrix, axis=0)
    gob_regret = np.mean(gob_regret_matrix, axis=0)
    gob_error = np.mean(gob_error_matrix, axis=0)

    linucb_regret_matrix_beta[index] = linucb_regret
    linucb_error_matrix_beta[index] = linucb_error
    gob_regret_matrix_beta[index] = gob_regret
    linucb_model = LINUCB(dimension, iteration, item_num, user_feature,
                          item_features, true_payoffs, alpha, delta, sigma,
                          beta)
    lints_model = LINTS(dimension, iteration, item_num, user_feature,
                        item_features, true_payoffs, alpha, delta, sigma,
                        epsilon)
    giro_model = GIRO(dimension, iteration, item_num, user_feature,
                      item_features, true_payoffs, alpha, sigma, pseudo_num)
    online_model = LSE_soft_online(dimension, iteration, item_num,
                                   user_feature, item_features, true_payoffs,
                                   alpha, sigma, step_size_beta, weight1,
                                   beta_online, gamma, time_width)

    #####################

    linucb_regret, linucb_error = linucb_model.run()
    lints_regret, lints_error = lints_model.run()
    giro_regret, giro_error = giro_model.run()

    lse_soft_regret, lse_soft_error, lse_soft_prob_matrix, lse_soft_s_matrix, lse_soft_g_s_matrix = lse_soft_model.run(
        user_feature, item_features, true_payoffs)
    online_regret, online_error, online_soft_matrix, online_s_matrix, online_beta_list = online_model.run(
    )

    linucb_regret_matrix[l] = linucb_regret
    lints_regret_matrix[l] = lints_regret
    giro_regret_matrix[l] = giro_regret
    lse_soft_regret_matrix[l] = lse_soft_regret
    online_regret_matrix[l] = online_regret
    offline_prob_matrix[l] = lse_soft_prob_matrix[best_arm]
    online_prob_matrix[l] = online_soft_matrix[best_arm]
	edges=nx.draw_networkx_edges(graph, pos, width=0.05, alpha=1, edge_color='k')
	edge_labels=nx.draw_networkx_edge_labels(graph,pos, edge_labels=labels, font_size=5)
	plt.axis('off')
	plt.savefig(path+'network_rbf_thres_%s_edge_num_%s'%(int(thres*10), edge_num)+'.png', dpi=300)
	plt.savefig(path+'network_rbf_thres_%s_edge_num_%s'%(int(thres*10), edge_num)+'.eps', dpi=300)


	for l in range(loop):
		print('loop/total_loop', l, loop)
		linucb_model=LINUCB(dimension, user_num, item_num, pool_size, item_feature_matrix, user_feature_matrix, true_payoffs, alpha, delta, sigma, state)
		gob_model=GOB(dimension, user_num, item_num, pool_size, item_feature_matrix, user_feature_matrix, true_payoffs, true_adj, alpha, delta, sigma, beta, state)
		lapucb_model=LAPUCB(dimension, user_num, item_num, pool_size, item_feature_matrix, user_feature_matrix, true_payoffs, true_adj, noise_matrix, alpha, delta, sigma, beta, thres, state)
		lapucb_sim_model=LAPUCB_SIM(dimension, user_num, item_num, pool_size, item_feature_matrix, user_feature_matrix, true_payoffs, true_adj, noise_matrix, alpha, delta, sigma, beta, thres, state)
		club_model = CLUB(dimension, user_num, item_num, pool_size, item_feature_matrix, user_feature_matrix, true_payoffs, alpha, alpha_2, delta, sigma, beta, state)

		linucb_regret, linucb_error, linucb_beta=linucb_model.run(user_seq, item_pool_seq, iteration)
		gob_regret, gob_error, gob_beta, gob_graph=gob_model.run(user_seq, item_pool_seq, iteration)
		lapucb_regret, lapucb_error, lapucb_beta, lapucb_graph=lapucb_model.run(user_seq, item_pool_seq, iteration)
		lapucb_sim_regret, lapucb_sim_error, lapucb_sim_beta, lapucb_sim_graph=lapucb_sim_model.run( user_seq, item_pool_seq, iteration)
		club_regret, club_error,club_cluster_num, club_beta=club_model.run(user_seq, item_pool_seq, iteration)

		linucb_regret_matrix[l], linucb_error_matrix[l]=linucb_regret, linucb_error
		gob_regret_matrix[l], gob_error_matrix[l], gob_graph_matrix[l]=gob_regret, gob_error, gob_graph
		lapucb_regret_matrix[l], lapucb_error_matrix[l], lapucb_graph_matrix[l]=lapucb_regret, lapucb_error, lapucb_graph
		lapucb_sim_regret_matrix[l], lapucb_sim_error_matrix[l], lapucb_sim_graph_matrix[l]=lapucb_sim_regret, lapucb_sim_error, lapucb_sim_graph
		club_regret_matrix[l], club_error_matrix[l]=club_regret, club_error


	linucb_regret=np.mean(linucb_regret_matrix, axis=0)
	linucb_error=np.mean(linucb_error_matrix, axis=0)
	gob_regret=np.mean(gob_regret_matrix, axis=0)
                          item_feature, true_payoffs, alpha, delta, sigma,
                          gaps)

    lse_model = LSE(dimension, iteration, item_num, user_feature, item_feature,
                    true_payoffs, alpha, delta, sigma)

    lse_soft_model = LSE_soft2(dimension, iteration, item_num, user_feature,
                               item_feature, true_payoffs, alpha, sigma,
                               step_size_beta, step_size_gamma, weight1,
                               lse_soft_loops)

    # linucb_soft_model=LinUCB_soft(dimension, iteration, item_num, user_feature, item_feature, true_payoffs, alpha, sigma, step_size, lse_soft_loops)

    #####################

    linucb_regret, linucb_error, linucb_item_index, linucb_upper_matrix, linucb_low_matrix, linucb_payoff_error_matrix, linucb_worst_payoff_error, linucb_noise_norm, linucb_error_bound, linucb_threshold = linucb_model.run(
    )

    lse_regret, lse_error, lse_upper_matrix, lse_low_matrix, lse_payoff_error_matrix, lse_worst_payoff_error, lse_nosie_norm, lse_noise_norm_phase, lse_error_bound, lse_error_bound_phase, lse_threshold, lse_est_beta, lse_left_item_num, lse_est_beta2 = lse_model.run(
    )

    lse_soft_regret, lse_soft_error, lse_soft_beta, lse_soft_gamma, lse_soft_max = lse_soft_model.run(
    )

    # linucb_soft_regret, linucb_soft_error, linucb_soft_beta, linucb_soft_gamma, linucb_soft_max=linucb_soft_model.run()

    linucb_regret_matrix[l] = linucb_regret
    lse_regret_matrix[l] = lse_regret
    lse_soft_regret_matrix[l] = lse_soft_regret
    lse_soft_beta_matrix[l] = lse_soft_beta
    lse_soft_gamma_matrix[l] = lse_soft_gamma
    lse_soft_prob_best_arm_matrix[l] = lse_soft_max[best_arm]
Пример #5
0
sigma = 0.01  # noise
delta = 0.1  # high probability
alpha = 1  # regularizer
state = 1  # small beta (exploitation), large beta(exploration), 1: true beta

item_feature = Normalizer().fit_transform(
    np.random.normal(size=(item_num, dimension)))
user_feature = np.random.normal(size=dimension)
user_feature = user_feature / np.linalg.norm(user_feature)
true_payoffs = np.dot(item_feature, user_feature)
best_arm = np.argmax(true_payoffs)

linucb_model = LINUCB(dimension, iteration, item_num, user_feature,
                      item_feature, true_payoffs, alpha, delta, sigma, state)

linucb_regret, linucb_error, linucb_item_index, linucb_x_norm_matrix, linucb_est_y_matrix, linucb_hist_low_matrix, linucb_hist_upper_matrix = linucb_model.run(
    iteration)

x = range(iteration)
color_list = matplotlib.cm.get_cmap(name='Paired', lut=None).colors

plt.figure(figsize=(5, 5))
for i in range(item_num):
    if i == best_arm:
        plt.plot(x,
                 linucb_est_y_matrix[i],
                 color=color_list[i],
                 linewidth=3,
                 label='Best Arm=%s' % (i))
        plt.plot(x,
                 linucb_hist_upper_matrix[i],
                 '-*',
Пример #6
0
user_feature = np.random.normal(size=dimension)
user_feature = user_feature / np.linalg.norm(user_feature)
true_payoffs = np.dot(item_feature, user_feature)
best_arm = np.argmax(true_payoffs)

linucb_model = LINUCB(dimension, iteration, item_num, user_feature,
                      item_feature, true_payoffs, alpha, delta, sigma, state)

eli_model = ELI(dimension, phase_num, item_num, user_feature, item_feature,
                true_payoffs, alpha, delta, sigma)

lse_test_model = LSE_TEST(dimension, iteration, item_num, user_feature,
                          item_feature, true_payoffs, alpha, delta, sigma)
#####################

linucb_regret, linucb_error, linucb_item_index, linucb_x_norm_matrix = linucb_model.run(
    iteration)

eli_regret, eli_error, eli_item_index, eli_x_norm_matrix, eli_est_y_matrix = eli_model.run(
    iteration)

lse_test_regret, lse_test_error, lse_test_low_matrix, lse_test_upper_matrix, lse_test_x_norm_matrix = lse_test_model.run(
    iteration)

plt.figure(figsize=(5, 5))
plt.plot(linucb_regret, label='LinUCB')
plt.plot(eli_regret, label='Eliminator')
plt.plot(lse_test_regret, label='LSE')
plt.legend(loc=0, fontsize=12)
plt.xlabel('Time', fontsize=12)
plt.ylabel('Cumulative Regret', fontsize=12)
plt.show()