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

Tabular Q-Learning (Single Update)

Reinforcement Learning
Easy

Apply one tabular Q-learning update. The target uses the best next-state action value:

y=r+γmax⁡a′Q(snext,a′)y=r+\gamma\max_{a'}Q(s_{\mathrm{next}},a')y=r+γa′max​Q(snext​,a′)

Update the selected state-action entry:

Qnew(s,a)=Q(s,a)+α[y−Q(s,a)]Q_{\mathrm{new}}(s,a)=Q(s,a)+\alpha[y-Q(s,a)]Qnew​(s,a)=Q(s,a)+α[y−Q(s,a)]

Here, rrr is the reward, γ\gammaγ is the discount factor, α\alphaα is the learning rate, and a′a'a′ ranges over next-state actions. Do not modify the input table. Return the updated Q-table as a NumPy array.

Loading visualization...

Examples

Input: Q = [[0, 0], [0.5, 1]], s = 0, a = 1, r = 1, s_next = 1, alpha = 0.5, gamma = 0.9

Output: [[0, 0.95], [0.5, 1]]

Explanation: The target is 1.9, and moving halfway from 0 toward 1.9 gives 0.95.

Input: Q = [[0, 0], [0, 0]], s = 1, a = 0, r = 2, s_next = 1, alpha = 1.0, gamma = 0

Output: [[0, 0], [2, 0]]

Hint 1

Use np.max(table[s_next]) to build the TD target.

Hint 2

Copy the table before updating table[s, a].

Requirements

  • Use the maximum action value from the next state
  • Update only entry (s, a)
  • Leave the input Q-table unchanged
  • Return a NumPy array

Constraints

  • State and action indices are valid for Q
  • 0 < alpha <= 1 and 0 <= gamma <= 1
  • Use NumPy only
Try Similar Problems
Sarsa UpdateTd Value UpdateValue Iteration StepEpsilon GreedyMc Policy Evaluation

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.
PrevNext

Tabular Q-Learning (Single Update)

Reinforcement Learning
Easy

Apply one tabular Q-learning update. The target uses the best next-state action value:

y=r+γmax⁡a′Q(snext,a′)y=r+\gamma\max_{a'}Q(s_{\mathrm{next}},a')y=r+γa′max​Q(snext​,a′)

Update the selected state-action entry:

Qnew(s,a)=Q(s,a)+α[y−Q(s,a)]Q_{\mathrm{new}}(s,a)=Q(s,a)+\alpha[y-Q(s,a)]Qnew​(s,a)=Q(s,a)+α[y−Q(s,a)]

Here, rrr is the reward, γ\gammaγ is the discount factor, α\alphaα is the learning rate, and a′a'a′ ranges over next-state actions. Do not modify the input table. Return the updated Q-table as a NumPy array.

Loading visualization...

Examples

Input: Q = [[0, 0], [0.5, 1]], s = 0, a = 1, r = 1, s_next = 1, alpha = 0.5, gamma = 0.9

Output: [[0, 0.95], [0.5, 1]]

Explanation: The target is 1.9, and moving halfway from 0 toward 1.9 gives 0.95.

Input: Q = [[0, 0], [0, 0]], s = 1, a = 0, r = 2, s_next = 1, alpha = 1.0, gamma = 0

Output: [[0, 0], [2, 0]]

Hint 1

Use np.max(table[s_next]) to build the TD target.

Hint 2

Copy the table before updating table[s, a].

Requirements

  • Use the maximum action value from the next state
  • Update only entry (s, a)
  • Leave the input Q-table unchanged
  • Return a NumPy array

Constraints

  • State and action indices are valid for Q
  • 0 < alpha <= 1 and 0 <= gamma <= 1
  • Use NumPy only
Try Similar Problems
Sarsa UpdateTd Value UpdateValue Iteration StepEpsilon GreedyMc Policy Evaluation

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.