SlideShare a Scribd company logo
BANDIT ALGORITHMS
Max Pagels, Data Science Specialist
max.pagels@sc5.io, @maxpagels
13.10.2016
Learning about the world
PROGRAMMING, IN A NUTSHELL
OUTPUTINPUT
ALGORITHM
MACHINE LEARNING, IN A NUTSHELL
PROGRAMINPUT & OUTPUT
LEARNING ALGORITHM
REINFORCEMENT LEARNING, IN A NUTSHELL
ACTION
WORLD
OBSERVATION
AGENT
REWARD
LEARNING HOW TO PLAY TETRIS
ACTION
WORLD
OBSERVATION
AGENT
REWARD
(Rotate/Up/Down/
Left/Right etc)
Score since
previous action
THE (STOCHASTIC)
MULTI-ARMED
BANDIT PROBLEM
Let’s say you are in a Las Vegas casino, and
there are three vacant slot machines (one-
armed bandits). Pulling the arm of a machine
yields either $0 or $1.
Given these three bandit machines, each with
an unknown payoff strategy, how should we
choose which arm to pull to maximise* the
expected reward over time?



* Equivalently, we want to minimise the expected
regret over time (minimise how much money we
lose).
FORMALLY(ISH)
Problem
We have three one-armed bandits. Each arm
yields a reward of $1 according to some fixed
unknown probability Pa , or a reward of $0 with
probability 1-Pa.
Objective
Find Pa, ∀a ∈ {1,2,3}
OBSERVATION #1
This is a partial information problem: when we
pull an arm, we don’t get to see the rewards of
the arms we didn’t pull.
(For math nerds: a bandit problem is an MDP
with a single, terminal, state).
OBSERVATION #2
We need to create some approximation, or best
guess, of how the world works in order to
maximise our reward over time.
We need to create a model.
“All models are wrong but some are useful” —
George Box
OBSERVATION #3
Clearly, we need to try (explore) the arms of all
the machines, to get a sense of which one is
best.
OBSERVATION #4
Though exploration is necessary, we also need
to choose the best arm as much as possible
(exploit) to maximise our reward over time.
THE EXPLORE/EXPLOIT TUG OF WAR
HOW DO WE SOLVE THE BANDIT PROBLEM?
A NAÏVE ALGORITHM
Step 1: For the first N pulls
Evenly pull all the arms, keeping track of the
number of pulls & wins per arm
Step 2: For the remaining M pulls
Choose the arm the the highest expected
reward
A NAÏVE ALGORITHM
Step 1: For the first N pulls
Evenly pull all the arms, keeping track of the
number of pulls & wins per arm
Step 2: For the remaining M pulls
Choose the arm the the highest expected
reward
Arm 1: {trials: 100, wins: 2}
Arm 2: {trials: 100, wins: 21}
Arm 3: {trials: 100, wins: 17}
Arm 1: 2/100 = 0.02
Arm 2: 21/100 = 0.21
Arm 3: 17/100 = 0.17
A NAÏVE ALGORITHM
Step 1: For the first N pulls
Evenly pull all the arms, keeping track of the
number of pulls & wins per arm
Step 2: For the remaining M pulls
Choose the arm the the highest expected
reward
Arm 1: {trials: 100, wins: 2}
Arm 2: {trials: 100, wins: 21}
Arm 3: {trials: 100, wins: 17}
Arm 1: 2/100 = 0.02
Arm 2: 21/100 = 0.21
Arm 3: 17/100 = 0.17
Explore
Exploit
EPOCH-GREEDY [1]
Step 1: For the first N pulls
Evenly pull all the arms, keeping track of the
number of pulls & wins per arm
Step 2: For the remaining M pulls
Choose the arm the the highest expected
reward
Arm 1: {trials: 100, wins: 2}
Arm 2: {trials: 100, wins: 21}
Arm 3: {trials: 100, wins: 17}
Arm 1: 2/100 = 0.02
Arm 2: 21/100 = 0.21
Arm 3: 17/100 = 0.17
Explore
Exploit
[1]: http://hunch.net/~jl/projects/interactive/sidebandits/bandit.pdf
EPSILON-GREEDY/Ε-GREEDY [2]
Choose a value for the hyperparameter ε
Loop forever
With probability ε:
Choose an arm uniformly at random, keep track of trials and wins
With probability 1-ε:
Choose the arm the the highest expected reward
Explore
Exploit
[2]: people.inf.elte.hu/lorincz/Files/RL_2006/SuttonBook.pdf
OBSERVATIONS
For N = 300 and M = 1000, the Epoch-Greedy algorithm will choose
something other than the best arm 200 times, or about 15% of the time.
At each turn, the ε-Greedy algorithm will choose something other than the
best arm with probability P=(ε/n) × (n-1), n=number of arms. It will always
explore with this probability, no matter how many time steps we have
done.
Ε-GREEDY: SUB-OPTIMAL LINEAR REGRET*
- O(N)Cumulativeregret
4
Timesteps
*Assuming no annealing
THOMPSON SAMPLING ALGORITHM
For each arm, initialise a uniform probability distribution (prior)
Loop forever
Step 1: sample randomly from the probability distribution of each
arm
Step 2: choose the arm with the highest sample value
Step 3: observe reward for the chosen and update the
hyperparameters of its probability distribution (posterior)
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
Assumption: rewards follow a Bernoulli process, which allows us to use a 𝛽-distribution as a
conjugate prior.
FIRST, INITIALISE A UNIFORM RANDOM PROB.
DISTRIBUTION FOR BLUE AND GREEN
0 10 1
FIRST, INITIALISE A UNIFORM RANDOM PROB.
DISTRIBUTION FOR BLUE AND GREEN
0 1
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
RANDOMLY SAMPLE FROM BOTH ARMS (BLUE GETS THE
HIGHER VALUE IN THIS EXAMPLE)
0 1
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
PULL BLUE , OBSERVE REWARD (LET’S SAY WE GOT A
REWARD OF 1)
0 1
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
UPDATE DISTRIBUTION OF BLUE
0 1
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
REPEAT THE PROCESS: SAMPLE, CHOOSE ARM WITH
HIGHEST SAMPLE VALUE, OBSERVE REWARD, UPDATE.
0 1
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
0 1
AFTER 100 TIMESTEPS, THE DISTRIBUTIONS MIGHT LOOK
LIKE THIS
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
0 1
AFTER 1,000 TIMESTEPS, THE DISTRIBUTIONS MIGHT LOOK
LIKE THIS: THE PROCESS HAS CONVERGED.
EXAMPLE WITH TWO ARMS (BLUE & GREEN)
THOMPSON SAMPLING: LOGARITHMIC REGRET -
O(LOG(N))Cumulativeregret
100
Timesteps
MULTI-ARMED BANDITS ARE
GOOD…
So far, we’ve covered the “vanilla” multi-armed bandit problem. Solving this
problem lets us find the globally best arm to maximise our expected reward
over time.
However, depending on the problem, the globally best arm may not always
be the best arm.
…BUT CONTEXTUAL BANDITS
ARE THE HOLY GRAIL
The the contextual bandit setting, once we pull an arm and receive a reward,
we also get to see a context vector associated with the reward. The
objective is now to maximise the expected reward over time given the
context at each time step.
Solving this problem gives us a higher reward over time in situations where
the globally best arm isn’t always the best arm.
Example algorithm: Thompson Sampling with Linear Payoffs [3]
[3]: https://arxiv.org/abs/1209.3352
…ACTUALLY, ADVERSARIAL
CONTEXTUAL BANDITS ARE THE
HOLY GRAIL
Until now, we’ve assumed that each one-armed bandit gives a $100 reward
according to some unknown probability P. In real-world scenarios, the world
rarely behaves this well. Instead of a simple dice roll, the bandit may pay out
differently depending on the day/hour/amount of money in the machine. It
works as an adversary of sorts.
A bandit algorithm that is capable of dealing with changes in payoff
structures in a reasonable amount of time tend to work better than
stochastic bandits in real-world settings.
Example algorithm: EXP4 (a.k.a the “Monster” algorithm) [4]
[4]: https://arxiv.org/abs/1002.4058
CONTEXTUAL BANDIT
ALGORITHMS ARE 1) STATE-OF-
THE-ART & 2) COMPLEX
• Many algorithms are <5 years old. Some of the most interesting ones
are less than a year old.
• Be prepared to read lots of academic papers and struggle
implementing the algorithms.
• Don’t hesitate to contact the authors if there is some detail you don’t
understand (thanks John Langford and Shipra Agrawal!)
• Always remember to simulate and validate bandits using real data.
REAL-WORLD APPLICATIONS OF BANDITS
MEDICAL TREATMENTS
BIVARIATE & MULTIVARIATE TESTING
Vanilla MAB
UI OPTIMISATION
CODEC SELECTION
ONLINE MATCHMAKING
PERSONALISED RECOMMENDATIONS
… & COUNTLESS OTHER POSSIBILITIES
TIP: CONTEXTUAL BANDIT IMPLEMENTED IN
PYTHON + LAMBDA + API GATEWAY + REDIS
= OPTIMISATION ENGINE
DEMO: HTTPS://
MWTDS.AZUREWEBSITES.NET/HOME/
APITESTDRIVE
LAUNCHED YESTERDAY (!): AZURE
CUSTOM DECISION SERVICE
IF YOU CAN MODEL IT AS A
GAME, YOU CAN USE A BANDIT
ALGORITHM TO SOLVE IT*.
*Given rewards that aren’t delayed.
THANK YOU
Questions?

