q-learning.tex 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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[noend]{algpseudocode}
  12. \DeclareCaptionFormat{myformat}{#3}
  13. \captionsetup[algorithm]{format=myformat}
  14. \DeclareMathOperator*{\argmax}{arg\,max}
  15. \begin{document}
  16. \begin{preview}
  17. \begin{algorithm}[H]
  18. \begin{algorithmic}
  19. \Require
  20. \Statex Sates $\mathcal{X} = \{1, \dots, n_x\}$
  21. \Statex Actions $\mathcal{A} = \{1, \dots, n_a\},\qquad A: \mathcal{X} \Rightarrow \mathcal{A}$
  22. \Statex Reward function $R: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$
  23. \Statex Black-box (probabilistic) transition function $T: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X}$
  24. \Statex Learning rate $\alpha \in [0, 1]$, typically $\alpha = 0.1$
  25. \Statex Discounting factor $\gamma \in [0, 1]$
  26. \Procedure{QLearning}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$}
  27. \State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
  28. \While{$Q$ is not converged}
  29. \State Start in state $s \in \mathcal{X}$
  30. \While{$s$ is not terminal}
  31. \State Calculate $\pi$ according to Q and exploration strategy (e.g. $\pi(x) \gets \argmax_{a} Q(x, a)$)
  32. \State $a \gets \pi(s)$
  33. \State $r \gets R(s, a)$ \Comment{Receive the reward}
  34. \State $s' \gets T(s, a)$ \Comment{Receive the new state}
  35. \State $Q(s', a) \gets (1 - \alpha) \cdot Q(s, a) + \alpha \cdot (r + \gamma \cdot \max_{a'} Q(s', a'))$
  36. \State $s \gets s'$
  37. \EndWhile
  38. \EndWhile
  39. \Return $Q$
  40. \EndProcedure
  41. \end{algorithmic}
  42. \caption{$Q$-learning: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
  43. \label{alg:q-learning}
  44. \end{algorithm}
  45. \end{preview}
  46. \end{document}