Reinforcement learning is the problem of learning to act through interaction with an unknown environment. It is not:
- A solution.
- Supervised learning
- Unsupervised learning.
However, algorithms for reinforcement learning can use (un)supervised learning algorithms as components.
Uncertainty and sequential decision making are central in reinforcement learning.
The course will give a thorough introduction to reinforcement learning. The first 8 weeks will be devoted to the core theory and algorithms of reinforcement learning. The final 6 weeks will be focused on project work, during which more advanced topics will be inroduced.
The first 6 weeks will require the students to complete 5 assignments. The remainder of the term, the students will have to prepare a project, for which they will need to submit a report.
The course is run in parallel with a seminar course.
No previous machine learning knowledge is needed.
The following topics must be absolutely mastered, although a refresher will be given as needed.
- Set theory and logic.
- Probability and expectation.
- Elementary calculus (limits, integration, differentiation)
- Elementary linear algebra (vector and matrix manipulations)
- Mature programming ability, preferably in python.
- Use of git or other version control system
- Use of (La)TeX.
- Course book Decision Making Under Uncertainty and Reinforcement Learning, Dimitrakakis and Ortner
- Basic RL Reference Reinforcement Learning: An Introduction, Sutton and Barto.
- Statistical reference Optimal Statistical Decisions, De Groot.
- MDP Reference Markov Decision Processes, Putterman.
- Quick Reference Algorithms for Reinforcement Learning, Czepesvari.
- Huge Reference Dynamic Programming and Optimal Control, Bertsekas.
- Advanced Neurodynamic Programming, Bertsekas and Tsitsiklis.
- Advanced Bandit Algorithms, Czepesvari and Lattimore
In this course, the use of automated methods for writing and translating text, such generative AI models, web-based translation and code development tools is allowed under certain conditions.
The general principle is the following:
To understand it, you must do it yourself.
The recommended workflow is this: read the material, think of a solution for yourself, try and implement it, and then ask for help in the specific place you get stuck. If you remain in class during the exercises, then you will be able to solve most of the high-level problems with me or the assistant. You can also ask for help in the forums. Do so early.
The general idea for the use of advanced algorithms is the same as when you are using any other external resource, such as verbal advice, online forums, or material from books or websites. In all cases, you are not allowed to present anybody’s work as your own work. This includes both human and machine generated output. Misrepresentation will be considered misuses in this class. So, you must cite each and every use of any external tool, reference, or personal help. Here are some examples:
- Verbal advice: Cite as “A. Student: Personal Communication”
- Online forums: Stackoverflow is an example. Cite as “We based this part of the work on URL where we modified the code to … ”
- Books or websites: Cite normally explaining how you used the material, e.g. “From Theorem 1 (Aardvark et al, 1975) which we reproduce here…”
- Automated translation: Specify what you used and where. Note, however, that you can write your reports in French or English. Use [*] superscripts.
- Advanced coding aids: Specify what you used, including generative-AI. Say where you used it exactly, so we can filter out. eg “We used X-Bot to implement to set up the data structures”.
- Advanced models for grammar and rewriting: Specify which model you used and for which parts of the text. Highlight the edited text in a different colour.
- Advanced models for text structuring and code architecture. You are not encouraged to do that: we can discuss this in class if needed. However, if you do make use of such models, then you must explain how you used them, including a copy of the intermediate output.
- You must use a git repository to create your work. This way we can track changes.
- If you do not stick to the above advice, then the automated AI-detection tools may provide false positives, or you may fail.
- You will be tested in the oral presentation.
When using any external tool, you must be aware that the answers can be incorrect, or you may apply them in the wrong way. We have seen examples of this even before the chatbot era, when people were copying from other students, or collating answers from stackoverflow to produce a Frankestein monster of a project.
There are two main types of projects, though a project can be hybrid.
Application projects proposals need to contain the following:
- Domain description and goals: What is the problem, in general terms, and which aspect would you try and solve in an MDP/RL framework? Make sure to cite relevant literaure.
- Methodology: How would you formalise the problem mathematically? Which algorithms and/or models do you intend to apply at different stages of the project? Feel free to read widely about both the problem and algorithms and do cite relevant literature.
- Experiment design: How would you know that the method is working? How would you compare with existing solutions? In what context would you expect an improvement? How would you measure it? How will you test the robustness of your solution over variations in the problem instance?
- Expected results: What results do you expect to obtain, and what do you think might go wrong? In what way do you expect an improvement?
- Algorithmic/theory problem and goals: What is the deficiency, in general terms, of current theory and algorithms that your method would try to improve? As an example, the goal could be reducing computational complexity, increasing data efficiency, improving robustness or applicability of a specific family of algorithms; or introducing a slightly different setting to existing ones. In other words, which is the open problem you will be addressing? Make sure to cite relevant literature to better identify the problem.
- Methodology: What kind of existing algorithms, theory or technical result would you rely on? Would you be combining various existing results? What would be the most significant novelty of your methodology? Do cite relevant literature.
- Experiment design (if applicable): How would you know that the method is working? How would you compare with existing solutions? In what context would you expect an improvement? How would you measure it?
- Expected results: What results do you expect to obtain, and what do you think might go wrong? In what way do you expect an improvement?
Grades will be adjusted based on group size with on letter grade up/down for double/half the mean group size. See also the detailed Examination rubrics.
- Environments: A. Complex, well described environment that captures all of the elements of the application or algorithmic cproblem. B. The environment is simple or lacks description. C. An adequate environment that captures the basic setting. D. Insufficient environment or description. E. Insuffcient environment and description.
- Algorithms: A. Significantly novel algorithms that are well described. B. Some novelty in the algorithms, with good descriptions. C. Some novelty in the algorithms, but descriptions are lacking. D. Insufficient novelty or descriptions. E. Insufficient novelty and descriptions.
- Experiments: A. Thorough experiments with ablation tests and comparisons over algorithms and environments, that are well-described. B. Somewhat incomplete experiments or descriptions. C. Sufficient experiments and descriptions. D. Insufficient experiments or descriptions. E. Insufficient experiments and descriptions.
- Mathematics (Calculus, Linear Algebra)
- Python programming.
- Elementary knowledge of probability and statistics.
There is one project, taking up 40% of the credit. There is one written exam, for 40% of the credit. Assignments, for 20% of the credit.
Criteria for full marks in each part of the project are the following.
- Documenting of the work in a way that enables reproduction.
- Technical correctness of their analysis.
- Demonstrating that they have understood the assumptions underlying their analysis.
- Addressing issues of reproducibility in research.
- Consulting additional resources beyond the source material with proper citations.
The follow marking guidelines are what one would expect from students attaining each grade.
- Submission of a detailed report from which one can definitely reconstruct their work without referring to their code. There should be no ambiguities in the described methodology. Well-documented code where design decisions are explained.
- Extensive analysis and discussion. Technical correctness of their analysis. Nearly error-free implementation.
- The report should detail what models are used and what the assumptions are behind them. The conclusions of the should include appropriate caveats. When the problem includes simple decision making, the optimality metric should be well-defined and justified. Simiarly, when well-defined optimality criteria should given for the experiment design, when necessary. The design should be (to some degree of approximation, depending on problem complexity) optimal according to this criteria.
- Appropriate methods to measure reproducibility. Use of an unbiased methodology for algorithm, model or parameter selection. Appropriate reporting of a confidence level (e.g. using bootstrapping) in their analytical results. Relevant assumptions are mentioned when required.
- The report contains some independent thinking, or includes additional resources beyond the source material with proper citations. The students go beyond their way to research material and implement methods not discussed in the course. See section on LLMs.
- Submission of a report from which one can plausibly reconstruct their work without referring to their code. There should be no major ambiguities in the described methodology.
- Technical correctness of their analysis, with a good discussion. Possibly minor errors in the implementation.
- The report should detail what models are used, as well as the optimality criteria, including for the experiment design. The conclusions of the report must contain appropriate caveats.
- Use of an unbiased methodology for algorithm, model or parameter selection.
- The report contains some independent thinking, or the students mention other methods beyond the source material, with proper citations, but do not further investigate them.
- Submission of a report from which one can partially reconstruct most of their work without referring to their code. There might be some ambiguities in parts of the described methodology.
- Technical correctness of their analysis, with an adequate discussion. Some errors in a part of the implementation.
- The report should detail what models are used, as well as the optimality criteria and the choice of experiment design. Analysis caveats are not included.
- Use of a possibly biased methodology for algorithm, model or parameter selection - but in a possibly inconsistent manner.
- There is little mention of methods beyond the source material or independent thinking.
- Submission of a report from which one can partially reconstruct most of their work without referring to their code. There might be serious ambiguities in parts of the described methodology.
- Technical correctness of their analysis with limited discussion. Possibly major errors in a part of the implementation.
- The report should detail what models are used, as well as the optimality criteria. Analysis caveats are not included.
- Some effort for methodological algorithm/parameter selection.
- There is little mention of methods beyond the source material or independent thinking.
- Submission of a report from which one can obtain a high-level idea of their work without referring to their code. There might be serious ambiguities in all of the described methodology.
- Technical correctness of their analysis with very little discussion. Possibly major errors in only a part of the implementation.
- The report might mention what models are used or the optimality criteria, but not in sufficient detail and caveats are not mentioned.
- Reproducibility is only partially addressed.
- There is no mention of methods beyond the source material or independent thinking.
- The report does not adequately explain their work.
- There is very little discussion and major parts of the analysis are technically incorrect, or there are errors in the implementation.
- The models used might be mentioned, but not any other details.
- There is no effort to ensure reproducibility or robustness in the project.
- There is no mention of methods beyond the source material or independent thinking.
cd
| Week | Topic | Seminar |
|---|---|---|
| 1 | Reinforcement learning | |
| Beliefs and Decisions | ||
| 2 | Bayesian Decision Rules | Sufficient statistics |
| Bayesian inference and decisions exercises | Concentration inequalities | |
| 3 | Bandit problems. | |
| Bandit problem exercises. | ||
| 4 | Finite Horizon MDPs | |
| Backwards Induction | ||
| The Bandit MDP | ||
| 5 | Finite Horizon Lab | |
| 6 | Infite Horizon MDPs | |
| Value Iteration | ||
| Policy Iteration | ||
| 7 | Sarsa / Q-Learning | |
| 8 | Model-Based RL | |
| 9 | Function Approximation, Gradient Methods | |
| 10 | Bayesian RL: Dynamic Programming, Sampling | |
| 11 | UCB/UCRL/UCT. | |
| UCT/AlphaZero. | ||
| 12 | Project Lab | |
| 13 | Project presentations | |
| 14 | Q&A, Mock exam |
The first meeting will be jointly with the RL course. There will be scheduled progress meetings, and room B013 will be available for group work otherwise. The professor responsible and the students will normally also be available for questions during this time, but alternative times could be scheduled.
| 2026.02.17 | 8:45 A017 | - Joint RL Course |
| 2026.02.24 | 14:15 B013 | Single-Agent Intro: Bandits, MDPs |
| 2026.03.03 | 14:15 B013 | Supervisor/Topic selection |
|---|---|---|
| 2026.03.10 | 14:15 B013 | First supervisor meeting |
| 2026.03.17 | 14:15 B013 | Group work |
| 2026.03.24 | 14:15 B013 | Group work |
| 2026.03.31 | 14:15 B013 | Progress meeting |
| 2026.04.07 | 14:15 B013 | Easter break |
| 2026.04.14 | 14:15 B013 | Group work |
| 2026.04.21 | 14:15 B013 | Group work |
| 2026.04.28 | 14:15 B013 | Progress meeting |
| 2026.05.05 | 14:15 B013 | Group work |
| 2026.05.12 | 14:15 B013 | Group work |
| 2026.05.19 | 14:15 B013 | Group work |
| 2026.05.26 | 14:15 B013 | Project Presentation |
- Rewards and preferences (15’)
- Transitivity of preferences (15’)
- Random rewards (5’)
- Decision Diagrams (10’)
- Utility functions and the expected utility hypothesis (15’)
- Utility exercise: Gambling (10’ pen and paper)
- The St. Petersburg Paradox (15’)
- Preferences
We assume that, given a choice between items in a set of possible rewards
(I) Prefer
- Transitivity
The above assumptions do not preclude cycles. However, we can also assume that:
If
- Random rewards.
Now consider the case where, instead of directly choosing rewards, we make a choice, and then obtain a random reward. Here, the reward depends in some way in our decision, but we are not sure exactly how.
Examples:
- Choosing between taking the train and a car.
- Gambling in a casino.
- Deciding how much to study for the exam.
- Objective vs Subjective Probability: Example (5’)
- Relative likelihood: Completeness, Consistency, Transitivity, Complement, Subset (5’)
- Measure theory (5’)
- Axioms of Probability (5’)
- Random variables (5’)
- Expectations (5’)
- Expectations exercise (10’)
- Objective vs Subjective probability
- Quantum Physics: There is real underlying randomness. The probabilities of all possible outcomes can be computed exactly a priori
- Coin toss: We model our uncertainty about the outcome through randomness. However, the coin is not really random, and we must experiment to determine the proportion of each possible outcome. We simply lack the information to compute the probabilities a priori.
Everything that can possibly happen is contained in the universe of events
Events
- Relative Likelihood
(I) Completeness:
- Measure theory
We can use probability to quantify this, so that
Measure as a concept: area, length, probability
- Axioms of Probability
- Exercise: Prove that P satisfies the given properties of relative likelihood.
- Random variables
If
- Expectations
$E_P[f] = ∑ω f(ω) P(ω)$.
- Exercise Set 1. Probability introduction.
- Exercise Set 2. Sec 2.4, Exercises 4, 5.
Exercise 7, 8, 9.
Decision Making Under Uncertainty and Reinforcement Learning. Chapter 1, 2.
Utility. What is the concept of utility? Why do we want to always maximise utility?
Example:
| U | w1 | w2 |
|---|---|---|
| a1 | 4 | 1 |
| a2 | 3 | 3 |
Regret. Alternative notion.
| L | w1 | w2 |
|---|---|---|
| a1 | 0 | 2 |
| a2 | 1 | 0 |
Minimising regret is the same as maximising utility when w does not depend on a.
Hint: So that if
The utility analysis of choices involving risk: https://www.journals.uchicago.edu/doi/abs/10.1086/256692
The expected-utility hypothesis and the measurability of utility https://www.journals.uchicago.edu/doi/abs/10.1086/257308
1.. MSE Estimation (5’) [not done]
- Linearity of Expectations (5’) [not done]
- Convexity of Bayes Decisions (5’) [not done]
- Discrete set of models example: the meteorologists problem (15’)
- Marginal probabilities (5’).
- Conditional probability (5’).
- Bayes theorem (10’).
-$n$ metereological stations
-
$x_t$ : Weather on day t (0 = dry, 1 = rain)$ - $P_\mdp(x_t | xt-1, xt-2, \ldots)$ station
$\mdp$ prediction for dry/rain.
| Station | Day 1 | Day 2 | Day 3 | Day 4 |
|---|---|---|---|---|
| 1 | 60% | 50% | 40% | 30% |
| 2 | 30% | 25% | 20% | 15% |
| 3 | 40% | 50% | 50% | 40% |
- How should we combine these predictions?
Simplified notation
- $ωML = \argmax_ω P(x | ω)$.
- $a^* = \argmax_a U(ωML, a)$.
- $ωMAP = \argmax_ω P(ω | x)$
- $a^* = \argmax_a U(ωMAP, a)$.
-
$a^* = \argmax_a ∑_ω P(ω | x) U(ω, a)$ .
Model-index notation.
- A family of models
$\{P_μ | μ ∈ \MDPs\}$ - Data
$x$ .
- Find
$μ$ maximising$P_μ(x)$
- Prior belief
$\bel$ - Find
$μ$ maximising$\bel(μ) P_μ(x)$
- Return function $\bel(μ | x) = P_μ(x) \bel(μ) / ∑μ’ Pμ’(x) \bel(μ’)$
- Find
$\hat{μ}$ minimising$\E_\bel[(\hat{μ} - μ)^2 | x] = ∑_μ (\hat{μ} - μ)^2 \bel(μ | x)$
- Input: Data
$x_1, \ldots, x_t$ , A set of models$\{P_\mdp | \mdp ∈ \MDPs\}$ - Inference: The model $\mdp^*ML$ maximising \[ P_\mdp(x_1, \ldots, x_t) \]
- Prediction: $P\mdp^*_{ML}(xt+1 | x_1, \ldots, x_t)$.
- Input: Data
$x_1, \ldots, x_t$ , set of models$\{P_\mdp | \mdp ∈ \MDPs\}$ , prior$\bel(\mdp)$ on models - Inference: The model $\mdp^*MAP$ maximising \[ P_\mdp(x_1, \ldots, x_t) \bel(\mdp) \]
- Prediction: $P\mdp^*_{MAP}(xt+1 | x_1, \ldots, x_t)$.
- Input: Data
$D$ , set of models$\{P_\mdp | \mdp ∈ \MDPs\}$ , prior$\bel(\mdp)$ on models - Inference: The posterior probability over models: \[ \bel(\mdp | x_1, \ldots, x_t) = \frac{P\mdp(x_1, \ldots, x_t) \bel(\mdp)}{∑\mdp’ P\mdp’(x_1, \ldots, x_t) \bel(\mdp)} \]
- Prediction: $P(xt+1 | x_1, \ldots, x_t) = ∑_\mdp P_\mdp(xt+1 | x_1, \ldots, x_t)$.
Sometimes we care about finding a point estimate for some distribution.
For example, let us say we have some distribution
Consider a coin with an unknown distribution of head or tails. We can model this as
\begin{align*}
x_t \mid \mdp ∼ \Bern(\mdp)
\mdp ∼ Β(α_0, β_0)
\end{align*}
[Drawing on board]
Data:
$α_T = α_0 + ∑t=1^T x_t$, $β_T = β_0 + ∑t=1^T (1 - x_t)$
We can show that $\mdp^*ML = \hat{\mdp}$.
We can show that $\mdp^*MAP = {α_T - 1}{T}$.
We can show that $\mdp^*MSE = {α_T}{α_T + β_T}$.
- Problems with no observations. Book Exercise: 13,14,15.
- Problems with observations. Book Exercise: 17, 18.
- Predictions $p_t= pt,1, \ldots, pt,n$ of all models for outcomes
$y_t$ - Make decision
$a_t$ .- Observe true outcome
$y_t$
- Observe true outcome
- Obtain instant reward
$r_t = ρ(a_t, y_t)$ - Utility $U = ∑t=1^T r_t$.
-
$T$ is the problem horizon
- Observe
$p_t$ . - Calculate $\hat{p}_t = ∑_μ ξt(μ) pt,μ$
- Make decision $a_t = \argmax_a ∑y \hat{p}_t(y) ρ(a, y)$.
- Observe
$y_t$ and obtain reward$r_t = ρ(a_t, y_t)$ . - Update: $ξt+1(μ) \propto ξ_t(μ) pt,μ(y_t)$.
The update does not depend on
- Advice $p_t= pt,1, \ldots, pt,n ∈ D$
- Make prediction
$\hat{p}_t ∈ D$ - Observe true outcome
$y_t ∈ Y$ - Obtain instant reward
$r_t = u(\hat{p}_t, y_t)$ - Utility $U = ∑t=1^T r_t$.
-
$D$ is the set of distributions on$Y$ . - However, there are only predictions, no actions. To add actions:
\[ u(\hat{p}_t, y_t) = ρ(a^*(\hat{p}_t), y_t), \qquad a^*(\hat{p}_t) = \argmax_a ρ(a, y_t) \]
The update does not depend on
- Predict by averaging all of the predictions:
\[ \hat{p}_t(y) = ∑μ \bel_t(μ) pt,μ(y) \]
- Update by weighting the quality of each prediction
\[ \belt+1(μ) = \frac{\bel_t(μ) exp[η u(pt, μ , y_t)]}{∑μ’ \bel_t(μ’) exp[η u(pt,μ, y_t)]} \]
- $u(pt,μ, y_t) = ln pt,μ(y_t)$,
$η = 1$ , Bayes’s theorem. - $u(pt,μ, y_t) = ρ(a^*(pt,μ), y_t)$: quality of expert prediction.
- Take action
$a_t$ - Obtain reward $r_t ∼ Pa_t(r)$ with expected value $μa_t$.
- The utility is
$U = ∑_t r_t$ , while$P$ is unknown.
-Total regret with respect to the best arm: \[ L \defn ∑t = 1^T [μ^* - r_t], \qquad μ^* = max_a μ_a \]
- Expected regret of an algorithm
$π$ :
\[ \E^π [L] = ∑t = 1^T \E^π[μ^* - r_t], = ∑a=1^n \E^π[nT,a](μ^* - μ_a) \]
- $nT,a$ is the number of times
$a$ has been pulled after$T$ steps.
A classical example of this is when the rewards are Bernoulli, i.e. \[ r_t | a_t = i ∼ \textrm{Bernoulli}(μ_i) \]
- Take action $a_t = \argmax_a \hat{μ}t,a$
- Obtain reward $r_t ∼ Pa_t(r)$ with expected value $μa_t$.
- Update arm: $st, a_t = st - 1, a_t + r_t$, $nt, a_t = nt - 1, a_t + 1$.
- Others stay the same: $st,a = st-1, a$, $nt,a = nt-1, a$ for
$a ≠ a_t$ . - Update means: $\hat{μ}t,i = st,i / nt,i$.
The standard prior
- $nt,i, st,i$ are sufficient statistics for Bernoulli bandits.
- The more often we pull an arm, the more certain we are the mean is correct.
- Take action $a_t = \argmax_a \hat{μ}t,a + O(1/\sqrt{nt,a})$.
- Given some prior parameters
$α, β > 0$ (e.g. 1). - $\bel_t(μ_a) = \textrm{Beta}(α + st,a, β + nt,a - st,a)$.
- Sample
$\hat{μ} ∼ \bel_t(μ)$ . - Take action
$a_t = \argmax_a \hat{μ}_a$ .
Let
\[
\hat{μ}_n = ∑i=1^t r_i / n,
\]
be the sample mean estimate of an iid RV in [0,1] with
- [Go through Chapter 4, Beta distribution]
- [Visualise Beta distribution]
- [Do the James Random Exercise 3]
- Note that the problem here is that this is only a point estimate: it ignores uncertainty. In fact, we can represent our uncertainty about the arms in a probabilistic way with the Beta distribution:
If our prior over an arm’s mean is
$\textrm{Beta}(α, β)$ then the -posterior at time$t$ is $\textrm{Beta}(α + st,i, β + nt,i - st,i)$. - [Visualise how the posterior changes for a biased coin as we obtain more data].
- Implement epsilon-greedy bandits (lab, 30’)
- Implement Thompson sampling bandits (lab, 30’)
3, Implement UCB bandits (home)
- Compare them in a benchmark (home)
Consider the following special case for prediction with expert advice:
At time
- Each expert
$i ∈ A$ makes probabilistic predictions $pi,t(x)$ for every possible$x ∈ X$ . - You make a choice of some expert
$a_t ∈ A$ - You observe
$x_t ∈ X$ - You obtain reward $r_t = - ln pa_t, t(x)$
- You calculate the rewards of all experts, $ri,t = - ln pi, t(x)$.
Show that the EWA algorithm, which updates the weights according to:
\[
wt+1(i)
=
\frac{w_t(j) exp[η ri,t)]}{∑j w_t(j) exp[η rj,t]}
\]
Corresponds to a modified posterior update of the form,
\[
\belt+1(i) = \frac{P_i(x_t)^η \bel_t(i)}{∑_j P_j(x_t)^η \bel_t(j)}
\]
where
- Implement an approximation of the Beta distribution prior, where the
you instead have a prior distribution on a finite set of
- Starting with a uniform prior on these values, calculate the posterior distribution after you observe 100 throws of a fair coin.
- How does this posterior compare to the one resulting from the Beta(1,1) prior?
Where you toss a coin of unknown bias
- The bandit MDP (30’)
- MDP definitions (15’)
- MDP examples (15’)
- Monte Carlo Policy Evaluation (15’)
- DP: Finite Horizon Policy Evaluation (15’)
- DP: Finite Horizon Backward Induction (15’)
- DP: Proof of Backwards Induction (15’)
- DP: Implementation of Backwards Induction (30’)
- Observe state
$s_t ∈ S$ - Take action
$a_t ∈ A$ . - Obtain reward
$r_t ∈ \Reals$ .
- Transition kernel $P_μ(st+1 | s_t, a_t)$.
- Reward with mean
$ρ_μ(s_t, a_t)$
- Markov policies
$\pol(a_t | s_t)$
Total reward up to a finite (but not necessarily fixed) horizon
- Goal state
$s^* ∈ S$ . - Reward
$r_t = -1$ for all$s ≠ s^*$ - Game ends time
$T$ where$s_T = s^*$ .
- Croupier shows one card.
- Current state is croupier’s card and your cards.
- Reward is
$r_T = 1$ if you win,$r_T = -1$ if you lose at the end, otherwise$0$ .
\begin{align*}
V^π_t(s)
& = \E^π[U_t | s_t = s]
& ≈ \frac{1}{N} ∑n=1^N U(n)_t
\end{align*}
- Markov inequality
\[ Pr(x \geq t) \leq \E[x] / t \]
- For general
$x$ , use$e^x$ :
\[ Pr(x \geq t) = Pr(e^x \geq e^t) \leq \E[e^x] / e^t. \]
\begin{align*}
V^π_t(s)
&= \E^π[U_t | s_t = s]
&= \E^π[∑k=t^T r_k | s_t=s]\
&= \E^π[r_t | s_t = s] + \E^π[∑k=t+1^T r_k | s_t=s]\
&= \E^π[r_t | s_t = s] + \E^π[Ut+1 | s_t=s]\
&= \E^π[r_t | s_t = s] + ∑s’ \E^π[Ut+1 | st+1=s’] Pr^π(st+1 = s’ | s_t = s)\
&= \E^π[r_t | s_t = s] + ∑s’ V^πt+1(s’) Pr^π(st+1 = s’ | s_t = s)\
&= \E^π[r_t | s_t = s] + ∑s’ V^πt+1(s’) ∑_a Pr(st+1 = s’ | s_t = s, a_t = a) π_t( a | s).
\end{align*}
Let
& \geq max_a {r(s) + ∑_j p(j|s,a) V^*t+1(j)}\
& \geq max_a {r(s) + ∑_j p(j|s,a) V^πt+1(j)} & & ∀ π\
& \geq V_t^π(s)
\end{align*}
If
- DP: Value Iteration (45’)
- DP: Policy Iteration (45’)
\[ U = ∑t=0^∞ γ^t r_t \]
Tells us how much we care about the future. Note that \[ ∑t=0^∞ γ^t = \frac{1}{1 - γ} \]
Idea: Run backwards induction, discounting by
- Input: MDP
$μ$ , discount factor$γ$ , threshold$ε$ -
$v_0(s) = ρ_μ(s)$ for all$s$ - For
$n=1, \ldots$
\[ vn+1(s) = ρ_μ(s) + γ ∑j P_μ(j | s, a) v_n(j). \]
- Until $\|vn+1 - v_n\|_∞ \leq ε$.
$\|x\|_1 = ∑_t |x_t|$ $\|x\|_∞ = max_t |x_t|$ - $\|x\|_p = \left(∑_t |x_t|^p\right)1/p$
-
$r$ : reward vector. -
$P_π$ : transition matrix. -
$v$ : value function vector.
\[ π(a_t | s_t) = π(a_k | s_k) \]
\[
v^π = ∑t=0^∞ γ^t P_π^t r.
\]
Note that
- Define the VI operator
$L$ so that $vn+1 = L v_n$. - Show that if
$v = V^*$ then$v = L v$ . - Show that $limn → ∞ v = V^*$.
- How fast does it converge?
- When is the policy actually optimal?
For any stationary policy
If
Is the total discounted number of times reaching a state \[ X(i, j) = \E ∑t=0^∞ γ^t \ind{s_t = j | s_0 = i} \]
\[ L_π v = r + γ P_π v. \]
\[ L v = max_π \{r + γ P_π v\}. \]
\[ v = Lv \]
If
- There is a unique
$x^*$ so that$Mx^* = x^*$ . - If $xn+1 = M x_n$ then
$x_n → x^*$ .
- The mapping has the property
$f(x) = x$ for the solution. - So if
$x = \sqrt{x_0}$ , we can write$x^2 - x_0 = 0$ . - Rewrite as
$2 x^2 = x^2 + x_0$ $⇒$ $x = \frac{1}{2} \left(x + x_0/x \right)$ . - Or..
$(c+1) x^2 = c x^2 + x_0$ $⇒$ $x = \frac{1}{c+1} \left(c x + x_0/x \right)$ .
- Since
$L$ is a contraction mapping, it converges to$v^* = L v^*$ (Theorem 6.5.7) - If
$v = L v$ then$v = max_π v^π$ (Theorem 6.5.3) - Hence, value iteration converges to
$v^*$ .
If
Note that
- Input: MDP
$\mdp$ , discount factor$γ$ , initial policy$\pol_0$ . - For
$n = 0, 1,\ldots$ - $v_n = (I - γ P\pol_n)-1 r = V\pol_n$.
- $πn+1 = \argmax_\pol \{r + γ P_\pol v_n$.
- Until $πn+1 = π_n$.
- $v_n \leq vn+1$ (Theorem 6.5.10)
- There is a finite number of policies.
$v_n = max_\pol \{r + γ P_π v_n\}$
- Sarsa (45’)
- Q-learning (45’)
-
Observe state
$s_t$ - Take action
$a_t$ - Get reward $rt+1$
- See next state $st+1$
-
Select a state
$s_t$ - Take action
$a_t$ - Get reward $rt+1$
- See next state $st+1$
\[ v^π_t → V^π \qquad q^π_t → Q^π \] \[ v^*_t → V^* \qquad q^*_t → Q^* \]
\[ π_t → π^* \]
\[ π_t ≈ \argmax_π ∫μ \bel_t(μ) \]
- For all states
$s$ - For
$k= 1, \ldots, K$ - Run policy
$π$ , obtain $U(k) = ∑t=1^T r(k)_t$
\[ v_K(s) = \frac{1}{K} U(k) \]
- For each
$k$
\[ v_k(s) = vk-1(s) + α_k[U(k)- vk-1(s)] \]
- For
$α_k = 1/k$ , the algorithm is the same as direct MC.
- Observe trajectory
$(s_t, r_t)_t$ , set$U = 0$ . - For
$t = T, T-1, \ldots$ $U = U + r_t$ $n(s_t) = n(s_t) + 1$ -
$v(s_t) = v(s_t) + \frac{1}{n(s_t)}[U - v(s_t)]$ .
- Observe trajectory
$(s_t, r_t)_t$ , set$U = 0$ . - For
$t = T, T-1, \ldots$ $U = U + r_t$ - If
$s_t$ not observed before $n(s_t) = n(s_t) + 1$ -
$v(s_t) = v(s_t) + \frac{1}{n(s_t)}[U - v(s_t)]$ .
- Idea: Replace actual
$U$ with an estimate: $r_t + γ v(st+1)$. - Temporal difference error: $d_t = r_t + γ v(st+1) - v(s_t)$.
\[ v(s_t) = v(s_t) + α_t d_t \]
\[ v(s_t) = v(s_t) + α_t ∑\ell=t^∞ (γ λ)\ell - t d_t \]
- $n(st+1) = n(st+1) + 1$
- For all
$s$
\[ v(s_t) = v(s_t) + α_t n(s) d_t \]
$n = λ n$
- Input policy
$π$ - Generate $s_t, a_t, r_t, st+1, at+1$
- Update value
\[ q(s_t, a_t) = q(s_t, a_t) + α[r_t + γ q(st+1, at+1) - q(s_t, a_t)] \]
- Observe $s_t, a_t, r_t, st+1$
- Update value
\[ q(s_t, a_t) = q(s_t, a_t) + α[r_t + γ max_a q(st+1, a) - q(s_t, a_t)] \] \[ q(s_t, a_t) += α[r_t + γ max_a q(st+1, a) - q(s_t, a_t)] \] \[ q(s_t, a_t) = (1 - α) q(s_t, a_t) + α[r_t + γ max_a q(st+1, a) \]
- Observe $s_t, a_t, r_t, st+1$
- $es_t, a_t += 1$
- Update value
For every state-action
-
$e = λ e$ ,$λ < 1$ .
When
Run any of these algorithm repeatedly on a dataset you have collected so far.
Built using data
At time
$\hat{\mdp}_t = f(h_t)$ - $\pol_t = \argmax_\pol V\hat{\mdp}^\pol$.
\[ P_t(s’|s,a) = \frac{∑_t \ind{st+1 = s’ ∧ s_t = s ∧ a_t = a}}{∑_t \ind{s_t = s ∧ a_t = a}} = \frac{N_t(s,a,s’)}{N_t(s,a)} \] \[ ρ_t(s,a) = \frac{∑_t r_t \ind{s_t = s, a_t = a}}{N_t(s,a)} \]
For $n = 1, \ldots, nmax$, all
\[ a_t = \argmax_a ρ_t(s,a) γ ∑s’ P_t(s’|s,a) vn_max(s’ | s,a) \]
Why do value full iteration at every step?
For some
\[ a_t = \argmax_a q_t(s,a) \]
- Is a point-estimate of the MDP enough?
- How fully do we need to update the value function?
- Which states should we update?
- How fast should the policy change?
- Fitted Value Iteration (45’)
- Approximate Policy Iteration (45’)
- From Tables to Functions
- Linear feature representation
\[ v_θ(s) = ∑i φ_i(s) θ_i \]
- Linear-softmax (Discrete Actions)
\[ \pol_θ(a | s) = exp{∑i φ_i(s) θ_i} \]
\[ \|f - g\| \defn ∫_x |f(x) - g(x)| dx \]
\[ min_g \|f - g\| \]
- Input
$\pol, K, N, γ, ε$ - Sample
$N$ states$s_n$ - Calculate
$\hat{V}_n$ through$K$ rollouts of depth $T > ln1/γ[1/ε (1 - γ)]$ - Call
$θ = \textsc{Regression}(Θ, (s_n, \hat{V}_n))$
- Initialise
$θ ∈ Θ$ . - For
$n = 1, \ldots, N$ - $θ
- For
$s ∈ S$ - Calculate $u(s) = max_a r(s,a) + γ ∫S dP(s’|s,a) v_θ(s’)$ for all
$s ∈ \hat{S}$ . - $min_\param \| v_\param - u\|\hat{S}$, e.g.
\[ \|v_\param(s) - u\|\hat{S} = ∑s ∈ \hat{S} |v_\param(s) - u(s)|^2 \]
\[ qt+1(s_t, a_t) = (1 - α_t) q_t(s_t, a_t) + α_t [r_t + γ max_a q_t(st+1, a)] \]
Minimise the squared TD-error \[ d_t = r_t + γ max_a q_t(st+1, a) - q_t(s_t, a_t) \] \[ ∇_\param d_t^2 = 2 d_t ∇_\param q_t(s_t, a_t) \]
- $π_k = \argminπ ∈ Π \|\hat{L} vk-1 - \hat{L} vk-1\|$
- $v_k = \argminv ∈ V \|v - \hat{V}π_k\|$
\[ \|v - Lv\| = ∑_s D(s)^2 \] \[ D(s) = v(s) - max_a ∫_S v(j) dP(j | s,a) \]
- Direct Policy Gradient, i.e. REINFORCE (45’)
- Actor-Critic Methods, e.g. Soft Actor Critic (45’)
We want to solve the problem \[ max_θ \E_θ[U], \qquad \E_θ[U] = ∫_S dy(s) ∫H p_θ(h \mid s_1 = s) U(h), \] where
-
$θ$ parametrises a policy -
$y(s)$ is a starting-state distribution - $h = (s_t, a_T, r_t)t=1^T$ is a trajectory and
- $U(h) = ∑_t r_t γt-1$ is its utility
\[ V = (I - γ P)-1 r \] First of all, $∇ A-1 = - A-1 ∇ A A-1$ and so \[ ∇_θ V = γ (I - γ P)-1 ∇ P (I - γ P)-1 \] Finally, \[ ∇ Pij = ∇ ∑_a P(s’ = j | s = i , a) \pol (a \mid s) \]
- $X = (I - γ P)-1$ discounted state-visitation matrix
-
$x = y^\top X$ expected state visitations from starting state distribution
Then \[ ∇ \E[U] = ∑_x x(s) ∑_a ∇ \pol(a | s) Q^\pol(s,a) \]
- We can approximate
$x$ and$Q$ for the gradient update.
\[ ∇ \E[U] = ∑_h U(h) ∇ P(h) = ∑_h U(h) P(h) ∇ ln P(h). \] This allows us to use the approximation \[ ∇ \E[U] ≈ \frac{1}{K} ∑k=1^K ∑_h U(h(k)) ∇ ln P(h(k)), \qquad h(k) ∼ P(h) \]
Given a utility function
- At time
$t$ : - The state is
$s_t$ , players receive rewards$ρ(s_t), -ρ(s_t)$ - Player chooses action
$a_t$ , which is revealed. - The state changes to $st+1$, and is revealed.
- Players receive reward $ρ(st+1), -ρ(st+1)$
- Player chooses action $ωt+1$.
- The state changes to $st+2$.
- Player
$a$ receives$ρ(s_t)$ and$b$ receives$-ρ(s_t)$ .
The utility for player
Let $π_1$ and $π_2$ be the policies of each player and $π$ the joint policy.
For the utility of player 1, we get:
\begin{align}
V1,\pol_t(s)
&\defn \E_π [U1_t \mid s_t = s]
= ρ(s) + \E[U1t+1 \mid s_t = s]
&= ρ(s) + ∑_a \pol(a \mid s) ∑j V1,πt+1(j) P(j\mid s, a)\
V1,\polt+1(j)
&= ρ(j) + ∑_b \pol(b \mid j) ∑j V1,πt+2(j) P(k \mid j, b)
\end{align}
We can define the optimal value function analogously to MDPs:
\begin{align}
V1,*_t(s)
&= maxπ_1 minπ_2 \E_π [U+_t \mid s_t = s]
&= ρ(s) + max_a ∑j V1,*t+1(j) P(j\mid s, a)\
V1,*t+1(j)
&= ρ(j) + min_ω ∑j V1,*t+1(j) P(k \mid j, ω)
\end{align}
The above recursion can be used to calculate the minimax value function.
| turn | dare | |
|---|---|---|
| / | < | < |
| turn | 0, 0 | -5, -1 |
| dare | 1, -5 | -10, -10 |
| cooperate | defect | |
|---|---|---|
| / | < | < |
| cooperate | 0, 0 | -5, -1 |
| defect | 1, -5 | -10, -10 |
| kick left | kick right | |
|---|---|---|
| / | < | < |
| dive left | 1, -1 | -1, 1 |
| dive right | -1 1 | 1, -1 |
- At time
$t$ : - The state is
$s_t$ , players receive rewards$ρ^i(s_t)$ . - Player
$i = I(s_t)$ chooses an action. - The state changes to $st+1$, and is revealed.
The utility for each player is \[ Ui = ∑_t ρ^i(s_t) \]
Let $π_i$ be the policy of the \(i\)-th player and $π$ the joint policy.
For any player
&= ρ^i(s) + ∑a ∈ A \polI(s)(a \mid s) ∑j V1,πt+1(j) P(j\mid s, a)
\end{align}
For perfect information games, we can use this recursion:
\begin{align}
a^*_t(s) &=
\argmaxa ∈ A
∑j VI(s),*t+1(j)P(j\mid s, a)
Vi,*_t &= ρ^i(s) + ∑j Vi,πt+1(j) P(j\mid s, a^*_t(s)) &&∀ i
\end{align}
This ensures that we update the values of all players at each step.
- Board representation
- Rollouts
- Monte-Carlo Tree Search
- Value approximation
- Policy approximation
- Model approximation
- Alpha Go (MCTS, value approximation)
- Alpha Go Zero (MCTS, value and policy approximation)
- Alpha Zero (almost the same)
- Mu Zero (MCTS, value, policy and model approximation)
For each state
- Number of visits
- Move probability
- Expected value
- Start from
$s_t$ - Generate
$a_t = \argmax_a Q_θ(s, a) + U(s_t, a)$ where
\[ U(s,a) = P(s,a) / N(s,a) \]
- Update $Q_θ(s,a) → 1/N(s,a) ∑s’ ∈ S_T V(s’)
- Loses
- Thompson sampling (25’)
- Bayesian Policy Gradient (20’)
- BAMDPs (25’)
- POMDPs (20’)
- Maximising expected utility
- Memoryless policies
- Adaptive policies
- Mixed MDP
- Many bandit problems
- Just Bayes’s theorem
- Example: Discrete MDPs
\[ ∇_\pol E^\pol_\bel[U] = ∫_\MDPs ∇_\pol \E^\pol_\mdp[U] d \bel(\mdp) ≈ \frac{1}{K} ∑k=1^K ∇_\pol \E^\pol\mdp^{k}[U], ∼ \mdpk ∼ \bel \]
\[ U^*(\bel) = max_\pol U(\pol, \bel) \] \[ U(\pol, \bel) \leq U^*(\bel) \leq ∫_\MDPs max_\pol U(\pol, \mdp) d \bel(\mdp) \]
- Exact solution: Bayes-Adaptive Markov Decision Processesx
- In POMDPs, the state is unknown, so we must infer both
$\mdp, s$ .
- UCB (45’)
- UCRL (45’)
- UCT (45’)
- Alphazero (45’)
- repeat {
- search(state, 0)
- } until TimeOut
- return BestAction(state, 0)
- if Terminal(state) return 0
- if Leaf(state) return Evaluate(state)
- a = SelectAction(state, depth)
- (NextState, reward) = Simulate(state, action)
- q = reward + γ search(NextState, depth + 1)
- UpdateValue(state, action, q, depth)
- return q
- $Ns,d(t)$: Visits of state
$s$ - $Ns,a,d(t)$: Number of times
$s,a$ is selected
\[ a^*(s,t) = \argmax_a Q_t(s, a, d) + C \sqrt{ln(Ns,d(t))/Ns,a,d(t)} \]
- $a = SelectAction(s,d)$
$q = ρ(s, a) + Search(S+1)$ - $Q_t(s, a, d) = Qt-1(s,a, d) (1 - α) + α q$
- Return
$q$
- Linear Models (20’)
- Gaussian Processes (25’)
- GPTD (45’)
- Apprenticeship learning (45’)
- Probabilistic IRL (45’)
Bayesian games (90’)