Home/Reinforcement Learning

Introduction to Reinforcement Learning

An agent observes a state, picks an action, receives a reward, and repeats. That simple loop — run for millions of iterations — is how machines learn to play chess, control robots, and optimise ads.

Grid World

A random agent navigates a 5×5 grid. ■ = agent, ■ = goal, ■ = obstacle.

Total Reward0.0
Steps0
Episodes0
Goals Reached0

Agent in the Environment

Reward Signal

Last Reward
0.0
Last Action
-
State
(0,0)

RL Loop

Introduction to Reinforcement Learning

Learning by doing: the agent discovers what works by trying actions and observing consequences.

What is reinforcement learning?

Reinforcement learning (RL) is a framework for sequential decision-making. An agent interacts with an environment over time: at each step it observes the current state, selects an action, receives a scalar reward, and transitions to a new state. The agent’s goal is to maximise the cumulative reward over time — not just the next reward, but the long-run total.

Unlike supervised learning, there are no labelled examples. The agent learns purely from the consequences of its own actions, which may be delayed by many steps from the moment they were taken.

The RL loop

Every RL algorithm repeats the same four-step cycle:

  1. Observe the current state st from the environment.
  2. Select an action at using the current policy π(a|s).
  3. Receive a scalar reward rt and observe the next state st+1.
  4. Update the policy to make rewarding actions more likely in the future.

Run this loop for millions of steps and the agent gradually finds behaviours that accumulate high reward — even if no single step’s reward told it what to do.

RL vs supervised learning

Supervised learning needs a dataset of (input, correct-output) pairs — someone had to label the training data. RL receives only a scalar reward, and that reward can be sparse (only at episode end: win/lose) and delayed (the action that caused the win happened 200 steps ago).

The credit assignment problem is the challenge of figuring out which actions in a long sequence were responsible for a good or bad outcome. Supervised learning sidesteps this entirely by providing a direct target at every step. RL must solve it from scratch.

Types of RL

RL algorithms split along two main axes:

  • Model-free vs model-based — model-free methods (Q-Learning, policy gradients) learn directly from experience without building a model of the environment. Model-based methods (Dyna, MuZero) learn the transition dynamics P(s′|s,a) and use that model to plan ahead.
  • On-policy vs off-policy — on-policy algorithms (Sarsa, PPO) learn about the policy they are currently executing. Off-policy algorithms (Q-Learning, DQN) can learn from data generated by a different (e.g., older or random) policy.

Exploration vs exploitation

At any moment the agent faces a dilemma: exploit what it already knows to earn reward now, or explore unfamiliar actions that might turn out to be better. A purely greedy agent gets stuck in local optima. A purely random agent never uses what it has learned.

Every RL algorithm must balance this tradeoff. The grid-world visualisation above makes it vivid: the random agent wanders aimlessly, reaching the goal by chance. An agent that has learned to exploit knowledge reaches the goal in a straight line.

Real-world applications

RL has produced some of the most dramatic results in AI:

  • Games — AlphaGo (2016) defeated the world Go champion; AlphaZero learned chess, Go, and shogi from scratch in hours, reaching superhuman level in each.
  • Robotics — OpenAI’s Dactyl learned to manipulate a Rubik’s Cube using a robotic hand, entirely in simulation then transferred to hardware.
  • Ads and recommendations — every major ad platform uses RL-like systems to decide which ad to show next based on click/conversion feedback.
  • Drug discovery — RL agents propose molecular structures and receive reward based on predicted binding affinity, exploring chemical space far faster than human chemists.
  • Hyperparameter tuning — AutoML systems use RL (or Bayesian optimisation, which is related) to search neural architecture and hyperparameter spaces.

Key challenges

  • Sparse rewards — when reward only arrives at episode end, the agent must explore for a long time before receiving any learning signal.
  • Sample efficiency — RL typically requires millions of environment interactions. Real robots cannot be crashed a million times, so simulation + transfer is essential.
  • Non-stationarity — as the policy improves, the distribution of states visited changes, which can destabilise learning.
  • Reward hacking — agents sometimes find unexpected ways to maximise the reward signal that violate the designer’s intent. Specifying reward functions is harder than it looks.

The reward hypothesis

The reward hypothesis, attributed to Sutton, states: all goals and purposes of an intelligent agent can be described as the maximisation of the expected value of the cumulative sum of a scalar reward signal.

This is a working assumption, not a proven theorem. It is powerful because it reduces the problem of goal-specification to the problem of reward-function design — difficult, but tractable. Whether every goal can be described this way remains an open philosophical question.

Recap

  • RL is about sequential decision-making under uncertainty with a scalar reward signal.
  • The four-step loop (observe, act, reward, update) is common to all RL algorithms.
  • The key difference from supervised learning is the absence of direct labels and the presence of delayed, sparse credit assignment.
  • The exploration–exploitation tradeoff is fundamental and unsolved in general.
  • Applications range from games and robotics to ads, drug discovery, and AutoML.
Random Agent in Grid World

Recall check

0 of …

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. What is the difference between a reward and a return in RL?

  2. Why is the exploration vs exploitation tradeoff fundamental to RL?

  3. What distinguishes RL from supervised learning?

  4. What is the reward hypothesis?

Cheat sheet

Introduction to Reinforcement Learning

RL = agent + environment + reward signal. The agent observes state s, picks action a, receives reward r, transitions to s'. Goal: maximise cumulative discounted return G_t = r_t + γr_{t+1} + ... Key challenge: credit assignment (which actions caused good outcomes?) and exploration-exploitation tradeoff.

REINFORCEMENT LEARNING · AI.Cruz

About the author

AI.Cruz builds and maintains AI.Cruz. Every module here is written and the visualisation behind it hand-built. Corrections are genuinely welcome — if a page states something wrong, get in touch.