[Chapter 4] Reinforcement Learning (2) Model-Free Method

Model-Free RL Method

In model-based method, we need firstly model the environment by learning/estimating the transition and reward functions. However, in model-free method, we consider learning the value/utility functions or or action-value functions directly without learning and . There are also two main kinds of approaches, one is called Monte Carlo (MC) Learning and another one is called Temporal Difference (TD) Learning. The main difference between them is how often to update the policy.

Monte Carlo Learning

Firstly, we consider the prediction problem, how to compute/estimate the or ?

In Monte Carlo learning, the agent executes a set of trails based on the GLIE scheme (trading the exploration and exploitation off). In our example environment, a trail starts from location and ends in either terminal states or , e.g., shown below with the rewards in subscripts:

image

The trails collected by the agent are samples or data, on which we can learn based. You must remember the Bellman equation for the utility function, and we have another version of it for the Q-function:

where is the discounted factor.

Using these two equations, we can compute the utility or Q-value for each state, for example, in the trail 3, the return or reward-to-go of state can be computed as (suppose here):

It can be an estimation of the return of state , while we have many many trials/samples, take an average value of all estimations, then we can get an approximate value for each state. And in infinitely many trails, sample average will converge to the expected value.

Here, actually you can see that in trail 1, location appears two times, in this case, if we only use the first one, it becomes a first visit method, or if we use both of the samples, it becomes a every visit method, we will focus on the first visit method in this section.

Assume state is encountered times giving returns. We can rewrite the average, of returns as:

where is the estimate after receiving returns, so can be considered the prediction error for the -th return.

In a similar way, we can also choose to learn the Q-functions instead of learning the value functions. After that, for the control problem, we only need to greedy choose the policy by:

There is another problem you may want to know, how to sample trails in MC learning? As we have stated above, it's better to using a GLIE scheme, for example, -greedy, which means that for a probability of , using the current policy (computed by the control problem part) to select a current-best action, and for a probability of , choosing actions randomly.

MC learning is an instance of supervised learning: each example has state as input and observed return as output, so it's simple and unbiased. However, the biggest disadvantage for MC learning is that we need to wait till the end of episode to get one trail and then learn can be done. So let's introduce another method, which can learn after each step -- temporal difference learning.

Temporal Difference Learning

Temporal difference (TD) learning exploits more of the Bellman equation constraints than Monte Carlo learning. For a transition from state to , TD learning does:

where is the learning rate and is the discounted factor.

In the formula, we can see that it will increase if is larger than and decrease it otherwise. So we call the TD target and the TD error. The update formula will converge if decreases appropriately with the number of times the state has been visited, e.g. .

The TD learning algorithm can be illustrated as following:

image

As you can see, TD can learn online after every step, instead, MC needs complete episode before learning. However, TD target depends only on one measured reward, while MC target depends on the sum of many rewards, so TD target has lower variance but is biased. Usually TD can converge faster than MC in practice.

To make it more accurate, we can also set more than one steps in TD target, which is called n-step TD: Let be the target for TD update. TD sets equals to 1 while MC sets to . Usually, an intermediate value of tends to work better.

Based on the n-step TD that using one value of , a new method averages over different values of is called TD(). It sets the following as the target for update:

It calculates the weighted sum of n-step returns, where the n-th step is weighted by , and this can be computed efficiently using a method called eligibility traces. Actually, it converges to TD as approaches 0, and to MC as approaches 1.

Now, we have seen the basic rule for prediction in TD method, now we turn the aim from utility function to Q-function, there are two different approaches to update the Q-function. They are called On-Policy methods and Off-Policy methods respectively and two examples for them are SARSA (State-Action-Reward-State-Action) algorithm and Q-learning algorithm.

  • SARSA Algorithm:

where is the action taken at based on the -greedy action selection with the current policy.

  • Q-learning Algorithm:

where represents all available actions at state .

The biggest difference between these two methods is the operator.

SARSA is an on-policy method, which means that it only tries to improve the same policy that is used to generate the training data. For example, in the learning, for the current policy , at the state , the agent selects the action (based on and the action-selection policy, e.g. -greedy, same thing below), then the environment transits to state and returns reward , finally, on the new state , the agent again selects an action , for now, we have get a tuple , using the formula above, we can do one-step update of the Q-function. In this method, selecting and selecting is based on the same policy, so we generate data from the policy and update the same policy.

Q-learning is an off-policy method, which means that the updated policy can be different from the policies that are used to generate data. This is because of the operation, just as the formula shows, to update the Q-function for a pair, we need the part. Here, we choose the maximum value among all possible actions, the new action in not limited to the current policy, we can use the data collected by other policies. You may have many differernt policies that generates and collects data in the environment, which are called behaivor policy, they can all be used to update a target policy. Here is also a pseudo-code of the Q-learning algorithm:

image

你可能感兴趣的:([Chapter 4] Reinforcement Learning (2) Model-Free Method)