7. Value Function Methods

이은상·2024년 10월 27일

Can we remove policy gradient completely?

YES!

Aπ(st,at)A^\pi(s_t,a_t) : ata_t가 다른 π\pi에 따른 average action보다 얼마나 나은지에 대한 정보
복기해보자면 A(s,a)=Q(s,a)V(s)A(s,a) = Q(s,a)-V(s)
V는 avrage action, Q와 V는 whether action is a or not만 다름

그러면
arg maxatAπ(st,at)\argmax_{a_t} A^\pi(s_t,a_t): π\pi를 따를 때, sts_t에서의 최고의 action
이는 basicly means policy \Rightarrow policy 대신 사용!

따라서 forget policies, let's just do arg maxatAπ(st,at)\argmax_{a_t} A^\pi(s_t,a_t)!

이때,
π(atst)={1if at=arg maxatAπ(st,at)0otherwise\pi'(a_t|s_t)=\begin{cases}1 & \text{if }a_t=\argmax_{a_t}A^\pi(s_t,a_t)\\0&\text{otherwise}\end{cases}
1과 0은 각각 probability
as good as π\pi (probably better)

이렇게 해가지고, 하나만 가지고 actor-critic algorithm이 작동할 수 있도록 변경됨!

Policy iteration

High level idea

policy iteration algorithm

  1. evaluate Aπ(s,a)A^\pi(s,a)
    how to do this?
  2. set ππ\pi\rightarrow\pi'
    π\pi : theoritical policy
    π\pi' : implicit policy

π(atst)={1if at=arg maxatAπ(st,at)0otherwise\pi'(a_t|s_t)=\begin{cases}1 & \text{if }a_t=\argmax_{a_t}A^\pi(s_t,a_t)\\0&\text{otherwise}\end{cases}

as before: Aπ(s,a)=r(s,a)+γE[Vπ(s)]Vπ(s)A^\pi(s,a) = r(s,a) + \gamma E[V^\pi(s')] - V^\pi(s)s=st+1\quad s' = s_{t+1}

Dynamic Programing

one way to evaluate VπV^\pi
advantage function을 구하는 것은 value function을 구하는 것으로 formate될 수 있음

Assumption

we know

  • p(ss,a)p(s'|s,a)
    transition function (\rightarrow assume we know the transition probability)
    원래 model-free RL은 transition function이 없음
    \rightarrow model based function이라 가정 \Rightarrow environment =의 dynamic을 알고 있음
  • ss and aa are noth discrete (and small)
    dp 사용을 위한 가정

Example

  • 16 states
  • 4 actions
    up, down, left, right

T\Tau is 16×16×416\times16\times4 tensor

bootstrapped update: Vπ(s)Eaπ(as)[r(s,a)+γEsp(ss,a)[Vπ(s)]]V^\pi(s)\leftarrow E_{a\sim\pi(a|s)}[r(s,a)+\gamma E_{s'\sim p(s'|s,a)}[V^\pi(s')]]

  • Eaπ(as)E_{a\sim\pi(a|s)} : deterministic policy이므로 걷어낼 수 있음
  • Vπ(s)V^\pi(s')에는 just use the current estimate

π(atst)={1if at=arg maxatAπ(st,at)0otherwise deterministic policy π(s)=a\pi'(a_t|s_t)=\begin{cases}1 & \text{if }a_t=\argmax_{a_t}A^\pi(s_t,a_t)\\0&\text{otherwise}\end{cases} \rightarrow\text{ deterministic policy } \pi(s)=a

deterministic policy π(s)=a\pi(s)=a : state에 따라 정해진 a들 존재하여 변화X

simplified: Vπr(s,π(s))+γEsp(ss,π(s))[Vπ(s)]V^\pi\leftarrow r(s,\pi(s))+\gamma E_{s'\sim p(s'|s,\pi(s))}[V^\pi(s')]

policy iteration with dynamic programming

policy iteration

  1. evaluate Vπ(s)V^\pi(s)
  2. set ππ\pi\leftarrow\pi'

π(atst)={1if at=arg maxatAπ(st,at)0otherwise\pi'(a_t|s_t)=\begin{cases}1 & \text{if }a_t=\argmax_{a_t}A^\pi(s_t,a_t)\\0&\text{otherwise}\end{cases}

policy evaluation

Vπr(s,π(s))+γEsp(ss,π(s))[Vπ(s)]V^\pi\leftarrow r(s,\pi(s))+\gamma E_{s'\sim p(s'|s,\pi(s))}[V^\pi(s')]
이걸 사용해서 위의 iteration의 1 수행

Simplify A function

π(atst)={1if at=arg maxatAπ(st,at)0otherwise\pi'(a_t|s_t)=\begin{cases}1 & \text{if }a_t=\argmax_{a_t}A^\pi(s_t,a_t)\\0&\text{otherwise}\end{cases}

  • arg maxatAπ(st,at)=r(s,a)+γE[Vπ(s)]Vπ(s)\argmax_{a_t}A^\pi(s_t,a_t) = r(s,a)+\gamma E[V^\pi(s')]-V^\pi(s)로, too much equations!
    • Vπ(s)V^\pi(s)는 constant로 ignore 가능
      arg maxatAπ(st,at)=arg maxatQπ(st,at)\rightarrow\argmax_{a_t} A^\pi(s_t,a_t) = \argmax_{a_t}Q^\pi(s_t,a_t)
    • Qπ(s,a)=r(s,a)+γE[Vπ(s)]Q^\pi(s,a) = r(s,a)+\gamma E[V^{\pi}(s')] (a bit simpler)

skip the policy and compute values directly!

\Rightarrow value iteration algorithm

  1. set Q(s,a)r(s,a)+γE[V(s)]Q(s,a)\leftarrow r(s,a)+\gamma E[V(s')]
    estimate all Q(s,a)Q(s,a) value
  2. set V(s)maxaQ(s,a)V(s)\leftarrow\max_a Q(s,a)
    V는 expected reward at state s. argmax 통해 update


이렇게 행이 state이므로 각 행마다의 최댓값을 선택해서 V update

0개의 댓글