본문으로 건너뛰기

RL 004

· 약 3분

Bellman Equation

vπ(s)=Eπ[Rt+1Immediate Reward+γvπ(St+1)Discounted Future Value  |  St=sStarting at state s]v_\pi(s) = \mathbb{E}_\pi \left[ \underbrace{R_{t+1}}_{\text{Immediate Reward}} + \gamma \underbrace{v_\pi(S_{t+1})}_{\text{Discounted Future Value}} \;\middle|\; \underbrace{S_t = s}_{\text{Starting at state s}} \right]

  • Fundamental concept in RL using a recursive equation to express a way to compute the value of a state based on the values of its successor states.
v(s)=E[Rt+1+γRt+2+γ2Rt+3+  |  St=s]=E[Rt+1+γ(Rt+2+γRt+3+)Gt+1  |  St=s]=E[Rt+1+γGt+1  |  St=s]=E[Rt+1+γv(St+1)  |  St=s]=E[Rt+1St=s]Immediate Reward R(s)+γE[v(St+1)St=s]Expected Next State Value(E[X+γY]=E[X]+γE[Y])=R(s)+γsP(ss)v(s)Transition Dynamics(E[g(X)]=xP(x)g(x))\begin{aligned} v(s) &= \mathbb{E} \left[ R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \dots \;\middle|\; S_t = s \right] \\[8pt] &= \mathbb{E} \left[ R_{t+1} + \gamma \underbrace{\left( R_{t+2} + \gamma R_{t+3} + \dots \right)}_{G_{t+1}} \;\middle|\; S_t = s \right] \\[8pt] &= \mathbb{E} \left[ R_{t+1} + \gamma G_{t+1} \;\middle|\; S_t = s \right] \\[8pt] &= \mathbb{E} \left[ R_{t+1} + \gamma v(S_{t+1}) \;\middle|\; S_t = s \right] \\[8pt] &= \underbrace{\mathbb{E}[R_{t+1} \mid S_t = s]}_{\text{Immediate Reward } \mathcal{R}(s)} + \gamma \, \underbrace{\mathbb{E}[v(S_{t+1}) \mid S_t = s]}_{\text{Expected Next State Value}} && (\because \mathbb{E}[X + \gamma Y] = \mathbb{E}[X] + \gamma\mathbb{E}[Y]) \\[10pt] &= \mathcal{R}(s) + \gamma \underbrace{\sum_{s'} \mathcal{P}(s' \mid s) v(s')}_{\text{Transition Dynamics}} && \left(\because \mathbb{E}[g(X)] = \sum_x P(x)g(x)\right) \end{aligned}

Bellman Equation Example

Bellman Example

v(sBL)=7+γ(0.1v(sBL)+0.5(sTL)+0.4(sBR))v(s_{\text{BL}}) = 7 + \gamma(0.1 \cdot v(s_{\text{BL}}) + 0.5 \cdot(s_{TL}) + 0.4 \cdot(s_{BR}))

Bellman Equation in Matrix Form

v=R+γPvv = \mathcal{R} + \gamma \mathcal{P} v

[v(s1)v(sn)]V of a particular state=[R(s1)R(sn)]Immediate Reward+γ[P11P1nPn1Pnn]Transition Matrix[v(s1)v(sn)]V of future state\begin{aligned} \underbrace{ \begin{bmatrix} v(s_1) \\ \vdots \\ v(s_n) \end{bmatrix}}_{\text{V of a particular state}} = \underbrace{\begin{bmatrix} \mathcal{R}(s_1) \\ \vdots \\ \mathcal{R}(s_n) \end{bmatrix}}_{\text{Immediate Reward}} + \gamma \underbrace{\begin{bmatrix} \mathcal{P}_{11} & \cdots & \mathcal{P}_{1n} \\ \vdots & \ddots & \vdots \\ \mathcal{P}_{n1} & \cdots & \mathcal{P}_{nn} \end{bmatrix}}_{\text{Transition Matrix}} \underbrace{\begin{bmatrix} v(s_1) \\ \vdots \\ v(s_n) \end{bmatrix}}_{\text{V of future state}} \end{aligned}

Solving the Bellman Equation

Linear System of Equations

v=R+γPvvγPv=R(IγP)v=Rv=(IγP)1R\begin{aligned} \mathcal{v} &= \mathcal{R} + \gamma \mathcal{P}\mathcal{v} \\ \mathcal{v} - \gamma \mathcal{P}\mathcal{v} &= \mathcal{R} \\ (I - \gamma \mathcal{P})\mathcal{v} &= \mathcal{R} \\ \mathcal{v} &= (I - \gamma \mathcal{P})^{-1} \mathcal{R} \end{aligned}
  • Computational Complexity: O(n3)O(n^3)
  • For small MDPs: direct solution is possible (up to 100 states)
  • For large MDPs:
    • Iterative methods
    • Dynamic Programming
    • Monte Carlo Tree
    • TD learning