More Related Content

What's hot (20)

PDF
Recent Trends in Personalization: A Netflix Perspective
Justin Basilico
 
PDF
Markov decision process
Jie-Han Chen
 
PDF
Sequential Decision Making in Recommendations
Jaya Kawale
 
PDF
Deep Reinforcement Learning
MeetupDataScienceRoma
 
PPTX
Resnet.pptx
YanhuaSi
 
PDF
Modern Recommendation for Advanced Practitioners
Flavian Vasile
 
PDF
Introduction to Multi-armed Bandits
Yan Xu
 
PPTX
Neural Network Back Propagation Algorithm
Martin Opdam
 
PDF
Hands on Explainable Recommender Systems with Knowledge Graphs @ RecSys22
GiacomoBalloccu
 
PPTX
What’s next for deep learning for Search?
Bhaskar Mitra
 
PPTX
Gamification Elements and Mechanics
Andrzej Marczewski
 
PDF
Generative Adversarial Networks and Their Medical Imaging Applications
Kyuhwan Jung
 
PDF
Literature Survey on Detection of Brain Tumor from MRI Images
IOSR Journals
 
PPTX
Control as Inference.pptx
ssuserbd1647
 
PPTX
Explainable AI is not yet Understandable AI
epsilon_tud
 
PDF
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
Jinwon Lee
 
