dyna-q.tex 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. \Statex $\lambda \in [0, 1]$: Trade-off between TD and MC
  29. \Procedure{QLearning}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$, $\lambda$}
  30. \State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
  31. \State Initialize $M: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X} \times \mathbb{R}$ arbitrarily \Comment{Model}
  32. \While{$Q$ is not converged}
  33. \State Select $s \in \mathcal{X}$ arbitrarily
  34. \State $a \gets \pi(s)$
  35. \State $r \gets R(s, a)$
  36. \State $s' \gets T(s, a)$ \Comment{Receive the new state}
  37. \State $Q(s, a) \gets (1 - \alpha) \cdot Q(s, a) + \alpha \cdot (r + \gamma \cdot \max_{a'} Q(s, a'))$
  38. \State $M(s, a) \gets (s', r)$
  39. \For{$i$ in range $1, \dots, N$}
  40. \State Select $(\tilde{s}, \tilde{a}) \in \mathcal{X} \times \mathcal{A}$ arbitrarily
  41. \State $(s', r) \gets M(\tilde{x}, \tilde{a})$
  42. \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'))$
  43. \EndFor
  44. \State Calculate $\pi$ based on $Q$ (e.g. $\varepsilon$-greedy)
  45. \EndWhile
  46. \Return $Q$
  47. \EndProcedure
  48. \end{algorithmic}
  49. \caption{Dyna-Q: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
  50. \label{alg:dyna-q}
  51. \end{algorithm}
  52. \end{preview}
  53. \end{document}