The Wayback Machine - https://web.archive.org/web/20240927094837/https://www.geeksforgeeks.org/understanding-reinforcement-learning-in-depth/
Open In App

Understanding Reinforcement Learning in-depth

Last Updated : 31 Jul, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The subject of reinforcement learning has absolutely grown in recent years ever since the astonishing results with old Atari games deep Minds victory with AlphaGo stunning breakthroughs in robotic arm manipulation which even beats professional players at 1v1 dota. Since the impressive breakthrough in the ImageNet classification challenge in 2012, supervised deep learning’s successes have continued to pile up, and people from all walks of life have begun to use deep neural nets to solve a variety of new problems, including how to learn intelligent behavior in complex dynamic environments.

Why Supervised Learning is different from Reinforcement Learning?

As a result, supervised learning is used in the majority of machine learning applications. This means that you provide an input to your neural network model and know what output your model should create. As a result, you may compute gradients using a backpropagation approach to train the network to produce your desired outputs. So, let’s say you want to teach a neural network to play pong in a supervised setting, you’d get a good human player to play pong for a couple of hours, and you’d create a data set where you log all of the frames that the human sees on the screen, as well as the actions that he takes in response to those frames. So, whatever is driving the up or down arrow, we can feed those input frames into a very simple neural network, which can yield two simple behaviors at the output. It will either choose the up or down action, and we can train that neural network to duplicate the actions of a human gamer by simply training on the data set of human games using things like backpropagation. 

However, there are two significant drawbacks to this approach:

  • Supervised learning requires the creation of a data set to train on, which is not always an easy task.
  • If you train your neural network model to simply imitate the actions of the human player well, your agent can never be better at playing the game of pong than that human gamer. For example, if you want to train a neural network to be better at playing the game of pong than that human gamer.

Working on Reinforcement Learning:

There is, fortunately, and it is known as reinforcement learning. As a result, the framework and reinforcement learning are surprisingly similar to the supervised learning framework. So we still have an input frame, we run it through a neural network model, and the network produces an output action, either up or down. But now we don’t know the target label, so we don’t know whether we should have gone up or down in any case since we don’t have a data set to train on. The Policy Network is the network in reinforcement learning that converts input frames to output actions. A strategy known as Policy Gradients is now one of the simplest ways to train a policy network. In policy gradients, the strategy is to start with a completely random network. You feed a frame from the game engine to that network. It generates a random up with an activity you are aware of, either up or down. return to the game engine with that action The loop continues while the game engine generates the next frame, and the network, in this example, might be a completely connected network.

However, you may use convolutions there as well, and your network’s output will now consist of two numbers: the probability of going up and the probability of going down. While training, you’ll sample from the distribution so that you’re not always repeating the same exact activities. This will help your agent to explore the world more randomly, hopefully discovering greater rewards and, more crucially, better behavior. Because we want our agent to be able to learn entirely on its own, the only feedback we’ll give it is the game’s scoreboard. So, anytime our agent scores a goal, it receives a +1 reward, and if the opponent scores a goal, our agent receives a minus 1 penalty, and the agent’s main purpose is to optimize its policy to collect as much reward as possible. So, in order to train our policy network, the first thing we’ll do is gather a lot of data. Simply run a few of those game frames over your network, select random actions, and feed them back into the engine to generate a series of random pong games. Obviously, because our agent hasn’t learned anything valuable yet, it’ll lose the majority of those games, but the point is, our agent might get lucky and select an entire series of actions that really leads to a goal at random. In this instance, our agent will be rewarded, and it’s important to remember that for each episode, regardless of whether we desire a positive or negative reward, we can already compute the gradients that will make our agent’s actions more likely in the future. This is critical, as policy gradients will employ normal gradients to raise the probability of those acts in the future for every episode when we have a positive reward. When we get a negative, we’ll apply the same gradient, but we’ll multiply it by minus one, and this minus sign will ensure that all of the actions we made in a particularly awful episode will be less likely in the future. As a result, when training our policy network, acts that lead to negative rewards will gradually be filtered out, while actions that lead to good rewards will become increasingly likely, so in a way, our agent is learning to play pong.

The drawback of Policy Gradients:

So, we can utilize policy gradients to train a neural network to play pong. But there are a few substantial drawbacks to employing this strategy, as there always are. Let’s return to pong once more. Imagine that your agent has been practicing for a while and is actually quite good at playing pong, bouncing the ball back and forth, but then it makes a mistake at the conclusion of the episode. It allows the ball to pass through and receives a penalty. The problem with policy gradients is that they assume that because we lost that episode, all of the acts we made there must have been poor, and this will diminish the likelihood of repeating those actions in the future.

