TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

ε-Greedy Action Selection

Reinforcement Learning
Medium

Select an action with an epsilon-greedy policy. Draw one random value uuu from a generator initialized with seed:

a={uniform random action,u<εarg⁡max⁡jqj,u≥εa=\begin{cases}\text{uniform random action},&u<\varepsilon\\\arg\max_j q_j,&u\ge\varepsilon\end{cases}a={uniform random action,argmaxj​qj​,​u<εu≥ε​

Here, ε\varepsilonε is the exploration probability and qjq_jqj​ is the value of action jjj. NumPy argmax resolves greedy ties by choosing the first maximum. Return the selected action index as a Python integer.

Loading visualization...

Examples

Input: q_values = [1, 2, 0.5], epsilon = 0, seed = 0

Output: 1

Explanation: With zero exploration probability, the action with the largest value is selected.

Input: q_values = [1, 2, 0.5], epsilon = 1, seed = 42

Output: 1

Hint 1

Create the generator with rng = np.random.default_rng(seed).

Hint 2

Use rng.integers(values.size) for exploration and np.argmax(values) otherwise.

Requirements

  • Initialize np.random.default_rng with the supplied seed
  • Explore when the random draw is below epsilon
  • Otherwise choose the first maximum Q-value
  • Return a Python integer

Constraints

  • q_values is a nonempty one-dimensional numeric list
  • 0 <= epsilon <= 1
  • seed is a nonnegative integer
  • Use NumPy only
Try Similar Problems
Q Learning UpdateSarsa UpdateReplay Buffer SampleMc Policy EvaluationTd Value Update

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

Accepts: number

You must run your code first.
PrevNext

ε-Greedy Action Selection

Reinforcement Learning
Medium

Select an action with an epsilon-greedy policy. Draw one random value uuu from a generator initialized with seed:

a={uniform random action,u<εarg⁡max⁡jqj,u≥εa=\begin{cases}\text{uniform random action},&u<\varepsilon\\\arg\max_j q_j,&u\ge\varepsilon\end{cases}a={uniform random action,argmaxj​qj​,​u<εu≥ε​

Here, ε\varepsilonε is the exploration probability and qjq_jqj​ is the value of action jjj. NumPy argmax resolves greedy ties by choosing the first maximum. Return the selected action index as a Python integer.

Loading visualization...

Examples

Input: q_values = [1, 2, 0.5], epsilon = 0, seed = 0

Output: 1

Explanation: With zero exploration probability, the action with the largest value is selected.

Input: q_values = [1, 2, 0.5], epsilon = 1, seed = 42

Output: 1

Hint 1

Create the generator with rng = np.random.default_rng(seed).

Hint 2

Use rng.integers(values.size) for exploration and np.argmax(values) otherwise.

Requirements

  • Initialize np.random.default_rng with the supplied seed
  • Explore when the random draw is below epsilon
  • Otherwise choose the first maximum Q-value
  • Return a Python integer

Constraints

  • q_values is a nonempty one-dimensional numeric list
  • 0 <= epsilon <= 1
  • seed is a nonnegative integer
  • Use NumPy only
Try Similar Problems
Q Learning UpdateSarsa UpdateReplay Buffer SampleMc Policy EvaluationTd Value Update

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

Accepts: number

You must run your code first.