CS 285, Lecture 4, Intro to RL
CS 285 Deep Reinforcement Learning, Sergey Levine, Lecture 4 notes.
# Cornell insight
Imitation Learning different from supervised learning Motivation: implicitly program robots
Problem: feedback compounds errors feedback drives covariate shift btw train and test distr training distr: states visited by human test distr: states visited by learner
Solution:
interactively query expert on states learner visits, s.t. training distr is similar to test distr
seminal algorithm:
DAGGER (Dataset Aggregation)
4 steps:
- collect human demonstration, train initial policy
- rollout to collect states
- ask human for correct action
- aggregate data & train , go back to step 2
# CS285
- imitation learning via behavioral cloning is not guaranteed to work
- different from supervised learning
- reason: iid assumption does not hold
- theory explains why (the quadratic term in # error expectation)
- solutions:
- be smart about how to collect (and augment) data
- powerful models that make few mistakes
- use multi-task learning
- change the algorithm (DAgger)
Following is notes for CS285, lecture 4.
# Markov Decision Process
state: , observation: , action:
policy: , policy (fully observed):
observations are partially observed, while states are fully observed and satisfy the Markov property ( is independent of given the current state and action )
reward function: , which tells us which state-action pairs are better
Markov Decision Process (MDP): , , ,
state space (discrete or continuous):
action space (discrete or continuous):
transition operator: , a tensor
let , ,
then
reward function:
# Partially Observed Markov Decision Process
make decisions based on partially observed observations, without access to true states
additionally, observations (discrete or continuous):
emission probability:
# Goal of RL
let , then
if we define augmented state , then
# Finite horizon case: state-action marginal
state-action marginal:
# Infinite horizon case: stationary distribution
Let be the state-action transition operator, then:
when , we generally have 2 ways:
- because is a constant, this way does not change the max. but when , the return is well-defined (discuss now)
- discount factor (will discuss later)
under ergodicity and aperiodicity, stationary distribution (same before and after the transition) exists:
is eigenvector of with eigenvalue , and always exists under ergodicity and aperiodicity assumptions:
ergodicity: every state can be reached from every other state with non-zero probability (if starting in one part of MDP may never reach another part, then starting state matters, and stationary distribution does not exist)
aperiodicity: Markov chain is not periodic
when , have initially finite number of terms not in stationary distribution, and infinite number of terms under stationary distribution . The goal of RL in infinite horizon as becomes:
the average reward is expected reward under stationary distribution.
For example, is if not fall, and -1 if fall off the cliff, and not smooth. Policy . The expectation is:
even if the function (reward) is discontinuous, the expectation is usually continuous.
In RL, we almost always care about expectations. Even though the reward itself may be sparse, discontinuous, and non-differentiable, the policy is typically differentiable with respect to its parameters, and the expected reward is often differentiable enough to optimize with gradient-based methods.
# Anatomy of a RL algorithm
the following 3 steps in a cycle:
- generate samples run the policy in the env, get trajectories can be prohibitively expensive in real world, but trivially cheap in simulator
- fit a model / estimate the return measure how good the trajectories are can just sum up the rewards into return (fast)
in model-based RL, learn such that (can be slow)
- improve the policy
modify policy to make the better trajectories have a higher probability (1 gradient step, cheap)
in model-based RL, backprop through and , train (backprop, can be expensive)
# Value Functions
The expectation can be decoupled:
define:
then the RL objective is:
it's easy to modify if is known. e.g., if (always choose the action giving max Q)
# Q-function definition
total reward from taking action in state
expected sum of future rewards conditioned on starting at
# Value function definition
total reward from , conditioned only on state, rather than state and action
also can be written as the expected value over actions of the Q function:
the expectation of value function at state is the RL objective:
# Using Q-function and value function
2 important ideas:
idea 1: if we have policy , and we know , then can improve :
set if
this policy is at least as good as
used in policy iteration and Q learning
idea 2: compute gradient to increase probability of good actions :
if , then is better than average (recall: )
can modify to increase probability of
will reoccur in model-free RL algos
# Types of RL algorithms
- policy gradients: directly differentiate the objective, then gradient descent
- value-based: estimate or of the optimal policy (no explicit policy). value function represented by a function approximator like NN
- actor-critic: estimate or of the current policy, improve policy with policy gradient
- model-based RL: estimate the transition model, and then:
- use it for planning (no explicit policy)
- use it to improve a policy
TODO: diff btw value-based & actor-critic?
# Model-based RL algorithms
in 2nd step: fit a model / estimate the return
learn a model for
if a deterministic model, just predict
in 3rd step: improve the policy
a few options:
- use the model to plan (no policy)
- in continuous action spaces: trajectory optimization / optimal control, essentially backprop to optimize over actions
- in discrete action spaces: discrete planning, e.g., Monte Carlo tree search
- backprop gradients into the policy
- requires some tricks to work
- use the model to learn a value function, then improve policy
- V or Q learned using dynamic programming
- use a model to generate simulated experience for model-free learner
# Value function based algorithms
in 2nd step: fit a model / estimate the return
fit or
in 3rd step: improve the policy
set
# Direct policy gradients
in 2nd step: fit a model / estimate the return
evaluate returns by adding rewards obtained during the rollout (sample policy 1 step at a time):
in 3rd step: improve the policy
using gradient ascent
# Actor-critic
in 2nd step: fit a model / estimate the return
like value-based methods
fit or
in 3rd step: improve the policy
like policy gradient methods, utilize or to obtain a more accurate gradient
# Why so many RL algorithms
- different tradeoffs
- sample efficiency
- stability & ease of use (hyperparams can be difficult to select)
- different assumptions
- stochastic vs deterministic
- continuous vs discrete state & action
- episodic vs infinite horizon
- different things are easy/hard in different settings
- easier to represent the policy
- easier to represent the model
# Comparison: sample efficiency
sample efficiency: how many samples needed to obtain a good policy
off-policy: able to improve policy without generating new samples from that policy
on-policy: each time the policy is changed (even a little bit), new samples must be collected
Why would we use a less efficient algorithm? Because wall clock time is not the same as efficiency!
# Comparison: stability and ease of use
- Does it converge?
- And if it converges, to what?
- And does it converge every time?
supervised learning: almost always gradient descent
RL: often not gradient descent
- Q-learning: fixed point iteration, guarantee convergence under simplified tabular discrete state assumptions (often not held in practice). convergence of many RL algos is an open problem
- model-based RL: getting a better model does not mean a better expected reward
- policy gradient: is gradient descent, but often the least efficient
- value function fitting
- at best, minimize error of fit (Bellman error). eval value function predicting error accurately, but not the same as expected reward
- at worst, does not optimize anything. many popular deep RL value fitting algorithms are not guaranteed to converge to anything in the nonlinear case
- model-based RL
- model minimizes error of fit (will converge), but no guarantee that better model = better policy
- policy gradient
- actually performs gradient descent (ascent) on the true objective
# Comparison: common assumptions
- full observability
- generally assumed by value function fitting methods
- can be mitigated by adding recurrence
- episodic learning: make a trial, reset, make another trial
- often assumed by pure policy gradient methods
- assumed by some model-based RL methods
- value-based methods work better under this assumption
- continuity or smoothness
- assumed by some continuous value function learning methods
- often assumed by some model-based RL methods
# Examples of specific algorithms
- Value function fitting methods
- Q-learning, DQN
- Temporal difference learning
- Fitted value iteration
- Policy gradient methods
- REINFORCE
- Natural policy gradient
- Trust region policy optimization
- Actor-critic algorithms
- Asynchronous advantage actor-critic (A3C)
- Soft actor-critic (SAC)
- Model-based RL algorithms
- Dyna
- Guided policy search