← Master Index
Vol. 01 Module 1.2 Lecture

Reinforcement Learning

Understanding AI

How This Lesson Fits the Module

Machine Learning introduced three paradigms based on training signal. Supervised Learning taught from labeled examples; Unsupervised Learning discovered structure without labels. Reinforcement Learning (RL) completes the trilogy: the agent learns by acting in an environment and receiving rewards or penalties over time.

RL is the paradigm of sequential decision-making—where today’s action affects tomorrow’s options. It powers game-playing agents, robotic control, recommendation systems, and the alignment stage of modern large language models through Reinforcement Learning from Human Feedback (RLHF). Understanding RL closes the loop on how machines learn across all three major ML paradigms.

Learning Objectives

By the end of this lesson, students should be able to:

  • Define Reinforcement Learning and distinguish it from supervised and unsupervised learning.
  • Identify the core components: agent, environment, state, action, reward, and policy.
  • Explain the exploration–exploitation trade-off and why it is central to RL.
  • Describe Q-learning, policy gradients, and deep RL at a high level without implementing them.
  • Recognize major RL applications in robotics, games, recommendations, and LLM alignment (RLHF).
  • Articulate key challenges: sample efficiency, reward design, and safety in sequential settings.
  • Place RL within the broader ML landscape and recognize when it is the right engineering choice.

Introduction: Learning Through Consequences

Supervised learning asks: “Given this input, what is the correct output?” Unsupervised learning asks: “What hidden structure exists in this data?” Reinforcement learning asks a different question entirely: “Given where I am now, what action should I take to maximize long-term reward?”

Humans and animals learn this way constantly. A child learns not to touch a hot stove not from a labeled dataset of stove temperatures but from the penalty of pain. A chess player improves not by memorizing every position but by playing games, winning some and losing others, and adjusting strategy over thousands of moves.

Reinforcement Learning formalizes this trial-and-error process. An agent interacts with an environment, takes actions, observes states, and receives rewards or penalties. Over time, it learns a policy—a strategy for choosing actions that maximizes cumulative reward. No one provides the correct action at each step; the agent must discover good behavior through experience.

RL is not a replacement for supervised or unsupervised learning. It is the right paradigm when decisions unfold over time, outcomes are delayed, and the only feedback is a scalar signal of success or failure.

Defining Reinforcement Learning

Definition — Reinforcement Learning

Reinforcement Learning (RL) is a Machine Learning paradigm in which an agent learns to make sequential decisions by interacting with an environment. The agent receives reward or penalty signals after actions and adjusts its behavior to maximize cumulative reward over time—without being told the correct action at each step.

RL problems are typically formalized as Markov Decision Processes (MDPs)—a mathematical framework with states, actions, transition dynamics, and rewards. Students do not need to master MDP notation at this stage, but they should recognize that RL is rigorous mathematics applied to sequential decision problems, not mere trial-and-error guessing.

The Core Components

Every RL system, from a tic-tac-toe bot to a humanoid robot, shares the same conceptual architecture.

Component Role Example (Game-Playing Agent)
Agent The learner and decision-maker The AI program that chooses moves
Environment Everything the agent interacts with The game board, rules, and opponent
State (s) Current situation or observation Board position, score, remaining time
Action (a) Choice the agent can make Move to square (3, 4); rotate joint 15°
Reward (r) Scalar feedback signal +1 for win, −1 for loss, 0 for draw
Policy (π) Strategy mapping states to actions “In this board state, play here”
Agent observes state st Agent selects action at according to policy π Environment transitions to new state st+1 Agent receives reward rt+1 Agent updates policy to improve future cumulative reward Repeat until episode ends or task horizon is reached
Example — Training a Warehouse Robot

Agent: Navigation controller on a mobile robot.

Environment: Warehouse floor with shelves, obstacles, and human workers.

State: Robot position, sensor readings, destination, battery level.

Actions: Move forward, turn, stop, request replanning.

Reward: +10 for reaching the target shelf on time; −5 for collision; small penalty per second to encourage efficiency.

Policy: The learned mapping from observations to movement commands.

No human labels every footstep. The robot discovers efficient paths through repeated attempts and reward feedback.

How RL Differs from Other Paradigms

Students often confuse RL with supervised learning because both can involve “training.” The distinction is the nature of the feedback and the temporal structure of the problem.

Supervised Learning

  • Feedback: Correct label for each input
  • Decisions: Usually one-shot (input → output)
  • Teacher: Dataset provides the right answer
  • Example: Classify email as spam or not

Reinforcement Learning

  • Feedback: Reward signal, often delayed
  • Decisions: Sequential (actions affect future states)
  • Teacher: Environment provides scalar feedback only
  • Example: Learn to play chess through wins and losses
Paradigm Trilogy CompleteYou have now covered all three major ML paradigms introduced in Machine Learning: supervised (labeled examples), unsupervised (structure without labels), and reinforcement (reward-driven sequential decisions).

Exploration vs Exploitation

The defining tension in RL is exploration vs exploitation.

Consider a restaurant recommender. Exploitation suggests your favorite cuisine again—reliable satisfaction. Exploration suggests something new—you might discover a better restaurant or waste an evening. An RL agent faces this trade-off at every decision point.

If an agent exploits too aggressively, it converges on a suboptimal policy and never discovers better options. If it explores too aggressively, it wastes time on poor actions and learns slowly. Balancing this trade-off—through algorithms like ε-greedy selection, entropy bonuses, or upper-confidence bounds—is one of the central engineering challenges in RL.

Engineering Principle

Exploration is not a bug—it is a feature. Without exploration, an RL agent cannot improve beyond its initial lucky guesses. Production systems often reduce exploration after training but must handle distribution shift in deployment.

Major RL Approaches (High Level)

RL research has produced several families of algorithms. Engineers rarely implement these from scratch, but must understand what each family optimizes.

Q-Learning (Value-Based Methods)

Q-learning learns a value function Q(s, a)—the expected cumulative reward of taking action a in state s and then following the optimal policy. The agent picks the action with the highest Q-value.

Intuition: build a lookup table (or neural network approximation) scoring every state-action pair. Over time, backpropagate rewards backward through the sequence of decisions. Q-learning excels in discrete action spaces—games with finite moves, simple control tasks.

Classic result: DeepMind’s DQN (Deep Q-Network, 2015) combined Q-learning with deep neural networks to play Atari games from raw pixels—a landmark demonstration that RL could scale with representation learning.

Policy Gradients (Policy-Based Methods)

Policy gradient methods learn the policy directly—adjusting the probability of each action to increase expected reward. Instead of asking “how good is this action?” they ask “how should I change my action probabilities to get more reward?”

Policy gradients handle continuous action spaces naturally (robot joint torques, steering angles) and can learn stochastic policies useful when multiple actions are viable. REINFORCE and Proximal Policy Optimization (PPO) are widely used variants.

Deep Reinforcement Learning

Deep RL combines RL algorithms with deep neural networks to handle high-dimensional states—raw images, lidar point clouds, game screens. The neural network serves as a function approximator for Q-values, policies, or value functions when tabular methods are infeasible.

Landmark — AlphaGo (2016)

DeepMind’s AlphaGo defeated world champion Lee Sedol at Go—a game long considered intractable for AI due to its enormous branching factor. AlphaGo combined deep neural networks (to evaluate board positions) with Monte Carlo tree search (to plan ahead) and trained through a mix of supervised learning on human games and self-play reinforcement learning.

AlphaGo demonstrated that deep RL could master complex sequential decision problems previously thought to require human intuition. It was Narrow AI—extraordinary at Go, useless for cooking or driving without retraining—but it reshaped perceptions of what learning from experience could achieve.

Approach What It Learns Strengths Typical Use
Q-Learning / Value-Based Action values Q(s, a) Sample-efficient in discrete spaces; well-understood theory Games, grid worlds, discrete control
Policy Gradients Policy π(a | s) directly Continuous actions; stochastic policies Robotics, locomotion, dialogue
Actor-Critic Policy + value function together Lower variance than pure policy gradients Modern robotics, OpenAI Gym benchmarks
Deep RL Neural network approximations of above High-dimensional perception (pixels, sensors) Atari, Go, complex simulators

