5D Library › 分销网络幂律激活、网红矩阵组合优化与激励稳定边界 · English
第四章 在投放中学习:汤普森抽样与 CAC 的尾部
先试一周,还是边投边学
第三章假定每位达人的获客能力已知。实际上要靠投放去学:四十位中小达人,每位每次点击的真实转化率不同(中位数 1%,差异很大),每周有固定数量的付费点击要分给他们,共十二周。三种规则:平均分配;第一周平均、之后全部给目前表现最好的人(贪心);以及汤普森抽样,按每位达人「是最好的人」的后验概率分配点击 (Thompson 1933; Russo et al. 2018)。
推导
# Chapter 4. p07: Learning which micro creators convert. 40 creators;
# each has a true conversion rate per click, lognormal with median 1%
# and log sd 0.8 (capped at 10%). Each week 2,000 or 8,000 paid clicks
# are split among them, for 12 weeks. Uniform: equal shares every
# week. Greedy: uniform in week 1, then everything to the best rate seen
# so far. Thompson: each creator's rate has a Beta(1 + sales, 1 + misses)
# posterior; clicks go in proportion to how often (in 100 draws) each
# creator's draw is the highest. Oracle: all clicks to the true best.
# Mean and 10th percentile over 150 repeats, seed 87.
import random
from math import exp, sqrt
K, WEEKS = 40, 12
def count(rng, n, p):
lam = n * p
if lam > 30:
return max(0, round(rng.gauss(lam, sqrt(lam * (1 - p)))))
k, t, u = 0, exp(-lam), rng.random()
c = t
while u > c:
k += 1
t *= lam / k
c += t
return k
def world(rng):
return [min(0.10, 0.01 * exp(0.8 * rng.gauss(0, 1))) for _ in range(K)]
def play(rng, rates, rule, clicks):
s, f, total = [0] * K, [0] * K, 0
for week in range(WEEKS):
if rule == "uniform" or (rule == "greedy" and week == 0):
share = [1.0 / K] * K
elif rule == "greedy":
best = max(range(K), key=lambda i: (s[i] + 1) / (s[i] + f[i] + 2))
share = [1.0 if i == best else 0.0 for i in range(K)]
else:
wins = [0] * K
for _ in range(100):
d = [rng.betavariate(1 + s[i], 1 + f[i]) for i in range(K)]
wins[d.index(max(d))] += 1
share = [w / 100 for w in wins]
for i in range(K):
n = int(round(clicks * share[i]))
if n:
c = count(rng, n, rates[i])
s[i] += c
f[i] += n - c
total += c
return total
if __name__ == "__main__":
rng = random.Random(87)
print(" clicks a week rule share of oracle 10th percentile")
for clicks in (2000, 8000):
res = {r: [] for r in ("uniform", "greedy", "thompson")}
for _ in range(150):
rates = world(rng)
o = max(rates) * clicks * WEEKS
for r in res:
res[r].append(play(rng, rates, r, clicks) / o)
for r, v in res.items():
v.sort()
print(" {:14,d} {:<8} {:15.3f} {:15.3f}".format(
clicks, r, sum(v) / 150, v[15]))
# clicks a week rule share of oracle 10th percentile
# 2,000 uniform 0.257 0.165
# 2,000 greedy 0.674 0.425
# 2,000 thompson 0.663 0.573
# 8,000 uniform 0.251 0.173
# 8,000 greedy 0.891 0.803
# 8,000 thompson 0.822 0.776平均分配只拿到理想情况(全部给真正最好的人)的四分之一左右(0.257 与 0.251)。每周 8,000 次点击时,贪心规则平均拿到 0.891,汤普森抽样 0.822,贪心反而略好:第一周每人分到两百次点击,已足以大致认出最好的人。每周只有 2,000 次点击时,两者的平均相近(0.674 与 0.663),但最差的一成情况差别明显:贪心只有 0.425,汤普森抽样有 0.573。预算小、第一周的信息不够时,贪心容易押错人,汤普森抽样的价值在于保护下限。
报告哪一个 CAC
每场中小达人活动投入 2,500 令吉,获得的客户数是一个泊松计数,其均值本身差异很大。p08 比较一年 384 场活动的几种 CAC 报告方式。
推导
# Chapter 4. p08: Which CAC to report. Each micro campaign spends
# RM 2,500 and wins a Poisson number of customers whose mean is
# lognormal (median 5, log sd 1.0). Over a year of 32 campaigns a month
# (384 campaigns), compare the share of campaigns with no customer at
# all, the mean and the median of per-campaign CAC (over campaigns with
# at least one customer), and the pooled CAC = total spend / total
# customers, and the share of campaigns that bring in half of all
# customers. 1,000 simulated years, seed 87.
import random
from math import exp
def poisson(rng, lam):
k, t, u = 0, exp(-lam), rng.random()
c = t
while u > c and k < 1000:
k += 1
t *= lam / k
c += t
return k
def year(rng):
wins = [poisson(rng, 5.0 * exp(rng.gauss(0, 1.0))) for _ in range(384)]
cac = sorted(2500.0 / w for w in wins if w)
zero = 1 - len(cac) / 384
pooled = 2500.0 * 384 / sum(wins)
acc, half = 0, 0
for w in sorted(wins, reverse=True):
acc += w
half += 1
if acc >= sum(wins) / 2:
break
return zero, sum(cac) / len(cac), cac[len(cac) // 2], pooled, half / 384
if __name__ == "__main__":
rng = random.Random(87)
ys = [year(rng) for _ in range(1000)]
names = ("share with no customer", "mean per-campaign CAC (RM)",
"median per-campaign CAC (RM)", "pooled CAC (RM)",
"campaigns giving half of sales")
print(" measure median 5% to 95% of years")
for j, name in enumerate(names):
v = sorted(y[j] for y in ys)
fmt = "{:.3f}" if j in (0, 4) else "{:,.0f}"
print(" {:<31} {:>7} {} to {}".format(
name, fmt.format(v[500]), fmt.format(v[50]), fmt.format(v[949])))
# measure median 5% to 95% of years
# share with no customer 0.073 0.049 to 0.094
# mean per-campaign CAC (RM) 723 663 to 789
# median per-campaign CAC (RM) 500 417 to 500
# pooled CAC (RM) 304 271 to 341
# campaigns giving half of sales 0.154 0.130 to 0.174约 0.073 的活动一个客户都没有,它们的 CAC 是无穷大,只能被排除在「平均每场 CAC」之外。即便如此,平均每场 CAC 是 723 令吉,每场 CAC 的中位数是 500 令吉,而真正决定盈亏的合并 CAC(总投入除以总客户)只有 304 令吉。三个数相差一倍以上,却都可以被叫作「CAC」。另外,0.154 的活动带来了一半的客户:活动层面的产出同样是重尾的。
注
CAC 的报告规矩: 以合并 CAC(总投入除以总客户)作为主要指标;另报零客户活动的比例与带来一半客户的活动比例;不要对每场活动的 CAC 取平均。
小结
在投放中学习时,预算充足则「先平均试一周再集中」已经不错;预算小时,汤普森抽样能明显改善最差情况。CAC 有三种常见算法,彼此相差一倍以上;只有合并 CAC 对应真实的盈亏。
参考文献
Fan, Y. (2026). Affiliate Network Power Laws, Influencer Portfolio Optimization and Incentive Stability Bounds: Heavy-Tailed Productivity, Markowitz Traffic Allocation and Single-Tier Commission Equilibria [分销网络幂律激活、网红矩阵组合优化与激励稳定边界] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090229 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).