All problems
N-Step Q Target
Problem
Compute the n-step Q-learning target from a list of n rewards.
G = sum of gamma^t * rewards[t]. If the episode is not done, add gamma^n * next_q; if it is done, do not bootstrap.
Hint
The discount applied to next_q is gamma raised to the number of collected rewards.
Test cases
case 1
in: [[1,1],0.9,5,false]
expected: 5.950000000000001
case 2
in: [[1,1],0.9,100,true]
expected: 1.9
case 3
in: [[],0.9,3,false]
expected: 3
case 4
in: [[2],0.5,4,false]
expected: 4
Starter codePython
def n_step_q_target(rewards, gamma, next_q, done):
# Your code here
pass4 test cases · run your code against them in the editor