Bellman Equation and Optimality

Roh's warehouse·2025년 9월 22일

Introduction to RL

목록 보기
3/10

Bellman Equation for MRP

MRP S,P,R,γ\langle S,P,R,\gamma \rangle에서 value function V(st)V(s_t)에 대한 Bellman equation은 다음과 같이 정의된다.

V(s)=E[Gtst=s]=E[Rt+1+γRt+2+γ2Rt+3+st=s]=E[Rt+1+γk=0γkRt+k+2st=s]=E[Rt+1+γV(St+1)st=s]=st+1p(st+1st)[R(st,st+1)+γV(st+1)]\begin{aligned} V(s) &= E[G_t \mid s_t=s] \\ &= E[R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \cdots \mid s_t=s] \\ &= E[R_{t+1} + \gamma \sum_{k=0}^{\infty} \gamma^k R_{t+k+2} \mid s_t=s] \\ &= E[R_{t+1} + \gamma V(S_{t+1}) \mid s_t=s] \\ &= \sum_{s_{t+1}} p(s_{t+1} \mid s_t) [R(s_t, s_{t+1}) + \gamma V(s_{t+1})] \end{aligned}

즉, 현재 state sts_t에서의 value function은 미래 state st+1s_{t+1}의 value function으로 표현할 수 있다 (one-step look ahead).

