sarsa-lambda.tex 2.8 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[noend]{algpseudocode}
  12. \DeclareCaptionFormat{myformat}{#3}
  13. \captionsetup[algorithm]{format=myformat}
  14. \begin{document}
  15. \begin{preview}
  16. \begin{algorithm}[H]
  17. \begin{algorithmic}
  18. \Require
  19. \Statex Sates $\mathcal{X} = \{1, \dots, n_x\}$
  20. \Statex Actions $\mathcal{A} = \{1, \dots, n_a\},\qquad A: \mathcal{X} \Rightarrow \mathcal{A}$
  21. \Statex Reward function $R: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$
  22. \Statex Black-box (probabilistic) transition function $T: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X}$
  23. \Statex Learning rate $\alpha \in [0, 1]$, typically $\alpha = 0.1$
  24. \Statex Discounting factor $\gamma \in [0, 1]$
  25. \Statex $\lambda \in [0, 1]$: Trade-off between TD and MC
  26. \Procedure{QLearning}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$, $\lambda$}
  27. \State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
  28. \State Initialize $e: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ with 0. \Comment{eligibility trace}
  29. % \State Start in state $s \in \mathcal{X}$
  30. \While{$Q$ is not converged}
  31. \State Select $(s, a) \in \mathcal{X} \times \mathcal{A}$ arbitrarily
  32. \While{$s$ is not terminal}
  33. \State $r \gets R(s, a)$
  34. \State $s' \gets T(s, a)$ \Comment{Receive the new state}
  35. \State Calculate $\pi$ based on $Q$ (e.g. epsilon-greedy)
  36. \State $a' \gets \pi(s')$
  37. \State $e(s, a) \gets e(s, a) + 1$
  38. \State $\delta \gets r + \gamma \cdot Q(s', a') - Q(s, a)$
  39. \For{$(\tilde{s}, \tilde{a}) \in \mathcal{X} \times \mathcal{A}$}
  40. \State $Q(\tilde{s}, \tilde{a}) \gets Q(\tilde{s}, \tilde{a}) + \alpha \cdot \delta \cdot e(\tilde{s}, \tilde{a})$
  41. \State $e(\tilde{s}, \tilde{a}) \gets \gamma \cdot \lambda \cdot e(\tilde{s}, \tilde{a})$
  42. \EndFor
  43. \State $s \gets s'$
  44. \State $a \gets a'$
  45. \EndWhile
  46. \EndWhile
  47. \Return $Q$
  48. \EndProcedure
  49. \end{algorithmic}
  50. \caption{SARSA($\lambda$): Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
  51. \label{alg:sarsa-lambda}
  52. \end{algorithm}
  53. \end{preview}
  54. \end{document}