|
@@ -1,6 +1,7 @@
|
|
|
import json
|
|
|
import random
|
|
|
import time
|
|
|
+import math
|
|
|
|
|
|
import gevent
|
|
|
from db_helper import RedisHelper
|
|
@@ -39,8 +40,11 @@ def thompson_process(creative_id):
|
|
|
random_flag = 'initial_random'
|
|
|
|
|
|
# 生成参数为(param_alpha+1, param_beta+1)的beta分布随机数
|
|
|
- score = random.betavariate(alpha=param_alpha + 1, beta=param_beta + 1)
|
|
|
- thompson_res = [creative_id, score, thompson_param_initial, thompson_param, random_flag]
|
|
|
+ alpha = math.log(param_alpha + 1) + 1
|
|
|
+ beta = math.log(param_beta + 1) + 1
|
|
|
+ score = random.betavariate(alpha=alpha, beta=beta)
|
|
|
+ betavariate_param = [alpha, beta]
|
|
|
+ thompson_res = [creative_id, score, thompson_param_initial, thompson_param, betavariate_param, random_flag]
|
|
|
return thompson_res
|
|
|
|
|
|
|
|
@@ -58,7 +62,8 @@ def get_creative_id_with_thompson(mid, creative_id_list, gevent_pool):
|
|
|
'score': thompson_res_rank[0][1],
|
|
|
'thompson_param_initial': thompson_res_rank[0][2],
|
|
|
'thompson_param': thompson_res_rank[0][3],
|
|
|
- 'random_flag': thompson_res_rank[0][4],
|
|
|
+ 'betavariate_param': thompson_res_rank[0][4],
|
|
|
+ 'random_flag': thompson_res_rank[0][5],
|
|
|
'thompson_res_rank': thompson_res_rank
|
|
|
}
|
|
|
return rank_res
|