time_num = settings.TIME_SLICE train_percent = 0.95 alpha = 0.95 x_values = [] y_values1 = [] y_values2 = [] y_values3 = [] # data, axis_users, axis_pois, check_data = init_data(region, filter_count, train_percent) data, axis_users, axis_pois, check_data = init_data_by_user(tuple([0, 3, 4, 5, 30]), filter_count, train_percent) user_num = len(axis_users) poi_num = len(axis_pois) init_tensor = [[[1/(poi_num * time_num * user_num) for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] transition_tensor = inreducible_tensor(mtt(data, user_num, poi_num), user_num, time_num, poi_num, alpha) res1, iterator_values1 = tensor_three_mode_product(transition_tensor, init_tensor) order = 1 while order <= settings.ITERATOR_NUMBER: x_values.append(order) y_values1.append(iterator_values1[order]) order += 1 label = ""+str(((settings.TIME_SLICE*user_num*poi_num)**2)) pylab.plot(x_values, y_values1, 'rs', linewidth=1, linestyle="-", label=label) data, axis_users, axis_pois, check_data = init_data_by_user(tuple([0, 3, 4]), filter_count, train_percent) user_num = len(axis_users) poi_num = len(axis_pois)
if __name__ == '__main__': # beijing = (39.433333, 41.05, 115.416667, 117.5) # haidian = (39.883333, 40.15, 116.05, 116.383333) region = (39.883333, 40.05, 116.05, 116.383333) filter_count = 600 alpha = 0.8 alpha_shift = 0.1 data, axis_users, axis_pois, check_data = init_data(region, filter_count) user_num = len(axis_users) time_num = settings.TIME_SLICE poi_num = len(axis_pois) transition_tensor = mtt(data, user_num, poi_num) transition_tensor2 = inreducible_tensor(transition_tensor, user_num, time_num, poi_num, alpha) transition_tensor3 = mtt(data, user_num, poi_num, zero_adjustment=False) # equal_all_sum_one: equal # init_tensor1 = [[[1/(poi_num * time_num * user_num) for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] # # random_all_sum_one: no zero element # temp_tensor = [[[random.choice([1, 2, 3, 100]) for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] # init_tensor2 = three_tensor_hadarmard(1/three_order_tensor_first_norm(temp_tensor), temp_tensor) # # init_tensor3 = [[[0 for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] # init_tensor3[0][0][0] = 1 # # random_all_sum_one: exist zero element # temp_tensor = [[[random.choice([0, 1, 2, 3, 4]) for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] # init_tensor3 = three_tensor_hadarmard(1/three_order_tensor_first_norm(temp_tensor), temp_tensor) # # user_slice_sum_one: equal
filter_count = 600 time_num = settings.TIME_SLICE train_percent = 0.1 x_values = [] y_values1 = [] y_values2 = [] order = 1 while train_percent < 1: data, axis_users, axis_pois, check_data = init_data( region, filter_count, train_percent) user_num = len(axis_users) poi_num = len(axis_pois) transition_tensor = mtt(data, user_num, poi_num) # equal_all_sum_one: equal init_tensor1 = [[[ 1 / (poi_num * time_num * user_num) for i in range(poi_num) ] for j in range(time_num)] for k in range(user_num)] # user_slice_sum_one: equal init_tensor2 = [[[1 / (poi_num * time_num) for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] res1, iterator_values1 = tensor_three_mode_product( transition_tensor, init_tensor1) res2, iterator_values2 = tensor_three_mode_product( transition_tensor, init_tensor2) # print res
values = [] x_values = [] y_values1 = [] y_values2 = [] y_values3 = [] y_values4 = [] order = 1 while alpha >= 0.2: data, axis_users, axis_pois, check_data = init_data( region, filter_count, train_percent) user_num = len(axis_users) poi_num = len(axis_pois) transition_tensor = inreducible_tensor(mtt(data, user_num, poi_num), user_num, time_num, poi_num, alpha) # equal_all_sum_one: equal init_tensor = [[[ 1 / (poi_num * time_num * user_num) for i in range(poi_num) ] for j in range(time_num)] for k in range(user_num)] res, iterator_values = tensor_three_mode_product( transition_tensor, init_tensor) values.append(iterator_values) alpha -= 0.2 print values # print values.keys() value1 = values[0]
region = (39.883333, 40.05, 116.05, 116.383333) filter_count = 600 time_num = settings.TIME_SLICE train_percent = 0.1 x_values = [] y_values1 = [] y_values2 = [] order = 1 while train_percent < 1: data, axis_users, axis_pois, check_data = init_data(region, filter_count, train_percent) user_num = len(axis_users) poi_num = len(axis_pois) transition_tensor = mtt(data, user_num, poi_num) # equal_all_sum_one: equal init_tensor1 = [[[1/(poi_num * time_num * user_num) for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] # user_slice_sum_one: equal init_tensor2 = [[[1/(poi_num * time_num) for i in range(poi_num)] for j in range(time_num)] for k in range(user_num)] res1, iterator_values1 = tensor_three_mode_product(transition_tensor, init_tensor1) res2, iterator_values2 = tensor_three_mode_product(transition_tensor, init_tensor2) # print res check_tensor = get_check_tensor(check_data, user_num, time_num, poi_num) residual1 = delta_tensor_norm(res1, check_tensor) residual2 = delta_tensor_norm(res2, check_tensor)