LeveredDocs
Concepts

Inference

The statistical structure of the Levered model, with the likelihood used for each kind of metric and the regressors in the linear predictor.

This page describes the statistical structure of the Levered model. It covers the quantity that the model treats as random and the likelihood used for each kind of metric. For the surrounding workflow, including how observations are built and how posteriors drive serving, see models.

Outcomes and rewards

Each exposure ends in one outcome, which is what the user did or did not do. A reward is the value assigned to that outcome. The model treats the two separately, as described in Modeled quantity. There are three kinds of outcome:

  • Binary outcomes. The user converted or did not convert. The two outcomes are mutually exclusive, and the canonical reward map is {success: 1, failure: 0}. The expected reward is the conversion probability.
  • Discrete (non-binary) outcomes. The user did one of several things, for example bought the Basic plan, bought the Pro plan, or bought nothing. Each outcome has its own reward weight, for example {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 the warehouse data.
  • Real-valued outcomes. The outcome is a number, such as the revenue of an order or the time on page. There is no finite set of buckets to weight, and the reward is equal to the outcome.

Modeled quantity

Levered models the outcome-generating process and treats the reward as a deterministic function of the outcome. The randomness is in which outcome occurs. The reward map contains no randomness. The likelihood is therefore chosen to match the cardinality of the outcome space. The numeric values of the rewards do not affect the choice of likelihood.

This has two consequences:

  1. Uncertainty. A weighted discrete reward is a mixture of point masses. A user pays $9, $29 or $0, and no amount in between such as $17.40. A continuous distribution on the reward would misstate the noise and produce miscalibrated posteriors. A model of the outcome counts represents this uncertainty correctly.
  2. Separation of inference and valuation. The posterior is over outcome probabilities. Reward weights 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.

Regressor categories

The linear predictor is built from three categories of regressors. They enter the model in a similar way and have different roles:

  • Design factors are the factors whose levels Levered chooses. Their combinations define the variants. Thompson Sampling draws from the posterior over the design effects.
  • Context factors are user attributes such as country and device type. Levered observes them and does not choose them. They interact with design factors. Through this interaction, the best variant can differ by segment.
  • Nuisance factors are covariates that the model accounts for and that are neither optimized nor used for personalization. Currently the only nuisance factor is is_weekend, a derived time correction. It is computed from the day of each observation at training time and from the calendar at serving time. Both paths use the same derivation, so they cannot drift apart. Nuisance factors get first-order effects only. A nuisance level shifts the baseline for every variant equally and does not interact with design factors. The model estimates the effect of a nuisance factor in order to remove it from the comparison of variants.

Time as a confounder

A classical A/B test with a fixed split can ignore time. Randomization guarantees that 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.

An adaptive allocation does not have this guarantee. Thompson Sampling reallocates traffic as the posterior evolves, so the variants that get exposure are correlated with the time at which they get it. If event probabilities also vary over time, for example if conversion is systematically higher on weekends, time becomes a confounder. A variant that received its exploration traffic over a weekend inherits the weekend lift in its raw conversion rate and appears better than it is.

Without a time regressor, this bias feeds back into the policy:

  1. The model exploits the weekend-inflated variant, which then underdelivers on weekdays. The demoted variants are re-explored under another time mix. The posteriors oscillate and do not tighten, and convergence stalls.
  2. 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 lock onto a suboptimal variant with high confidence. Once its allocation collapses to a winner, the data needed to correct the error stops arriving.

The is_weekend nuisance factor removes the confounder. Its own additive term on the latent scale absorbs the weekend lift, 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 the exposures of each variant across the week. The design-effect posteriors stay unbiased, and Thompson Sampling converges to the variant with the highest expected reward.

Nuisance factors are restricted to first-order terms for the same reason. They correct the baseline and cannot change the variant ranking the way context factors can. If the best variant is expected to differ between weekends and weekdays, the day type is a targeting dimension and belongs in a context factor.

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. With this factorization, the model learns segment-specific winners for an optimization with context factors without a free parameter for every variant-context cell. Effects are tied together with grouped hierarchical priors, in which levels of the same factor share a scale. The posterior is sampled with MCMC (NUTS). The cardinality of the outcome changes 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 the conversion rate. With the canonical 0/1 weights, this is 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 and still win on expected reward by shifting buyers from Basic to Pro. The linear terms are constrained to sum to zero across categories. This constraint removes the shift invariance of the softmax symmetrically and does not privilege 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 supported yet. The planned extension keeps the same FM predictor and replaces the likelihood with a continuous one, for example a lognormal FM for positive, right-skewed metrics such as revenue, where eta parameterizes the log-scale location. Real-world value metrics are usually zero-inflated, because most exposures generate no revenue. The practical form is therefore a hurdle model: a binomial FM for whether value occurs, composed with a continuous FM for the amount, with the expected reward combining both parts. Until then, real-valued metrics can be approximated by discretizing them into weighted outcome buckets and using the multinomial model.