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