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

One-Step TD Value Update

Reinforcement Learning
Easy

Apply one TD(0) update to a state-value array. First compute the temporal-difference error:

δ=r+γV(snext)−V(s)\delta=r+\gamma V(s_{\mathrm{next}})-V(s)δ=r+γV(snext​)−V(s)

Then update only the current state:

Vnew(s)=V(s)+αδV_{\mathrm{new}}(s)=V(s)+\alpha\deltaVnew​(s)=V(s)+αδ

Here, rrr is the observed reward, γ\gammaγ is the discount factor, and α\alphaα is the learning rate. Do not modify the input. Return the updated values as a NumPy array.

Loading visualization...

Examples

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

Output: [0.5, 0, 0]

Explanation: The next-state estimate is zero, so the TD target is 1 and the halfway update sets V(0) to 0.5.

Input: V = [0.2, 0.8], s = 0, r = 0, s_next = 1, alpha = 1.0, gamma = 0.5

Output: [0.4, 0.8]

Hint 1

Compute target = r + gamma * values[s_next].

Hint 2

Copy with np.asarray(V, dtype=float).copy() before updating index s.

Requirements

  • Compute the TD target from the reward and next-state value
  • Update only the current-state entry
  • Leave the input value array unchanged
  • Return a NumPy array

Constraints

  • State indices are valid for V
  • 0 < alpha <= 1 and 0 <= gamma <= 1
  • Use NumPy only
Try Similar Problems
Mc Policy EvaluationSarsa UpdateQ Learning UpdateValue Iteration StepDiscount Returns

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.
PrevNext

One-Step TD Value Update

Reinforcement Learning
Easy

Apply one TD(0) update to a state-value array. First compute the temporal-difference error:

δ=r+γV(snext)−V(s)\delta=r+\gamma V(s_{\mathrm{next}})-V(s)δ=r+γV(snext​)−V(s)

Then update only the current state:

Vnew(s)=V(s)+αδV_{\mathrm{new}}(s)=V(s)+\alpha\deltaVnew​(s)=V(s)+αδ

Here, rrr is the observed reward, γ\gammaγ is the discount factor, and α\alphaα is the learning rate. Do not modify the input. Return the updated values as a NumPy array.

Loading visualization...

Examples

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

Output: [0.5, 0, 0]

Explanation: The next-state estimate is zero, so the TD target is 1 and the halfway update sets V(0) to 0.5.

Input: V = [0.2, 0.8], s = 0, r = 0, s_next = 1, alpha = 1.0, gamma = 0.5

Output: [0.4, 0.8]

Hint 1

Compute target = r + gamma * values[s_next].

Hint 2

Copy with np.asarray(V, dtype=float).copy() before updating index s.

Requirements

  • Compute the TD target from the reward and next-state value
  • Update only the current-state entry
  • Leave the input value array unchanged
  • Return a NumPy array

Constraints

  • State indices are valid for V
  • 0 < alpha <= 1 and 0 <= gamma <= 1
  • Use NumPy only
Try Similar Problems
Mc Policy EvaluationSarsa UpdateQ Learning UpdateValue Iteration StepDiscount Returns

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.