Overview of Multi-Armed Bandits and different RL Approaches
This post captures my takeaways from Chapter 3 of the book Reinforcement Learning: An Introduction by Sutton and Barto, the bible of RL.
The K-Armed Bandit Problem
An agent is told to repeatedly chose one of K available actions. Each action leads to a numerical reward that is sampled from a probability distribution corresponding to the action. The goal is to maximize the total reward over a fixed number of trials or time steps.
The name "K-armed bandit" comes from the idea of a slot machine but with K levers, each corresponding to an action. The reward distribution for each action is unknown to the agent, and the agent must learn the best action to take in order to maximize its total reward. Each of K actions has an expected or mean reward given that action is selected which we defines as value of that action denoted as . Let be the reward at time and be the action taken at time . Then the expected reward for action is given by
If we maintain the estimate of action values, it can help the agent to make better decisions in the future. If we chose the action with the highest estimated value, we call it greedy action and we are exploiting our knowledge. But if we chose a random action, we call it random action and we are exploring the environment. Exploitation might yield immediate higher rewards but exploration may produce greater rewards in the long run. The decision to explore or exploit is a very complex trade-off that depends on accurate values of actions, uncertainities and the number of trials. This blog covers few simpler balancing methods to tackle exploration-exploitation dilemma.
Below is an example for a 10-armed bandit testbed. The "True Value" of each arm is drawn from a distribution. Actual rewards are then drawn from .
The true value of each arm is drawn from a distribution (dotted line). Actual rewards are then drawn from (distributions for each arm)
We use this testbed to compare the performance of different action-value methods further in this blog.
Action-Value Methods
The methods ued for estimating values of actions and thereby using them to make decisions are called action-value methods. We start with a simpler and straight forward method called sample average method and build upon it to cover more complex methods for making action selection decisions.
Sample-Average Method
The sample average method is a simple and intuitive way to estimate the value of an action. It works by maintaining a running average of the rewards received for each action and using this average to make decisions. Let be the running average of the rewards received for action after trials. Then the running average is given by
converges to as by the law of large numbers.
Action selection
- Greedy Action: The simplest way to select an action is to always choose the action with the highest estimated value. This is called greedy action. Let be the action taken at time . Then the greedy action is given by
- -greedy Action: Greedy action exploits the existing knowledge to maximize the immediate rewards. But it might miss out on a "jackpot" it didn't know existed. -greedy action explores the environment to gather new information. Let be the action taken at time . Then the -greedy action is given by
Left: Average reward per step estimated from 10000 episodes. Right: % Optimal Action selected. It is very evident that ϵ-greedy outperforms greedy and greater the value of ϵ, greater is the performance.
The Efficiency Hack: Incremental Implementation
Though the sample average method is simple and intuitive, as we increase the number of trials and episodes, computing the action-values efficiently is very important. Let be the running average of the rewards received for action after trials. Then the running average can be computed efficiently using the following update rule (it's very straight forward to derive, I recommend you to derive it on your own):
This implementation reqquires use to keep store only and to compute the next action value. This is very efficient in terms of space and computational complexity. The equation resembles the update rule that can be seen very frequently in Reinforcement Learning (even in Deep Learning).
The final pseudocode for simple bandit algorithm with -greedy action selection is given below:
Adapting to Change: Non-Stationary Problems
The algorithm discussed above holds only for stationary problems where the reward distributions are constant over time. But in real world problems, the reward distributions may change over time. In such cases, we need to adapt our algorithm to handle non-stationary problems. In such cases it makes more sense to give more weight to recent rewards and less weight to older rewards. This can be achieved by using a learning rate that is constant over time. The update rule can be modified as follows:
This is also called as exponential recency-weighte average as weight decays exponentially wrto exponent of (Expand the above equation to reward to see it for yourself).
If we want to vary learning rate but in a different procedure from sample average method, we need to make sure that the learning rate satisfies certain conditions required for convergence. Let be the learning rate for action after its selection (equals for sample average method). Not all learning rates would lead to convergence. Based on stochastic pproximation theory 1, following conditions are required for the learning rate to lead to convergence:
Solving the Dilemma: Encouraging Exploration
All the methods discussed abobe are biased by the initial actio-value estimates (which is set to 0 here). While the effect goes away in simple average method once all the actions are selected atleast once, it stays for the learning rate based methods. Though they become a set of user-defined parameters which is cumbersome, it allows use to provide some provide knowledge about the level of rewards and also helps to encourage exploration.
For example, in the 10-armed bandit problem, if we know that the best action has a reward of 5, we can set for all actions. In the begining, even though the greedy action selection always selects the best action, the reward obtained is very less then initial estimate of 5. So the agent switches to other actions to explore the environment. This technique is known as optimistic initial values. This method doesn't work for non-stationary problems (the exploration power is temporary which doesn't work in a variable environment) but it is a good starting point to introduce exploration in the agent jusst like -greedy.
Comparison between ϵ-greedy and greedy with optimistic initial values. Notice a spike for optimistic greedy in the begining? why and where it could be occuring?
Smarter Exploration with Upper Confidence Bounds (UCB)
ϵ-greedy selects non-greedy actions randomly from the set of non-optimal actions but it doesn't give any preference to any nearly greedy or uncertain actions. Attaching a metric to actually assess the potential of an action to actually be optimal is the key idea behind Upper Confidence Bounds (UCB). UCB take into account the uncertainty of the action-value estimates and the closeness of their estimates for being optimal. UCB selects actions based on the following metric:
is the number of times action has been selected up to time . is a constant that controls the amount of exploration. The square root term is a measure of uncertainty of the action-value estimate. The overall term is a measure of upper bound of the action value estimate where kind of determines the confident level. The amount of uncertaainity decreases as the number of times an action is selected increases (the square root term is a quantified measure that explains this relationship).
Comparison between ϵ-greedy and UCB. Notice how the average reward is higher for UCB despite having lesser optimal actions selected? what could be the reason for the spike at the begining of UCB and where exactly it is occuring?
Gradient Bandits: Learning Preferences for Actions
All the methods that we discussed so far are using action-value estimates to select actions. Is there any way to disassociate the action selection criteria from action-value estimates? Gradient bandit algorithm does this to some extent by giving numerical preferences to every action. Let be the preference for action at time . The probability of selecting action is given by
The preferences are updated based on the rewards received. The update rule is given by
Here is the average reward of all actions up to time . is used as a baseline to compare the reward of the current action with the average reward of all actions thereby deciding whether to increase or decrease the preference for the current action. is the step size parameter. These update rules and probability calculation criterion are pretty common in Deep Learning to train neural networks.
Comparison of all the methods discussed so far.
Interactive Demo
Try out the interactive demo below to get a better understanding of how these algorithms work. You can change the parameters of the algorithms, compare them side by side and see how they perform on any k-armed bandit testbed you can think of with different reward distributions.
- ϵ-Greedy: Balance exploration and exploitation with the ϵ parameter.
- UCB (Upper Confidence Bound): Explore actions with high uncertainty using the confidence parameter.
- Gradient Bandit: Learn action preferences using gradient-based updates.
- Optimistic Initial Values: Set high initial Q-values to encourage early exploration.
Loading interactive lab…
References
- Sutton, R. S., & Barto, A. G. (2018). Reinforcement Learning: An Introduction.
Tools
- Image Generation: Gemini, ChatGPT
- Interactive Demo: Google AI Studio
- Editor: Antigravity
Citation
Shanmukha Sainath. "Multi-armed Bandits : Introducing evaluative aspect to RL". TensorWrites (Jan 2026). https://www.tensorwrites.com/posts/multi-armed-bandits
@article{multiarmedbandits2026,
title = "Multi-armed Bandits : Introducing evaluative aspect to RL",
author = "Shanmukha Sainath",
journal = "TensorWrites",
year = "2026",
month = "Jan",
url = "https://www.tensorwrites.com/posts/multi-armed-bandits"
}