![Revisit consent button](../images/body-df29beacd7496220cc94.svg)
We value your privacy
We use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking "Accept All", you consent to our use of cookies.
Customise Reject All Accept All
Customise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)
We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more
NecessaryAlways Active
Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.
  * Cookie
BCTempID
  * Duration
10 minutes
  * Description
No description available.


  * Cookie
__cf_bm
  * Duration
1 hour
  * Description
This cookie, set by Cloudflare, is used to support Cloudflare Bot Management. 


  * Cookie
AWSALBCORS
  * Duration
7 days
  * Description
Amazon Web Services set this cookie for load balancing.


  * Cookie
_cfuvid
  * Duration
session
  * Description
Cloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services


  * Cookie
li_gc
  * Duration
6 months
  * Description
Linkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.


  * Cookie
__hssrc
  * Duration
session
  * Description
This cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.


  * Cookie
__hssc
  * Duration
1 hour
  * Description
HubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.


  * Cookie
wpEmojiSettingsSupports
  * Duration
session
  * Description
WordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.


  * Cookie
BCSessionID
  * Duration
1 year 1 month 4 days
  * Description
Blueconic sets this cookie as a unique identifier for the BlueConic profile.


  * Cookie
_octo
  * Duration
1 year
  * Description
No description available.


  * Cookie
logged_in
  * Duration
1 year
  * Description
No description available.


  * Cookie
__Secure-YEC
  * Duration
past
  * Description
YouTube sets this cookie to stores the user's video player preferences using embedded YouTube video


  * Cookie
__eoi
  * Duration
6 months
  * Description
Description is currently not available.


  * Cookie
AWSALBTGCORS
  * Duration
7 days
  * Description
No description available.


  * Cookie
login-status-p
  * Duration
past
  * Description
Description is currently not available.


  * Cookie
AWSALBTG
  * Duration
7 days
  * Description
No description available.


  * Cookie
csrf_token
  * Duration
session
  * Description
No description available.


  * Cookie
token_v2
  * Duration
1 day
  * Description
Description is currently not available.


  * Cookie
D
  * Duration
1 year
  * Description
Description is currently not available.


  * Cookie
PHPSESSID
  * Duration
session
  * Description
This cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.


  * Cookie
VISITOR_PRIVACY_METADATA
  * Duration
6 months
  * Description
YouTube sets this cookie to store the user's cookie consent state for the current domain. 


  * Cookie
cookietest
  * Duration
session
  * Description
The cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.


  * Cookie
__Host-airtable-session
  * Duration
1 year
  * Description
This cookie is used to enable us to integrate the services of Airtable.


  * Cookie
__Host-airtable-session.sig
  * Duration
1 year
  * Description
This cookie is used to enable us to integrate the services of Airtable.


  * Cookie
m
  * Duration
1 year 1 month 4 days
  * Description
Stripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.


  * Cookie
BIGipServer*
  * Duration
session
  * Description
Marketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. 


  * Cookie
__cfruid
  * Duration
session
  * Description
Cloudflare sets this cookie to identify trusted web traffic.


  * Cookie
_GRECAPTCHA
  * Duration
6 months
  * Description
Google Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.


  * Cookie
__Secure-YNID
  * Duration
6 months
  * Description
Google cookie used to protect user security and prevent fraud, especially during the login process.


  * Cookie
cookieyes-consent
  * Duration
1 year
  * Description
CookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.


Functional
Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.
  * Cookie
lidc
  * Duration
1 day
  * Description
LinkedIn sets the lidc cookie to facilitate data center selection.


  * Cookie
brw
  * Duration
1 year
  * Description
No description available.


  * Cookie
brwConsent
  * Duration
5 minutes
  * Description
Description is currently not available.


  * Cookie
WMF-Uniq
  * Duration
1 year
  * Description
Description is currently not available.


  * Cookie
loom_anon_comment
  * Duration
1 year
  * Description
No description available.


  * Cookie
loom_referral_video
  * Duration
session
  * Description
Description is currently not available.


  * Cookie
VISITOR_INFO1_LIVE
  * Duration
6 months
  * Description
A cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.


  * Cookie
yt-remote-connected-devices
  * Duration
Never Expires
  * Description
YouTube sets this cookie to store the user's video preferences using embedded YouTube videos.


  * Cookie
