Introduction
In the previous part, we covered some additional Temporal-Difference (TD) learning methods, including Expected SARSA, which is an on-policy method that uses the expected value of the next state-action pair rather than a sample, and Double Q-learning, which is an off-policy method that addresses the overestimation bias in Q-learning. Finally, we discussed the general framework known as -step bootstrapping, which unifies TD and Monte Carlo (MC) methods.
In this part, we will introduce the concept of function approximation in reinforcement learning (RL), which is essential for handling large or continuous state and action spaces. We will discuss different types of function approximators, including linear and non-linear methods, and how they can be integrated into RL algorithms. Finally, we will provide an introduction to Deep Reinforcement Learning (Deep RL), which combines deep learning techniques with RL to tackle complex problems.
Function Approximation in Reinforcement Learning
In many (real-world) tasks, the state (and action) space is combinatorial and enormous, thus the memory, time, and, data requirements become infeasible.
Intuition (Function Approximation)
If we instead can find a good approximate solution using limited computational resources, while not losing (much) generalization, we can solve much larger problems.
But, how can experience with a limited subset of the state space be used to produce a good approximation for the entire state space?
This is what function approximation aims to solve.
Definition 1 (Value Function Approximation)
We represent the state value function approximation as a parameterized function with weight vector ,
might be a linear function but it can also be a function computed by a neural network.
Typically, the number of (shared) weights (the dimensionality of ) is much smaller than the number of states, i.e., . When a single state is updated, the change generalizes from that state to affect the values of many other states.
Definition 2 (Approximate Prediction of Value Functions)
We denote the individual update (target) by the notation ,
-
MC Updatew:
-
TD(0) Update:
-
-step TD Update:
-
DP Update:
The update means that the estimated value for state should be “more like” the updated target .
Thus, we can treat this as a supervised learning problem! However, there is a fundamental difference, in classical supervised learning, we have a stating training dataset. While in RL, learning occurs online (i.e., when the agent interacts with the environment), and the targets are incremental (i.e., non i.i.d. data) and non-stationary (i.e., the target changes as the value function changes).
Definition 3 (The Prediction Objective ())
For a supervised learning task, we need some notion of error or loss, a common choice is the mean squared value error (),
where is the weighting factor such that , is chosen to be the fraction of the time spent in state under policy (also called the on-policy distribution).
Another common choice is the square root of , called the root mean squared value error (RMSVE).
Note
Note that, in continuing tasks, the on-policy distribution is the stationary distribution under policy .
Definition 4 (On-Policy Distribution in Episodic Tasks)
Let be the probability that an episode starts in state . Further, let be the number of time steps spent, on average, in state in a single episode,
This system of equations can be solved for the expected number of visits to each state .
The on-policy distribution is then obtained by normalization,
Note
Note that, we assumed no discounting, i.e., here.
Intuition (Minimizing the Prediction Objective)
The next logical step would be to find a global optimum, in terms of the weights , that minimizes the prediction objective . This is possible if we have a nice simple function, such as linear, convex, or differentiable. However, this is rarely possible for more complex models, such as neural networks.
Thus, we instead will suffice with finding a local optimum.
Definition 5 (Stochastic Gradient Descent (SGD))
Firstly, the weightt vector is a column vector with a fixed number of real valued elements,
Secondly, the function is a differentiable function with respect to .
Since we will be updating at each of a series of discrete time steps , we will denote the weight vector at time by . Further, assume at time step , the agent observes a new example consisting of a state and its (true) value under the policy.
Lastly, for simplicity, assume that the states appearing in the examples have the same distribution .
Thus, the SGD update rule is given by,
where is the step-size parameter (or learning rate).
Definition 6 (SGD with Approximate Targets)
However, unlike the classical supervised learning setting, in RL we do not have acces to the true value . Instead, we have to use an approximate target of the -th training example , e.g., a noise-corrupted version of the true value or a bootstrapped estimate.
In this setting, we simply substitute for in the SGD update rule,
Warning
If is an unbiased estimate, i.e., , then is guaranteed to converge to a local optimum under some certain conditions.
Algorithm (Gradient Monte Carlo Algorithm for estimating )
Input: the policy to be evaluated
Input: a differentiable function
Algorithm parameter: step-size
Initialize value-function weights arbitrarily (e.g., )
Loop forever (for each episode):
- Generate an episode using policy
- Loop for each step of episode :
Note
The MC target is an unbiased estimate of 1Why? The answer is, by definition of the value function.. Thus, it is guaranteed to converge to a local optimum under some certain conditions.
Definition 7 (Semi-Gradient Methods)
When we are dealing with bootstrapping targets, such as the -step TD target or the DP target , all depend on the current value of the weight vector . Thus, the targets will be biased and they will not produce a true gradient descent method.
We instead call these methods semi-gradient methods.
Algorithm (Semi-Gradient TD(0) for estimating )
Input: the policy to be evaluated
Input: a differentiable function such that
Algorithm parameters: step-size
Initialize value-function weights arbitrarily (e.g., )
Loop for each episode:
- Initialize
- Loop for each step of episode:
- Choose
- Take action , observe
- until is terminal
Generalizing Function Approximation
Definition 8 (State Aggregation)
A simple form of generalizing function approximation is state aggregation, where states are grouped together, with one estimated value (one element in the weight vector ) for each group. The value of a state is estimated as its group’s component, and when the state is updated, that component alone is updated.
Thus, this is a special case of SGD in which the gradient is 1 for ’s group’s component and 0 for all other components.
Definition 9 (Linear Methods)
A more general and powerful form of function approximation is linear methods, where the value of a state is estimated as a linear combination of features. For every state , there is a vector with the same number of components as .
Linear methods approximate the state-value function by,
The real valued vector is called the feature vector representing state .
The gradient of the linear approximate value function with respect to is simply the feature vector,
Thus, the SGD update is,
Further, local optima are guaranteed to be global optima 2Why? The answer is, the prediction objective is a quadratic function in terms of , thus it is convex..
Note
The performance of linear methods depends critically on how the states are represented in terms of features.
Choosing appropriate features is an important way of adding prior domain knowledge to RL systems. There are several ways to construct the relevant features, but hand-crafted features can be brittle and non-transferable to other tasks.
Definition 10 (Nonlinear function approximation with neural networks)
Neural networks are widely used for nonlinear function approximation [^1] in RL. They can for example use the TD error/target to learn value functions. We use backpropagation to estimate the partial derivative of an objective function with respect to each weight in the network.
However, they can suffer from overfitting, especially for deep networks with many layers and parameters.
Summary (Parametric Approximation Methods)
So far, we have discussed the parametric approach to approximating value functions, let’s summarize the main points.
- A learning algorithm adjusts the parameters of a functional form intended to approximate the value function.
- Each update is a training example used by the learning algorithm to change the parameters with the aim of reducing the approximation error.
- After the update, the training example can be discarded (although, it might be saved to be used again).
- When an approximate value of a state (sometimes called the query state) is needed, the function is simply evaluated at that state using the latest parameters produced by the learning algorithm.
Non-Parametric (Memory-Based) Function Approximation
Definition 11 (Non-Parametric (Memory-Based) Function Approximation)
In the parametric setting, we update the parameters each time we receive a new training example, and then discard the example. However, in the non-parametric (memory-based) setting, we store the training examples without explicitly updating a parameterized function.
Whenever a query state’s value is needed, a set of examples is retrieved from memory and used to compute a value estimate for the query state. It is also sometimes called, lazy learning, because processing training examples is postponed until the system is queried to provide an output.
Definition 12 (Local-Learning Methods)
Local-learning methods are a class of methods where we approximate a value function only locally in the neighborhood of the current query state. The closer a training example’s state is to the query state, the more relevant it is considered to be. Distance can be defined in many different ways, e.g., Euclidean distance, Manhattan distance, or domain-specific distance measures.
An example is the nearest neighbor method, it simply finds the example in memory whose state is closest to the query state and returns that example’s valuea s the approximate value of the query state.