Skip to content
DeepForgeby svx
All problems
HardOptimizationop-049

Thompson Sampling Pick

Problem

Pick an arm by Thompson sampling from Beta posteriors.

After random.seed(seed), draw random.betavariate(successes[i] + 1, failures[i] + 1) for every arm and return the index of the largest sample, with the lowest index winning ties.

Hint

Adding 1 to both counts gives a uniform Beta(1, 1) prior per arm.

Test cases

case 1
in: [[1,10,5],[10,1,5],0]
expected: 1
case 2
in: [[0,0,0],[0,0,0],1]
expected: 1
case 3
in: [[9,1],[1,9],42]
expected: 0
case 4
in: [[2,2,2],[8,7,6],7]
expected: 1
Starter codePython
def thompson_sampling_pick(successes, failures, seed):
    # Your code here
    pass

4 test cases · run your code against them in the editor