Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 5

The Reinforcement Learning Loop: Core Components

Recommended resources

Introduction

Welcome to the final lesson of our first module, "Core Concepts of Artificial Intelligence." In our previous lessons, we explored supervised learning, where models learn from labeled data, and unsupervised learning, where models discover patterns in unlabeled data. Now, we turn to the third and final major paradigm of machine learning: Reinforcement Learning (RL).

This lesson addresses the learning outcome: Describe the core components of the reinforcement learning loop: agent, environment, state, action, and reward. Unlike supervised or unsupervised learning, which typically rely on static datasets, RL is about learning through active, trial-and-error interaction with a dynamic world.

Understanding RL is crucial for your goal of mastering AI governance. This paradigm powers the most advanced autonomous systems, from the game-playing prowess of DeepMind's AlphaGo to the control systems for robotics and self-driving cars. The legal and ethical questions surrounding agency, liability, and decision-making in these systems are directly tied to the concepts we will cover today.


1. What Makes Reinforcement Learning Different?

RL is fundamentally about learning to make good sequences of decisions. An RL system, or "agent," learns behavior by receiving feedback—rewards or punishments—from its actions, much like training a pet.

To grasp the unique nature of RL, let's start with a segment from a foundational lecture by David Silver, a principal researcher on landmark RL projects like AlphaGo.

RL Course by David Silver - Lecture 1: Introduction to Reinforcement Learning

This clip from David Silver's 'Introduction to Reinforcement Learning' lecture at UCL clearly distinguishes RL from the other machine learning paradigms you've already studied.