Credit Assignment Dilemma:

But keep in mind that for most portions of that episode, we were performing extremely well, so we don’t want to reduce the chance of those behaviors, which is known as the credit assignment dilemma in reinforcement learning. It’s the situation where, if you get a reward at the end of your episode, what were the particular acts that lead to that specific award, and this problem is totally due to the fact that we have a sparse reward setting. So, instead of receiving a reward for every single action, we only receive a reward after a complete episode, and our agent must figure out which element of its action sequence is causing the reward that it eventually receives, as in the example of punk. For example, our agent should understand that only the activities immediately preceding the ball’s impact are genuinely crucial; everything else after the ball has flown away is irrelevant to the final payoff. As a result of this sparse reward setting, reinforcement learning algorithms are often sampled inefficient, which means you’ll have to give them a lot of training time before they can learn anything valuable.

Montezuma’s revenge reinforcement learning algorithms

When comparing the efficiency of reinforcement learning algorithms to human learning, it turns out that the sparse reward setting fails altogether in some extreme circumstances. In the game, Montezuma’s Revenge, the agent’s mission is to negotiate a series of ladders, jump over a skull, retrieve a key, and then travel to the door – in order to progress to the next level. The issue is that by performing random acts, your agent will never see a single reward because you know the sequence of activities required to obtain that reward is far too complicated. With random actions, it’ll never get there, and your policy gradient will never receive a single positive reward, so it’ll have no idea what to do. The same is true in robotics, where you could want to train a robotic arm to pick up an object and stack it on top of something else. The average robot has roughly seven joints that can move, so it has a lot of action space. If you only give it a positive reward when it has successfully stacked a block by undertaking random exploration, it will never see any of the benefits. It’s also worth noting how this compares to the usual supervised deep learning accomplishments that we see in areas like computer vision. The reason computer vision works so well is that each input frame has a target label, allowing for very efficient gradient descent using techniques such as backpropagation. In a reinforcement learning scenario, on the other hand, you’re dealing with the huge problem of sparse reward setting. This is why, despite the fact that something as simple as stacking one block on top of another appears to be quite tough even for state-of-the-art deep learning, the usual method to solving the problem of sparse rewards has been to utilize rewards shaping.

Montezuma’s Revenge

Reward Chipping:

The practice of manually creating a reward function that has to direct your policy to some desired behavior is known as reward chipping. For example, in Montezuma’s Revenge, you may offer your agent a prize every time it avoids the skull or reaches the key, and these extra rewards will encourage your policy to behave in a certain way. 

While this obviously makes it easier for your policy to converge to intended behavior, reward shaping has a number of drawbacks:

  • For starters, reward shaping is a specific process that must be completed for each new environment in which you want to train a policy. If you use the Atari benchmark as an example, you’d have to create a different reward system for each of those games, which is simply not scalable.
  • The second issue is that reward shaping is plagued by what is known as the alignment problem. When it comes to shaping your reward function, it turns out that reward shaping is fairly tough in many circumstances. Your agent will devise some ingenious scheme to ensure that it receives a large sum of money while doing nothing. In a way, the policy is simply overfitting to that unique reward function that you designed, rather than generalizing to the anticipated behavior that you had in mind.

There are a lot of amusing examples of reward shaping gone bad. For example, if an agent was trained to jump and the reward function was the distance between its feet and the ground, the agent learned to develop a very tall body and do some sort of backflip to ensure that its feet were very far from the ground. Look at the equations below for a shaped reward function for a robotic control job to get a sense of how difficult reward shaping can be. 

R_{\text {grasp }}= \begin{cases}b_{\text {lift }}, & \text { if } h>\epsilon_{h} \\ w_{\theta}, & \text { if } d_{\text {orient }}<\epsilon_{d} \text { and } \theta_{\text {orient }}<\epsilon_{\theta} \\ 0, & \text { otherwise }\end{cases}

R_{\text {stack }}= \begin{cases}\gamma_{t} b_{\text {stack }}, & \text { if } d_{\text {stack }}<\epsilon_{d} \text { and } \theta_{\text {stack }}<\epsilon_{\theta} \\ \gamma_{t}\left(w_{\theta} r_{\theta}+w_{d} r_{d}\right), & \text { otherwise, }\end{cases}

