All problems
Epsilon-Greedy Action
Problem
Choose an action with the epsilon-greedy policy using a seeded random generator.
Create rng = random.Random(seed) and draw u = rng.random(). If u < epsilon return rng.randrange(len(Q)); otherwise return the greedy action (smallest index on ties). The seed makes the result fully deterministic.
Hint
Draw the uniform number first so the random stream matches for every epsilon.
Test cases
case 1
in: [[0.2,1,0.5],0,0]
expected: 1
case 2
in: [[0.2,1,0.5],0.5,1]
expected: 0
case 3
in: [[0.2,1,0.5],0.3,3]
expected: 2
case 4
in: [[0.2,1,0.5],1,7]
expected: 0
case 5
in: [[0.2,1,0.5],0.3,5]
expected: 1
Starter codePython
import random
def epsilon_greedy_action(Q, epsilon, seed):
# Your code here
pass5 test cases · run your code against them in the editor