kumulant

Exp3Bandit

class Exp3Bandit(val nbrArms: Int, val eta: Double = defaultEta(nbrArms), val gamma: Double = defaultGamma(eta), val random: Random = Random.Default) : UnivariateBandit, PerArmBandit<Exp3ArmResult> (source)

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

constructor(nbrArms: Int, eta: Double = defaultEta(nbrArms), gamma: Double = defaultGamma(eta), random: Random = Random.Default)(source)

Types

Link copied to clipboard
object Companion

EXP3 tuning defaults from Auer et al.

Properties

eta

Learning rate on per-arm gain updates.

gamma

Exploration mix: probability mass distributed uniformly across arms.

nbrArms

open override val nbrArms: Int(source)

Number of arms in the population. Fixed at construction; arm indices are [0, nbrArms).

random

open override val random: Random(source)

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

open override fun choose(): Int(source)

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

open override fun create(random: Random): Exp3Bandit(source)

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

open override fun merge(other: List<Exp3ArmResult>)(source)

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

open override fun reset()(source)

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

open override fun snapshot(): List<Exp3ArmResult>(source)

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

open override fun update(armIndex: Int, value: Double, weight: Double = 1.0)(source)

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.

Link copied to clipboard
open fun armResult(armIndex: Int): Exp3ArmResult

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.

Link copied to clipboard
open fun updateAll(armIndices: IntArray, values: DoubleArray, weights: DoubleArray? = null)

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.