R_{f u l l}= \begin{cases}w_{\text {stack }}, & \text { if } d_{\text {stack }}<\epsilon_{d} \wedge \theta_{\text {stack }}<\epsilon_{\theta} \\ w_{\text {stages }}, & \text { if } d_{\text {stack }}<\epsilon_{d} \wedge \theta_{\text {stack }}<\epsilon_{\theta} \\ w_{\text {grasp }}, & \text { if } h>\epsilon_{h} \\ w_{\text {stage }_{1}}, & \text { if } d_{\text {stage }_{1}}<\epsilon_{d} \\ 0, & \text { otherwise }\end{cases}

One can only imagine how much effort researchers spent developing this exact reward mechanism in order to achieve the desired behavior.

 Finally, in some circumstances, such as AlphaGo, you don’t want to conduct any reward shaping because it will confine your policy to human behavior, which isn’t always desirable. So the dilemma we’re in right now is that we know it’s difficult to train in a sparsely populated environment, but it’s also difficult to build a reward function, which we don’t always want to do. Many internet sources describe reinforcement learning as some kind of magical AI sauce that allows the agent to learn from itself or improve upon its previous form, but the reality is that the majority of these advances are the result of some of the world’s greatest minds at work today. There’s a lot of hard engineering going on behind the scenes, so I believe one of the most difficult aspects of navigating our digital landscape is separating fact from fiction in this sea of clickbait fuelled by the advertising business. Boston Dynamics’ Atlas robot is a great example of what I’m talking about. So, if you walk out on the streets and ask a thousand people who have the most advanced robots today, they’ll most likely point to Atlas from Boston Dynamics because everyone has seen the video of it doing a backflip. However, if you consider what Boston Dynamics is actually good at, it’s highly unlikely that there’s a lot of deep learning going on there if you look at their previous papers in the research track record. Don’t get me wrong, they’re doing a lot of advanced robotics, but there’s not a lot of self-driven behavior or intelligent decision-making going on in those robots, so don’t get me wrong. Boston Dynamics is an excellent robotics business, but the media impressions they’ve developed may be perplexing to many individuals who are unaware of what’s going on behind the scenes. Nonetheless, given the current state of research, we should not be dismissive of the possible dangers that these technologies may pose. It’s great that more individuals are becoming interested in AI safety research because concerns like autonomous weapons and widespread surveillance must be handled seriously. The only hope we have is that international law will be able to keep up with the tremendous technological advancements we are witnessing. On the other hand, I believe the media focuses far too much on the bad aspects of these technologies simply because people are afraid of what they don’t understand, and fear sells more ads than utopias. Most, if not all, technological advancements are good in the long term as long as we can ensure that no monopolies can preserve or enforce their dominance through the malicious use of AI.

References:

  • Gudimella, A., Story, R., Shaker, M., Kong, R., Brown, M., Shnayder, V., & Campos, M. (2017). Deep reinforcement learning for dexterous manipulation with concept networks. arXiv preprint arXiv:1709.06977.


Previous Article
Next Article

Similar Reads

