Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-395

Thompson Posterior Mean

Problem

Return the posterior mean for each Bernoulli bandit arm under a shared Beta(alpha, beta) prior.

For an arm with successes and trials, the mean is (alpha + successes) / (alpha + beta + trials). Return a list with one mean per arm, using 0.0 for a degenerate zero denominator.

Hint

The Beta posterior just adds successes to alpha and failures to beta.

Test cases

case 1
in: [1,1,[3,1,0],[5,2,0]]
expected: [0.5714285714285714,0.5,0.5]
case 2
in: [2,3,[1],[1]]
expected: [0.5]
case 3
in: [1,1,[],[]]
expected: []
case 4
in: [0.5,0.5,[4,0],[10,10]]
expected: [0.4090909090909091,0.045454545454545456]
case 5
in: [1,1,[7],[10]]
expected: [0.6666666666666666]
Starter codePython
def thompson_posterior_means(alpha, beta, successes, trials):
    # Your code here
    pass

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