WER-calculation.tex 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage[utf8]{inputenc} % this is needed for umlauts
  5. \usepackage[ngerman]{babel} % this is needed for umlauts
  6. \usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
  7. \usepackage{amssymb,amsmath,amsfonts} % nice math rendering
  8. \usepackage{braket} % needed for \Set
  9. \usepackage{algorithm,algpseudocode}
  10. \begin{document}
  11. \begin{preview}
  12. \begin{algorithm}[H]
  13. \begin{algorithmic}
  14. \Function{WER}{Reference $r$, Hypophysis $h$}
  15. \State int[$|r|+1$][$|h|+1$] $D$ \Comment{Initialisation}
  16. \For{($i=0$; $\;i \leq |r|$; $\;i$++)}
  17. \For{($j=0$; $\;j \leq |h|$; $\;j$++)}
  18. \If{$i==0$}
  19. \State $D[0][j] \gets j$
  20. \ElsIf{$j==0$}
  21. \State $D[i][0] \gets i$
  22. \EndIf
  23. \EndFor
  24. \EndFor
  25. \State
  26. \For{($i=1$; $\;i \leq |r|$; $\;i$++)} \Comment{Calculation}
  27. \For{($j=1$; $\;j \leq |h|$; $\;j$++)}
  28. \If{$r[i-1] == h[j-1]$}
  29. \State $D[i][j] \gets D[i-1][j-1]$
  30. \Else
  31. \State $sub \gets D[i-1][j-1] + 1$
  32. \State $ins \gets D[i][j-1] + 1$
  33. \State $del \gets D[i-1][j] + 1$
  34. \State $D[i][j] \gets \min(sub, ins, del)$
  35. \EndIf
  36. \EndFor
  37. \EndFor
  38. \State
  39. \State \Return $D[|r|][|h|]$
  40. \EndFunction
  41. \end{algorithmic}
  42. \caption{Calculation of WER with Levenshtein distance}
  43. \label{alg:seq1}
  44. \end{algorithm}
  45. \end{preview}
  46. \end{document}