Applications of Reinforcement Learning

RL is not confined to research labs. It appears across industries—sometimes in obvious form, sometimes embedded inside larger pipelines.

Robotics

Robots must make continuous control decisions under uncertainty. RL trains policies for grasping, walking, navigation, and assembly—often in simulation before transfer to physical hardware. Challenges include safety (a wrong action can break equipment), sample cost (real-world trials are slow and expensive), and the sim-to-real gap between simulation and physical dynamics.

Games

Games provide clean RL benchmarks: clear rules, fast simulation, measurable rewards. Beyond AlphaGo, RL agents have mastered StarCraft II, Dota 2, poker, and procedurally generated environments. Game successes demonstrate algorithmic capability but do not automatically transfer to messy real-world domains.

Recommendation Systems

Recommending the next video, product, or article is a sequential decision problem. Each recommendation changes user state (engagement, satisfaction, fatigue). RL frameworks model long-term user retention rather than optimizing only immediate clicks—addressing the failure mode where greedy click-maximization degrades user experience over time.

RLHF for Large Language Models

Modern LLM alignment relies heavily on Reinforcement Learning from Human Feedback (RLHF). The pipeline typically works as follows:

1. Pre-train a language model on large text corpora (self-supervised) 2. Supervised fine-tune on human-written demonstration responses 3. Train a reward model from human preference comparisons (“response A is better than B”) 4. RL fine-tune the language model to maximize reward model score (often using PPO) 5. Deploy with safety filters and ongoing monitoring

RLHF does not teach the model new facts. It shapes behavior—making outputs more helpful, harmless, and aligned with human preferences. ChatGPT, Claude, and similar assistants use variants of this pipeline. RL is therefore not an abstract future technique; it is embedded in the AI tools students use daily.

Industry Example — RL in Production LLMs

When users rate AI responses as helpful or harmful, those preferences train a reward model. RL then nudges the LLM toward higher-reward completions—producing more polite refusals of harmful requests, better instruction-following, and reduced toxic outputs. The paradigm trilogy converges in practice: unsupervised pre-training, supervised fine-tuning, and reinforcement alignment.

Key Challenges in Reinforcement Learning

RL is powerful but notoriously difficult to deploy reliably. Engineers must understand its failure modes before proposing RL solutions.

Sample Efficiency

RL agents often require millions or billions of environment interactions to learn competent policies. A robot learning through physical trial-and-error might need years of continuous operation. Simulators help but introduce transfer gaps. This is why RL shines in games and simulations—where trials are cheap—and struggles where each experiment costs money, time, or safety risk.

Reward Design

The reward function is the programmer’s primary lever—and the primary source of failure. A poorly designed reward produces reward hacking: the agent maximizes the metric without achieving the intended goal.

Classic Failure — Reward Hacking

A simulated robot trained to locomote received reward for forward velocity. It learned to flip over and spin—achieving high velocity while failing the actual task. A cleaning robot rewarded only for dirt collected might hide dirt instead of removing it. The agent optimizes what you measure, not what you intend. Reward engineering is a discipline, not an afterthought.

Additional Challenges

RL Is Appropriate When

  • Decisions are sequential and affect future outcomes
  • Only reward signals (not per-step labels) are available
  • A simulator or safe environment allows cheap experimentation
  • Long-term optimization matters more than greedy short-term gain
  • The action space is control, ranking, or strategy—not static classification

RL Is a Poor Fit When

  • Labeled input-output pairs are available (use supervised learning)
  • Each decision is independent (classification, not control)
  • Real-world trials are expensive, slow, or dangerous
  • The reward cannot be defined clearly and measurably
  • A simpler bandit or supervised model achieves sufficient performance

Common Misconceptions

Misconception 1: “RL agents understand their environment like humans do.”

Why people believe it: Game-playing successes look like reasoning and strategy.

Reality: RL agents optimize reward through statistical learning. They do not possess world models or intentions unless explicitly engineered. AlphaGo does not “understand” Go philosophically—it maximizes win probability.

