Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-394

UCB1 Exploration Bonus

Problem

Return the UCB1 exploration bonus sqrt(2 * ln(total) / pulls) for a bandit arm.

pulls is the number of times this arm was played and total is the total number of plays across all arms. Return 0.0 when pulls is non-positive or total is at most 1.

Hint

The bonus grows with the log of total plays and shrinks with the square root of this arm's pulls.

Test cases

case 1
in: [5,100]
expected: 1.3572280848830225
case 2
in: [1,10]
expected: 2.145966026289347
case 3
in: [0,10]
expected: 0
case 4
in: [3,1]
expected: 0
case 5
in: [10,1000]
expected: 1.1753940002383998
Starter codePython
import math


def ucb1_bonus(pulls, total):
    # Your code here
    pass

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