Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
\documentclass{article}
2
\usepackage[pdftex,active,tightpage]{preview}
3
\setlength\PreviewBorder{2mm}
4
5
\usepackage[utf8]{inputenc} % this is needed for umlauts
6
\usepackage[ngerman]{babel} % this is needed for umlauts
7
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
8
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
9
\usepackage{braket} % needed for \Set
10
\usepackage{caption}
11
\usepackage{algorithm}
12
\usepackage[noend]{algpseudocode}
13
14
\DeclareCaptionFormat{myformat}{#3}
15
\captionsetup[algorithm]{format=myformat}
16
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{SARSA}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$, $\lambda$}
30
\State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
31
\While{$Q$ is not converged}
32
\State Select $(s, a) \in \mathcal{X} \times \mathcal{A}$ arbitrarily
33
\While{$s$ is not terminal}
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 Calculate $\pi$ based on $Q$ (e.g. epsilon-greedy)
37
\State $a' \gets \pi(s')$
38
\State $Q(s, a) \gets (1 - \alpha ) \cdot Q(s, a) + \alpha \cdot (r + \gamma Q(s', a'))$
39
\State $s \gets s'$
40
\State $a \gets a'$
41
\EndWhile
42
\EndWhile
43
\Return $Q$
44
\EndProcedure
45
\end{algorithmic}
46
\caption{SARSA: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
47
\label{alg:sarsa}
48
\end{algorithm}
49
\end{preview}
50
\end{document}
51