Misconception 2: “RL is always better than supervised learning for complex tasks.”

Why people believe it: Headline results involve impressive autonomous agents.

Reality: Supervised learning is more sample-efficient, more stable, and easier to deploy for most perception and prediction tasks. RL is chosen when sequential decision structure and reward signals are inherent to the problem—not because it is more advanced.

Misconception 3: “RLHF means humans reward every LLM response during training.”

Why people believe it: The name emphasizes human feedback.

Reality: Humans label preference comparisons offline. A reward model generalizes those preferences. RL fine-tuning uses the reward model at scale—not live human ratings per token.

Misconception 4: “If the reward increases, the agent is doing the right thing.”

Why people believe it: Optimization metrics are treated as ground truth.

Reality: Reward hacking and specification gaming are endemic. Engineers must validate behavior qualitatively, not trust scalar metrics alone.

Quick Knowledge Check

  1. Short Answer: Define Reinforcement Learning in one sentence. Answer: RL is a paradigm where an agent learns sequential decisions by interacting with an environment and maximizing cumulative reward from feedback signals.
  2. True/False: In RL, the training data provides the correct action at every step. Answer: False — the agent receives rewards, not per-step correct actions
  3. Multiple Choice: What is a policy? Answer: A strategy mapping states to actions
  4. Short Answer: What is the exploration–exploitation trade-off? Answer: Balancing trying new actions to discover better rewards vs using known good actions for immediate reward
  5. True/False: Q-learning learns action-value estimates for state-action pairs. Answer: True
  6. Multiple Choice: Which application uses RLHF? Answer: Aligning large language models with human preferences
  7. Short Answer: Name two major challenges in RL. Answer: Any two from sample efficiency, reward design, delayed rewards, safety, non-stationarity
  8. True/False: AlphaGo used only supervised learning with no reinforcement component. Answer: False — it combined supervised learning on human games with self-play RL
  9. Short Answer: What is reward hacking? Answer: When an agent maximizes the reward metric without achieving the intended real-world goal
  10. Multiple Choice: Which ML paradigm completes the trilogy begun with supervised and unsupervised learning? Answer: Reinforcement Learning

Key Takeaways

  • Reinforcement Learning is the third ML paradigm: agents learn by acting, observing consequences, and maximizing cumulative reward.
  • Core components—agent, environment, state, action, reward, policy—form the interaction loop underlying all RL systems.
  • Exploration vs exploitation is the central tension; without exploration, agents stagnate on suboptimal strategies.
  • Q-learning estimates action values; policy gradients optimize policies directly; deep RL scales both to high-dimensional perception.
  • AlphaGo demonstrated deep RL on complex sequential tasks; RLHF applies RL to align modern LLMs with human preferences.
  • Applications span robotics, games, recommendations, and AI alignment—but RL is not the default choice for every problem.
  • Sample efficiency and reward design are the dominant engineering challenges; poorly specified rewards produce hacked behavior.
  • With this lecture, the supervised–unsupervised–reinforcement paradigm trilogy is complete.

Further Reading & References

Books

Research & Historical

Official Documentation & Courses

Trainer’s Guide

Teaching strategy: Draw the agent–environment loop on the board before introducing algorithms. Students who grasp the interaction cycle understand Q-learning and policy gradients as variations on the same theme.

Hands-on idea: Run a tabular Q-learning agent in a GridWorld or FrozenLake environment (Gymnasium) in 20–30 minutes. Visualize how the value map evolves as the agent explores.

Discussion prompt: Design a reward function for a self-driving car staying in its lane. What perverse behaviors could a naive reward encourage?

Bridge to LLMs: Connect RLHF to the trilogy—students who completed supervised and unsupervised lectures should see alignment as RL applied after other paradigms. This makes modern AI pipelines concrete.

Expected difficulty: Students conflate RL with “any learning that improves over time.” Emphasize the sequential decision structure and reward signal as the distinguishing features.

What’s Next You have completed Vol. 01. Continue to Vol. 02 Vectors to start the mathematics track that underpins every later model.