UCB1 Multi-Armed Bandit Trace
Problem statement
Simulate the deterministic action choices of the UCB1 multi-armed-bandit strategy. rewardStreams[a] contains the rewards observed from arm a, in the order that arm is pulled.
- Pull every arm once in increasing arm-index order.
- For each later step
t, wheretis the number of pulls already completed, choose the arm maximizingmeanReward + sqrt(2 * ln(t) / pullCount). - If scores tie exactly, choose the smaller arm index.
- Consume the next unused reward from the chosen arm and update its statistics.
Return the chosen arm index for each of the first rounds pulls. Inputs guarantee that every chosen arm has another reward available.
Function
ucb1BanditTrace(rewardStreams: int[][], rounds: int) → int[]Examples
Example 1
rewardStreams = [[1,1,1,1],[0,0,0,0]]rounds = 4return = [0,1,0,0]After the mandatory exploration pulls, arm 0's empirical reward advantage keeps its UCB score ahead for both remaining rounds.
Example 2
rewardStreams = [[0,1,1],[0,1,1]]rounds = 3return = [0,1,0]The scores tie after one zero reward from each arm, so arm 0 wins the deterministic tie.
Constraints
1 <= rewardStreams.length <= 100.rewardStreams.length <= rounds <= 100000.- Rewards are integers in
[0,1000000]. - Every arm stream is long enough for the pulls selected by UCB1.