Commit 1b433ee2 authored by 段英荣's avatar 段英荣

调试

parent 87717ea5
......@@ -21,7 +21,7 @@ import time
class LinUCB:
d = 2
d = 3
alpha = 0.1
r1 = 10
r0 = -0.1
......@@ -182,10 +182,10 @@ class LinUCB:
r = cls.r0
if user_features_array:
xa = np.array(user_features_array)
xaT = np.array(user_features_array)
else:
xa = np.array([user_features])
xaT = np.transpose(xa)
xaT = np.array([user_features])
xa = np.transpose(xaT)
ori_redis_tag_data = redis_cli.hget(redis_name_linucb_matrix, content_id)
......
......@@ -223,43 +223,44 @@ if __name__ == "__main__":
linucb_matrix_redis_name = "strategy:linucb:matrix:content_type:diary"
# diary_click_file = "/data/log/duan_test/feed_query_data/feed_click_info.txt"
# diary_fd = open(diary_click_file,"r")
#
# for line in diary_fd.readlines():
# line = line.strip()
# line = line.strip("\n")
# line = line.strip("\r")
# line = line.strip(" ")
#
# item_list = line.split(",")
# device_id = item_list[3]
# diary_id = item_list[4]
# # Generate_Feature_Info.generate_user_feature_to_redis(device_id, label_encoder,onehot_encoder)
#
# user_feature_list = Generate_Feature_Info.get_user_feature_by_device_id(device_id)
# content_feature_list = Generate_Feature_Info.get_content_feature(diary_id)
#
# offi_context_feature_list = list()
# if len(user_feature_list)>0 and len(content_feature_list)>0:
# offi_context_feature_list.append(user_feature_list[0])
# offi_context_feature_list.append(content_feature_list[0])
#
# print(offi_context_feature_list)
# LinUCB.update_linucb_info(user_features_array=offi_context_feature_list,reward=1,content_id=diary_id,
# redis_name_linucb_matrix=linucb_matrix_redis_name,redis_cli=redis_client)
# diary_fd.close()
diary_click_file = "/data/log/duan_test/feed_query_data/feed_click_info.txt"
diary_fd = open(diary_click_file,"r")
for line in diary_fd.readlines():
line = line.strip()
line = line.strip("\n")
line = line.strip("\r")
line = line.strip(" ")
duan_device_id="868771031984211"
user_feature_list = Generate_Feature_Info.get_user_feature_by_device_id(duan_device_id)
item_list = line.split(",")
device_id = item_list[3]
diary_id = item_list[4]
# Generate_Feature_Info.generate_user_feature_to_redis(device_id, label_encoder,onehot_encoder)
begin=time.time()
test_feature = [user_feature_list[0],user_feature_list[0]]
all_diary_content_redis_dict = redis_client.hgetall("strategy:linucb:matrix:content_type:diary")
top_tag_dict, top_tag_set = LinUCB.linucb_recommend_tag(all_diary_content_redis_dict,test_feature,list(all_diary_content_redis_dict.keys()))
print(time.time()-begin)
print(top_tag_dict)
user_feature_list = Generate_Feature_Info.get_user_feature_by_device_id(device_id)
content_feature_list = Generate_Feature_Info.get_content_feature(diary_id)
offi_context_feature_list = [1]
if len(user_feature_list)>0 and len(content_feature_list)>0:
offi_context_feature_list.append(user_feature_list[0])
offi_context_feature_list.append(content_feature_list[0])
print(offi_context_feature_list)
print("*"*50)
LinUCB.update_linucb_info(user_features_array=offi_context_feature_list,reward=1,content_id=diary_id,
redis_name_linucb_matrix=linucb_matrix_redis_name,redis_cli=redis_client)
diary_fd.close()
# duan_device_id="868771031984211"
# user_feature_list = Generate_Feature_Info.get_user_feature_by_device_id(duan_device_id)
#
# begin=time.time()
# test_feature = [user_feature_list[0],user_feature_list[0]]
# all_diary_content_redis_dict = redis_client.hgetall("strategy:linucb:matrix:content_type:diary")
# top_tag_dict, top_tag_set = LinUCB.linucb_recommend_tag(all_diary_content_redis_dict,test_feature,list(all_diary_content_redis_dict.keys()))
# print(time.time()-begin)
# print(top_tag_dict)
# test_val_list = ["切开双眼皮"]
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment