Video link
Terminology
- M={S,T} -- Markov chain where:
- S: State space (s∈S)
- T: Transition operator (matrix or tensor) denoting the probability of transition between states
- M={S,A,T,r} -- Markov decision process where:
- A: Action space (a∈A)
- r: Reward function which is a mapping from the state and action spaces into a real number r:S×A→ℜ
- M={S,A,O,T,E,r} -- Partially observed Markov decision process where:
- O: Observation space space (o∈O)
- E: Emission (or observation) probability p(ot∣st)
Objective

When looking at the system above, we can write down a probability distribution over trajectories, where trajectories are sequences of paired actions and states (e.g. (s1,a1), (s2,a2) and so on).
pθ(s1,a1,…,sT,aT)pθ(s1,a1,…,sT,aT)=p(s1)t=1∏Tπθ(at∣st)p(st+1∣st,at)=pθ(τ)Remember that πθ(at∣st) is the probability of an action, and p(st+1∣st,at) is the probability of a state transition.

Now we can define an objective for reinforcement learning as an expected value_under_ the trajectory distribution:
θ∗=argmaxθEτ∼pθ(τ)[t∑r(st,at)]We want to maximize the expected value of the sum of rewards over the trajectory. If we augment the Markov chain by bundling states and actions so that p((st+1,at+1∣(st,at))=p(st+1∣st,at)πθ(at+1∣st+1) we can use the linearity of expectation to rewrite the objective such that:
θ∗=argmaxθt=1∑TE(st,at)∼pθ(st,at)[r(st,at)]Which we can use to find out what happens when T=∞.

Does p(st,at) converge to a single distribution as k→∞? If we assume aperiodicity and ergodicity we can write μ=Tμ, where μ is a stationary distribution. It follows that (T−I)μ=0 so μ is an eigenvector of T with an eigenvalue of 1. As T→∞ the sum of the expectations of the marginals becomes dominated by the stationary distribution. We can divide the expectation by T to find the average:
θ∗=argmaxθT1t=1∑TE(st,at)∼pθ(st,at)[r(st,at)]Then take the limit as T→∞ we get the expected value of the reward under the stationary distribution, where the stationary distribution μ=pθ(s,a):
θ∗=E(s,a)∼pθ(s,a)[r(st,at)]Expected values can be continuous in the parameters of corresponding distributions even when the function that we're taking the expectation of is discontinuous. If we have a discontinuous reward function r(x), we could have a probability distribution over some action πθ(a)=θ which is a Bernoulli random variable with parameter θ. The expected value of the reward, Eπθ[r(x)], is actually smooth in θ! The takeaway is that expected values of non-smooth and non-differentiable functions under differentiable and smooth probability distributions, are themselves smooth and differentiable.
Algorithms
Reinforcement Learning algorithms all generally have the same three part structure:
- Generate Samples: Run the policy in the environment, have it interact with your Markov Decision Process, and collect samples (sampled trajectories from the policy-defined trajectory distribution (i.e. run your policy in the environment)).
- Fit Your Model: Estimate how well your policy is doing.
- Improve Your Policy: Make your policy better given the metric calculated in step 2.

Regarding the costs of these steps:
- Generate Samples: Depends greatly on the system in question. Real systems generate samples in real time, simulated systems can often run many times faster than real time
- Fit Your Model: Also depends on the system! If you're doing a sum of rewards (as you would with a Policy Gradient Algorithm) it can be very fast. If you're fitting an entire neural net (as you would with reinforcement learning with back-propagation), it can be expensive.
- Improve Your Policy: Same as 2.
Q and Value Functions
The Q Function
To recap: a reinforcement learning objective is often an expectation, defined as a sum over time for every state-action marginal. Recall that given a joint distribution of two discrete random variables X and Y, the marginal distribution of X is the probability distribution of X without taking into account Y. The expectation can be written as:
Eτ∼pθ(τ)[t=1∑Tr(st,at)]We can write this out recursively as a series of nested expectations, expanding it into this monster:
Es1∼p(s1)[Ea1∼π(a1∣s1)[r(s1,a1)+Es2∼p(s2∣s1,a1)[Ea2∼π(a2∣s2)[r(s2,a2)+⋯∣s2]∣s1,a1]∣s1]]Why on earth would anyone do this? Well, what if we knew what went inside the second expectation, defined by some function called Q?
Q(s1,a1)=r(s1,a1)+Es2∼p(s2∣s1,a1)[Ea2∼π(a2∣s2)[r(s2,a2)+⋯∣s2]∣s1,a1]That monstrous expansion from above becomes
Eτ∼pθ(τ)[t=1∑Tr(st,at)]=Es1∼p(s1)[Ea1∼π(a1∣s1)[Q(s1,a1)∣s1]]If we know this Q function then optimizing the policy π(a1∣s1) at t=1 is easy, we can just maximize the value of Q. A more formal definition of the Q function is:
Qπ(st,at)=t′=t∑TEπθ[r(st′,at′)∣st,at]This means that you will get the expected sum of rewards if you roll out your policy from st,at.
The Value Function
Defined below, the value function is essentially the same, except it's conditional only on the state, rather than the state and the action:
Vπ(st)=t′=t∑TEπθ[r(st′,at′)∣st]This means that the equation below is the entirety of the reinforcement learning objective!
Es1∼p(s1)=[Vπ(st)]Using Q and Value Functions
- If we have a policy π and we know Qπ(s,a) then we can improve π by setting π′(a∣s)=1 if a=argmaxaQπ(s,a). This means that regardless of what π is, π′ is at least as good, and is probably better.
- We could also compute the gradient to increase the probability of good actions a given that, if Qπ(s,a)>Vπ(s), then a is better than average. We would do this by modifying π(a∣s) to increase the probability of a if Qπ(s,a)>Vπ(s).
Types of RL Algorithms
Policy Gradient
Directly differentiate the objective w.r.t. the policy

Model Based

After estimating the transition model p there are several options for improving the policy:
- Use the model to plan without a policy
- Trajectory optimization; essentially backpropagation to optimize over actions (mainly continuous)
- Discrete planning in discrete action spaces e.g. Monte Carlo tree search
- Backpropagation: use the learned model to calculate derivatives of the reward function w.r.t. the policy.
- Can be tricky with regards to numerical stability
- Use the model to learn a Value or Q function, then use the learned function to improve the policy.
Value Function Based
V(s) and Q(s,a) are often NNs

Actor-critic
Improve the policy by estimating the value- or Q function.

How to decide?
Some things to consider when choosing an algorithm are:
- Trade-offs:
- Sample efficiency (how many samples do we need for a good policy?)
- Is the algorithm on or off policy (can we improve the policy without having to regenerate samples)?
- Real-world time = efficiency
- Stability and ease of use
- Convergence criteria
- Supervised learning is almost always gradient descent
- Reinforcement learning is often not gradient descent
- Required assumptions:
- Is the system fully observable? (Mitigated by adding recurrence)
- Episodic or per-step learning?
- Continuity or smoothness
Model comparison
Here's how each of the first three aforementioned model types compare (oversimplified):
|
Policy Gradient |
Model Based |
Value Function |
| Sample Efficiency |
Least efficient |
Most efficient |
Quite efficient |
| Gradient Descent? |
Yes |
No |
No (fixed-point iteration) |
| Assumptions |
Episodic Learning |
Continuity |
Full Observability and Continuity |
Here's how they line up on the efficiency scale:
