📚 The CoCalc Library - books, templates and other resources
License: OTHER
\documentclass{article}1\usepackage[pdftex,active,tightpage]{preview}2\setlength\PreviewBorder{2mm}34\usepackage[utf8]{inputenc} % this is needed for umlauts5\usepackage[ngerman]{babel} % this is needed for umlauts6\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf7\usepackage{amssymb,amsmath,amsfonts} % nice math rendering8\usepackage{braket} % needed for \Set9\usepackage{caption}10\usepackage{algorithm}11\usepackage{xcolor}12\usepackage[noend]{algpseudocode}13\usepackage{mathtools,bm}14\DeclareMathOperator*{\argmax}{arg\,max}1516\DeclareCaptionFormat{myformat}{#3}17\captionsetup[algorithm]{format=myformat}1819\begin{document}20\begin{preview}21\begin{algorithm}[H]22\begin{algorithmic}23\Require24\Statex Sates $\mathcal{X} = \{1, \dots, n_x\}$25\Statex Actions $\mathcal{A} = \{1, \dots, n_a\},\qquad A: \mathcal{X} \Rightarrow \mathcal{A}$26\Statex Reward function $R: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$27\Statex Black-box (probabilistic) transition function $T: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X}$28\Statex Learning rate $\alpha \in [0, 1]$, typically $\alpha = 0.1$29\Statex Discounting factor $\gamma \in [0, 1]$30\Procedure{QLearning}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$}31\State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily32\State Initialize $M: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X} \times \mathbb{R}$ arbitrarily \Comment{Model}33\While{$Q$ is not converged}34\State Select $s \in \mathcal{X}$ arbitrarily35\State $a \gets \pi(s)$ \Comment{Get action based on policy}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 $M(s, a) \gets (s', r)$40\For{$i$ in range $1, \dots, N$}41\State Select $(\tilde{s}, \tilde{a}) \in \mathcal{X} \times \mathcal{A}$ arbitrarily42\State $(s', r) \gets M(\tilde{x}, \tilde{a})$43\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'))$44\EndFor45\State Calculate $\pi$ based on $Q$ (e.g. $\varepsilon$-greedy)46\EndWhile47\Return $Q$48\EndProcedure49\end{algorithmic}50\caption{Dyna-Q: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}51\label{alg:dyna-q}52\end{algorithm}53\end{preview}54\end{document}555657