V(s)=Rs+γsSPssV(s)V(s) = R_s + \gamma \sum_{s'\in S} P_{ss'} V(s')

Bellman Equation in a Matrix Form

V=R+γPVV = R + \gamma PV
[V(s1)V(sn)]=[R1Rn]+γ[P11P1nPn1Pnn][V(s1)V(sn)]\begin{bmatrix} V(s_1) \\ \vdots \\ V(s_n) \end{bmatrix} = \begin{bmatrix} R_1 \\ \vdots \\ R_n \end{bmatrix} + \gamma \begin{bmatrix} P_{11} & \cdots & P_{1n} \\ \vdots & \ddots & \vdots \\ P_{n1} & \cdots & P_{nn} \end{bmatrix} \begin{bmatrix} V(s_1) \\ \vdots \\ V(s_n) \end{bmatrix}

위 식은 linear equation이므로, 다음과 같이 solution을 구할 수 있다.

V=(IγP)1RV = (I-\gamma P)^{-1}R

일반적으로 inverse matrix를 explicit하게 계산하는 경우, computation cost (O(n3)O(n^3) for nn states)가 너무 높으므로 DP와 같은 다른 방법을 사용한다.

Bellman Expectation Equation for MDP

위 방법과 유사하게, MDP에서 state-value function Vπ(s)V_\pi(s)와 action-value function Qπ(s,a)Q_\pi(s,a)에 대한 Bellman expectation equation을 다음과 같이 얻을 수 있다.

Vπ(s)=Eπ[Rt+1+γVπ(St+1)St=s]V_{\pi}(s) = E_{\pi} \left[ R_{t+1} + \gamma V_{\pi}(S_{t+1}) \mid S_{t} = s \right]
Qπ(s,a)=Eπ[Rt+1+γQπ(St+1,At+1)St=s,At=a]Q_{\pi}(s, a) = E_{\pi} \left[ R_{t+1} + \gamma Q_{\pi}(S_{t+1}, A_{t+1}) \mid S_{t} = s, A_{t} = a \right]

Bellman Equation for VπV_{\pi} and QπQ_{\pi}

Bellman expectation equation을 VπV_{\pi}QπQ_{\pi}의 관계로써 나타낼 수 있다.

Vπ(s)=aAπ(as)Qπ(s,a)V_{\pi}(s) = \sum_{a \in \mathcal{A}} \pi(a \mid s) Q_{\pi}(s, a)
Qπ(s,a)=Rsa+γsSPssaVπ(s)Q_{\pi}(s, a) = R_{s}^{a} + \gamma \sum_{s' \in \mathcal{S}} P_{ss'}^{a} V_{\pi}(s')

위 식을 이용하면, 아래와 같은 식을 얻는다.

Vπ(s)=aAπ(as)(Rsa+γsSPssaVπ(s))V_{\pi}(s) = \sum_{a \in \mathcal{A}} \pi(a \mid s) \left( R_{s}^{a} + \gamma \sum_{s' \in \mathcal{S}} P_{ss'}^{a} V_{\pi}(s') \right)
Qπ(s,a)=Rsa+γsSPssa(aAπ(as)Qπ(s,a))Q_{\pi}(s, a) = R_{s}^{a} + \gamma \sum_{s' \in \mathcal{S}} P_{ss'}^{a} \left( \sum_{a' \in \mathcal{A}} \pi(a' \mid s') Q_{\pi}(s', a') \right)

Bellman Expectation Equation in a Matrix Form

Vπ=Rπ+γPπVπV_{\pi} = R^{\pi} + \gamma P^{\pi} V_{\pi}
[Vπ(s1)Vπ(sn)]=[R1πRnπ]+γ[P11πP1nπPn1πPnnπ][Vπ(s1)Vπ(sn)]\begin{bmatrix} V_{\pi}(s_1) \\ \vdots \\ V_{\pi}(s_n) \end{bmatrix} = \begin{bmatrix} R_1^{\pi} \\ \vdots \\ R_n^{\pi} \end{bmatrix} + \gamma \begin{bmatrix} P_{11}^{\pi} & \cdots & P_{1n}^{\pi} \\ \vdots & \ddots & \vdots \\ P_{n1}^{\pi} & \cdots & P_{nn}^{\pi} \end{bmatrix} \begin{bmatrix} V_{\pi}(s_1) \\ \vdots \\ V_{\pi}(s_n) \end{bmatrix}

위 식 역시 다음과 같이 solution을 얻을 수 있다.

Vπ=(IγPπ)1RπV_{\pi} = (I - \gamma P^{\pi})^{-1} R^{\pi}

Bellman Optimality Equation

Optimal Value Function

Optimal state-value function V(s)V_\ast(s)는 모든 policy들을 고려했을 때, 가장 높은 state-value를 말한다.

V(s)=maxπVπ(s)V_\ast(s) = \max_\pi V_\pi(s)

Optimal action-value function Q(s,a)Q_\ast(s,a) 역시 동일하게 정의된다.

Q(s,a)=maxπQπ(s,a)Q_\ast(s,a) = \max_\pi Q_\pi(s,a)

만약 모든 state sSs \in S에 대해, Vπ1(s)Vπ2(s)V_{\pi_1}(s) \geq V_{\pi_2}(s)인 경우, π1π2\pi_1 \geq \pi_2라고 표현하며, π1\pi_1π2\pi_2보다 더 나은 (better) policy라고 말한다.

만약 모든 policy에 대해 더 나은 policy π\pi_\ast가 있다면, 이를 optimal policy라고 한다.

Theorem

  • Optimal policy π\pi_\ast는 항상 존재한다.
  • Optimal policy π\pi_\ast를 통해 계산된 state-value Vπ(s)V_{\pi_\ast}(s)Qπ(s,a)Q_{\pi_\ast}(s,a)는 각각 optimal state-value 및 action-value 이다.
    즉, Vπ(s)=V(s)V_{\pi_\ast}(s) = V_\ast(s), Qπ(s,a)=Q(s,a)Q_{\pi_\ast}(s,a) = Q_\ast(s,a).

Finding an Optimal Policy

만약 optimal action-value function Q(s,a)Q_\ast(s,a)를 안다면, optimal policy를 다음과 같이 바로 얻을 수 있다.

π(as)={1if a=argmaxaAQ(s,a)0otherwise\pi_{*}(a|s) = \begin{cases} 1 & \text{if } a = \arg\max\limits_{a \in A} Q_\ast(s, a) \\ 0 & \text{otherwise} \end{cases}

즉, Q(s,a)Q_\ast(s,a)가 가장 큰 action을 고르는 것이 optimal policy가 된다.

Bellman Optimality Equation for V(s)V_\ast(s) and Q(s,a)Q_\ast(s,a)

Bellman optimality equationV(s)V_\ast(s)Q(s,a)Q_\ast(s,a)에 대한 iterative equation을 제시하며, 이를 풀어냄으로써 optimal value function 및 optimal policy를 얻을 수 있다.

앞서 Bellman expectation equation과 마찬가지로 V(s)V_\ast(s)Q(s,a)Q_\ast(s,a) 관계를 다음과 같이 표현할 수 있다.

V(s)=maxaAQ(s,a)V_{\ast}(s) = \max_{a \in \mathcal{A}} Q_{\ast}(s, a)
Q(s,a)=Rsa+γsSPssaV(s)Q_{\ast}(s, a) = R_{s}^{a} + \gamma \sum_{s' \in \mathcal{S}} P_{ss'}^{a} V_{\ast}(s')

위 식을 이용하면, 다음 Bellman optimality equation을 얻을 수 있다.

Vπ(s)=maxaA(Rsa+γsSPssaV(s))V_{\pi}(s) = \max_{a \in \mathcal{A}} \left( R_{s}^{a} + \gamma \sum_{s' \in \mathcal{S}} P_{ss'}^{a} V_{\ast}(s') \right)
Qπ(s,a)=Rsa+γsSPssamaxaAQ(s,a)Q_{\pi}(s, a) = R_{s}^{a} + \gamma \sum_{s' \in \mathcal{S}} P_{ss'}^{a} \max_{a' \in \mathcal{A}} Q_{\ast}(s', a')

Bellman optimality equation은 non-linear 하므로 단순한 matrix 연산으로 solution을 구할 수는 없다. 따라서, iterative alogirthm을 통해 solution을 구하게 된다. 자세한 방법에 대해서는 다음 post에서 다룰 예정이다.

profile
공부랑 연구랑 생각

0개의 댓글