Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132939 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{xcolor}
13
\usepackage[noend]{algpseudocode}
14
\usepackage{mathtools,bm}
15
\DeclareMathOperator*{\argmax}{arg\,max}
16
17
\DeclareCaptionFormat{myformat}{#3}
18
\captionsetup[algorithm]{format=myformat}
19
20
\begin{document}
21
\begin{preview}
22
\begin{algorithm}[H]
23
\begin{algorithmic}
24
\Require
25
\Statex Sates $\mathcal{X} = \{1, \dots, n_x\}$
26
\Statex Actions $\mathcal{A} = \{1, \dots, n_a\},\qquad A: \mathcal{X} \Rightarrow \mathcal{A}$
27
\Statex Reward function $R: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$
28
\Statex Black-box (probabilistic) transition function $T: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X}$
29
\Statex Learning rate $\alpha \in [0, 1]$, typically $\alpha = 0.1$
30
\Statex Discounting factor $\gamma \in [0, 1]$
31
\Procedure{QLearning}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$}
32
\State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
33
\State Initialize $M: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X} \times \mathbb{R}$ arbitrarily \Comment{Model}
34
\While{$Q$ is not converged}
35
\State Select $s \in \mathcal{X}$ arbitrarily
36
\State $a \gets \pi(s)$ \Comment{Get action based on policy}
37
\State $r \gets R(s, a)$ \Comment{Receive the reward}
38
\State $s' \gets T(s, a)$ \Comment{Receive the new state}
39
\State $Q(s, a) \gets (1 - \alpha) \cdot Q(s, a) + \alpha \cdot (r + \gamma \cdot \max_{a'} Q(s, a'))$
40
\State $M(s, a) \gets (s', r)$
41
\For{$i$ in range $1, \dots, N$}
42
\State Select $(\tilde{s}, \tilde{a}) \in \mathcal{X} \times \mathcal{A}$ arbitrarily
43
\State $(s', r) \gets M(\tilde{x}, \tilde{a})$
44
\State $Q(\tilde{s}, \tilde{a}) \gets (1 - \alpha) \cdot Q(\tilde{s}, \tilde{a}) + \alpha \cdot (r + \gamma \cdot \max_{a'} Q(s', a'))$
45
\EndFor
46
\State Calculate $\pi$ based on $Q$ (e.g. $\varepsilon$-greedy)
47
\EndWhile
48
\Return $Q$
49
\EndProcedure
50
\end{algorithmic}
51
\caption{Dyna-Q: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
52
\label{alg:dyna-q}
53
\end{algorithm}
54
\end{preview}
55
\end{document}
56
57