ML | Reinforcement Learning Algorithm : Python Implementation using Q-learning
Prerequisites: Q-Learning technique. Reinforcement Learning is a type of Machine Learning paradigms in which a learning algorithm is trained not on preset data but rather based on a feedback system. These algorithms are touted as the future of Machine Learning as these eliminate the cost of collecting and cleaning the data. In this article, we are
6 min read
Difference Between Depth First Search, Breadth First Search and Depth Limit Search in AI
In AI, search algorithms like Depth First Search (DFS), Breadth First Search (BFS), and Depth Limit Search (DLS) are essential for systematically exploring a search space to find solutions. In this article, we'll compare these algorithms, detailing their features, benefits, and uses. Table of Content Depth First Search (DFS):Breadth First Search (B
4 min read
Genetic Algorithm for Reinforcement Learning : Python implementation
Most beginners in Machine Learning start with learning Supervised Learning techniques such as classification and regression. However, one of the most important paradigms in Machine Learning is Reinforcement Learning (RL) which is able to tackle many challenging tasks. It is an aspect of Machine learning where an agent learns to behave in an environ
5 min read
SARSA Reinforcement Learning
Prerequisites: Q-Learning techniqueSARSA algorithm is a slight variation of the popular Q-Learning algorithm. For a learning agent in any Reinforcement Learning algorithm it's policy can be of two types:- On Policy: In this, the learning agent learns the value function according to the current action derived from the policy currently being used.Off
5 min read
Epsilon-Greedy Algorithm in Reinforcement Learning
In Reinforcement Learning, the agent or decision-maker learns what to do—how to map situations to actions—so as to maximize a numerical reward signal. The agent is not explicitly told which actions to take, but instead must discover which action yields the most reward through trial and error. Multi-Armed Bandit Problem The multi-armed bandit proble
4 min read
Introduction to Thompson Sampling | Reinforcement Learning
Reinforcement Learning is a branch of Machine Learning, also called Online Learning. It is used to decide what action to take at t+1 based on data up to time t. This concept is used in Artificial Intelligence applications such as walking. A popular example of reinforcement learning is a chess engine. Here, the agent decides upon a series of moves d
4 min read
Neural Logic Reinforcement Learning - An Introduction
Neural Logic Reinforcement Learning is an algorithm that combines logic programming with deep reinforcement learning methods. Logic programming can be used to express knowledge in a way that does not depend on the implementation, making programs more flexible, compressed and understandable. It enables knowledge to be separated from use, ie the mach
3 min read
Upper Confidence Bound Algorithm in Reinforcement Learning
In Reinforcement learning, the agent or decision-maker generates its training data by interacting with the world. The agent must learn the consequences of its actions through trial and error, rather than being explicitly told the correct action. Multi-Armed Bandit Problem In Reinforcement Learning, we use Multi-Armed Bandit Problem to formalize the
6 min read
Expected SARSA in Reinforcement Learning
Prerequisites: SARSASARSA and Q-Learning technique in Reinforcement Learning are algorithms that uses Temporal Difference(TD) Update to improve the agent's behaviour. Expected SARSA technique is an alternative for improving the agent's policy. It is very similar to SARSA and Q-Learning, and differs in the action value function it follows. Expected
9 min read
Sparse Rewards in Reinforcement Learning
Prerequisite: Understanding Reinforcement Learning in-depth In the previous articles, we learned about reinforcement learning, as well as the general paradigm and the issues with sparse reward settings. In this article, we'll dive a little further into some more technical work aimed at resolving the sparse reward setting problem. The fact that we'r
15+ min read
A Beginner's Guide to Deep Reinforcement Learning
Deep Reinforcement Learning (DRL) is the crucial fusion of two powerful artificial intelligence fields: deep neural networks and reinforcement learning. By combining the benefits of data-driven neural networks and intelligent decision-making, it has sparked an evolutionary change that crosses traditional boundaries. In this article, we take a detai
10 min read
On-policy vs off-policy methods Reinforcement Learning
In the world of Reinforcement Learning (RL), two primary approaches dictate how an agent (like a robot or a software program) learns from its environment: On-policy methods and Off-policy methods. Understanding the difference between these two is crucial for grasping the fundamentals of RL. This tutorial aims to demystify the concepts, providing a
13 min read
Model-Free Reinforcement Learning: An Overview
In Reinforcement learning, we have agents that use a particular 'algorithm' to interact with the environment. Now this algorithm can be model-based or model-free. The traditional algorithms are model-based in the sense they tend to develop a 'model' for the environment. This developed model captured the 'transition probability' and 'rewards' for ea
15+ min read
What is Compatible Function Approximation Theorem in Reinforcement Learning?
Answer: The Compatible Function Approximation theorem in reinforcement learning states that in order to guarantee convergence, the use of a compatible function approximator, such as a linear function approximator, with a compatible gradient is essential when applying gradient-based optimization algorithms to update the value function.The Compatible
3 min read
Reinforcement learning from Human Feedback
Reinforcement Learning from Human Feedback (RLHF) is a method in machine learning where human input is utilized to enhance the training of an artificial intelligence (AI) agent. Let's step into the fascinating world of artificial intelligence, where Reinforcement Learning from Human Feedback (RLHF) is taking center stage, forming a powerful connect
8 min read
Reinforcement Learning using PyTorch
Reinforcement learning using PyTorch enables dynamic adjustment of agent strategies, crucial for navigating complex environments and maximizing rewards. The article aims to demonstrate how PyTorch enables the iterative improvement of RL agents by balancing exploration and exploitation to maximize rewards. The article introduces PyTorch's suitabilit
7 min read
The Role of Reinforcement Learning in Autonomous Systems
Modern te­ch advances allow robots to operate inde­pendently. Reinforce­ment learning makes this possible­. Reinforcement le­arning is a type of artificial intelligence­. It allows machines to learn and make choice­s. This article discusses reinforce­ment learning's key role­ in autonomous systems. We look at real-world use­s, advantages, and diffi
6 min read
Function Approximation in Reinforcement Learning
Function approximation is a critical concept in reinforcement learning (RL), enabling algorithms to generalize from limited experience to a broader set of states and actions. This capability is essential when dealing with complex environments where the state and action spaces are vast or continuous. This article delves into the significance, method
5 min read
Reinforcement Learning in Python: Implementing SARSA Agent in Taxi Environment
SARSA (State-Action-Reward-State-Action) is an on-policy reinforcement learning algorithm that updates its policy based on the current state-action pair, the reward received, the next state, and the next action chosen by the current policy. In this article, we will implement SARSA in Gymnasium's Taxi-v3 environment, walking through the setup, agent
8 min read
Multi-Agent Reinforcement Learning in AI
Reinforcement learning (RL) can solve complex problems through trial and error, learning from the environment to make optimal decisions. While single-agent reinforcement learning has made remarkable strides, many real-world problems involve multiple agents interacting within the same environment. This is where multi-agent reinforcement learning (MA
7 min read
Optimizing Production Scheduling with Reinforcement Learning
Production scheduling is a critical aspect of manufacturing operations, involving the allocation of resources to tasks over time to optimize various performance metrics such as throughput, lead time, and resource utilization. Traditional scheduling methods often struggle to cope with the dynamic and complex nature of modern manufacturing environmen
10 min read
Reinforcement Learning with TensorFlow Agents
Reinforcement learning (RL) represents a dynamic and powerful approach within machine learning, focusing on how agents should take actions in an environment to maximize cumulative rewards. TensorFlow Agents (TF-Agents) is a versatile and user-friendly library designed to streamline the process of developing RL algorithms and applications. This arti
6 min read
How does reward maximization work in reinforcement learning?
Reinforcement learning (RL) is a subset of machine learning that enables an agent to learn optimal behaviors through interactions with an environment to maximize cumulative rewards. In essence, RL revolves around the concept of reward maximization, where an agent takes actions that maximize the expected long-term reward. This article delves into th
7 min read
Differences between Model-free and Model-based Reinforcement Learning
Reinforcement learning (RL) is a type of machine learning where an agent learns to make decisions by performing actions in an environment to maximize some notion of cumulative reward. Two primary approaches in RL are model-free and model-based reinforcement learning. This article explores the distinctions between these two methodologies. Overview o
7 min read
What is Markov Decision Process (MDP) and Its relevance to Reinforcement Learning
In artificial intelligence and machine learning, Reinforcement Learning (RL) stands out as a powerful technique for training agents to make sequential decisions. At the heart of RL lies the concept of the Markov Decision Process (MDP). Understanding MDPs is crucial for comprehending how RL algorithms work and why they are effective. This article de
5 min read
Reinforcement Learning for Production Scheduling : The SOLO Method
Production scheduling is a critical aspect of manufacturing and operations management, involving the allocation of resources, planning of production activities, and optimization of workflows to meet demand while minimizing costs and maximizing efficiency. Traditional methods often rely on heuristic or rule-based approaches, which can be inflexible
7 min read
Multi-armed Bandit Problem in Reinforcement Learning
The Multi-Armed Bandit (MAB) problem is a classic problem in probability theory and decision-making that captures the essence of balancing exploration and exploitation. This problem is named after the scenario of a gambler facing multiple slot machines (bandits) and needing to determine which machine to play to maximize their rewards. The MAB probl
7 min read
Dyna Algorithm in Reinforcement Learning
The Dyna algorithm introduces a hybrid approach that leverages both real-world and simulated experiences, enhancing the agent's learning efficiency. This article delves into the key concepts, architecture, and benefits of the Dyna algorithm, along with its applications. Table of Content Understanding Dyna Algorithm in Reinforcement Learning Key Con
5 min read
Actor-Critic Algorithm in Reinforcement Learning
Reinforcement learning (RL) stands as a pivotal component in the realm of artificial intelligence, enabling agents to learn optimal decision-making strategies through interaction with their environments. Let's Dive into the actor-critic algorithm, a key concept in reinforcement learning, and learn how it can improve your machine learning models. Ta
12 min read
Hierarchical Reinforcement Learning (HRL) in AI
In the rapidly evolving field of Artificial Intelligence (AI), Reinforcement Learning (RL) has emerged as a powerful tool for solving complex decision-making problems. Traditional RL algorithms have shown remarkable success in various domains, from gaming to robotics. However, as tasks become more intricate, the limitations of flat RL approaches be
7 min read