v9.1.1
Menu

TD(0) Value Update Step

easyPROTemporal-Difference Learning and ControlReinforcement LearningRL 1: Foundations

Problem Statement

Apply one TD(0) update to the value of the current state:

V(s)←V(s)+α [ r+γV(s′)−V(s) ]V(s) \leftarrow V(s) + \alpha\, [\, r + \gamma V(s') - V(s)\,]

Implement td_update(v_current, reward, gamma, v_next, alpha) returning the new V(s).

Example

Input
td_update(5.0, 1.0, 0.9, 10.0, 0.1)
Output
5.5
Reasoning
  • Calculate the temporal difference error (TD error) by combining the immediate reward, the discounted value of the next state, and the current value estimate: δ=1.0+(0.9×10.0)−5.0=1.0+9.0−5.0=5.0\delta = 1.0 + (0.9 \times 10.0) - 5.0 = 1.0 + 9.0 - 5.0 = 5.0.
  • Scale the TD error by the learning rate to determine the magnitude of the adjustment: α×δ=0.1×5.0=0.5\alpha \times \delta = 0.1 \times 5.0 = 0.5.
  • Update the current value estimate by adding this adjustment to the original value: V(s)new=5.0+0.5=5.5V(s)_{new} = 5.0 + 0.5 = 5.5.
  • The final output is 5.5

Constraints

  • 0 < alpha <= 1.
  • Return a float.

Learn this in

More from RL 1: Foundations

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.