Inference
How we model event probabilities from design and context factors.
This page summarizes how Levered's models are structured statistically: what they treat as the random quantity, and which likelihood is used for which kind of metric. For the surrounding workflow, covering how observations are built and how posteriors drive serving, see models.
Outcomes and rewards
Every exposure ends in exactly one outcome, meaning the thing the user did (or didn't do). A reward is the value you attach to that outcome. The two are related but not the same, and the distinction shapes the whole inference setup:
- Binary outcomes. The user converted or did not. Two mutually exclusive outcomes, with the canonical reward map
{success: 1, failure: 0}. The expected reward is just the conversion probability. - Discrete (non-binary) outcomes. The user did one of several things: bought the Basic plan, bought the Pro plan, or bought nothing. Each outcome carries its own reward weight (say
{basic: 9, pro: 29, failure: 0}). The expected reward is the weight-averaged outcome probability. See exposures and rewards for how these outcome buckets are defined against your warehouse data. - Real-valued outcomes. The outcome is itself a number, such as revenue of an order or time on page. There is no finite set of buckets to weight; the reward is the outcome.
Why the model follows the outcome, not the reward
Levered always models the outcome-generating process and treats the reward as a deterministic function applied on top. All of the randomness lives in which outcome occurs; none lives in the reward map. So the likelihood is chosen to match the cardinality of the outcome space, not the numeric values of the rewards.
This matters for two reasons:
- Correct uncertainty. A weighted discrete reward is a mixture of point masses (a user pays exactly $9, $29, or $0, never $17.40). Modeling the reward directly with a continuous distribution would misstate the noise and produce miscalibrated posteriors. Modeling the outcome counts gets the uncertainty right by construction.
- Inference is separated from valuation. The posterior is over outcome probabilities. Reward weights only enter afterwards, when variants are scored: the expected reward of a variant is the posterior outcome distribution contracted with the weight vector. Thompson Sampling then draws from this induced reward posterior as usual.
Regressor categories
The linear predictor is built from three categories of regressors. They enter the model similarly, but play very different roles:
- Design factors are the levers, meaning the factor levels Levered chooses. Their combinations define the variants, and their effects are what the whole exercise is about: the posterior over design effects is what Thompson Sampling draws from.
- Context factors are user attributes (country, device type). They are observed, not chosen, and they interact with design factors. That interaction is what personalization is: the best variant is allowed to differ by segment.
- Nuisance factors are covariates the model must account for but that nobody optimizes or personalizes on. Today these are derived time corrections. Currently that means
is_weekend, computed from each observation's day at training time and from the calendar at serving time (the same derivation on both paths, so they cannot drift apart). They get first-order effects only: a nuisance level shifts the baseline for every variant equally, and never interacts with design factors. The model estimates them precisely so it can ignore them, hence the name.
Why nuisance factors matter: time confounds an adaptive experiment
In a classical fixed-split A/B test you can get away with ignoring time. Randomization guarantees every variant sees the same mix of weekdays and weekends, so a weekend conversion lift inflates all arms equally and cancels out of the comparison.
A bandit breaks that guarantee by design. Thompson Sampling reallocates traffic as the posterior evolves, so which variants get exposure is correlated with when they get it. If event probabilities are also time-varying, say conversion is systematically higher on weekends, then time becomes a confounder: a variant that happened to receive its exploration traffic over a weekend inherits the weekend's lift in its raw conversion rate and looks better than it is.
Without a time regressor, this bias feeds back into the policy:
- The weekend-inflated variant gets exploited, then underdelivers on weekdays; the freshly demoted variants get re-explored under yet another time mix. The posteriors whipsaw instead of tightening, and convergence stalls.
- Worse, the bias does not average out the way noise does. More data shrinks the posterior variance, but a confounded posterior shrinks around the wrong mean. The policy can confidently lock onto a suboptimal variant, and once its allocation collapses to a winner, the data needed to correct the error stops arriving.
The is_weekend nuisance factor removes the confounder at the source. The weekend lift is absorbed by its own additive term on the latent scale, so design effects are estimated within day-type. Every variant comparison is weekend against weekend and weekday against weekday, regardless of how unevenly the adaptive allocation spread each variant's exposures across the week. The design-effect posteriors stay unbiased, and Thompson Sampling converges to the variant that is genuinely best, not the one with the luckiest schedule.
Restricting nuisance factors to first-order terms is the flip side of the same policy: they correct the baseline, but they are not allowed to change the variant ranking the way context factors can. If you believed the best variant genuinely differed between weekends and weekdays, that would no longer be a nuisance. It would be a targeting dimension, which is the job of context factors.
Models by cardinality
All model variants share one architecture: a Bayesian factorization machine (FM). Each design, context, and nuisance factor level gets a first-order effect, and a low-rank factorization captures pairwise interactions between design and context levels. This is what lets a CMAB learn segment-specific winners without a free parameter for every variant-context cell. Effects are tied together with grouped hierarchical priors (levels of the same factor share a scale), and the posterior is sampled with MCMC (NUTS). What changes with the outcome's cardinality is only the likelihood head on top of this shared linear predictor.
Binary: Binomial FM
With two outcomes, observations aggregate to successes out of trials per cell, and the model is
successes ~ Binomial(n = trials, logit_p = eta)where eta is the FM predictor. The posterior over p is the posterior over conversion rate, which (with the canonical 0/1 weights) is directly the expected reward.
Discrete: Multinomial FM
With J > 2 outcomes, each cell carries a count vector over the outcome buckets (including the implicit failure bucket), and the likelihood generalizes to
counts ~ Multinomial(n = trials, p = softmax(eta))Every parameter gains an outcome-category axis, so the model learns how each factor level shifts probability between outcomes. A variant can lose signups overall but win on expected reward by shifting buyers from Basic to Pro. The linear terms are constrained to sum to zero across categories, which removes the softmax's shift invariance symmetrically instead of privileging one bucket as a reference. At J = 2 this is a reparameterization of the binomial model, so the two heads agree where they overlap.
Real-valued: continuous FM (planned)
Real-valued outcomes are not handled yet. The architecture extends naturally, though: keep the same FM predictor and swap in a continuous likelihood, for example a lognormal FM for positive, right-skewed metrics like revenue, where eta parameterizes the log-scale location. Since real-world value metrics are usually zero-inflated (most exposures generate no revenue at all), the practical shape is a hurdle model: a binomial FM for whether value occurs, composed with a continuous FM for how much, with the expected reward combining both parts. Until then, real-valued metrics can be approximated by discretizing into weighted outcome buckets and using the multinomial model.