ytidb::LAST_RESULT_ENTRY_KEY
  * Duration
Never Expires
  * Description
The cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.


  * Cookie
yt-remote-device-id
  * Duration
Never Expires
  * Description
YouTube sets this cookie to store the user's video preferences using embedded YouTube videos.


  * Cookie
yt-remote-session-name
  * Duration
session
  * Description
The yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.


  * Cookie
yt-remote-fast-check-period
  * Duration
session
  * Description
The yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.


  * Cookie
yt-remote-session-app
  * Duration
session
  * Description
The yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.


  * Cookie
yt-remote-cast-available
  * Duration
session
  * Description
The yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.


  * Cookie
yt-remote-cast-installed
  * Duration
session
  * Description
The yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.


  * Cookie
cp_session
  * Duration
3 months
  * Description
Codepen sets this cookie for Help systems found in the website.


  * Cookie
loid
  * Duration
1 year 1 month 4 days
  * Description
This cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.


Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.
  * Cookie
__hstc
  * Duration
6 months
  * Description
Hubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).


  * Cookie
hubspotutk
  * Duration
6 months
  * Description
HubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.


  * Cookie
_ga
  * Duration
1 year 1 month 4 days
  * Description
Google Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.


  * Cookie
_ga_*
  * Duration
1 year 1 month 4 days
  * Description
Google Analytics sets this cookie to store and count page views.


  * Cookie
__Host-psifi.analyticsTrace
  * Duration
6 hours
  * Description
Description is currently not available.


  * Cookie
__Host-psifi.analyticsTraceV2
  * Duration
6 hours
  * Description
Description is currently not available.


  * Cookie
_gh_sess
  * Duration
session
  * Description
GitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.


  * Cookie
YSC
  * Duration
session
  * Description
YSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.


  * Cookie
ajs_anonymous_id
  * Duration
1 year
  * Description
This cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.


  * Cookie
vuid
  * Duration
1 year 1 month 4 days
  * Description
Vimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. 


Performance
Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.
  * Cookie
AWSALB
  * Duration
7 days
  * Description
AWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.


  * Cookie
acq
  * Duration
past
  * Description
Description is currently not available.


  * Cookie
acq.sig
  * Duration
past
  * Description
Description is currently not available.


  * Cookie
ptc
  * Duration
2 years
  * Description
No description available.


Advertisement
Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.
  * Cookie
muc_ads
  * Duration
1 year 1 month 4 days
  * Description
Twitter sets this cookie to collect user behaviour and interaction data to optimize the website.


  * Cookie
guest_id_marketing
  * Duration
1 year 1 month 4 days
  * Description
Twitter sets this cookie to identify and track the website visitor.


  * Cookie
guest_id_ads
  * Duration
1 year 1 month 4 days
  * Description
Twitter sets this cookie to identify and track the website visitor.


  * Cookie
personalization_id
  * Duration
1 year 1 month 4 days
  * Description
Twitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.


  * Cookie
guest_id
  * Duration
1 year 1 month 4 days
  * Description
Twitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.


  * Cookie
bcookie
  * Duration
1 year
  * Description
LinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.


  * Cookie
__Secure-ROLLOUT_TOKEN
  * Duration
6 months
  * Description
YouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.


  * Cookie
yt.innertube::nextId
  * Duration
Never Expires
  * Description
YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.


  * Cookie
yt.innertube::requests
  * Duration
Never Expires
  * Description
YouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.


  * Cookie
session_tracker
  * Duration
session
  * Description
This cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.


  * Cookie
edgebucket
  * Duration
session
  * Description
Reddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.


  * Cookie
did
  * Duration
1 year
  * Description
Arbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.


