5D Library › Order-Bump Friction Elasticity, One-Click Upsell Kinetics and Cross-Domain Recommendation Matrices · 中文
Chapter 6. Learning the Bump Price Online, and Simpson’s Paradox
Even split or Thompson sampling
Chapter 1 said the best bump price must be measured on one’s own traffic. The usual method is an even split: four candidate prices each take a quarter of orders, and the best is chosen when the test ends. Another is Thompson sampling: keep a beta posterior for each price’s take rate, choose for each order the price whose sampled revenue is highest, and gradually concentrate traffic on good prices (Thompson 1933; Russo et al. 2018).
Calculation
# Chapter 6. p11: Choosing a bump price by Thompson sampling.
# Four candidate bump prices with true take rates from p01's model at
# zero friction. Revenue per order = price x take. Over 20,000 orders we
# compare an even split (A/B/C/D test, then nothing learned until the
# end) with Thompson sampling on Beta posteriors of take, choosing the
# price with the highest sampled revenue. Regret = revenue lost against
# always using the best price.
import random
from math import log, erf, sqrt
def take(p, med=0.45, sd=0.8):
return 0.5 * (1 - erf((log(p / 98) - log(med)) / sd / sqrt(2)))
PRICES = (19.0, 29.0, 44.0, 69.0)
def run(policy, n=20000, seed=78011):
rng = random.Random(seed)
a = [1.0] * 4
b = [1.0] * 4
rev = 0.0
for t in range(n):
if policy == "split":
k = t % 4
else:
k = max(range(4), key=lambda i: PRICES[i] * rng.betavariate(
a[i], b[i]))
if rng.random() < take(PRICES[k]):
rev += PRICES[k]
a[k] += 1
else:
b[k] += 1
return rev
if __name__ == "__main__":
for p in PRICES:
print(" bump RM {:4.0f}: take {:.3f}, per order {:.2f}".format(
p, take(p), p * take(p)))
best = max(p * take(p) for p in PRICES) * 20000
for pol in ("split", "thompson"):
r = run(pol)
print(" {:8s} revenue RM {:,.0f}; regret RM {:,.0f}".format(
pol, r, best - r))
# bump RM 19: take 0.854, per order 16.22
# bump RM 29: take 0.700, per order 20.30
# bump RM 44: take 0.501, per order 22.05
# bump RM 69: take 0.288, per order 19.86
# split revenue RM 392,991; regret RM 48,005
# thompson revenue RM 439,165; regret RM 1,831In the model of Chapter 1, the four candidate prices RM 19, 29, 44 and 69 bring bump revenue per order of 16.22, 20.30, 22.05 and 19.86; the best is RM 44. Over 20,000 orders, the even split earns RM 48,005 less than “always using the best price”, Thompson sampling only RM 1,831 less. The price is that Thompson sampling delivers “money earned” rather than a clean estimate of effects; if precise take rates for each price must be reported, the even split is better suited.
Pooled numbers can deceive
Calculation
# Chapter 6. p12: Simpson's paradox in pooled cross-sell numbers.
# Two recommendation layouts, shown to two traffic sources with very
# different baseline interest (returning buyers vs new readers). Layout
# B wins within each source but loses in the pooled total, because it
# was shown mostly to new readers. Counts are illustrative.
DATA = {"A": {"returning": (900, 81), "new": (100, 2)},
"B": {"returning": (100, 10), "new": (900, 27)}}
if __name__ == "__main__":
for lay, d in DATA.items():
for src, (n, k) in d.items():
print(" layout {} {:9s}: {:4d} shown, {:3d} clicks, rate {:.3f}"
.format(lay, src, n, k, k / n))
n = sum(v[0] for v in d.values())
k = sum(v[1] for v in d.values())
print(" layout {} pooled : {:4d} shown, {:3d} clicks, rate {:.3f}"
.format(lay, n, k, k / n))
# layout A returning: 900 shown, 81 clicks, rate 0.090
# layout A new : 100 shown, 2 clicks, rate 0.020
# layout A pooled : 1000 shown, 83 clicks, rate 0.083
# layout B returning: 100 shown, 10 clicks, rate 0.100
# layout B new : 900 shown, 27 clicks, rate 0.030
# layout B pooled : 1000 shown, 37 clicks, rate 0.037Two recommendation layouts are shown to returning buyers and to new readers. Layout B has a click-through of 0.100 among returning buyers (A: 0.090) and 0.030 among new readers (A: 0.020), winning in both groups; pooled, B has only 0.037 and A 0.083, because B was shown mostly to new readers, whose click-through is low anyway. This is Simpson’s paradox (Simpson 1951): comparisons of recommendation effects must be stratified by traffic source, or randomised.
Note
The only reliable way to avoid the trap is randomisation. If layouts are assigned by hand or by algorithm according to traffic type, the pooled comparison mixes the layout effect with the traffic difference.
Summary
Thompson sampling cuts the loss of a price test from RM 48,005 to RM 1,831 (illustrative model) and suits continuous optimisation aimed at revenue. Comparisons of recommendation effects must be stratified or randomised; otherwise pooled numbers can point the opposite way to every stratum.
References
Fan, Y. (2026). Order-Bump Friction Elasticity, One-Click Upsell Kinetics and Cross-Domain Recommendation Matrices: Zero-Reentry Impulse Attachment, Conditional Mutual Information and Cart-Value Multipliers [结账顺手加购弹性、一键升单动力学与跨领域推荐矩阵] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090207 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).