Reinforcement Learning: A Comprehensive Guide for Engineers (2023)

Welcome back to our blog for engineers eager to delve into the realm of artificial intelligence! In our last post, we explored ways to enhance your career path in machine learning. Today, we take the next step by introducing Reinforcement Learning (RL). Alongside defining RL, this article provides a fundamental yet essential glimpse into its practical application. By the end, you'll gain foundational knowledge in:

Understanding Reinforcement Learning

Reinforcement Learning, a subset of machine learning, involves an agent learning to select actions within its action space in a specific environment to maximize rewards over time. It comprises four essential elements:

  1. Agent: The program you train with the goal of accomplishing a specified task.
  2. Environment: The real or virtual world where the agent executes actions.
  3. Action: The shift made by the agent causing a status change in the environment.
  4. Reward: The evaluation of an action, which can be positive or negative.

The initial step in modeling an RL task is determining these four elements as defined above. Once each element is defined, you can assign your task to it. Here are some examples to aid in developing your RL intuition:

Placing Ads on a Website

  • Agent: The program deciding how many ads are suitable for a page.
  • Environment: The webpage.
  • Action: One of three - add another ad, remove an ad, or do nothing.
  • Reward: Positive for increasing revenue; negative for decreasing revenue.

In this scenario, the agent observes the environment, considering factors like the current number of ads on the webpage, and decides on one of the three actions at each step.

Creating a Personalized Learning System

  • Agent: The program deciding what appears next in an online learning catalog.
  • Environment: The learning system.
  • Action: Playing a new class video and an ad.
  • Reward: Positive if the user clicks on the presented class video, higher positive reward if the user clicks on the ad; negative if the user leaves.

This program enhances the value of a personalized class system, benefiting both the user and the system.

Controlling a Walking Robot

  • Agent: The program controlling a walking robot.
  • Environment: The real world.
  • Action: One of four moves - forward, backward, left, or right.
  • Reward: Positive if it approaches the goal; negative if it wastes time, goes in the wrong direction, or falls.

In this example, a robot can teach itself to move more effectively by adjusting its policy based on received rewards.

Key Differences with Supervised and Unsupervised Learning

1. Static vs. Dynamic

Unlike supervised and unsupervised learning, which seek static patterns in training data, RL aims to develop a dynamic policy guiding an agent's actions over time.

2. No Explicit Correct Answer

While supervised learning relies on training data providing correct answers, RL does not receive explicit correct answers. The agent learns through experimentation, guided by rewards received after actions.

3. Exploration Requirement

An RL agent must balance exploring the environment for new ways to gain rewards with exploiting already discovered sources. This is unlike supervised and unsupervised learning systems that directly derive answers from training data.

4. Multi-Decision Process

RL involves a multi-decision process, forming a decision chain over time to complete a specific task. In contrast, supervised learning is a single-decision process - one instance, one prediction.

Utilizing OpenAI Gym

OpenAI Gym, a toolkit for developing and comparing RL algorithms, supports activities ranging from walking to playing games like Pong or Pinball. It provides game environments where programs can execute actions. Each environment has an initial state, and after the agent takes an action, the state is updated. The policy, a crucial element, determines the agent's next steps based on its learned rules.

Here's a snippet showcasing a demo of the CartPole game from OpenAI:

import gym

env = gym.make("CartPole-v1")
observation = env.reset()

for _ in range(1000):
    action = env.action_space.sample()  # your agent here (this takes random actions)
    observation, reward, done, info = env.step(action)

    if done:
        observation = env.reset()


The policy can be programmed in various ways, such as using if-else rules or a neural network. Below is a simple demo with the most basic policy for the CartPole game:

import gym

def policy(observation):
    angle = observation[2]
    return 0 if angle < 0 else 1

env = gym.make("CartPole-v1")
observation = env.reset()

for _ in range(1000):
    action = policy(observation)
    observation, reward, done, info = env.step(action)

    if done:
        observation = env.reset()


Reinforcement Learning in Comparison

Reinforcement Learning operates parallel to supervised and unsupervised learning but differs in requiring simulated data and environments, making application to practical business situations challenging. However, its innate suitability for sequential decision scenarios renders RL technology undeniably promising.

For a more in-depth exploration of these topics, refer to our previous posts:

Stay tuned for more exciting updates!

Note: The above content is an original piece created to provide comprehensive insights into Reinforcement Learning. Our goal is to deliver valuable information to engineers eager to expand their knowledge in the field. For more detailed exploration and updates, continue following our blog.


Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated: 09/12/2023

Views: 6003

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.