sarsa.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. \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{SARSA}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$, $\lambda$}
  27. \State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
  28. \While{$Q$ is not converged}
  29. \State Select $(s, a) \in \mathcal{X} \times \mathcal{A}$ arbitrarily
  30. \While{$s$ is not terminal}
  31. \State $r \gets R(s, a)$ \Comment{Receive the reward}
  32. \State $s' \gets T(s, a)$ \Comment{Receive the new state}
  33. \State Calculate $\pi$ based on $Q$ (e.g. epsilon-greedy)
  34. \State $a' \gets \pi(s')$
  35. \State $Q(s, a) \gets (1 - \alpha ) \cdot Q(s, a) + \alpha \cdot (r + \gamma Q(s', a'))$
  36. \State $s \gets s'$
  37. \State $a \gets a'$
  38. \EndWhile
  39. \EndWhile
  40. \Return $Q$
  41. \EndProcedure
  42. \end{algorithmic}
  43. \caption{SARSA: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
  44. \label{alg:sarsa}
  45. \end{algorithm}
  46. \end{preview}
  47. \end{document}