Full Return-to-Go Sequence
Difficulty: Medium · Concept: RL Fundamentals — Markov Decision Processes (MDPs)
Discounted Return computed a single number, , from the start of an episode. But every value function needs for every timestep in a trajectory, not just the first — training a value estimator means comparing its prediction at each state against the actual return-to-go from that point onward.
The naive approach re-runs the whole sum from scratch at every — work per timestep, total across the trajectory. There's a much cheaper way, using the same recursive identity noted at the end of the original problem: . Compute backward from the end of the episode, and each costs given — no re-summing.
Your task: implement returns_to_go(rewards, gamma) in time, returning a list the same length as rewards, where entry is .
Next: Design a Min Stack