Exp3Bandit
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.
Computes a joint sampling distribution across arms, with regret bound O(sqrt(T · K · ln K)) under default tunings.
Rewards passed to update must lie in [0, 1] for the regret theory to apply; outside-bound rewards are accepted but may destabilise the exponential weight update.
Use cases: non-stationary or adversarial scalar-reward problems where the per-arm reward distribution may shift over time; settings where a regret bound is wanted without distributional assumptions.
Arms: indexless, nbrArms fixed at construction; per-arm state is one exponential weight.
Memory: O(nbrArms); weights, pending play probabilities, and pending pull counts.
Choose: O(nbrArms); build the play distribution, inverse-CDF sample.
Update: O(nbrArms); additive update of the log weight and a shift so the largest is zero. Uses the arm's most recently recorded play probability while feedback is pending, otherwise recomputes the current distribution.
Randomness: every choose consumes one random.nextDouble(); reproducible under a fixed seed.
Concurrency: not thread-safe; weights and the cached play distribution are mutated without synchronisation. Serialise choose and update externally for multi-thread use.
Constructors
Exp3Bandit
Properties
eta
gamma
nbrArms
random
Single source of randomness for UnivariateBandit.choose / ContextualBandit.choose and any policy-internal sampling. Callers pass a Random(seed) at construction for reproducible exploration; the bandit threads the same instance through every randomised decision.
Functions
choose
Pick an arm to play next. Uses Bandit.random for any sampling. The returned index is in [0, nbrArms). Repeated calls without intervening updates may return different arms (for randomised selection) or the same arm (for argmax-style policies once the leading arm is well-separated).
create
Spawn a fresh bandit with the same configuration; state resets to the prior seed. The random source is replaced; pass the source you want the new bandit to use for exploration (which is independent of merging in another snapshot's state).
Useful when a worker accepts a stream of snapshots to apply sequentially: create(random).also { it.merge(snapshot) }.
merge
Approximate pooling by multiplying corresponding arm weights, adding their logs. Non-finite log weights carry no usable evidence and are skipped. Pending play probabilities and pull counts are not included in the snapshot.
playDistribution
Current play distribution: weight-normalised softmax blended with uniform gamma.
reset
Clear all state back to the prior-seeded baseline. Equivalent to spawning a fresh bandit with the same configuration via Snapshotable.create, but in place; keeps the same arm count, policy, concurrency mode, and random instance.
snapshot
Return the current state without adding observations or choosing an arm. Consistency follows the implementation's concurrency contract; a snapshot of independently updated cells need not represent a single instant.
update
Record reward value for armIndex with weight. Arm indices must be in [0, nbrArms). Weight and reward handling follow the implementation's accumulator or policy; see com.eignex.kumulant.core.Stat for the shared accumulator weight rules.
Per-arm snapshot at armIndex. Default implementation reads from the full snapshot; implementations may override to avoid building the entire list when only one arm is needed.
Record each arm/reward pair in order by calling update. armIndices and values must have equal sizes. Non-null weights must have the same size; null applies 1.0 to every observation. Size checks run before any update, but a later update failure can leave earlier observations applied.