PPTX
Cricket score and winner predictor
KeyaShukla3
 
PDF
Unity ml agent quick guide
Kyoungman Lee
 
PPTX
Neural Learning to Rank
Bhaskar Mitra
 
PDF
그림 그리는 AI
NAVER Engineering
 
Recent Trends in Personalization: A Netflix Perspective
Justin Basilico
 
Markov decision process
Jie-Han Chen
 
Sequential Decision Making in Recommendations
Jaya Kawale
 
Deep Reinforcement Learning
MeetupDataScienceRoma
 
Resnet.pptx
YanhuaSi
 
Modern Recommendation for Advanced Practitioners
Flavian Vasile
 
Introduction to Multi-armed Bandits
Yan Xu
 
Neural Network Back Propagation Algorithm
Martin Opdam
 
Hands on Explainable Recommender Systems with Knowledge Graphs @ RecSys22
GiacomoBalloccu
 
What’s next for deep learning for Search?
Bhaskar Mitra
 
Gamification Elements and Mechanics
Andrzej Marczewski
 
Generative Adversarial Networks and Their Medical Imaging Applications
Kyuhwan Jung
 
Literature Survey on Detection of Brain Tumor from MRI Images
IOSR Journals
 
Control as Inference.pptx
ssuserbd1647
 
Explainable AI is not yet Understandable AI
epsilon_tud
 
PR-330: How To Train Your ViT? Data, Augmentation, and Regularization in Visi...
Jinwon Lee
 
Cricket score and winner predictor
KeyaShukla3
 
Unity ml agent quick guide
Kyoungman Lee
 
Neural Learning to Rank
Bhaskar Mitra
 
그림 그리는 AI
NAVER Engineering
 

Similar to Bandit Algorithms (20)

PDF
Intro to Quant Trading Strategies (Lecture 8 of 10)
Adrian Aley
 
PDF
John Maxwell, Data Scientist, Nordstrom at MLconf Seattle 2017
MLconf
 
PPTX
mcp-bandits.pptx
Blackrider9
 
PDF
Intro to Quantitative Investment (Lecture 6 of 6)
Adrian Aley
 
ODP
Bias correction, and other uncertainty management techniques
Olivier Teytaud
 
ODP
Uncertainties in large scale power systems
Olivier Teytaud
 
PDF
Rotting Infinitely Many-Armed Bandits
JunghunKim27
 
PPTX
UNIT - I Reinforcement Learning .pptx
DrUdayKiranG
 
DOCX
Lab 2 7_the_titanic_shuffle
monicamunguia23
 
PDF
HMM & R & FK
陳 柏宏
 
PPT
44 randomized-algorithms
AjitSaraf1
 
PDF
Dalembert
Richard Gill
 
PDF
13 Amortized Analysis
Andres Mendez-Vazquez
 
PPTX
Lecture 7 artificial intelligence .pptx
diya172004
 
PPTX
AlphaGo Zero: Mastering the Game of Go Without Human Knowledge
Joonhyung Lee
 
PPT
Marketing management planning on it is a
DagimNegash1
 
PPT
lect1207
webuploader
 
PDF
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
Masanori HIRANO
 
PPTX
Lecture 8 artificial intelligence .pptx
diya172004
 
PDF
Complex models in ecology: challenges and solutions
Peter Solymos
 
Intro to Quant Trading Strategies (Lecture 8 of 10)
Adrian Aley
 
John Maxwell, Data Scientist, Nordstrom at MLconf Seattle 2017
MLconf
 
mcp-bandits.pptx
Blackrider9
 
Intro to Quantitative Investment (Lecture 6 of 6)
Adrian Aley
 
Bias correction, and other uncertainty management techniques
Olivier Teytaud
 
Uncertainties in large scale power systems
Olivier Teytaud
 
Rotting Infinitely Many-Armed Bandits
JunghunKim27
 
UNIT - I Reinforcement Learning .pptx
DrUdayKiranG
 
Lab 2 7_the_titanic_shuffle
monicamunguia23
 
HMM & R & FK
陳 柏宏
 
44 randomized-algorithms
AjitSaraf1
 
Dalembert
Richard Gill
 
13 Amortized Analysis
Andres Mendez-Vazquez
 
Lecture 7 artificial intelligence .pptx
diya172004
 
AlphaGo Zero: Mastering the Game of Go Without Human Knowledge
Joonhyung Lee
 
Marketing management planning on it is a
DagimNegash1
 
lect1207
webuploader
 
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
Masanori HIRANO
 
Lecture 8 artificial intelligence .pptx
diya172004
 
Complex models in ecology: challenges and solutions
Peter Solymos
 
Ad

More from SC5.io (12)

PDF
AWS Machine Learning & Google Cloud Machine Learning
SC5.io
 
PDF
Transfer learning with Custom Vision
SC5.io
 
PDF
Decision trees & random forests
SC5.io
 
PDF
Machine Learning Using Cloud Services
SC5.io
 
PDF
Angular.js Primer in Aalto University
SC5.io
 
PDF
Miten design-muutosjohtaminen hyödyttää yrityksiä?
SC5.io
 
PDF
Securing the client side web
SC5.io
 
PDF
Engineering HTML5 Applications for Better Performance
SC5.io
 
PDF
2013 10-02-backbone-robots-aarhus
SC5.io
 
PDF
2013 10-02-html5-performance-aarhus
SC5.io
 
PDF
2013 04-02-server-side-backbone
SC5.io
 
PPTX
Building single page applications
SC5.io
 
AWS Machine Learning & Google Cloud Machine Learning
SC5.io
 
