Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Bellman Equations | Dynamic Programming
Introduction to Reinforcement Learning
course content

Conteúdo do Curso

Introduction to Reinforcement Learning

Introduction to Reinforcement Learning

1. RL Core Theory
2. Multi-Armed Bandit Problem
3. Dynamic Programming
4. Monte Carlo Methods
5. Temporal Difference Learning

book
Bellman Equations

To clarify the definition:

  • A functional equation is an equation whose solution is a function. For Bellman equation, this solution is the value function for which the equation was formulated;
  • A recursive form means that the value at the current state is expressed in terms of values at future states.

In short, solving the Bellman equation gives the desired value function, and deriving this equation requires identifying a recursive relationship between current and future states.

State Value Function

As a reminder, here is a state value function in compact form:

vπ(s)=Eπ[GtSt=s]\def\E{\operatorname{\mathbb{E}}} v_\pi(s) = \E_\pi[G_t | S_t = s]

To obtain the Bellman equation for this value function, let's expand the right side of the equation and establish a recursive relationship:

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+γGt+1St=s]=aπ(as)s,rp(s,rs,a)(r+γEπ[Gt+1St+1=s])=aπ(as)s,rp(s,rs,a)(r+γvπ(s))\def\E{\operatorname{\mathbb{E}}} \begin{aligned} v_\pi(s) &= \E_\pi[G_t | S_t = s]\\ &= \E_\pi[R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + ... | S_t = s]\\ &= \E_\pi[R_{t+1} + \gamma \sum_{k=0}^\infty \gamma^k R_{t+k+2} | S_t = s]\\ &= \E_\pi[R_{t+1} + \gamma G_{t+1} | S_t = s]\\ &= \sum_a \pi(a | s) \sum_{s', r} p(s', r | s, a)\Bigl(r + \gamma \E_\pi\Bigl[G_{t+1} | S_{t+1} = s'\Bigr]\Bigr)\\ &= \sum_a \pi(a | s) \sum_{s', r} p(s', r | s, a)\Bigl(r + \gamma v_\pi(s')\Bigr) \end{aligned}

The last equation in this chain is a Bellman equation for state value function.

Intuition

To find the value of a state ss, you:

  1. Consider all possible actions aa you might take from this state, each weighted by how likely you are to choose that action under your current policy π(as)\pi(a | s);
  2. For each action aa, you consider all possible next states ss' and rewards rr, weighted by their likelihood p(s,rs,a)p(s', r | s, a);
  3. For each of these outcomes, you take the immediate reward rr you get plus the discounted value of the next state γvπ(s)\gamma v_\pi(s').

By summing all these possibilities together, you get the total expected value of the state ss under your current policy.

Action Value Function

Here is an action value function in compact form:

qπ(s,a)=Eπ[GtSt=s,At=a]\def\E{\operatorname{\mathbb{E}}} q_\pi(s, a) = \E_\pi[G_t | S_t = s, A_t = a]

The derivation of Bellman equation for this function is quite similar to the previous one:

qπ(s,a)=Eπ[GtSt=s,At=a]=Eπ[Rt+1+γRt+2+γ2Rt+3+...St=s,At=a]=Eπ[Rt+1+γk=0γkRt+k+2St=s,At=a]=Eπ[Rt+1+γGt+1St=s,At=a]=s,rp(s,rs,a)(r+γEπ[Gt+1St+1=s])=s,rp(s,rs,a)(r+γaπ(as)(Eπ[Gt+1St+1=s,At+1=a]))=s,rp(s,rs,a)(r+γaπ(as)q(s,a))\def\E{\operatorname{\mathbb{E}}} \begin{aligned} q_\pi(s, a) &= \E_\pi[G_t | S_t = s, A_t = a]\\ &= \E_\pi[R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + ... | S_t = s, A_t = a]\\ &= \E_\pi[R_{t+1} + \gamma \sum_{k=0}^\infty \gamma^k R_{t+k+2} | S_t = s, A_t = a]\\ &= \E_\pi[R_{t+1} + \gamma G_{t+1} | S_t = s, A_t = a]\\ &= \sum_{s', r} p(s', r | s, a)\Bigl(r + \gamma \E_\pi\Bigl[G_{t+1} | S_{t+1} = s'\Bigr]\Bigr)\\ &= \sum_{s', r} p(s', r | s, a)\Biggl(r + \gamma \sum_{a'} \pi(a' | s') \Bigl(\E_\pi\Bigl[G_{t+1} | S_{t+1} = s', A_{t+1} = a'\Bigr]\Bigr)\Biggr)\\ &= \sum_{s', r} p(s', r | s, a)\Biggl(r + \gamma \sum_{a'} \pi(a' | s') q(s', a')\Biggr) \end{aligned}

The last equation in this chain is a Bellman equation for action value function.

Intuition

To find the value of a state-action pair (s,a)(s, a), you:

  1. Consider all possible next states ss' and rewards rr, weighted by their likelihood p(s,rs,a)p(s', r | s, a);
  2. For each of these outcomes, you take the immediate reward rr you get plus the discounted value of the next state;
  3. To compute the value of the next state ss', for all actions aa' possible from state ss', multiply the action value q(s,a)q(s', a') by the probability of choosing aa' in state ss' under current policy π(as\pi(a' | s'. Then, sum up everything to receive the final value.

By summing all these possibilities together, you get the total expected value of the state-action pair (s,a)(s, a) under your current policy.

question mark

Which of the following best describes the function of the Bellman equation?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 2
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt