A/B tests and experiment programmes¶
sequential_analysis.procedures.ab
¶
Continuously monitored A/B tests.
Each observation is one unit (a user, a session) with the arm it was assigned to and its outcome. The tests may be looked at after every unit and stopped whenever one likes; none needs a sample size fixed in advance.
SampleRatioMismatch -- is traffic split in the intended proportions? Units fall into arm k with probability p_k under H0. The Bayes factor of a Dirichlet(c p) mixture of multinomials against H0 (Lindon and Malek 2022),
BF_n = prod_t (c p_{k_t} + n_{k_t, t-1}) / ((c + t - 1) p_{k_t}),
is a test martingale under H0, so rejecting at BF_n >= 1/alpha is an
exact level-alpha test at any stopping time. A mismatch means the
assignment or the logging is broken and no other result of the
experiment can be trusted; run it alongside every A/B test.
TwoProportionTest -- do two conversion rates differ? Exact, any n. H0: p_T = p_C (or p_T <= p_C, p_T >= p_C), the common rate unknown. By default (method="grow") units are grouped, in arrival order, into blocks of k_T treatment and k_C control units, and each block contributes the e-value of Turner, Ly and Grunwald (2024),
E_block = prod q_a(y_T) prod q_b(y_C) / prod q_pbar(y),
pbar = (k_T a + k_C b) / (k_T + k_C),
q_r being the Bernoulli(r) likelihood and (a, b) the rates estimated
from the earlier blocks. pbar is the projection of (a, b) onto H0
that makes E_block an e-value for every common rate at once (checked
in the tests by enumerating every outcome of a block), so the product
over blocks is a test supermartingale under H0 and Ville's inequality
gives P(sup E >= 1/alpha) <= alpha. This needs an allocation that does
not look at outcomes -- randomised, or a fixed schedule, as in an A/B
test: a later block's estimates use units that arrived after some of
its own, which is harmless only when the assignment ignores outcomes.
Estimation errors in the common rate cancel between numerator and
denominator; by simulation it needs 1.3 to 1.6 times the units of the
asymptotic test, against 2.3 to 3 times for method="universal".
method="universal" is sequential universal inference (Wasserman,
Ramdas and Balakrishnan 2020), E_n = m_T(y_T) m_C(y_C) / sup_H0 L, with
Beta marginal likelihoods m_k: no blocks, valid for any allocation
rule, adaptive ones included, at the price of more units.
ABTest -- difference of means, optionally adjusted by a covariate. With units assigned to treatment with known probability pi (the allocation), the inverse-propensity score
psi_t = (T_t / pi - C_t / (1 - pi)) (y_t - f_{t-1}(x_t))
has mean E[y(T)] - E[y(C)] for every f fitted on earlier units only:
assignment is independent of x and of f. Choosing f as the regression
of y on the pre-experiment covariate x fitted on the past (pooled over
arms) removes the part of the variance that x explains, like CUPED
(Deng et al. 2013), without the bias that fitting on the current unit
would bring. The confidence sequence for the effect is the asymptotic
one of Waudby-Smith et al. (2024) applied to psi, valid uniformly over
time once n is large (start=1000 by default; see robust_mean). Without
a covariate f is the running mean of y, which already removes the
variance an uncentred inverse-propensity estimate would carry.
`variance_ratio` reports var(psi with covariate) / var(psi without):
the fraction of the sample size the covariate saves is 1 minus it.
e_bh and MultipleTests -- many metrics or many arms, false discovery rate.
Every exact test here produces an e-process: at any stopping time its
value is an e-value. The e-BH procedure (Wang and Ramdas 2022) rejects
the k hypotheses with the largest e-values, k the largest such that the
k-th largest is at least K / (k alpha); the false discovery rate is at
most alpha under any dependence between the tests. MultipleTests runs
several procedures on the same observations and applies e-BH after
every step: the set it reports when one stops has FDR <= alpha (the
guarantee is at the stopping time chosen, not simultaneously for all
times). MultipleTests.versus_control builds the multi-arm
comparison: each treatment arm against the control.
Cost per step (PERFORMANCE.md): constant time and state for the three tests, 3 to 4 µs; MultipleTests costs the sum of its tests plus e-BH over K e-values (25 µs for two two-proportion tests).
SampleRatioMismatch
¶
Bases: Procedure
Anytime-valid test that units arrive in each arm in the intended proportions.
weights are the intended proportions (normalised to sum 1); the input
is the index of the arm a unit was assigned to. concentration c sets
the Dirichlet(c p) mixture: larger values look for smaller imbalances
and need more units to find a large one.
log_e_value(counts)
¶
Closed form of log BF_n (the step accumulates it term by term).
TwoProportionTest
¶
Bases: Procedure
Exact anytime-valid comparison of two conversion rates; see the module docstring.
Inputs: the arm of the unit (arm_input, an integer label) and its
outcome (input, 0 or 1). arms = (treatment label, control label);
units of other arms are ignored, so several tests can share one stream
of a multi-arm experiment. alternative "greater" tests H0: p_T <= p_C
against p_T > p_C.
method="grow" (the default) groups units into blocks of block =
(treatment units, control units) in arrival order and multiplies the
blocks' e-values; choose block in the proportion of the allocation,
(1, 1) for 50/50, (2, 1) for 2:1. Units wait for their block, so the
state holds the unmatched outcomes: with random allocation in that
proportion their number grows like the square root of n.
method="universal" needs no blocks and is valid for any allocation
rule, outcome-adaptive ones (bandits) included, but needs about twice
as many units.
prior = (a, b) is the Beta prior of the plug-in estimates (grow) or of
the mixture (universal); (1/2, 1/2) by default.
log_null_likelihood(successes, trials)
¶
log sup of the likelihood over H0 (method="universal").
plug_in(successes, trials)
¶
(a, b, p): the alternative fitted on completed blocks, and its projection on H0.
For a one-sided test an estimate on the null side is not bet on: a = b = p, and the block's e-value is 1.
block_log_e(a, b, p, treated, control)
¶
log of one block's e-value: prod q_a(y_T) prod q_b(y_C) / prod q_p(y).
ABTest
¶
Bases: Procedure
Anytime-valid confidence sequence for a difference of means, with covariate adjustment.
Inputs: the arm (arm_input), the outcome (input) and, with
covariate=True, a pre-experiment covariate (covariate_input) such as
the same metric before the experiment. allocation is the probability
that a unit of the two compared arms goes to treatment, as set by the
randomisation. Rejects H0: no effect when 0 leaves the interval. The
coverage is asymptotic (see the module docstring and robust_mean).
BoundedABTest
¶
Bases: Procedure
Exact anytime-valid confidence sequence and test for an effect on a bounded metric.
For outcomes y in [lower, upper] -- a conversion (0/1), a click-through
rate, a capped revenue, a score -- and units assigned to treatment with
known probability allocation, the scores
psi = (T / pi - C / (1 - pi)) (y - c), c = (lower + upper) / 2,
have conditional mean E[y(T)] - E[y(C)] given the past, whatever the distribution of y, and lie in [-B, B] with B = (upper - lower) / 2 * max(1/pi, 1/(1 - pi)). The confidence sequence for their mean is the hedged-capital one of Waudby-Smith and Ramdas (BettingConfidenceSequence) and the test of effect = effect0 the betting test (BettingMeanTest): both exact for every distribution, at every sample size, monitored after every unit -- unlike ABTest, whose coverage is asymptotic. The price is width: the scores' range grows as the allocation moves away from 50/50.
The allocation must be the randomisation probability, the same for
every unit and independent of outcomes. Units of other arms are
ignored. log_e_value is an e-process (usable by MultipleTests).
When the split changes during the experiment -- traffic redirected
towards the better arm, as ThompsonAllocation does -- give
propensity_input: an input holding, for each unit, the probabilities
with which it could have gone to each of the arm_count arms (the
shares in force when it was assigned), and floor, a lower bound on
the probabilities of the two compared arms. The scores are then
psi = (1[arm = T] / pi_T - 1[arm = C] / pi_C) (y - c)
for every unit (the propensities must sum to 1, and arms are labelled 0..arm_count-1), 0 for units of other arms, which counts them as they must be counted. Their conditional mean is still E[y(T)] - E[y(C)], whatever the rule that set the shares, as long as each unit's shares were fixed before its outcome; their range is (upper - lower) / (2 floor). The sequence and the test stay exact.
Cost per step (PERFORMANCE.md): that of BettingConfidenceSequence on
grid points: 0.14 ms with numpy, 0.5 to 0.7 ms in Python for grid=1000.
MultipleTests
¶
Bases: Procedure
Several anytime-valid tests on the same observations, with e-BH false discovery rate control.
tests maps a name to a procedure with an e-process (one that declares
e_value_field: TwoProportionTest, SampleRatioMismatch,
NormalMixtureSPRT, TMixtureSPRT, BettingMeanTest, SequentialSignTest,
QuantileTest, KernelTwoSampleTest). A test that has stopped keeps its
last e-value.
versus_control(treatments, control=0, *, alpha=0.05, test=None)
classmethod
¶
Each treatment arm against the control: test(treatment, control), two proportions by default.
e_bh(log_e_values, alpha)
¶
Indices rejected by the e-BH procedure at level alpha, from log e-values.
With K e-values, the k largest are rejected for the largest k such that the k-th largest e-value is at least K / (k alpha); none if there is no such k. FDR <= alpha under arbitrary dependence (Wang and Ramdas 2022).
sequential_analysis.procedures.rates
¶
Exact anytime-valid comparison of two event rates: orders per user, errors per hour.
Each unit (a user, a machine, a site) reports its arm, a count k of events and its exposure e (days observed, sessions, hours of operation); its count is Poisson with mean lambda_arm * e. The question is the rate ratio rho = lambda_T / lambda_C.
Units are paired as they arrive: a unit waits for the next unit of the other arm, and is replaced (not used) if one of its own arm comes first, so that a pair is always two units adjacent in time. Given the pair's total count K, its treatment count is
K_T ~ Binomial(K, rho E_T / (rho E_T + E_C)),
E_T and E_C the two exposures, whatever the common rate -- which may drift over time (seasonality, a growing user base): only the two units of a pair have to share it, and they are neighbours. Which units are paired depends on the arms alone, never on the counts, so discarding the replaced units costs data (a third of the units at 50/50, almost half at 30/70), not validity. Conditioning makes H0: rho = rho0 a simple hypothesis, so
E_pair = Bin(K_T; K, q(rho_hat)) / Bin(K_T; K, q(rho0)),
with rho_hat estimated from earlier pairs, has conditional mean exactly 1 under H0, and the product over pairs is a test martingale: an exact anytime-valid test. The confidence sequence for rho inverts the same e-processes over a log-spaced grid of rho0 (each excluded value stays excluded; the interval is intersected over time). If every grid point is excluded, the least-excluded one says where rho is: beyond the top of the grid, the interval stays [top point, None); below the bottom, (None, bottom point]; inside the grid (a level-alpha event) it collapses onto that point and its neighbours, as in AnytimeLogRankTest.
The counts must be Poisson given the exposure. Overdispersed counts (negative binomial: some users order far more than others) break exactness: use BoundedABTest on capped counts or ABTest instead. As in TwoProportionTest the allocation must not depend on outcomes.
Cost per step (PERFORMANCE.md): a few µs, plus O(grid) for each completed pair -- 55 µs per unit on average with grid=200; the state holds at most one waiting unit and one log-wealth per grid point.
RateRatioTest
¶
Bases: Procedure
Exact anytime-valid test and confidence sequence for a ratio of Poisson rates; see the module docstring.
Inputs: the arm (arm_input), the count (input, a non-negative
integer) and the exposure (exposure_input, positive; omit it with
exposure=False when every unit has exposure 1). rho0 is the null
rate ratio, alternative "greater" tests rho <= rho0 against rho > rho0.
grid points log-spaced over [ratio_range[0], ratio_range[1]] carry the
confidence sequence (grid=0: none).
plug_in(counts, exposures)
¶
rho_hat from the completed pairs, shrunk towards 1 by prior pseudo-events in each arm.
share(rho, e_t, e_c)
staticmethod
¶
P(an event of the pair is the treatment unit's) under rate ratio rho.
pair_log_e(rho_hat, rho0, alternative, k_t, k, e_t, e_c)
¶
log of one pair's e-value against rho0 (0 when not betting).
sequential_analysis.procedures.online_fdr
¶
Online false discovery rate control for a stream of experiments (e-LOND).
A team runs experiments one after another, each ending with an e-value for its own hypothesis (the e-process of any test here, read at the time the experiment stopped). Deciding each one on its own at level alpha lets false discoveries pile up; waiting to apply e-BH to all of them is impossible when decisions are needed now. e-LOND (Xu and Ramdas 2024) decides each hypothesis when its e-value arrives:
reject H_t when e_t >= 1 / alpha_t, alpha_t = alpha gamma_t (D_{t-1} + 1),
D_{t-1} being the number of discoveries so far and gamma a fixed non-negative sequence with sum <= 1. The false discovery rate, E[false discoveries / max(1, discoveries)], is at most alpha at every time, under arbitrary dependence between the experiments. Every discovery raises the level of the following ones; the default gamma is that of Javanmard and Montanari (2018), gamma_j proportional to log(max(j, 2)) / (j exp(sqrt(log j))), with the constant 0.07720838 of Ramdas et al. (2017), which makes it sum to 0.976 (checked in the tests): it suits an open-ended series. For a series of at most N experiments planned in advance, horizon=N spreads the budget evenly, gamma_j = 1/N, which demands far less evidence of the later experiments; the N+1-th is refused.
The level alpha_t is known before experiment t starts, so the experiment itself can be run until its e-process reaches 1/alpha_t (a test with alpha = alpha_t), or stopped earlier: an e-process read at any stopping time is an e-value.
The input is the experiment's log e-value (input, "log_e" by default),
a finite number; pass a large negative one for an e-value of 0.
Cost per step (PERFORMANCE.md): constant, about 1 µs; a constant state.
sequential_analysis.procedures.ratio
¶
Continuously monitored A/B tests of ratio metrics and of relative lift.
Many product metrics are ratios whose analysis unit is not the unit of randomisation. Revenue per session, click-through rate (clicks per impression) and average order value (revenue per order) are examples. Users are randomised, and each user contributes a numerator y_i and a denominator d_i: their revenue and their number of sessions. The metric of an arm is
R = E[y] / E[d], estimated by the ratio of sums R_hat = sum y / sum d
over the arm's users. Treating the sessions as independent observations is wrong: one user's sessions are correlated, and the per-session standard error is too small. The delta method on the user totals is correct (Deng, Knoblich and Lu 2018, "Applying the delta method in metric analytics"). To first order, the error of the ratio of sums in arm k is the average of the per-user influence scores
phi_i = (y_i - R d_i) / E[d],
so its variance is estimated by
V_k = sum_k (y_i - R_hat d_i)^2 / (sum_k d_i)^2 * n_k / (n_k - 1),
with the sum over the arm's n_k users. This is Deng et al.'s formula (s_y^2 - 2 R s_yd + R^2 s_d^2) / (n_k dbar^2). The state holds each arm's sums and centred second moments of y and d, updated as in Welford's algorithm, so it has a constant size.
RatioABTest -- confidence sequences for R_T - R_C and for R_T / R_C - 1. Over all n users of the two arms, the treatment indicator T_i and (y_i, d_i) are independent and identically distributed. The difference of the ratios of sums is then
R_hat_T - R_hat_C = R_T - R_C + (1/n) sum_i psi_i + r_n,
psi_i = T_i (y_i - R_T d_i) / E[T d] - C_i (y_i - R_C d_i) / E[C d].
The psi_i are independent, with mean zero. The remainder r_n is a
product of two estimation errors, so by the law of the iterated
logarithm it is O(log log n / n) almost surely. The asymptotic
confidence sequence of Waudby-Smith, Arbour, Sinha, Kennedy and Ramdas
(2024, "Time-uniform central limit theory and asymptotic confidence
sequences") covers the mean of such scores uniformly over time. It is
the one that AsymptoticConfidenceSequence and ABTest use, and its
half-width is a function of n and the scores' standard deviation:
(R_hat_T - R_hat_C) +- half_width(n, sqrt(n (V_T + V_C))),
since n (V_T + V_C) estimates var(psi). The remainder shifts the sum
of the scores by O(log log n), which is less than the strong
approximation error the asymptotic sequence already allows. Coverage
is therefore 1 - alpha asymptotically and uniformly over time, as for
ABTest. It is not exact at small n.
The relative lift L = R_T / R_C - 1 has its sequence on the log scale:
log(R_hat_T / R_hat_C) +- half_width(n, sqrt(n (V_T / R_hat_T^2 + V_C / R_hat_C^2))),
mapped back by exp(.) - 1. The bounds stay above -1 and are not
symmetric about the estimate. This needs both ratios positive, and
no lift is reported otherwise. The direct delta-method interval
L_hat +- ... missed far more often in the simulations below, so it is
not offered. Monitored from 30 users it missed in 0.11 to 0.35 of the
runs, against 0.048 to 0.098 on the log scale.
The test rejects H0 when `effect0` leaves the chosen sequence. With
scale="difference" it tests R_T - R_C = effect0; with
scale="relative" it tests R_T / R_C - 1 = effect0. The decision then
stays. The intervals are not intersected over time, because
asymptotic coverage does not license that.
With denominator=False every d_i is 1. R is then the mean per user,
and the same procedure gives the relative lift of a mean: of revenue
per user, for instance, which is how product teams report results.
The difference is then the usual difference of means with the
unpooled variance s_T^2 / n_T + s_C^2 / n_C.
Why not a predictable plug-in? ABTest centres each unit with a
regression fitted on earlier units only, so that its scores have
conditional mean exactly the effect. No such score exists for a
ratio: R_T - R_C is not linear in the means. The one-step scores
R_T,t-1 - R_C,t-1 + T_t (y_t - R_T,t-1 d_t) / (pi dbar_T,t-1) - ...,
with plug-ins from the past, have a conditional bias that is a product
of two estimation errors, of the same order as r_n above. So the
predictable form gains no exactness. It also centres the interval
away from the ratio of sums that is reported. In the simulations
below its time-uniform miscoverage was within 0.013 of the ratio of
sums' in every cell. The ratio of sums is used.
The allocation probability cancels from the ratio of sums, so it is
not a parameter. The variance uses the observed arm sizes, which
allows for chance imbalance. It must still be fixed for the whole
run and independent of the outcomes.
Assumptions: users, the units of randomisation, are independent, and
each one is counted once, with its totals over the window of the
analysis. They are randomised to an arm with a fixed probability
that does not look at outcomes. y and d have finite variances, a
little more than two moments in fact. d >= 0. A user with d = 0,
who had no session, must be kept: dropping them conditions on an
outcome of the treatment. Coverage is asymptotic, as for ABTest.
Measured coverage. The table gives the probability that the interval
misses the truth at some n from `start` to 20,000 users, at
alpha = 0.05, over 1,000 runs per cell. The Monte Carlo standard
error is about 0.007. Sessions are Poisson(2) per user, so 14% of
users have none. Revenue per session is lognormal, with a per-user
multiplier exp(sigma_u Z - 0.1 sessions) shared by the user's
sessions. This makes sessions within a user strongly correlated, and
spend per session depends on the number of sessions. The treatment
multiplies spend by 1 (no effect) or 1.1:
allocation, sigma_u effect difference, from 30 / 300 / 1000 lift, from 30 / 300 / 1000
50/50, 1.0 none 0.028 / 0.028 / 0.020 0.048 / 0.041 / 0.025
+10% 0.035 / 0.033 / 0.027 0.060 / 0.052 / 0.033
50/50, 1.5 (heavy) none 0.019 / 0.018 / 0.014 0.070 / 0.050 / 0.031
+10% 0.020 / 0.019 / 0.016 0.056 / 0.044 / 0.029
30/70, 1.0 none 0.038 / 0.032 / 0.022 0.058 / 0.041 / 0.027
+10% 0.071 / 0.059 / 0.033 0.078 / 0.058 / 0.034
30/70, 1.5 (heavy) none 0.046 / 0.044 / 0.035 0.098 / 0.069 / 0.043
+10% 0.065 / 0.058 / 0.047 0.096 / 0.065 / 0.045
From 1,000 users, the default `start`, the miscoverage was at most
0.047. Monitored from 30 users, the difference's exceeded alpha only
at 30/70 (up to 0.071), and the lift's in 7 of the 8 cells (up to
0.098). This is the small-sample behaviour of the asymptotic sequence
(see robust_mean).
The naive per-session test treats every session as an observation.
It has the same estimate and the same boundary, but the session-level
variance. In the same simulations, with no effect, it rejected in
0.24 to 0.26 of the runs when monitored from 1,000 users, and in 0.35
to 0.43 from 30 users. This test rejected in 0.014 to 0.035 from
1,000 users, and in 0.019 to 0.046 from 30.
Not covered:
- Covariate adjustment of a ratio metric (CUPED for ratios).
- Randomisation by clusters above the unit, such as households or
cities, which needs the cluster as the unit.
- Interference between units.
- An allocation that changes during the run.
- Small samples: below a few hundred users, use an exact test on a
bounded metric (BoundedABTest) or a Poisson rate (RateRatioTest).
Cost per step (PERFORMANCE.md): constant time and state, 7 µs (ABTest with a covariate: 5 µs on the same machine). The state is each arm's count, two sums and three centred second moments.
RatioABTest
¶
Bases: Procedure
Anytime-valid confidence sequences for a ratio metric's difference and relative lift; see the module docstring.
Inputs: the user's arm (arm_input), numerator (input) and
denominator (denominator_input, at least 0; leave it out with
denominator=False to compare means per user). arms = (treatment
label, control label). Units of other arms are ignored. Rejects H0
when effect0 leaves the sequence of the chosen scale:
"difference" (R_T - R_C) or "relative" (R_T / R_C - 1). No interval
is reported before start users. The coverage is asymptotic (see
robust_mean).
half_width(n, sd)
¶
The asymptotic confidence sequence's half-width for scores of standard deviation sd.
ratio(state, k)
staticmethod
¶
The ratio of sums of arm k (0: treatment, 1: control).
variance(state, k)
staticmethod
¶
V_k, the delta-method variance of arm k's ratio of sums; None below two units or while sum d = 0.
sequential_analysis.procedures.allocation
¶
Redirecting traffic during an experiment: Thompson allocation and a deployment rule.
ThompsonAllocation follows K arms of an experiment and says how to split the next units between them. Each arm's mean gets a posterior:
- metric="binary" (conversions): Beta(a + successes, b + failures);
- metric="normal" (revenue, time, any real outcome): with the prior p(mu, sigma^2) ~ 1/sigma^2, the mean's posterior is Student t with n - 1 degrees of freedom, location the sample mean and scale s / sqrt(n).
From these it computes, for each arm, the probability that it is the best (the highest mean) and its expected loss, E[max_j mu_j - mu_k]: what is lost, in units of the metric, by deploying arm k if it is not the best. Both are one-dimensional integrals,
P(k best) = int f_k(x) prod_{j != k} F_j(x) dx,
E[max_j mu_j] = int x d(prod_j F_j(x)),
computed by Gauss-Legendre quadrature (16 points) on pieces cut at each posterior's location and multiples of its scale, so that every posterior, narrow or wide, is resolved: deterministic, no random draws.
The allocation is Thompson sampling's: arm k gets the share P(k best),
which sends most traffic to arms likely to be best and keeps exploring
the others in proportion to their chance. floor reserves a minimum
share for every arm (so that every comparison keeps data coming and the
inverse-propensity weights of the tests stay bounded):
share_k = floor + (1 - K floor - reserve) P(k best) + reserve [k = control].
reserve keeps a fixed extra share for a control arm (a holdout), so
that every variant can still be compared with the control quickly: with
traffic redirected, the comparisons the traffic left behind starve, and a
test of a variant against a control at the floor needs many units.
Until every arm has min_units units the split stays equal; afterwards
the shares are recomputed every update_every units, as a production
system would push a new split periodically. The output's shares are
the split to use for the next units, and the assignment of each unit must
use them: record them with the unit (they are the propensities that
BoundedABTest(propensity_input=...) needs).
deploy is the expected-loss rule of Bayesian A/B testing: once some
arm's expected loss is at most threshold (the "threshold of caring", in
units of the metric), that arm can take all the traffic. This is a
decision rule, not a test: it controls the expected cost of the choice
under the posterior, not an error rate. When an error rate matters,
confirm with a test that stays valid under redirected traffic --
TwoProportionTest(method="universal") for conversions, or
BoundedABTest(propensity_input=...) for any bounded metric -- before
deploying. Tests that assume a fixed split (TwoProportionTest with
method="grow", ABTest, RatioABTest, RateRatioTest, BoundedABTest without
propensities) are not valid once the split follows the outcomes.
Cost per step (PERFORMANCE.md): constant time and state. The quadrature
runs once per update_every units and takes about 15 ms for three binary
arms (the incomplete beta function at some 800 points per arm): 0.15 ms
per unit with the default update_every=100.
ThompsonAllocation
¶
Bases: Procedure
Traffic split by Thompson sampling with a floor, and the expected-loss deployment rule.
See the module docstring. arms is the number of arms, labelled
0..arms-1; the inputs are a unit's arm and its outcome.
best_arm_probabilities(posteriors, metric)
¶
(P(k best), expected loss of k) for each arm, by piecewise Gauss-Legendre quadrature.