v9.1.1
Menu

TD Error

easyPROTemporal-Difference Learning and ControlReinforcement LearningRL 1: Foundations

Problem Statement

The TD error (delta) drives the value update:

δ=r+γV(s′)−V(s)\delta = r + \gamma V(s') - V(s)

Implement td_error(reward, gamma, v_next, v_current) returning a float.

Example

Input
td_error(1.0, 0.9, 10.0, 5.0)
Output
5.0
Reasoning
  • Identify the input parameters for the TD error formula: immediate reward r=1.0r = 1.0, discount factor γ=0.9\gamma = 0.9, next state value V(s′)=10.0V(s') = 10.0, and current state value V(s)=5.0V(s) = 5.0.
  • Calculate the discounted value of the next state to account for future rewards: γ⋅V(s′)=0.9×10.0=9.0\gamma \cdot V(s') = 0.9 \times 10.0 = 9.0.
  • Add the immediate reward to the discounted next state value to determine the target value: r+γ⋅V(s′)=1.0+9.0=10.0r + \gamma \cdot V(s') = 1.0 + 9.0 = 10.0.
  • Subtract the current state value from the target value to find the difference (error): 10.0−5.0=5.010.0 - 5.0 = 5.0.
  • The final output is 5.0

Constraints

  • 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.