dyna-q.tex 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage[utf8]{inputenc} % this is needed for umlauts
  5. \usepackage[ngerman]{babel} % this is needed for umlauts
  6. \usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
  7. \usepackage{amssymb,amsmath,amsfonts} % nice math rendering
  8. \usepackage{braket} % needed for \Set
  9. \usepackage{caption}
  10. \usepackage{algorithm}
  11. \usepackage{xcolor}
  12. \usepackage[noend]{algpseudocode}
  13. \usepackage{mathtools,bm}
  14. \DeclareMathOperator*{\argmax}{arg\,max}
  15. \DeclareCaptionFormat{myformat}{#3}
  16. \captionsetup[algorithm]{format=myformat}
  17. \begin{document}
  18. \begin{preview}
  19. \begin{algorithm}[H]
  20. \begin{algorithmic}
  21. \Require
  22. \Statex Sates $\mathcal{X} = \{1, \dots, n_x\}$
  23. \Statex Actions $\mathcal{A} = \{1, \dots, n_a\},\qquad A: \mathcal{X} \Rightarrow \mathcal{A}$
  24. \Statex Reward function $R: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$
  25. \Statex Black-box (probabilistic) transition function $T: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X}$
  26. \Statex Learning rate $\alpha \in [0, 1]$, typically $\alpha = 0.1$
  27. \Statex Discounting factor $\gamma \in [0, 1]$
  28. \Procedure{QLearning}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$}
  29. \State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
  30. \State Initialize $M: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X} \times \mathbb{R}$ arbitrarily \Comment{Model}
  31. \While{$Q$ is not converged}
  32. \State Select $s \in \mathcal{X}$ arbitrarily
  33. \State $a \gets \pi(s)$ \Comment{Get action based on policy}
  34. \State $r \gets R(s, a)$ \Comment{Receive the reward}
  35. \State $s' \gets T(s, a)$ \Comment{Receive the new state}
  36. \State $Q(s, a) \gets (1 - \alpha) \cdot Q(s, a) + \alpha \cdot (r + \gamma \cdot \max_{a'} Q(s, a'))$
  37. \State $M(s, a) \gets (s', r)$
  38. \For{$i$ in range $1, \dots, N$}
  39. \State Select $(\tilde{s}, \tilde{a}) \in \mathcal{X} \times \mathcal{A}$ arbitrarily
  40. \State $(s', r) \gets M(\tilde{x}, \tilde{a})$
  41. \State $Q(\tilde{s}, \tilde{a}) \gets (1 - \alpha) \cdot Q(\tilde{s}, \tilde{a}) + \alpha \cdot (r + \gamma \cdot \max_{a'} Q(s', a'))$
  42. \EndFor
  43. \State Calculate $\pi$ based on $Q$ (e.g. $\varepsilon$-greedy)
  44. \EndWhile
  45. \Return $Q$
  46. \EndProcedure
  47. \end{algorithmic}
  48. \caption{Dyna-Q: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
  49. \label{alg:dyna-q}
  50. \end{algorithm}
  51. \end{preview}
  52. \end{document}