📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / source-code / Pseudocode / dynamic-programming / dynamic-programming.tex
132939 viewsLicense: 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 Cost function $g: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$24\Statex Horizon $N \in \mathbb{N}_{\geq 1}$25\Statex Discounting factor $\alpha \in [0, 1]$26\Procedure{DynamicProgramming}{$\mathcal{X}$, $A$, $g$, $N$, $\alpha$}27\State $J_N(x) \gets g_N(x) \quad \forall x \in \mathcal{X}$28\For{$k = N - 1$ to $0$}29\For{$x \in \mathcal{X}$}30\For{$a \in A(x)$}31\State $Q(x, a) \gets g_k(x, a) + \alpha \sum_{j=1}^{n_x} f_{xj}(a) \cdot J_{k+1}(j)$32\EndFor3334\State $J_k (x) \gets \min_a (Q_k(x,a))$35\State $\pi_k(x) \gets \arg \min_a (Q_k(x, a))$36\EndFor37\EndFor38\Return $\pi_{0:N-1}$39\EndProcedure40\end{algorithmic}41\caption{Dynamic Programming}42\label{alg:dynamic-programming: Learn a strategy}43\end{algorithm}44\end{preview}45\end{document}464748