Transfer learning with Custom Vision
SC5.io
 
Decision trees & random forests
SC5.io
 
Machine Learning Using Cloud Services
SC5.io
 
Angular.js Primer in Aalto University
SC5.io
 
Miten design-muutosjohtaminen hyödyttää yrityksiä?
SC5.io
 
Securing the client side web
SC5.io
 
Engineering HTML5 Applications for Better Performance
SC5.io
 
2013 10-02-backbone-robots-aarhus
SC5.io
 
2013 10-02-html5-performance-aarhus
SC5.io
 
2013 04-02-server-side-backbone
SC5.io
 
Building single page applications
SC5.io
 
Ad

Recently uploaded (20)

PPTX
Advanced_NLP_with_Transformers_PPT_final 50.pptx
Shiwani Gupta
 
PPTX
Climate Action.pptx action plan for climate
justfortalabat
 
PPTX
The _Operations_on_Functions_Addition subtruction Multiplication and Division...
mdregaspi24
 
PDF
What does good look like - CRAP Brighton 8 July 2025
Jan Kierzyk
 
PPTX
apidays Munich 2025 - Building Telco-Aware Apps with Open Gateway APIs, Subhr...
apidays
 
PDF
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
PPTX
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
PDF
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
PPTX
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
PPTX
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
AUDITABILITY & COMPLIANCE OF AI SYSTEMS IN HEALTHCARE
GAHI Youssef
 
PDF
apidays Helsinki & North 2025 - REST in Peace? Hunting the Dominant Design fo...
apidays
 
PPTX
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
PPTX
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
PPTX
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
PDF
How to Connect Your On-Premises Site to AWS Using Site-to-Site VPN.pdf
Tamanna
 
PDF
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
PDF
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
PDF
Context Engineering for AI Agents, approaches, memories.pdf
Tamanna
 
Advanced_NLP_with_Transformers_PPT_final 50.pptx
Shiwani Gupta
 
Climate Action.pptx action plan for climate
justfortalabat
 
The _Operations_on_Functions_Addition subtruction Multiplication and Division...
mdregaspi24
 
What does good look like - CRAP Brighton 8 July 2025
Jan Kierzyk
 
apidays Munich 2025 - Building Telco-Aware Apps with Open Gateway APIs, Subhr...
apidays
 
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
AUDITABILITY & COMPLIANCE OF AI SYSTEMS IN HEALTHCARE
GAHI Youssef
 
apidays Helsinki & North 2025 - REST in Peace? Hunting the Dominant Design fo...
apidays
 
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
How to Connect Your On-Premises Site to AWS Using Site-to-Site VPN.pdf
Tamanna
 
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
Context Engineering for AI Agents, approaches, memories.pdf
Tamanna
 

