📚 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[noend]{algpseudocode}1213\DeclareCaptionFormat{myformat}{#3}14\captionsetup[algorithm]{format=myformat}1516\begin{document}17\begin{preview}18\begin{algorithm}[H]19\begin{algorithmic}20\Require21\Statex Sates $\mathcal{X} = \{1, \dots, n_x\}$22\Statex Actions $\mathcal{A} = \{1, \dots, n_a\},\qquad A: \mathcal{X} \Rightarrow \mathcal{A}$23\Statex Reward function $R: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$24\Statex Black-box (probabilistic) transition function $T: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X}$25\Statex Learning rate $\alpha \in [0, 1]$, typically $\alpha = 0.1$26\Statex Discounting factor $\gamma \in [0, 1]$27\Statex $\lambda \in [0, 1]$: Trade-off between TD and MC28\Procedure{SARSA}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$, $\lambda$}29\State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily30\While{$Q$ is not converged}31\State Select $(s, a) \in \mathcal{X} \times \mathcal{A}$ arbitrarily32\While{$s$ is not terminal}33\State $r \gets R(s, a)$ \Comment{Receive the reward}34\State $s' \gets T(s, a)$ \Comment{Receive the new state}35\State Calculate $\pi$ based on $Q$ (e.g. epsilon-greedy)36\State $a' \gets \pi(s')$37\State $Q(s, a) \gets (1 - \alpha ) \cdot Q(s, a) + \alpha \cdot (r + \gamma Q(s', a'))$38\State $s \gets s'$39\State $a \gets a'$40\EndWhile41\EndWhile42\Return $Q$43\EndProcedure44\end{algorithmic}45\caption{SARSA: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}46\label{alg:sarsa}47\end{algorithm}48\end{preview}49\end{document}5051