ε-Greedy Action Selection
ε-Greedy Action Selection
Implement ε-greedy action selection for exploration in reinforcement learning.
Mathematical Definition
ε-Greedy Policy:
a=⎩⎨⎧argmaxaQ(s,a),random action,with probability 1−ε,with probability ε.where ε∈[0,1] controls the exploration rate.
Function Arguments
q_values: 1D array, shape (n_actions,)- Q(s, ·) for current stateepsilon: float in [0,1]- exploration probabilityrng: optional np.random.Generator- for deterministic testing
Examples
Input: q_values=[1,2,0.5], ε=0
Output: action = 1
Input: q_values=[1,2,0.5], ε=1
Output: action ∈ {0,1,2} with equal probability
Hint 1
Generate a random number between 0 and 1. If it's less than ε, choose random action, else choose greedy.
Hint 2
Use np.argmax() for greedy action and rng.integers() or np.random.randint() for random action.
Requirements
- If ε=0 always return greedy action (argmax)
- If ε=1 always return random action
- Use rng if provided, else use
np.random - Return Python int action index
- Do not modify q_values
Constraints
- 1 ≤ len(q_values) ≤ 10,000
- NumPy only
- Time limit: 200ms
Log in to take notes on this problem
Accepts: array
Accepts: number
Accepts: any
ε-Greedy Action Selection
ε-Greedy Action Selection
Implement ε-greedy action selection for exploration in reinforcement learning.
Mathematical Definition
ε-Greedy Policy:
a=⎩⎨⎧argmaxaQ(s,a),random action,with probability 1−ε,with probability ε.where ε∈[0,1] controls the exploration rate.
Function Arguments
q_values: 1D array, shape (n_actions,)- Q(s, ·) for current stateepsilon: float in [0,1]- exploration probabilityrng: optional np.random.Generator- for deterministic testing
Examples
Input: q_values=[1,2,0.5], ε=0
Output: action = 1
Input: q_values=[1,2,0.5], ε=1
Output: action ∈ {0,1,2} with equal probability
Hint 1
Generate a random number between 0 and 1. If it's less than ε, choose random action, else choose greedy.
Hint 2
Use np.argmax() for greedy action and rng.integers() or np.random.randint() for random action.
Requirements
- If ε=0 always return greedy action (argmax)
- If ε=1 always return random action
- Use rng if provided, else use
np.random - Return Python int action index
- Do not modify q_values
Constraints
- 1 ≤ len(q_values) ≤ 10,000
- NumPy only
- Time limit: 200ms
Log in to take notes on this problem
Accepts: array
Accepts: number
Accepts: any