Advantage Computation
Advantage Computation
Compute the advantage for every time step in an episode.
Mathematical Definition
Return from time t:
Gt=rt+γrt+1+γ2rt+2+⋯Advantage:
At=Gt−V(st)where At measures how much better the actual return was compared to expected value.
Function Arguments
states: list of ints- state at each timesteprewards: list of floats- reward at each timestepV: NumPy array- state valuesgamma: float ∈ [0,1]- discount factor
Examples
Input: states=[0,1,2], rewards=[1,2,3], V=[0.5,1,1.5], γ=1
Output: A = [5.5, 4.0, 1.5]
Input: states=[0,1,2], rewards=[1,2,3], V=[0,0,0], γ=0
Output: A = [1.0, 2.0, 3.0]
Hint 1
Compute returns backward: start from the last timestep where GT=rT then work backward.
Hint 2
Once you have all returns, compute advantage as At=Gt−V(st) for each timestep.
Requirements
- Compute returns backward for efficiency
- Do not modify inputs
- Return NumPy array of advantages
Constraints
- Episode length ≤ 10,000
- NumPy only
- Time limit: 200ms
Log in to take notes on this problem
Accepts: array
Accepts: array
Accepts: array
Accepts: number
Advantage Computation
Advantage Computation
Compute the advantage for every time step in an episode.
Mathematical Definition
Return from time t:
Gt=rt+γrt+1+γ2rt+2+⋯Advantage:
At=Gt−V(st)where At measures how much better the actual return was compared to expected value.
Function Arguments
states: list of ints- state at each timesteprewards: list of floats- reward at each timestepV: NumPy array- state valuesgamma: float ∈ [0,1]- discount factor
Examples
Input: states=[0,1,2], rewards=[1,2,3], V=[0.5,1,1.5], γ=1
Output: A = [5.5, 4.0, 1.5]
Input: states=[0,1,2], rewards=[1,2,3], V=[0,0,0], γ=0
Output: A = [1.0, 2.0, 3.0]
Hint 1
Compute returns backward: start from the last timestep where GT=rT then work backward.
Hint 2
Once you have all returns, compute advantage as At=Gt−V(st) for each timestep.
Requirements
- Compute returns backward for efficiency
- Do not modify inputs
- Return NumPy array of advantages
Constraints
- Episode length ≤ 10,000
- NumPy only
- Time limit: 200ms
Log in to take notes on this problem
Accepts: array
Accepts: array
Accepts: array
Accepts: number