Action Chains & Rewards
Nobody tells this agent where the goal is. It starts with a policy that is pure noise — every direction equally likely — and the only feedback it ever gets is a number after each step. Press Run and watch it teach itself:
What it models. A tabular REINFORCE learner (chapter 4) with a value baseline (chapter 5’s critic, in miniature) on a 4×4 gridworld: step −1, trap −5, goal +10. Blue arrows are the policy π(a|s); the cell tint is the learned value V(s); the green curve is the return per episode climbing toward the dashed optimal line.
Knobs. Speed trades watchability for wall-clock learning; the learning rate α controls how hard each episode’s outcome yanks the policy.
Try this. Let it converge at the default α ≈ 0.1 (about 10 seconds at 5×; 28 of 30 calibration runs reach the optimal route), then reset and retry with α pushed to 2 or beyond. Now most runs lock onto a bad route: the entropy readout falls to 0 bits, the arrows freeze, and the curve flatlines below the optimal line — oversized updates destroy a policy irreversibly. Every later chapter exists to explain, and then prevent, what you just watched.
Reinforcement learning is built on the idea of an agent interacting with an environment over time. At each step, the agent observes a state, takes an action, and receives a reward. This loop — the action chain — is the core abstraction. The rest of this page builds the vocabulary to describe precisely what the demo above is doing.
The Markov Decision Process (MDP)
Section titled “The Markov Decision Process (MDP)”An MDP is defined by the tuple :
| Symbol | Meaning |
|---|---|
| Set of states | |
| Set of actions | |
| Transition probability | |
| Reward function | |
| Discount factor |
The Markov property means the future depends only on the current state, not on the history:
The Action Chain
Section titled “The Action Chain”A trajectory (or episode) is a sequence of states, actions, and rewards:
The agent’s behavior is governed by a policy — a distribution over actions given a state. The goal of RL is to find the policy that maximizes the expected cumulative reward.
The Chain Rule of Probability for Trajectories
Section titled “The Chain Rule of Probability for Trajectories”The probability of a trajectory under policy decomposes by the chain rule:
Breaking this apart:
- — the initial state distribution (given by the environment)
- — the policy’s action probability (what we control)
- — the environment’s transition dynamics (not in our control)
This factorization is fundamental. When we later derive the policy gradient, we’ll differentiate with respect to the policy parameters . The chain rule gives us:
When we take the gradient , the environment terms vanish (they don’t depend on ), leaving only:
This is why policy gradient methods work without knowing the environment dynamics — we only need the gradient of our own policy.
Interactive Demo: Build a Trajectory
Section titled “Interactive Demo: Build a Trajectory”This is the same world the learner at the top of the page is solving — but now you are the policy. Navigate the agent to the goal, and watch the trajectory and the discounted return get constructed step by step — the exact quantities the learner uses to update itself after every episode:
What’s Next
Section titled “What’s Next”In the following pages, we’ll look at:
- States and Actions — how to think about the state and action spaces
- Rewards and Return — how rewards accumulate over time, and why discounting matters
References
Section titled “References”- Sutton & Barto. Reinforcement Learning: An Introduction (2nd ed., 2018), ch. 3 — the canonical treatment of MDPs, returns, and the agent–environment loop. Free official PDF
- Bellman. Dynamic Programming. Princeton University Press, 1957 — where the recursive structure of sequential decision problems began.