📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / source-code / Pseudocode / WER-calculation / WER-calculation.tex
132930 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{algorithm,algpseudocode}1011\begin{document}12\begin{preview}13\begin{algorithm}[H]14\begin{algorithmic}15\Function{WER}{Reference $r$, Hypophysis $h$}16\State int[$|r|+1$][$|h|+1$] $D$ \Comment{Initialisation}17\For{($i=0$; $\;i \leq |r|$; $\;i$++)}18\For{($j=0$; $\;j \leq |h|$; $\;j$++)}19\If{$i==0$}20\State $D[0][j] \gets j$21\ElsIf{$j==0$}22\State $D[i][0] \gets i$23\EndIf24\EndFor25\EndFor2627\State28\For{($i=1$; $\;i \leq |r|$; $\;i$++)} \Comment{Calculation}29\For{($j=1$; $\;j \leq |h|$; $\;j$++)}30\If{$r[i-1] == h[j-1]$}31\State $D[i][j] \gets D[i-1][j-1]$32\Else33\State $sub \gets D[i-1][j-1] + 1$34\State $ins \gets D[i][j-1] + 1$35\State $del \gets D[i-1][j] + 1$36\State $D[i][j] \gets \min(sub, ins, del)$37\EndIf38\EndFor39\EndFor4041\State42\State \Return $D[|r|][|h|]$43\EndFunction44\end{algorithmic}45\caption{Calculation of WER with Levenshtein distance}46\label{alg:seq1}47\end{algorithm}48\end{preview}49\end{document}505152