Bandit Algorithms

  • 1. BANDIT ALGORITHMS Max Pagels, Data Science Specialist [email protected], @maxpagels 13.10.2016 Learning about the world
  • 2. PROGRAMMING, IN A NUTSHELL OUTPUTINPUT ALGORITHM
  • 3. MACHINE LEARNING, IN A NUTSHELL PROGRAMINPUT & OUTPUT LEARNING ALGORITHM
  • 4. REINFORCEMENT LEARNING, IN A NUTSHELL ACTION WORLD OBSERVATION AGENT REWARD
  • 5. LEARNING HOW TO PLAY TETRIS ACTION WORLD OBSERVATION AGENT REWARD (Rotate/Up/Down/ Left/Right etc) Score since previous action
  • 6. THE (STOCHASTIC) MULTI-ARMED BANDIT PROBLEM Let’s say you are in a Las Vegas casino, and there are three vacant slot machines (one- armed bandits). Pulling the arm of a machine yields either $0 or $1. Given these three bandit machines, each with an unknown payoff strategy, how should we choose which arm to pull to maximise* the expected reward over time?
 
 * Equivalently, we want to minimise the expected regret over time (minimise how much money we lose).
  • 7. FORMALLY(ISH) Problem We have three one-armed bandits. Each arm yields a reward of $1 according to some fixed unknown probability Pa , or a reward of $0 with probability 1-Pa. Objective Find Pa, ∀a ∈ {1,2,3}
  • 8. OBSERVATION #1 This is a partial information problem: when we pull an arm, we don’t get to see the rewards of the arms we didn’t pull. (For math nerds: a bandit problem is an MDP with a single, terminal, state).
  • 9. OBSERVATION #2 We need to create some approximation, or best guess, of how the world works in order to maximise our reward over time. We need to create a model. “All models are wrong but some are useful” — George Box
  • 10. OBSERVATION #3 Clearly, we need to try (explore) the arms of all the machines, to get a sense of which one is best.
  • 11. OBSERVATION #4 Though exploration is necessary, we also need to choose the best arm as much as possible (exploit) to maximise our reward over time.
  • 13. HOW DO WE SOLVE THE BANDIT PROBLEM?
  • 14. A NAÏVE ALGORITHM Step 1: For the first N pulls Evenly pull all the arms, keeping track of the number of pulls & wins per arm Step 2: For the remaining M pulls Choose the arm the the highest expected reward
  • 15. A NAÏVE ALGORITHM Step 1: For the first N pulls Evenly pull all the arms, keeping track of the number of pulls & wins per arm Step 2: For the remaining M pulls Choose the arm the the highest expected reward Arm 1: {trials: 100, wins: 2} Arm 2: {trials: 100, wins: 21} Arm 3: {trials: 100, wins: 17} Arm 1: 2/100 = 0.02 Arm 2: 21/100 = 0.21 Arm 3: 17/100 = 0.17
  • 16. A NAÏVE ALGORITHM Step 1: For the first N pulls Evenly pull all the arms, keeping track of the number of pulls & wins per arm Step 2: For the remaining M pulls Choose the arm the the highest expected reward Arm 1: {trials: 100, wins: 2} Arm 2: {trials: 100, wins: 21} Arm 3: {trials: 100, wins: 17} Arm 1: 2/100 = 0.02 Arm 2: 21/100 = 0.21 Arm 3: 17/100 = 0.17 Explore Exploit
  • 17. EPOCH-GREEDY [1] Step 1: For the first N pulls Evenly pull all the arms, keeping track of the number of pulls & wins per arm Step 2: For the remaining M pulls Choose the arm the the highest expected reward Arm 1: {trials: 100, wins: 2} Arm 2: {trials: 100, wins: 21} Arm 3: {trials: 100, wins: 17} Arm 1: 2/100 = 0.02 Arm 2: 21/100 = 0.21 Arm 3: 17/100 = 0.17 Explore Exploit [1]: http://hunch.net/~jl/projects/interactive/sidebandits/bandit.pdf
  • 18. EPSILON-GREEDY/Ε-GREEDY [2] Choose a value for the hyperparameter ε Loop forever With probability ε: Choose an arm uniformly at random, keep track of trials and wins With probability 1-ε: Choose the arm the the highest expected reward Explore Exploit [2]: people.inf.elte.hu/lorincz/Files/RL_2006/SuttonBook.pdf
  • 19. OBSERVATIONS For N = 300 and M = 1000, the Epoch-Greedy algorithm will choose something other than the best arm 200 times, or about 15% of the time. At each turn, the ε-Greedy algorithm will choose something other than the best arm with probability P=(ε/n) × (n-1), n=number of arms. It will always explore with this probability, no matter how many time steps we have done.
  • 20. Ε-GREEDY: SUB-OPTIMAL LINEAR REGRET* - O(N)Cumulativeregret 4 Timesteps *Assuming no annealing
  • 21. THOMPSON SAMPLING ALGORITHM For each arm, initialise a uniform probability distribution (prior) Loop forever Step 1: sample randomly from the probability distribution of each arm Step 2: choose the arm with the highest sample value Step 3: observe reward for the chosen and update the hyperparameters of its probability distribution (posterior)
  • 22. EXAMPLE WITH TWO ARMS (BLUE & GREEN) Assumption: rewards follow a Bernoulli process, which allows us to use a 𝛽-distribution as a conjugate prior. FIRST, INITIALISE A UNIFORM RANDOM PROB. DISTRIBUTION FOR BLUE AND GREEN 0 10 1
  • 23. FIRST, INITIALISE A UNIFORM RANDOM PROB. DISTRIBUTION FOR BLUE AND GREEN 0 1 EXAMPLE WITH TWO ARMS (BLUE & GREEN)
  • 24. RANDOMLY SAMPLE FROM BOTH ARMS (BLUE GETS THE HIGHER VALUE IN THIS EXAMPLE) 0 1 EXAMPLE WITH TWO ARMS (BLUE & GREEN)
  • 25. PULL BLUE , OBSERVE REWARD (LET’S SAY WE GOT A REWARD OF 1) 0 1 EXAMPLE WITH TWO ARMS (BLUE & GREEN)
  • 26. UPDATE DISTRIBUTION OF BLUE 0 1 EXAMPLE WITH TWO ARMS (BLUE & GREEN)
  • 27. REPEAT THE PROCESS: SAMPLE, CHOOSE ARM WITH HIGHEST SAMPLE VALUE, OBSERVE REWARD, UPDATE. 0 1 EXAMPLE WITH TWO ARMS (BLUE & GREEN)
  • 28. 0 1 AFTER 100 TIMESTEPS, THE DISTRIBUTIONS MIGHT LOOK LIKE THIS EXAMPLE WITH TWO ARMS (BLUE & GREEN)
  • 29. 0 1 AFTER 1,000 TIMESTEPS, THE DISTRIBUTIONS MIGHT LOOK LIKE THIS: THE PROCESS HAS CONVERGED. EXAMPLE WITH TWO ARMS (BLUE & GREEN)
  • 30. THOMPSON SAMPLING: LOGARITHMIC REGRET - O(LOG(N))Cumulativeregret 100 Timesteps
  • 31. MULTI-ARMED BANDITS ARE GOOD… So far, we’ve covered the “vanilla” multi-armed bandit problem. Solving this problem lets us find the globally best arm to maximise our expected reward over time. However, depending on the problem, the globally best arm may not always be the best arm.
  • 32. …BUT CONTEXTUAL BANDITS ARE THE HOLY GRAIL The the contextual bandit setting, once we pull an arm and receive a reward, we also get to see a context vector associated with the reward. The objective is now to maximise the expected reward over time given the context at each time step. Solving this problem gives us a higher reward over time in situations where the globally best arm isn’t always the best arm. Example algorithm: Thompson Sampling with Linear Payoffs [3] [3]: https://arxiv.org/abs/1209.3352
  • 33. …ACTUALLY, ADVERSARIAL CONTEXTUAL BANDITS ARE THE HOLY GRAIL Until now, we’ve assumed that each one-armed bandit gives a $100 reward according to some unknown probability P. In real-world scenarios, the world rarely behaves this well. Instead of a simple dice roll, the bandit may pay out differently depending on the day/hour/amount of money in the machine. It works as an adversary of sorts. A bandit algorithm that is capable of dealing with changes in payoff structures in a reasonable amount of time tend to work better than stochastic bandits in real-world settings. Example algorithm: EXP4 (a.k.a the “Monster” algorithm) [4] [4]: https://arxiv.org/abs/1002.4058
  • 34. CONTEXTUAL BANDIT ALGORITHMS ARE 1) STATE-OF- THE-ART & 2) COMPLEX • Many algorithms are <5 years old. Some of the most interesting ones are less than a year old. • Be prepared to read lots of academic papers and struggle implementing the algorithms. • Don’t hesitate to contact the authors if there is some detail you don’t understand (thanks John Langford and Shipra Agrawal!) • Always remember to simulate and validate bandits using real data.
  • 37. BIVARIATE & MULTIVARIATE TESTING Vanilla MAB
  • 42. … & COUNTLESS OTHER POSSIBILITIES
  • 43. TIP: CONTEXTUAL BANDIT IMPLEMENTED IN PYTHON + LAMBDA + API GATEWAY + REDIS = OPTIMISATION ENGINE
  • 45. LAUNCHED YESTERDAY (!): AZURE CUSTOM DECISION SERVICE
  • 46. IF YOU CAN MODEL IT AS A GAME, YOU CAN USE A BANDIT ALGORITHM TO SOLVE IT*. *Given rewards that aren’t delayed.