Uncategorised
Other uncategorised cookies are those that are being analysed and have not been classified into a category as yet.
No cookies to display.
Reject All Save My Preferences Accept All
Toggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation
[](https://towardsdatascience.com/)
Publish AI, ML & data-science insights to a global community of data professionals.
Sign in[Submit an Article](https://write.insightmediagroup.io)
[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)
* * *
[Write For TDS](https://towardsdatascience.com/submissions/)
[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search
[Reinforcement Learning](https://towardsdatascience.com/category/artificial-intelligence/reinforcement-learning/)
# The Reinforcement Learning Handbook: A Guide to Foundational Questions
Simplifying all the concepts required to master reinforcement learning
[Avishek Biswas](https://towardsdatascience.com/author/neural.avb/)
November 6, 202516 min read
![Reinforcement Learning](../images/000.png)
This article will explain the fundamental concepts you need to know to understand Reinforcement Learning!
We will progress from the absolute basics of "_what even is RL_ " to more advanced topics, including agent exploration, values and policies, and distinguish between popular training approaches. Along the way, we will also learn about the various challenges in RL and how researchers have tackled them.
At the end of the article, I will also share a YouTube video I made that explains all the concepts in this article in a visually engaging way. If you are not much of a reader, you can check out that companion video instead!
_Note: All images are produced by the author unless otherwise specified._
## Reinforcement Learning Basics
Suppose you want to train an AI model to learn how to navigate an obstacle course. RL is a branch of Machine Learning where our models learn by collecting experiences - taking actions and observing what happens. More formally, RL consists of two components - the agent and the environment.
Learn this step by step with the interactive [Machine Learning](https://roadmap.sh/machine-learning) roadmap.
### The Agent
The learning process involves two key activities that happen over and over again: **exploration** and **training**. During exploration, the agent collects experiences in the environment by taking actions and finding out what happens. And then, during the training activity, the agent uses these collected experiences to improve itself.
![](../images/001.jpeg)
The agent collects experiences in the environment, and uses these experience to train a policy
### The Environment
Once the agent selects an action, the environment updates. It also returns a reward depending on how well the agent is doing. The environment designer programs how the reward is structured.
For example, suppose you are working on an environment that teaches an AI to avoid obstacles and reach the goal. You can program your environment to return a positive reward when the agent is moving closer to the goal. But if the agent collides with an obstacle, you can program it to receive a large negative reward.
In other words, the environment provides a _positive reinforcement_ (a high positive reward, for example) when the agent does something _good_ and a _punishment_ (a negative reward for example) when it does something _bad._
Although the agent is oblivious to how the environment actually operates, it can still determine from its reward patterns how to pick optimal actions that lead to maximum rewards.
![](../images/002.jpeg)
The environment and the agent are at the center of RL
### Policy
At each step, the agent AI observes the current state of the environment and selects an action. The goal of RL is to learn a mapping from observations to actions, i.e. **"given the state I am observing, what action should I choose"?**
**In RL terms, this mapping from the state to action is also called a policy.**
This policy defines how the agent behaves in different states, and in _deep_ reinforcement learning we learn this function by training some kind of a _deep_ neural network.
### Reinforcement Learning
![](../images/003.jpeg)
The agent observes state S, queries a network to generate action A. The environment executes the action and returns a reward r and the next state s'. This continues until the episode terminates. Each step the agent takes is later used to train the agent's policy network.
Understanding the distinctions and interplay between the agent, the policy, and the environment is very integral to understand Reinforcement Learning. 
  1. The Agent is the learner that explores and takes actions within the environment
  2. The Policy is the strategy (often a neural network) that the agent uses to determine which action to take given a state. In RL, our ultimate goal is to train this strategy.
  3. The Environment is the external system that the agent interacts with, which provides feedback in the form of rewards and new states.


Here is a quick one-liner definition you should remember:
> In Reinforcement Learning, the **agent** follows a **policy** to select actions within the **environment**.
## Observations and Actions
The agent explores the environment by taking a sequence of "steps". Each step is one decision. The agent _observes_ the environment's state. Decideson an _action_. Receives a _reward_. Observes the _next state_. In this section, let's understand what observations and actions are.
### Observation
Observation is what the agent sees from the environment - the information it receives about the environment's current state. In an obstacle navigation environment, the observation might be LiDAR projections to detect the obstacles. For Atari games, it might be a history of the last few pixel frames. For text generation, it might be the context of the generated tokens so far. In chess, it is the position of all the pieces, whose move it is, etc.
The observation ideally contains all the information the agent needs to take an action.
The action space is all the available decisions the agent can take. Actions can be discrete or continuous. A discrete action space is when the agent has to choose between a specific set of categorical decisions. For example, in Atari games, the actions might be the buttons of an Atari controller. For text generation, it is to choose between all the tokens present in the model's vocabulary. In chess, it could be a list of available moves. 
![](../images/body-890ad7ebc60c22a3cb62.gif)
Example of an observation and action picked by an RL agent learning to navigate an obstacle course
The environment designer can also choose a continuous action space - where the agent generates continuous values to take a "step" in the environment. For example, in our obstacle navigation example, the agent can choose the x and y velocities to get a fine grain control of the movement. In a human character control task, the action is often to output the torque or target angle for every joint in the character's skeleton.
## The most important lesson
But here is something very important to understand: To the agent and the policy - the environment and its specifics can be a complete black box. The agent will receive vector-state information as an observation, generate an action, receive a reward, and later learn from it.
So in your mind, you can consider the agent and the environment as two separate entities. The environment defines the state space, the action space, the reward strategies, and the rules.
These rules are decoupled from how the agent explores and how the policy is trained on the collected experiences.
When studying a research paper, it is important to clarify in our mind which aspect of RL we are reading about. Is it about a new environment? Is it about a new policy training method? Is it about an exploration strategy? Depending on the answer, you can treat other things as a black box.
## Exploration
How does the agent explore and collect experiences?
Every RL algorithm must solve one of the largest dilemmas in training RL agents - exploration vs exploitation.
**Exploration means trying out new actions to gather information about the environment.** Imagine you are learning to fight a boss in a difficult video game. At first, you are going to try different approaches, different weapons, spells, random things just to see what sticks and what doesn't.
However, once you start seeing some rewards, like consistently deal damage to the boss, you will stop exploring and start exploiting the strategy you have already acquired. **Exploitation means greedily picking actions you think will get the best rewards.**
> A good RL exploration strategy must balance exploration and exploitation.
A popular exploration strategy is **Epsilon-Greedy** , where the agent explores with a random action a fraction of the time (defined by a parameter epsilon), and exploits its best-known action the rest of the time. This epsilon value is usually high at the start and is gradually decreased to favor exploitation as the agent learns.
![](../images/body-cec4908eccb962d1db72.jpeg)
Epsilon Greedy is an exploration method where the RL Agent selects a random action from time to time
Epsilon greedy only works in discrete action spaces. In continuous spaces, exploration is often handled in two popular ways. One way is to add a bit of random noise to the action the agent decides to take. Another popular technique is to add an **entropy bonus** to the loss function, which encourages the policy to be less certain about its choices, naturally leading to more varied actions and exploration.
Some other ways to encourage exploration are:
  * Design the environment to use random initialization of states at the beginning of the episodes.
  * Intrinsic exploration methods where the agent acts out of its own "curiosity." Algorithms like Curiosity and RND reward the agent for visiting novel states or taking actions where the outcome is hard to predict.


I cover these fascinating methods in my Agentic Curiosity video, so be sure to check that out!
Please accept cookies to access this content
## Training Algorithms
A majority of research papers and academic topics in Reinforcement Learning are about optimizing the agent's strategy to pick actions. The goal of optimization algorithms is to learn actions that maximize the long-term expected rewards.
Let's take a look at the different algorithmic choices one by one.
## Model-Based vs Model-Free
Alright, so our agent has explored the environment and collected a ton of experience. Now what?
Does the agent learn to act directly from these experiences? Or does it first try to model the environment's dynamics and physics?
One approach is **model-based learning.** Here, the agent first uses its experience to build its own internal simulation, or a world model. This model learns to predict the consequences of its actions, i.e., given a state and action, what is the resulting next state and reward? Once it has this model, it can practice and plan entirely within its own imagination, running thousands of simulations to find the best strategy without ever taking a risky step in the real world.
![](../images/body-398ccd015c8fc19a6f4c.jpeg)
Model-based RL learns a separate model to learn how the environment works
This is particularly useful in environments where collecting real world experience can be expensive - like robotics or self-driving cars. Examples of Model-Based RL are: [Dyna-Q](https://arxiv.org/abs/1801.06176), [World Models](https://arxiv.org/abs/1803.10122), [Dreamer](https://arxiv.org/abs/2301.04104), etc. I'll write a separate article someday to cover these models in more detail.
The second is called **model-free learning**. This is what the rest of the article is going to cover. Here, the agent treats the environment as a black box and learns a policy directly from the collected experiences. Let's talk more about Model-free RL in the next section.
## Value-Based Learning
There are two main approaches to model-free RL algorithms.
Value-based algorithms learn to evaluate how good each state is. Policy-based algorithms learn directly how to act in each state.
![](../images/body-517d20eb56b5a81e6a53.jpeg)
Value Based vs Policy Based methods
In value-based methods, the RL agent learns the _"value"_ of being in a specific state. The value of a state literally means how good the state is. The intuition is that if the agent knows which states are good, it can pick actions that lead to those states more regularly.
And thankful there is a mathematical way of doing this - **the Bellman Equation**.
**V(s) = r + γ * max V(s').**
This recurrence equation basically says the **value** **V(s)** of _state s_ is equal to the immediate **reward r** of being in the state plus the**value** of the best _next-state s_ ' the agent can reach from s. Gamma (**γ**) is a discounted factor (between 0 and 1) that nerfs the goodness of the next state. It essentially decides how much the agent cares about rewards in the distant future versus immediate rewards. A **γ** close to **1** makes the agent "far-sighted," whereas a **γ** close to **0** makes the agent "short-sighted," greedily caring almost only about the very next reward.
### Q-Learning
We learnt the intuition behind state values, but how do we use that information to learn actions? The Q-Learning equation answers this.
**Q(s, a) = r + γ * max_a Q(s', a')**
The Q-value Q(s,a) is the _**q**_ _uality-value_ of the action a in state s. The above equation basically states: The quality of an action a in state s is the immediate reward **r** you get from being in state s, plus the discounted quality value of the next best action.
So in summary: 
  * **Q-values** are the quality values of each action in each state.
  * **V-values** are the value of a specific state; it is equal to the maximum Q-value of all actions in that state.
  * **Policy π** at a specific state is the action that has the highest Q-value in that state.


![](../images/body-0963967acd4d9a2aa273.jpeg)
Q-values, State values, and Policy are deeply interconnected
To learn more about Q-Learning, you can research [Deep Q Networks](https://arxiv.org/abs/1312.5602), and their descendants, like [Double Deep Q Networks](https://arxiv.org/abs/1509.06461) and [Dueling Deep Q Networks.](https://arxiv.org/abs/1511.06581)
Value-based learning trains RL agents by learning the value of being in specific states. However, is there a direct way to learn optimal actions without needing to learn state values? Yes.
Policy learning methods directly learn optimal action strategies without explicitly learning state values. Before we learn how, we must learn another important concept first. Temporal Difference Learning vs Monte Carlo Sampling.
## TD Learning vs MC Sampling
How does the agent consolidate future experiences to learn?
In Temporal Difference (TD) Learning, the agent updates its value estimates after every single step using the Bellman equation. And it does so by seeing its own estimate of the Q-value in the next state. This strategy is called 1-step TD Learning, or one-step Temporal Difference Learning. You take one step and update your learning based on your past estimates.
![](../images/body-5fce1a433d4efa079150.gif)
In TD Learning, we take one step and use the value estimates of the next state
The second option is called Monte-Carlo sampling. Here, the agent waits for the entire episode to finish before updating anything. And then it uses the complete return from the episode:   
Q(s,a) = r₁ + γr₂ + γ²r₃ + ... + γⁿrₙ
![](../images/body-e79b9b9ba3ba663e6850.gif)
In MC Sampling, we complete the entire episode to compute the estimates from actual rewards
### Trade-offs between TD Learning and MC Sampling
TD Learning is pretty cool coz the agent can learn something from every single step, even before it completes an episode. Meaning you can save your collected experiences for a long time and keep training even on old experiences, but with new Q-values. However, TD learning is heavily biased by the agent's current estimate of the state. So if the agent's estimates are wrong, it will keep reinforcing those wrong estimates. This is called the "_bootstrapping problem_."
On the other hand, Monte Carlo learning is always accurate because it uses the true returns from actual episodes. But in most RL environments, rewards and state transitions can be random. Also, as the agent explores the environment, its own actions can be random, so the states it visits during rollout are also random. This results in the pure TD-Learning method suffering from high variance issues as returns can vary dramatically between episodes.
## Policy Gradients
Alright, now that we have understood the concept of TD-Learning vs MC Sampling, it's time to get back to Policy-Based Learning methods.
Recall that value-based methods like DQN first have to explicitly calculate the value, or Q-value, for every single possible action, and then they pick the best one. But it is possible to skip this step, and Policy Gradient methods like **REINFORCE** do exactly that.
![](../images/body-2dbadeca12069a98c0f6.jpeg)
Policy gradient methods input the state and output the probability of actions to take
In REINFORCE, the policy network outputs probabilities for each action, and we train it to increase the probability of actions that lead to good outcomes. For discrete spaces, PG methods output the probability of each action as a categorical distribution. For continuous spaces, PG methods output as Gaussian distributions, predicting the mean and standard deviation of each element in the action vector.
So the question is, how exactly do you train such a model that directly predicts action probabilities from states?
Here is where the **Policy Gradient Theorem** comes in. In this article, I will explain the core idea intuitively.
  * Our policy gradient model is often denoted in the literature as pi_theta(a|s). Here, theta denotes the weights of the neural network. pi_theta(a|s) is the predicted probability of action a in state s by neural network theta.
  * From a newly initialized policy network, we let the agent play out a full episode and collect all the rewards.
  * For every action it took, figure out the total discounted return that came after it. This is done using the Monte Carlo approach.
  * Finally, to actually train the model, the policy gradient theorem asks us to maximize the formula provided in the figure below.
  * If the return was high, this update will make that action more probable in the future by increasing pi(a|s). If the return was negative, this update will make the action less probable by reducing the pi(a|s).


![](../images/body-5ff69f693658df21af44.png)
Policy Gradients
**The distinction between Q-Learning and REINFORCE**
One of the core differences between Q-Learning and REINFORCE is that Q-Learning uses 1-step TD Learning, and REINFORCE uses Monte Carlo Sampling.
By using 1-step TD, Q-learning must determine the quality value Q of each state-action possibility. Because recall that in 1-step TD the agent can take just one step in the environment and determine a quality score of the state.
On the other hand, with Monte Carlo sampling, the agent does not need to rely on an estimator to learn. Instead, it uses actual returns observed during exploration. This makes REINFORCE "unbiased" with the caveat that it requires multiple samples to correctly estimate the value of a trajectory. Furthermore, the agent cannot train until it fully finishes a trajectory (that is reach a terminal state), and it cannot reuse trajectories after the policy network updates.
In practice, REINFORCE often leads to stability issues and sample inefficiency. Let's talk about how Actor Critic addresses these limitations.
## Advantage Actor Critic
If you try to use vanilla REINFORCE on most complex problems, it will struggle, and the reason why is twofold.
The first is because it suffers from high variance coz it's a Monte Carlo sampling method. Second, it has no sense of baseline. Like, imagine an environment that always gives you a positive reward, then the returns will never be negative, so REINFORCE will increase the probabilities of all actions, albeit in a disproportionate way.
We don't want to reward actions just for getting a positive score. We want to reward them for being **better than average**.
And that is where the concept of _advantage_ becomes important. Instead of just using the raw return to update our policy, we'll subtract the expected return for that state. So our new update signal becomes: 
**Advantage = The Return you got - The Return you expected**
While Advantage gives us a baseline for our observed returns, let's also discuss the concept of Actor Critic methods.
**Actor Critic** combines the best of Value-Based Methods (like DQN) and the best of Policy-Based Methods (like REINFORCE). Actor Critic methods train a separate "critic" neural network that is only trained to evaluate states, much like the Q-Network from earlier.
The actor method, on the other hand, learns the policy. 
![](../images/body-ded22e7542456775a330.png)
Advantage Actor Critic
Combining Advantage and Actor critics, we can understand how the [popular A2C algorithm](https://arxiv.org/abs/1602.01783) works:
  * Initialize 2 neural networks: the policy or actor network, and the value or critic network. The actor network inputs a state and outputs action probabilities. The critic network inputs a state and outputs a single float representing the state's value.
  * We generate some rollouts in the environment by querying the actor
  * We update the critic network using either TD Learning or Monte Carlo Learning. There are more advanced approaches, like [Generalized Advantage Estimates](https://arxiv.org/abs/1506.02438) as well, that combine the two approaches for more stable learning.
  * We evaluate the advantage by subtracting the observed return from the average return generated by the Critic Network
  * Finally, we update the Policy network by using the advantage and the policy gradient equation.


Actor-critic methods solve the variance problem in policy gradients by using a value function as a baseline. PPO (Proximal Policy Optimization) extends A2C by adding the concepts of "trust regions" into the learning algorithm, which prevents excessive changes to the network weights during learning. We won't get into details about [PPO](https://arxiv.org/abs/1707.06347) in this article; maybe someday we will open that Pandora's box.
## Conclusion
This article is a companion piece to the YouTube video below I made. Feel free to check it out, if you enjoyed this read.
Please accept cookies to access this content
Every algorithm makes specific choices for each question, and these choices cascade through the entire system, affecting everything from sample efficiency to stability to real-world performance.
In the end, creating an RL algorithm is about answering these problems by making your choices. DQNs choose to learn values. policy methods directly learns a **policy**. Monte Carlo methods update after a full episode using actual returns - this makes them unbiased, but they have high variance because of the stochastic nature of RL exploration. TD Learning instead chooses to learn at every step based on the agent's own estimates. Actor Critic methods combine DQNs and Policy Gradients by learning an actor and a critic network separately.
Note that there's a lot we didn't cover today. But this is a good base to get you started with Reinforcement Learning. 
That's the end of this article, see you in the next one! You can use the links below to discover more of my work.
**My Patreon:**  
<https://www.patreon.com/NeuralBreakdownwithAVB>
**My YouTube channel:**  
<https://www.youtube.com/@avb_fj>
**Follow me on Twitter:**  
<https://x.com/neural_avb>
**Read my articles:**   
<https://towardsdatascience.com/author/neural-avb/>
## Register Now to Continue Reading
### Unlock Towards Data Science with a Free Account
All articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.
Register for freeSign in to your account
* * *
![](../images/body-849620ef9680d77fc51e.jpeg)
Written By
## [Avishek Biswas](https://towardsdatascience.com/author/neural.avb/)
[See all from Avishek Biswas](https://towardsdatascience.com/author/neural.avb/)
[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Artificial Intelligence](https://towardsdatascience.com/tag/artificial-intelligence/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Q Learning](https://towardsdatascience.com/tag/q-learning/)[Reinforcement Learning](https://towardsdatascience.com/tag/reinforcement-learning/)
Share This Article
  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fthe-handbook-of-reinforcement-learning-guide-to-the-foundational-questions%2F&title=The%20Reinforcement%20Learning%20Handbook%3A%20A%20Guide%20to%20Foundational%20Questions)
  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-handbook-of-reinforcement-learning-guide-to-the-foundational-questions%2F&title=The%20Reinforcement%20Learning%20Handbook%3A%20A%20Guide%20to%20Foundational%20Questions)
  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fthe-handbook-of-reinforcement-learning-guide-to-the-foundational-questions%2F&text=The%20Reinforcement%20Learning%20Handbook%3A%20A%20Guide%20to%20Foundational%20Questions)


Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.
[Write for TDS](https://towardsdatascience.com/submissions/)
## Related Articles
  * [![](../images/004.jpg)](https://towardsdatascience.com/deep-reinforcement-learning-the-actor-critic-method/)
## [Deep Reinforcement Learning: The Actor-Critic Method](https://towardsdatascience.com/deep-reinforcement-learning-the-actor-critic-method/)
[Reinforcement Learning](https://towardsdatascience.com/category/artificial-intelligence/reinforcement-learning/)
Robot friends collaborate to learn to fly a drone
[Vedant Jumle](https://towardsdatascience.com/author/vedantjumle/)
January 1, 202617 min read
  * [![](../images/body-63beb50f664a055ed739.jpg)](https://towardsdatascience.com/latest-picks-why-how-to-use-the-naive-bayes-algorithms-in-a-regulated-industry-with-sklearn-51c11c87300a/)
## [Latest picks: Why & How to use the Naive Bayes algorithms in a regulated industry with sklearn](https://towardsdatascience.com/latest-picks-why-how-to-use-the-naive-bayes-algorithms-in-a-regulated-industry-with-sklearn-51c11c87300a/)
[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)
Your daily dose of data science
[TDS Editors](https://towardsdatascience.com/author/towardsdatascience/)
December 2, 20201 min read
  * [![](../images/006.jpg)](https://towardsdatascience.com/all-you-need-to-know-to-start-speech-processing-with-deep-learning-102c916edf62/)
## [Terms you need to know to start Speech Processing with Deep Learning](https://towardsdatascience.com/all-you-need-to-know-to-start-speech-processing-with-deep-learning-102c916edf62/)
[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)
We all love our Alexa's and our Siri's. Understand some of the key terms used in audio technology.
[Harsh Maheshwari](https://towardsdatascience.com/author/anveenaik/)
May 10, 20215 min read
  * [![](../images/007.jpg)](https://towardsdatascience.com/fake-news-detection-in-environmental-communication-322ad64dfaba/)
## [Fake News Detection in Environmental Communication](https://towardsdatascience.com/fake-news-detection-in-environmental-communication-322ad64dfaba/)
[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)
A Computational Conundrum
[Veronica Villa](https://towardsdatascience.com/author/veronica.villa/)
November 17, 20226 min read
  * [![](../images/008.jpg)](https://towardsdatascience.com/i-vibe-coded-an-app-in-just-two-hours-and-regretted-it-the-next-day/)
## [I Vibe-Coded an App in Just Two Hours (And Regretted It the Next Day)](https://towardsdatascience.com/i-vibe-coded-an-app-in-just-two-hours-and-regretted-it-the-next-day/)
[Agentic AI](https://towardsdatascience.com/category/artificial-intelligence/agentic-ai/)
I saved my day with a mere $52 bill. But you don't have to repeat my mistake.
[Thuwarakesh Murallie](https://towardsdatascience.com/author/thuwarakesh/)
September 7, 20266 min read
  * [![](../images/009.png)](https://towardsdatascience.com/my-first-exploratory-data-analysis-with-chatgpt-7f100005efdc/)
## [My First Exploratory Data Analysis with ChatGPT](https://towardsdatascience.com/my-first-exploratory-data-analysis-with-chatgpt-7f100005efdc/)
[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)
Unleashing the power of ChatGPT: A deep dive into an exploratory data analysis and future opportunities
[Jye Sawtell-Rickson](https://towardsdatascience.com/author/jyesr/)
May 10, 202316 min read
  * [![](../images/010.jpeg)](https://towardsdatascience.com/random-forest-regression-5f605132d19d/)
## [Random Forest Regression](https://towardsdatascience.com/random-forest-regression-5f605132d19d/)
[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)
A basic explanation and use case in 7 minutes
[Nima Beheshti](https://towardsdatascience.com/author/nimab/)
March 2, 20227 min read
  * [![](../images/011.jpg)](https://towardsdatascience.com/tpot-automated-machine-learning-in-python-e56800e69c11/)
## [TPOT: Automated Machine Learning in Python](https://towardsdatascience.com/tpot-automated-machine-learning-in-python-e56800e69c11/)
[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)
Machine learning for everybody?
[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)
July 2, 20207 min read
  * [![](../images/012.png)](https://towardsdatascience.com/gato-the-latest-from-deepmind-towards-true-ai-1ac06e1d18cd/)
## [Gato, the latest from Deepmind. Towards true AI?](https://towardsdatascience.com/gato-the-latest-from-deepmind-towards-true-ai-1ac06e1d18cd/)
[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)
Gato can play games, generate text, process images, and control robotic arms. And it's not even too big. Is true AI coming up?
[Luciano Abriata](https://towardsdatascience.com/author/lucianosphere/)
May 28, 20225 min read


  * [YouTube](https://www.youtube.com/c/TowardsDataScience)
  * [X](https://x.com/TDataScience)
  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)
  * [Threads](https://www.threads.net/@towardsdatascience)
  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)


[](https://towardsdatascience.com/)
Your home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.
Subscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)
© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)
####  Recommended Articles 
Close
  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ "Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1")
  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ "The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs")
  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ "Does Your Company Have a Data Strategy?")
  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500) Productivity Tips, Data Career Insights, and Other Recent Must-Reads ](https://towardsdatascience.com/productivity-tips-data-career-insights-and-other-recent-must-reads-5c47eb7a2fe0/ "Productivity Tips, Data Career Insights, and Other Recent Must-Reads")


