这是比 UCB 更“聪明”的版本。
它不是固定探索比例,而是用 贝叶斯概率采样 自动决定谁该被推荐。
每个商品都有一个成功概率分布:
θi∼Beta(αi,βi)\theta_i \sim Beta(\alpha_i, \beta_i)
其中:
α = 成功次数(转化)
β = 失败次数(未转化)
每次推荐时:
从每个商品的 Beta 分布中随机采样一个值
选采样值最高的商品展示
根据用户行为更新 α / β
进入下一轮
| UCB | Thompson Sampling |
|---|---|
| 固定探索公式 | 动态概率探索 |
| 容易偏向高历史样本 | 自动测试不确定商品 |
| 冷启动慢 | 冷启动更自然 |
它天生适合:
新品扶持
爆款挖掘
长尾商品优化
每个商品存:
这是 Beta(1,1) = 完全均匀分布。
购买 → α + 1
曝光未购买 → β + 1
function gamma_rand($shape){
return pow(mt_rand()/mt_getrandmax(), 1/$shape);
}
function ai_thompson_select($products){
$best_score = 0;
$best_product = null;
foreach($products as $product){
$alpha = (int)get_post_meta($product->ID,’ai_alpha’,true);
$beta = (int)get_post_meta($product->ID,’ai_beta’,true);
if($alpha < 1) $alpha = 1;
if($beta < 1) $beta = 1;
$sample = ai_beta_sample($alpha,$beta);
if($sample > $best_score){
$best_score = $sample;
$best_product = $product;
}
}
return $best_product;
}
$alpha = (int)get_post_meta($product_id,’ai_alpha’,true);
$beta = (int)get_post_meta($product_id,’ai_beta’,true);
if($converted){
$alpha++;
}else{
$beta++;
}
update_post_meta($product_id,’ai_alpha’,$alpha);
update_post_meta($product_id,’ai_beta’,$beta);
}
把利润融入成功概率:
购买更新改成:
高利润商品成功一次,增长更快。
每天执行:
实现记忆衰减。
这形成真正的:
自学习自治推荐系统
| 模型 | 难度 | 智能度 | 是否适合电商 |
|---|---|---|---|
| 固定权重 | 低 | 低 | 基础 |
| UCB | 中 | 高 | 推荐 |
| Thompson | 高 | 很高 | 自治电商级 |
下一层是:
用户分层 Thompson Sampling
每个用户群体独立 Beta 分布
地区级概率模型
搜索意图级概率模型
那会进入真正的“流量统治级推荐系统”。