mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-25 22:38:04 +02:00
Add q-learning and improve value iteration pseudocode
This commit is contained in:
parent
807b9268d0
commit
001350bae4
6 changed files with 88 additions and 3 deletions
45
source-code/Pseudocode/q-learning/q-learning.tex
Normal file
45
source-code/Pseudocode/q-learning/q-learning.tex
Normal file
|
@ -0,0 +1,45 @@
|
|||
\documentclass{article}
|
||||
\usepackage[pdftex,active,tightpage]{preview}
|
||||
\setlength\PreviewBorder{2mm}
|
||||
|
||||
\usepackage[utf8]{inputenc} % this is needed for umlauts
|
||||
\usepackage[ngerman]{babel} % this is needed for umlauts
|
||||
\usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
|
||||
\usepackage{amssymb,amsmath,amsfonts} % nice math rendering
|
||||
\usepackage{braket} % needed for \Set
|
||||
\usepackage{caption}
|
||||
\usepackage{algorithm}
|
||||
\usepackage[noend]{algpseudocode}
|
||||
|
||||
\DeclareCaptionFormat{myformat}{#3}
|
||||
\captionsetup[algorithm]{format=myformat}
|
||||
|
||||
\begin{document}
|
||||
\begin{preview}
|
||||
\begin{algorithm}[H]
|
||||
\begin{algorithmic}
|
||||
\Require
|
||||
\Statex Sates $\mathcal{X} = \{1, \dots, n_x\}$
|
||||
\Statex Actions $\mathcal{A} = \{1, \dots, n_a\},\qquad A: \mathcal{X} \Rightarrow \mathcal{A}$
|
||||
\Statex Reward function $R: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$
|
||||
\Statex Black-box (probabilistic) transition function $T: \mathcal{X} \times \mathcal{A} \rightarrow \mathcal{X}$
|
||||
\Statex Learning rate $\alpha \in [0, 1]$, typically $\alpha = 0.1$
|
||||
\Statex Discounting factor $\gamma \in [0, 1]$
|
||||
\Procedure{QLearning}{$\mathcal{X}$, $A$, $R$, $T$, $\alpha$, $\gamma$}
|
||||
\State Initialize $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$ arbitrarily
|
||||
\State Start in state $s \in \mathcal{X}$
|
||||
\While{$Q$ is not converged}
|
||||
\State Select $a \in \mathcal{A}$ by $Q$ and an exploration policy (e.g. $\varepsilon$ greedy)
|
||||
\State $r \gets R(s, a)$
|
||||
\State $s' \gets T(s, a)$ \Comment{Receive the new state}
|
||||
\State $Q(s', a) \gets (1 - \alpha) \cdot Q(s, a) + \alpha \cdot (r + \gamma \cdot \max_{a'} Q(s', a'))$
|
||||
\State $s \gets s'$
|
||||
\EndWhile
|
||||
\Return $Q$
|
||||
\EndProcedure
|
||||
\end{algorithmic}
|
||||
\caption{$Q$-learning: Learn function $Q: \mathcal{X} \times \mathcal{A} \rightarrow \mathbb{R}$}
|
||||
\label{alg:q-learning}
|
||||
\end{algorithm}
|
||||
\end{preview}
|
||||
\end{document}
|
Loading…
Add table
Add a link
Reference in a new issue