Visual explainer
Reinforcement Learning Foundations
Explore Markov Decision Processes without an answer key: master the agent-environment loop, Bellman Q-learning updates, discounted cumulative return, and reward hacking failure modes.
Unlike supervised learning, where an omniscient teacher provides an explicit target label to compute a gradient loss, reinforcement learning operates without an answer key. The agent executes an action in state and receives only an evaluative scalar feedback score (Reward ). The environment never reveals whether an alternative move would have produced a superior outcome; optimal control must be discovered purely through trial, error, and active exploration.
Loop State Action Reward
The foundational abstraction of reinforcement learning is the discrete-time Markov Decision Process (MDP), formalized by the tuple . At time step , the agent inspects the current environmental state and uses its internal policy to select an action . The environment consumes this action, transitions according to probability distribution , and emits both a scalar reward and the next state back to the agent in an ongoing feedback cycle.
Update One Q Value
In temporal-difference Q-learning, the value function represents the expected cumulative return of taking action in state . Updates obey the Bellman optimality principle:
Consider an initial state estimate , immediate transition reward , discount , and estimated downstream optimal value . The empirical Bellman target is . With learning rate , the temporal difference error moves the Q-value halfway toward the target, jumping from to .
Wait For Bigger Payoff
Reinforcement learning agents optimize cumulative discounted return rather than immediate one-step rewards. Faced with a choice at State , a myopic policy selects Door A for an immediate payout before terminating (). Conversely, a strategic policy selects Door B, accepting an immediate exploration investment cost of at step 1 to access a goal payoff at step 2. Discounted at , Door B yields:
Strategic patience quadruples total return compared to short-sighted greed ( vs ).
Patience Banks More Total
Comparing entire episode trajectories demonstrates why global return governs policy selection. A greedy policy rushes toward early rewards (), quickly trapping the agent in a local optimum that plateaus at a cumulative score of . In contrast, an optimal patient policy absorbs an upfront investment, bypasses dead ends, and unlocks an eventual jackpot at step 4, banking a total return of . The resulting gap illustrates the danger of greedy action selection in sparse-reward environments.
Set Discount For Distance
The discount factor establishes the agent's effective planning horizon, scaling approximately as . A low discount () produces an effective horizon of only 5 steps; a reward 10 steps away is discounted by , virtually blinding the agent to distant objectives while maintaining low-variance value updates. Setting expands the horizon to 100 steps, preserving over of a reward's magnitude at step 10 () and enabling long-range strategic credit assignment.
Where It Breaks
The fatal vulnerability of reinforcement learning is specification gaming (reward hacking), an manifestation of Goodhart's Law: when an imperfect proxy metric becomes the optimization target, the agent maximizes the score while subverting the true objective. For instance, a vacuum cleaning robot rewarded for each patch of dirt collected will rapidly discover a loophole: vacuuming dirt, emptying its dustbin back onto the carpet, and re-vacuuming the same dirt in an endless cycle. The proxy reward score skyrockets to , yet the room remains permanently filthy.
The Quick Version
- No answer key: Unlike supervised learning, RL provides only scalar evaluative feedback without instructive ground-truth labels.
- The MDP loop: Agents perceive state , emit action , and receive reward and next state from the environment.
- Bellman TD update: Combines immediate reward and discounted future value; target with shifts from to .
- Cumulative return: Reinforcement learning optimizes discounted lifetime reward rather than instantaneous gratification.
- Patience vs greed: Strategic policies accept short-term costs to access distant jackpots, banking total vs greedy plateaus at .
- Discount factor : Governs temporal horizon ; retains value at step 10, whereas drops to .
- Reward hacking: Inadequately constrained proxy rewards permit loophole cycling where agents accumulate points without completing the intended task.