Sarsa(λ) and Q(λ) in Tabular Case

‘Thanks R. S. Sutton and A. G. Barto for their great work in Reinforcement Learning: An Introduction.

Eligibility Traces in Prediction Problems

In the backward view of TD(λ) , there is a memory variable associated with each state, its eligibility trace. The eligibility trace for state s at time t is a random variable denoted Zt(s)R+ . On each step, the eligibility traces for all states decay by γλ , and the eligibility trace for the one state visited on the step is incremented by 1:

Zt(s)={γλZt1(s)γλZt1(s)+1sSts=St

for all nonterminal states s , where γ is the discount rate and λ is the λ -return 1 parameter or trace-decay parameter. This kind of eligibility trace is called an accumulating trace. The global TD error signal triggers proportional updates to all recently visited states, as signaled by their nonzero traces:
ΔVt(s)=αδtZt(s),sS

where
δt=Rt+1+γVt(St+1)Vt(St)

A complete prediction algorithm for on-line TD(λ) is given as follows:

  1. Initialize V(s) arbitrarily.
  2. Repeat for each episode:
    1. Initialize Z(s)=0 for all sS .
    2. Repeat for each step of episode:
      1. A action given by π for S .
      2. Observe reward R and the next state S .
      3. δR+γV(S)V(S)
      4. Z(S)Z(S)+1
      5. For all sS :
        1. V(s)V(s)+αδZ(s)
        2. Z(s)γλZ(s)
      6. SS
    3. Until S is terminal.

Sarsa(λ)

The main idea of control is simply to learn action values rather than state values. The idea in Sarsa(λ) is to apply the TD( λ ) prediction method to state-action pairs. Let Zt(s,a) denote the trace for state-action pair s,a . Substitute state-action variables for state variables, i.e.

Qt+1(s,a)=Qt(s,a)+αδtZt(s,a),s,a

where
δt=Rt+1+γQt(St+1,At+1)Qt(St,At)

and
Zt(s,a)={γλZt1(s,a)+1γλZt1(s,a)s=St,a=Atotherwise for all s,a

The complete Sarsa( λ ) algorithm is given as follows:

  1. Initialize Q(s,a) arbitrarily for all sS,aA(s)
  2. Repeat for each episode:
    1. Z(s,a)=0 for all sS,aA(s)
    2. Repeat for each step of episode:
      1. Take action A , observe R, S .
      2. Choose A from S using policy derived from Q .
      3. δR+γQ(S,A)Q(S,A)
      4. Z(S,A)Z(S,A)+1
      5. For all sS,aA(s) :
        1. Q(s,a)Q(s,a)+αδZ(s,a)
        2. Z(s,a)γλZ(s,a)
      6. SS,AA
    3. Unitl S is terminal.

Q(λ)

There are two different methods have been proposed that combine eligibility traces and Q-Learning: the Watkins’s Q(λ) and Peng’s Q(λ). Here we focus on Watkin’s Q(λ) only and give a brief description of Peng’s Q(λ).

Unlike TD(λ) and Sarsa(λ), Watkins’s Q(λ) does not look ahead all the way to the end of the episode in its backup. It only looks ahead as far as the next exploratory action. For example, suppose the first action, At+1, is exploratory. Watkins’s Q(λ) would still do the one-step update of Qt(St,At) toward Rt+1+γmaxaQ(St+1,a) . In general, if At+n is the first exploratory action, then the longest backup is toward

Rt+1+γRt+1++γn1Rt+n+γnmaxaQ(St+n,a)

where we assume off-line updating.

The mechanistic or backward view of Watkins’s Q(λ) is also very simple. Eligibility traces are used just as in Sarsa(λ), except that they are set to zero whenever an exploratory action is taken. That is to say. First, the traces for all state-action pairs are either decayed by γλ or, if an exploratory action was taken, set to 0. Second, the trace corresponding to the current state and action is incremented by 1, i.e.

Zt(s,a)=IsStIaAt+γλZt1(s,a)0 if Qt1(St,At)=maxaQt1(St,a) otherwise

where Ixy is an identity indicator function, equal to 1 if x=y and 0 otherwise. The rest of the algorithm is defined by
Qt+1(s,a)=Qt(s,a)+αδtZt(s,a),sS,aA(s)

where
δt=Rt+1+γmaxaQt(St+1,a)Qt(St,At)

The complete algorithm is given below:

  1. Initialize Q(s,a) arbitrarily, for all sS,aA(s) .
  2. Repeat for each episode:
    1. Z(s,a)=0 for all sS,aA(s)
    2. Repeat for each step of episode:
      1. Take action A , observe R, S
      2. Choose A from S using policy derived from Q .
      3. AargmaxaQ(S,a), if A ties for the max, then AA
      4. δR+γQ(S,A)Q(S,A)
      5. Z(S,A)Z(S,A)+1
      6. For all sS,aA(s) :
        1. Q(s,a)Q(s,a)+αδZ(s,a)
        2. If A=A , then Z(s,a)γλZ(s,a) , else Z(s,a)0 .
      7. SS,AA
    3. Until S is terminal

Unfortunately, cutting off traces every time an exploratory action is taken loses much of the advantage of using eligibility traces. Peng’s Q(λ) is an alternate version of Q(λ) meant to remedy this, which can be thought of as a hybrid of Sarsa(λ) and Watkins’s Q(λ). In Peng’s Q(λ), there is no distinction between exploratory and greedy actions. Each component beckup is over many steps of actual experiences, and all but the last are capped by a final maximization over actions. For a fixed nongreedy policy, Qt converges to neither qπ nor q , but to some hybrid of the two. However, if the policy is gradually made more greedy, then the method may still converge to q .

Replacing Traces

In some cases significantly better performance can be obtained by using a slightly modified kind of trace known as replacing trace:

Zt(s)={γλZt1(s)1sSts=St

There are several possible ways to generalize replacing eligibility traces for use in control methods. In some cases, the state-action traces are updated by the following:
Zt(s,a)=10γλZt1(s,a)s=St,a=Ats=St,aAtsSt


  1. λ -return: Gλt=(1λ)n=1λn1G(n)t
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值