Lesson 1 · The problem
States, actions, rewards, return
Training starts by writing the duck's task as a loop, set up as a Markov decision process: the next moment depends only on this one and the action. Strictly it is a partially observed one, since the policy sees an observation rather than the whole state. Every tick t the policy reads an observation ot of 61 numbers and chooses an action at of 14 joint targets, then physics advances and the environment pays a reward rt. The policies run at 50 Hz, so a tick, which is also a step here, lasts 20 ms.
So what is the policy trained to raise? Not the next reward but the expected discounted return, every reward still to come, each weighted less the further away it is. With the discount γ = 0.99, a reward one tick further away weighs 0.99 times as much.
Gt = rt + γrt+1 + γ2rt+2 + …, with a horizon of about 1/(1 − γ) ticks.
The figure
- Ticks. A reward arrives every 20 ms tick, one bar each.
- Discount. Each bar shrinks by γ for every tick of distance, so the far ones count for less.
- Horizon. A flag at 1/(1 − γ) ticks: 100 ticks, 2 s at 50 Hz, where the weight is 0.37.
- Return. The weighted bars stack into one number, the return the policy is trained to raise.
Big idea: a policy optimizes the near future it can see, about 1/(1 − γ) ticks, which for Microduck is about 2 s.