bandit.univariate
Indexless multi-armed bandits. Each round, the bandit picks one of K arms via choose(), the caller observes a reward, and update(arm, value, weight) folds it back into that arm's accumulator. No per-round feature vector; for that, see com.eignex.kumulant.bandit.contextual.
Bandit shells
MultiArmedBandit is the workhorse. It carries a BanditPolicy and a list of Arms; choose delegates to the policy's scoring rule. Most named bandits in the literature (UCB1, Thompson, epsilon-greedy, etc.) are just a policy swap on this shell.
| Bandit | Selection rule |
|---|---|
| MultiArmedBandit | Argmax over per-arm policy scores, or whatever else the policy implements (joint sampling, etc.). |
| Exp3Bandit | Adversarial bandit with exponential-weights updates and a regret bound under non-stationary reward distributions. |
| RouletteWheelBandit | Operator-selection roulette where arm probability is proportional to score. Used in meta-heuristics where each "arm" is a neighbourhood move and the score is the recent improvement rate. |
| TopTwoThompsonBandit | Top-two Thompson sampling: draw two samples, play the second-best with probability 1 - beta. Identifies the best arm faster than vanilla Thompson when many arms are competitive. |
Policies
BanditPolicy is the scoring strategy plugged into MultiArmedBandit. The library ships every commonly-cited one:
| Policy | Family |
|---|---|
| EpsilonGreedy | Mix of exploitation and uniform-random exploration; epsilon fixed, or annealed by decay. epsilon = 0 is the pure-greedy baseline and epsilon = 1 the uniform-exploration one. |
| Boltzmann | Softmax over per-arm means with a cooling temperature schedule. |
| UCB1 | Classical upper confidence bound for [0, 1]-bounded rewards. |
| KlUcb | KL-UCB; tighter bound than UCB1 for Bernoulli arms. |
| Moss | MOSS bound; near-optimal regret across stationary settings. |
| UcbV | UCB-V; UCB with variance-aware confidence width. |
| ThompsonSampling | Posterior sampling: draw from each arm's posterior, play argmax. |
Each policy reads its per-arm state through a Posterior adapter that projects the arm's com.eignex.kumulant.core.Result to whatever the scoring rule needs (a mean, a Beta posterior, a normal-gamma posterior, etc.).
Arms
Arm is the per-arm state contract. Each arm pairs a stat with the com.eignex.kumulant.core.Concurrency and reset story it needs:
| Arm | Backing stat | Suits |
|---|---|---|
| BernoulliArm | com.eignex.kumulant.stat.summary.BernoulliSumStat + count | Binary rewards (click / no click, pass / fail). |
| MeanArm | com.eignex.kumulant.stat.summary.MeanStat | Continuous rewards where mean suffices. |
| NormalArm | com.eignex.kumulant.stat.summary.VarianceStat | Continuous rewards with normally-distributed noise; carries enough state for UCB-V and Thompson with normal-gamma. |
| LogNormalArm | Welford over log(value) | Multiplicative rewards (revenue, latency). |
CompositeArm (and CompositeSubArm) model multi-component rewards like zero-inflated lognormal revenue, without writing a per-shape arm class. Routing and score combination travel as com.eignex.kumulant.schema.expr.ScalarExpr expressions, so the whole composite round-trips on the wire alongside the rest of the bandit config.
Wire portability
UnivariateBanditSpec is the sealed root of wire-portable bandit configs:
MultiArmedSpec: bandit + policy + arm list.
RouletteWheelSpec: roulette-wheel variant.
Other family-specific specs co-located here.
Configurations and policies round-trip through skema-based JSON / CBOR just like the com.eignex.kumulant.schema.spec.StatSpec family. The materializer in com.eignex.kumulant.bandit takes a spec and a Random and returns the live bandit; pass the same seed across replicas for reproducible exploration.
Interface hierarchy
See com.eignex.kumulant.bandit for the action/state interface split: which bandits expose com.eignex.kumulant.bandit.Scorable, which implement com.eignex.kumulant.bandit.PerArmBandit, and where joint- sampling bandits diverge from the per-arm-score path.
Types
Recipe for one bandit arm's cumulator side: how to build a freshly-seeded SeriesStat for that arm, and how to encode a raw observation before folding it into the stat. Posteriors and BanditPolicys pair with arm specs of the same R.
Scoring strategy for a com.eignex.kumulant.bandit.univariate.MultiArmedBandit. Decides which arm to play given snapshots of each arm's sufficient statistic R. The bandit calls evaluate for every arm and picks the argmax; the policy is the entire exploration/exploitation knob.
Wire-portable specification for a BanditPolicy.
Bernoulli arm. The reward is binary {0, 1} and the unknown is the success probability p. A Beta(priorAlpha, priorBeta) prior is conjugate to the Bernoulli likelihood; the posterior is Beta(priorAlpha + successes, priorBeta + failures).
Beta posterior over a Bernoulli rate. successes and trials-successes are the Beta parameters; both must be positive (i.e. snapshot must be prior-seeded).
Boltzmann exploration (softmax bandit): plays arm a with probability proportional to exp(mean(a) / tau(t)), where the temperature cools as tau(t) = max(minTau, initialTau / t^decay) over the 1-based round t; decay = 1 is Cesa-Bianchi & Fischer's classical recipe and decay = 0 a fixed temperature. High temperature flattens play toward uniform exploration; low temperature sharpens it toward greedy exploitation.
Spec for Boltzmann.
Composite Arm built from N independent sub-arms. Each observation is routed through every sub-arm's CompositeSubArm.valueExpr / CompositeSubArm.weightExpr / CompositeSubArm.filter AST before being fed to the corresponding per-sub-arm accumulator. The composite result is a ResultList of the sub-snapshots; pair with CompositePosterior to combine sub-arm draws into a single score.
Composite Posterior over the sub-snapshots produced by a CompositeArm. Each sub-posterior draws independently; the resulting samples are packed as V(0)..V(N-1) and reduced to a single score by the combine AST.
One leg of a CompositeArm: which arm receives observations, with optional AST-driven transformation of value, weight, and a filter predicate.
Epsilon-greedy: with probability eps pick a uniformly random arm (explore), otherwise pick the arm with the highest mean (exploit). The simplest exploration scheme that actually works; no math machinery.
Spec for EpsilonGreedy.
Per-arm snapshot for Exp3Bandit: the exponential-weight cell for one arm.
EXP3 (Auer, Cesa-Bianchi, Freund, Schapire 2002); adversarial multi-armed bandit over a fixed pool of nbrArms. Each round: compute play distribution p(a) = (1 - gamma) * w(a) / sum(w) + gamma/K, sample a ~ p, then on reward r ∈ [0,1] update w(a) *= exp(eta * r / p(a)) using the importance-sampling-corrected gain. Weights are held as logs, so no gain overflows or permanently zeroes an arm's weight.
Spec for Exp3Bandit. Pass null for eta / gamma to use the algorithm's defaults.
Gamma posterior over an Exponential rate, reported as the mean inter-arrival time 1/lambda.
KL-UCB (Garivier & Cappé 2011). UCB variant for Bernoulli arms with a KL-divergence confidence bound instead of the Hoeffding bound UCB1 uses. Score is the largest q in [mean, 1] such that n * KL(mean, q) <= ln(t) + c * ln(ln(t)); computed by binary search with tolerance precision.
Spec for KlUcb.
Log-Normal-Gamma posterior: same draw as NormalGammaPosterior but exp-transformed back to the real scale. Intended for arms whose stat already accumulates log-rewards (see LogNormalArm's encode).
Single-moment arm; tracks the running mean but not variance. The right pick when the likelihood's sufficient statistic is one running sum (or equivalently a running mean × count):
MOSS; Minimax Optimal Strategy in the Stochastic case (Audibert & Bubeck 2009). UCB variant where the confidence bound shrinks faster than UCB1 once an arm has accumulated more than t / K samples. Score is mean + sqrt(max(0, ln(t / (K * n))) / n).
Spec for Moss.
Univariate bandit with a fixed number of independent arms, each backed by a kumulant SeriesStat; on every choose the bandit asks the policy to score a fresh snapshot per arm and picks the argmax.
Spec for MultiArmedBandit.
Gaussian arm with a Normal-Gamma prior (unknown mean and variance). Tracks both the running mean and the sum of squared deviations, which gives NormalGammaPosterior enough to draw (mean, variance) jointly and gives the variance-aware policy UcbV a reasonable variance estimate.
Normal-Gamma posterior over a normal mean/variance. Draws (variance, mean) jointly: variance ~ Inverse-Gamma(n/2, n*s^2/2), mean | variance ~ Normal(snapshot.mean, sigma^2/n).
Gamma posterior over a Poisson rate: Gamma(sum, totalWeights).
Per-arm state snapshot for RouletteWheelBandit. Exposes the current weight plus the running segment counters callers may want to inspect for debugging.
Adaptive operator-selection bandit in the Ropke-Pisinger 2006 ALNS scheme: each arm carries a weight, choose samples proportional to weights (roulette wheel), and weights re-balance in batches.
Spec for RouletteWheelBandit.
Thompson sampling: score each arm by a draw from its conjugate posterior given the snapshot. The bandit then picks the arm with the highest sample; no explicit exploration knob, the exploration falls out of posterior variance shrinking as data accumulates.
Spec for ThompsonSampling.
Top-Two Thompson Sampling (Russo 2020); pure-exploration variant of Thompson sampling for best-arm identification: sample every arm's posterior, take the argmax arm1, play it with probability beta, or else resample until the argmax differs from arm1 and play that runner-up.
Spec for TopTwoThompsonBandit.
Spec for TrackedUnivariateBandit and its optional observation accumulators.
Classical UCB1 (Auer, Cesa-Bianchi, Fischer 2002). Score is mean + alpha * sqrt(2 * ln(totalSamples) / armSamples); exploitation (running mean) plus a confidence bound that shrinks as the arm accumulates pulls. Unexplored arms get +infinity so they're tried at least once.
Spec for UCB1.
UCB-V; variance-aware UCB with finite-sample honesty (Audibert, Munos, Szepesvári 2009). Score is mean + sqrt(2 * V * zeta * ln(t) / n) + 3 * c * zeta * ln(t) / n, where V is the running variance from the WeightedVarianceResult snapshot.
Spec for UcbV.
Wire-portable specification for a univariate bandit instance.
Functions
Thompson sampling over a Beta(priorAlpha, priorBeta) prior on a Bernoulli reward.
Thompson sampling over an exponential reward with a Gamma prior on the rate.
Thompson sampling over a log-normal reward via Normal-Gamma on log(value).
Thompson sampling over a Normal-Gamma prior; unknown mean and variance.
Thompson sampling over a Poisson reward with a Gamma prior on the rate.