def mtt(data, user_num, poi_num, zero_adjustment=True): print "共有" + str(user_num) + "个用户" for key in data.keys(): print "用户" + str(key) + "序列为" + str(data[key]) correlation_matrix = get_correlation_matrix(data, user_num) nor_cor_matrix = normalize(correlation_matrix) print "归一化相关系数矩阵: ", nor_cor_matrix transition_tensor = build_six_order_transition_tensor(data, poi_num, nor_cor_matrix, zero_adjustment) print "转移张量非零元素占比:", sparsity(transition_tensor) print "转移张量是否满足随机性:", check_six_order_transition_tensor(transition_tensor) return transition_tensor
def mtt(data, user_num, poi_num, zero_adjustment=True): print "共有" + str(user_num) + "个用户" for key in data.keys(): print "用户" + str(key) + "序列为" + str(data[key]) correlation_matrix = get_correlation_matrix(data, user_num) nor_cor_matrix = normalize(correlation_matrix) print "归一化相关系数矩阵: ", nor_cor_matrix transition_tensor = build_six_order_transition_tensor( data, poi_num, nor_cor_matrix, zero_adjustment) print "转移张量非零元素占比:", sparsity(transition_tensor) print "转移张量是否满足随机性:", check_six_order_transition_tensor(transition_tensor) return transition_tensor
def serialization(data, user_num, poi_num): correlation_matrix = get_correlation_matrix(data, user_num) nor_cor_matrix = normalize(correlation_matrix) print "归一化相关系数矩阵: ", nor_cor_matrix for i in range(user_num): for j in range(user_num): if zero_adjustment: temp_tensor = build_fouth_order_influence_tensor(data[i], data[j], poi_num, True) else: temp_tensor = build_fouth_order_influence_tensor(data[i], data[j], poi_num, False) print str(i)+"对"+str(j)+"是否满足随机性条件", check_fourth_order_transition_tensor(temp_tensor) fouth_influence_tensor = fouth_tensor_hadarmard(nor_cor_matrix[i][j], temp_tensor) file_name = str(i)+"_"+str(j)+".db" file_path = "data/step_one/"+file_name print file_path transition_tensor_db = open(file_path, 'w') pickle.dump(fouth_influence_tensor, transition_tensor_db) transition_tensor_db.close()