Watch from 06:07 to 12:28. Pay close attention to the four key distinctions he makes: There is no supervisor, only a reward signal. Feedback can be delayed. Time matters (it's a sequential process). The agent's actions influence the subsequent data it receives.

As you saw, RL is not about finding patterns in a fixed dataset. It's an active, online learning process. The agent is not a passive analyst but an active participant that influences its own experience and learning trajectory. This is the paradigm for building systems that can master a skill over time, whether it's playing a video game or managing an investment portfolio.


2. The Core Interaction Loop

The entire RL process can be modeled as a loop between two key entities: the agent and the environment.

  • The Agent is the learner or decision-maker. It is the algorithm we are training.
  • The Environment is the world the agent interacts with. It comprises everything outside the agent.

The interaction between them is a continuous cycle of observation, action, and feedback.

Reinforcement Learning Loop Diagram
This diagram illustrates the fundamental cycle of Reinforcement Learning. The agent observes the state and reward from the environment, takes an action, and the environment responds with a new state and reward, continuing the loop.

Let's break down the elements of this loop, which form the core components of any RL system. The following reading from OpenAI's "Spinning Up" documentation provides a concise, text-based summary of this framework.

Part 1: Key Concepts in RL — Spinning Up documentation

This short text will formalize the concepts of the agent, environment, and the reward signal, which are the central 'characters' in reinforcement learning.

Read the section titled 'Key Concepts and Terminology' up to the sub-heading 'States and Observations'.

This interaction gives us our five core components, which we will now explore in detail: State, Action, Reward, Agent, and Environment.


3. A Deeper Look at the Five Components

Let's dissect each component of the loop. This is where the mechanics of RL become clear.

State () and Environment

The environment is the world in which the agent operates. A state is a snapshot of that environment at a specific moment in time. It's the complete set of information the agent needs to make a decision.

Part 1: Key Concepts in RL — Spinning Up documentation

Let's refine our understanding of 'state' and introduce the important concept of 'action spaces'.

Read the sections 'States and Observations' and 'Action Spaces'. Notice the important distinction between a fully observed 'state' and a partially observed 'observation'.

As you read, a key distinction is between:

  • State: A complete description of the world. In a game of chess, the state is the position of all pieces on the board.
  • Observation: A partial description of the state. A robot with a camera receives an observation (an image), which may not capture everything in the environment (e.g., an object behind it).

In many RL problems, we work under the Markov property, which assumes the current state contains all necessary information to decide the future. The past history doesn't matter if you know the present state completely. For example, in chess, the path taken to reach a board configuration is irrelevant for deciding the next best move; only the current configuration matters.

Action ()

An action is a choice that the agent can make. The set of all possible actions is called the action space. As the reading noted, action spaces can be:

  • Discrete: A finite set of choices. For example, in an Atari game, the actions are [up, down, left, right, fire].
  • Continuous: A range of real-valued choices. For example, the action for a self-driving car could be a steering angle and an acceleration value, both of which can vary continuously.

The nature of the action space is a critical technical detail that heavily influences which RL algorithms can be used.

Reward ()

The reward is the single most important signal in RL. It is a scalar number that the environment provides to the agent after each action. The agent's sole objective is to maximize the cumulative reward over time. This concept is formalized in the Reward Hypothesis.

RL Course by David Silver - Lecture 1: Introduction to Reinforcement Learning

Let's return to David Silver's lecture to understand the role of the reward signal and the powerful 'Reward Hypothesis'.

Watch from 23:04 to 27:56. Focus on how a single scalar reward signal can be engineered to represent complex goals, like finishing a task quickly or avoiding a crash.

Crafting the right reward function is one of the most challenging aspects of applied RL. A poorly designed reward can lead to unintended and undesirable behaviors. For example:

  • Goal: A cleaning robot should clean a room.
  • Poor Reward: Reward for the amount of dirt collected.
  • Unintended Behavior: The robot might learn to dump dirt it has already collected and then pick it up again to maximize its reward, rather than cleaning the whole room.

Agent and Policy ()

Finally, we have the agent itself. The "brain" of the agent is its policy, denoted by the Greek letter pi (). The policy is the agent's strategy or rule for choosing an action based on the current state.

Part 1: Key Concepts in RL — Spinning Up documentation

The policy is the core component that an RL algorithm seeks to learn and improve. This reading defines it formally.

Read the section 'Policies'. Understand the difference between a deterministic policy (which always outputs the same action for a given state) and a stochastic policy (which outputs a probability distribution over actions).

To summarize the relationship:

  • The agent is the entity that learns.
  • The policy is the learned mapping from state to action that the agent uses to behave.

Over the course of training, the RL algorithm adjusts the agent's policy based on the rewards it receives, gradually improving its ability to achieve its goal.


4. Putting It All Together: A Grid-World Example

Let's solidify these concepts with a classic example: a robot in a "Grid World."

Reinforcement Learning Explained: Core Concepts & ...

This text provides a concrete example of a GridWorld, which is a simple but powerful tool for understanding how the five RL components interact.

Read the section 'Example: RL in a Simple Environment'. As you read, mentally map each of the five components to the description of the GridWorld task.

Let's explicitly map the five components to the GridWorld scenario:

  • Environment: The 5x5 grid itself, including the locations of the goal, the "cliffs," and the starting position. The environment's rules dictate how the agent moves and what rewards are given.
  • Agent: The robot that is trying to navigate the grid.
  • State (): The agent's current coordinates on the grid (e.g., row 2, column 3).
  • Action (): The set of possible moves: [up, down, left, right]. This is a discrete action space.
  • Reward (): A numerical value given after each move. For instance, +1 for reaching the goal, -10 for falling into a cliff, and -0.1 for every other move (to encourage finding the shortest path).

The agent starts by moving randomly (exploration). When it stumbles into a cliff, it gets a large negative reward, teaching its policy to avoid that state-action pair in the future. When it finds the goal, it gets a positive reward, reinforcing the sequence of actions that led to it. Over many episodes, the policy improves until the agent can reliably find the optimal path to the goal from any starting point.

Test your understanding!

Consider the development of an AI to play the game of chess. Map the five core RL components to this problem.

  1. Agent: ?
  2. Environment: ?
  3. State: ?
  4. Action: ?
  5. Reward: ?
Show answer
  1. Agent: The AI player itself, which contains the policy for choosing moves.
  2. Environment: The rules of chess and the opponent. The environment takes the agent's move and returns the opponent's counter-move and the new board state.
  3. State: The current arrangement of all pieces on the 8x8 chessboard, plus information like whose turn it is.
  4. Action: Making a legal move with one of its pieces (e.g., moving a pawn from e2 to e4). This is a discrete action space.
  5. Reward: A simple reward function could be: +1 for winning the game, -1 for losing, and 0 for all moves that do not end the game. This is an example of sparse and delayed feedback.

Conclusion

This lesson concludes our foundational module on the core concepts of AI. We have journeyed through the three main learning paradigms: supervised, unsupervised, and now, reinforcement learning.

Key Takeaways:

  • Reinforcement Learning is about an agent learning to achieve a goal by interacting with an environment.
  • The learning process is a continuous loop: the agent observes a state, takes an action, and receives a reward and a new state.
  • The agent's goal is to learn a policy (a strategy) that maximizes its cumulative reward over time.
  • The reward signal is the mechanism used to define the goal, and careful "reward engineering" is critical to achieving desired behavior.

These five components—agent, environment, state, action, and reward—are the building blocks of all RL systems. As you move forward in your study of AI law, you will encounter these concepts again when analyzing the autonomy and liability of complex systems, from algorithmic traders in finance to lethal autonomous weapons in warfare.

Preview of the Next Module:

So far, we have discussed the what and why of AI's main learning paradigms. In our next module, "The Mechanics of Modern AI," we will dive into the how. Our first lesson will introduce the fundamental architecture of a neural network, the powerful technology that underlies most modern deep learning and deep reinforcement learning systems. You will learn about neurons, layers, weights, and activation functions—the very components that allow an AI like the Atari player you saw today to learn directly from raw pixels.