Skip to content
AI360Xpert
Beta
Core ML

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.

No answer key tells your robot which move was right.
No answer key tells your robot which move was right.

Unlike supervised learning, where an omniscient teacher provides an explicit target label y∗y^* to compute a gradient loss, reinforcement learning operates without an answer key. The agent executes an action at∈Aa_t \in \mathcal{A} in state st∈Ss_t \in \mathcal{S} and receives only an evaluative scalar feedback score (Reward Rt+1R_{t+1}). 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

Your agent loops state to action to reward and back again.
Your agent loops state to action to reward and back again.

The foundational abstraction of reinforcement learning is the discrete-time Markov Decision Process (MDP), formalized by the tuple (S,A,P,R,γ)(\mathcal{S}, \mathcal{A}, \mathcal{P}, \mathcal{R}, \gamma). At time step tt, the agent inspects the current environmental state StS_t and uses its internal policy π(a∣s)\pi(a \mid s) to select an action AtA_t. The environment consumes this action, transitions according to probability distribution P(St+1∣St,At)P(S_{t+1} \mid S_t, A_t), and emits both a scalar reward Rt+1R_{t+1} and the next state St+1S_{t+1} back to the agent in an ongoing feedback cycle.

Update One Q Value

Reward 1 plus 0.9 times 2 gives target 2.8 and Q jumps to 1.4.
Reward 1 plus 0.9 times 2 gives target 2.8 and Q jumps to 1.4.

In temporal-difference Q-learning, the value function Q(s,a)Q(s, a) represents the expected cumulative return of taking action aa in state ss. Updates obey the Bellman optimality principle:

Q(s,a)←Q(s,a)+α[R+γmax⁡a′Q(s′,a′)−Q(s,a)]Q(s, a) \leftarrow Q(s, a) + \alpha \left[ R + \gamma \max_{a'} Q(s', a') - Q(s, a) \right]

Consider an initial state estimate Q(s,a)=0.0Q(s,a) = 0.0, immediate transition reward R=1.0R = 1.0, discount γ=0.9\gamma = 0.9, and estimated downstream optimal value max⁡a′Q(s′,a′)=2.0\max_{a'} Q(s', a') = 2.0. The empirical Bellman target is 1.0+(0.9×2.0)=2.81.0 + (0.9 \times 2.0) = 2.8. With learning rate α=0.5\alpha = 0.5, the temporal difference error δ=2.8−0.0=2.8\delta = 2.8 - 0.0 = 2.8 moves the Q-value halfway toward the target, jumping from 0.00.0 to 1.41.4.

Wait For Bigger Payoff

You skip a small now-reward to bank a bigger later one.
You skip a small now-reward to bank a bigger later one.

Reinforcement learning agents optimize cumulative discounted return Gt=∑k=0∞γkRt+k+1G_t = \sum_{k=0}^\infty \gamma^k R_{t+k+1} rather than immediate one-step rewards. Faced with a choice at State S0S_0, a myopic policy selects Door A for an immediate +2.0+2.0 payout before terminating (G=2.0G = 2.0). Conversely, a strategic policy selects Door B, accepting an immediate exploration investment cost of −1.0-1.0 at step 1 to access a +10.0+10.0 goal payoff at step 2. Discounted at γ=0.9\gamma = 0.9, Door B yields:

Gdelayed=−1.0+0.9×10.0=+8.0G_{\text{delayed}} = -1.0 + 0.9 \times 10.0 = +8.0

Strategic patience quadruples total return compared to short-sighted greed (+8.0+8.0 vs +2.0+2.0).

Patience Banks More Total

The patient policy banks 9 total while the greedy one banks 4.
The patient policy banks 9 total while the greedy one banks 4.

Comparing entire episode trajectories demonstrates why global return governs policy selection. A greedy policy rushes toward early rewards (+3,+1,0,0+3, +1, 0, 0), quickly trapping the agent in a local optimum that plateaus at a cumulative score of 4.04.0. In contrast, an optimal patient policy absorbs an upfront −1.0-1.0 investment, bypasses dead ends, and unlocks an eventual +8.0+8.0 jackpot at step 4, banking a total return of 9.09.0. The resulting +5.0+5.0 gap illustrates the danger of greedy action selection in sparse-reward environments.

Set Discount For Distance

Raise the discount near 0.99 for far payoffs, lower it when rewards should feel near.
Raise the discount near 0.99 for far payoffs, lower it when rewards should feel near.

The discount factor γ∈[0,1)\gamma \in [0, 1) establishes the agent's effective planning horizon, scaling approximately as Heff≈11−γH_{\text{eff}} \approx \frac{1}{1 - \gamma}. A low discount (γ=0.80\gamma = 0.80) produces an effective horizon of only 5 steps; a reward 10 steps away is discounted by 0.8010≈0.1070.80^{10} \approx 0.107, virtually blinding the agent to distant objectives while maintaining low-variance value updates. Setting γ=0.99\gamma = 0.99 expands the horizon to 100 steps, preserving over 90%90\% of a reward's magnitude at step 10 (0.9910≈0.9040.99^{10} \approx 0.904) and enabling long-range strategic credit assignment.

Where It Breaks

A loophole reward lets your agent score forever without doing the job.
A loophole reward lets your agent score forever without doing the job.

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 +1.0+1.0 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 +999+999, 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 StS_t, emit action AtA_t, and receive reward Rt+1R_{t+1} and next state St+1S_{t+1} from the environment.
  • Bellman TD update: Combines immediate reward and discounted future value; target 2.82.8 with α=0.5\alpha=0.5 shifts QQ from 0.00.0 to 1.41.4.
  • Cumulative return: Reinforcement learning optimizes discounted lifetime reward Gt=∑γkRt+k+1G_t = \sum \gamma^k R_{t+k+1} rather than instantaneous gratification.
  • Patience vs greed: Strategic policies accept short-term costs to access distant jackpots, banking 9.09.0 total vs greedy plateaus at 4.04.0.
  • Discount factor γ\gamma: Governs temporal horizon H≈11−γH \approx \frac{1}{1-\gamma}; γ=0.99\gamma=0.99 retains 90%90\% value at step 10, whereas γ=0.80\gamma=0.80 drops to 11%11\%.
  • Reward hacking: Inadequately constrained proxy rewards permit loophole cycling where agents accumulate points without completing the intended task.