Pular para o conteúdo

Aprendizado por reforço e por imitação: formulário e flashcards

Todas as fórmulas de Aprendizado por reforço e por imitação em uma página, tema por tema, das aulas do curso: imprima ou revise com os flashcards.

Programa e aulas Apostila (PDF) Apostila para anotar (PDF) Exercícios de prova 22 fórmulas

Processos de decisão de Markov

O retorno e o desconto

    \[ G_t = r_{t+1} + \gamma r_{t+2} + \gamma^2 r_{t+3} + \dots = \sum_{k=0}^{\infty}\gamma^k r_{t+k+1} \]

    \[ G_t = r_{t+1} + \gamma\,G_{t+1} \]

Política e funções de valor

    \[ V^\pi(s) = \mathbb E_\pi[G_t \mid s_t = s],\qquad Q^\pi(s, a) = \mathbb E_\pi[G_t \mid s_t = s,\ a_t = a] \]

Equações de Bellman

A equação de Bellman para uma política

    \[ V^\pi(s) = \sum_a\pi(a \mid s)\Big[R(s, a) + \gamma\sum_{s'}P(s' \mid s, a)\,V^\pi(s')\Big] \]

    \[ V^\pi(s) = \mathbb E_\pi[r_{t+1} \mid s_t = s] + \gamma\,\mathbb E_\pi[G_{t+1} \mid s_t = s] \]

A equação de otimalidade

    \[ V^*(s) = \max_a\Big[R(s, a) + \gamma\sum_{s'}P(s' \mid s, a)\,V^*(s')\Big],\qquad Q^*(s, a) = R(s, a) + \gamma\sum_{s'}P(s' \mid s, a)\max_{a'}Q^*(s', a') \]

A contração de Bellman

    \[ |(TU)(s) - (TV)(s)| \le \max_a\gamma\Big|\sum_{s'}P(s' \mid s, a)\big(U(s') - V(s')\big)\Big| \le \gamma\max_a\sum_{s'}P(s' \mid s, a)\,\|U - V\|_\infty = \gamma\|U - V\|_\infty \]

Melhoria da política

    \[ V^\pi(s) \le \mathbb E_{\pi'}[r_{t+1} + \gamma V^\pi(s_{t+1})] \le \mathbb E_{\pi'}[r_{t+1} + \gamma r_{t+2} + \gamma^2V^\pi(s_{t+2})] \le \dots \le V^{\pi'}(s) \]

Diferenças temporais, SARSA e Q-learning

Monte Carlo: a média dos retornos

    \[ V(s) \leftarrow V(s) + \alpha\,\big(G_t - V(s)\big) \]

Diferenças temporais

    \[ V(s_t) \leftarrow V(s_t) + \alpha\,\underbrace{\big(r_{t+1} + \gamma V(s_{t+1}) - V(s_t)\big)}_{\delta_t,\ \text{TD error}} \]

Do valor à ação: SARSA e Q-learning

    \[ \textbf{SARSA:}\quad Q(s, a) \leftarrow Q(s, a) + \alpha\big(r + \gamma\,Q(s', a') - Q(s, a)\big) \]

    \[ \textbf{Q-learning:}\quad Q(s, a) \leftarrow Q(s, a) + \alpha\big(r + \gamma\max_{a''}Q(s', a'') - Q(s, a)\big) \]

Deep Q-Network

Do Q-learning tabular à rede

    \[ L(\theta) = \Big(\underbrace{r + \gamma\max_{a'}Q_{\bar\theta}(s', a')}_{y,\ \text{target}} - Q_\theta(s, a)\Big)^2 \]

Superestimação do máximo e DQN duplo

    \[ y = r + \gamma\,Q_{\bar\theta}\big(s',\ \arg\max_{a'}Q_\theta(s', a')\big) \]

Gradiente de política e PPO

O teorema do gradiente de política

    \[ \nabla_\theta J = \nabla_\theta\int p_\theta(\tau)G(\tau)\,d\tau = \int p_\theta(\tau)\,\nabla_\theta\log p_\theta(\tau)\,G(\tau)\,d\tau = \mathbb E\big[\nabla_\theta\log p_\theta(\tau)\,G(\tau)\big] \]

A linha de base e o ator-crítico

    \[ \hat A_t = \sum_{l=0}^{\infty}(\gamma\lambda)^l\,\delta_{t+l} = \delta_t + \gamma\lambda\,\hat A_{t+1} \]

PPO: passos grandes, mas não grandes demais

    \[ L^{CLIP}(\theta) = \mathbb E_t\Big[\min\big(\rho_t\hat A_t,\ \text{clip}(\rho_t, 1 - \epsilon, 1 + \epsilon)\,\hat A_t\big)\Big] \]

Simulação e Gaussian splatting

Splatting gaussiano

    \[ C = \sum_i c_i\,\alpha_i\prod_{j\lt i}(1 - \alpha_j) \]

Aplicações: robótica, condução, RLHF

Modelos de linguagem: RLHF

    \[ \max_\pi\ \mathbb E_{x,\ y\sim\pi}\big[r(x, y)\big] - \beta\,\text{KL}\big(\pi(\cdot \mid x)\ \|\ \pi_{ref}(\cdot \mid x)\big) \]

DPO: preferências sem PPO

    \[ \pi^*(y) = \frac{1}{Z}\,\pi_{ref}(y)\,e^{r(y)/\beta},\qquad Z = \sum_y\pi_{ref}(y)\,e^{r(y)/\beta} \]

    \[ \sum_y\pi(y)\Big[r(y) - \beta\log\frac{\pi(y)}{\pi_{ref}(y)}\Big] = -\beta\sum_y\pi(y)\log\frac{\pi(y)}{\pi_{ref}(y)e^{r(y)/\beta}} = -\beta\,\text{KL}(\pi\ \|\ \pi^*) + \beta\log Z \]

    \[ L_{DPO}(\theta) = -\log\sigma\Big(\beta\log\frac{\pi_\theta(y_w \mid x)}{\pi_{ref}(y_w \mid x)} - \beta\log\frac{\pi_\theta(y_l \mid x)}{\pi_{ref}(y_l \mid x)}\Big) \]