0

I know this has been asked a couple of times, however the usual advices in using only the algorithmic environment without algorithm doesnt seem to work as i lose my algorithmn numbering and the short version of the caption with \captionof[short caption]{looooooooong caption}.

\documentclass[]{scrreprt}

\usepackage{algorithm,algpseudocode}    
\renewcommand{\thealgorithm}{\arabic{chapter}.\arabic{algorithm}}           % angepasste Nummerierung der Algorithmen
\newcommand{\alignedComment}[1]{\Comment{\parbox[t]{.35\linewidth}{#1}}}
\algnewcommand\algorithmicforeach{\textbf{foreach}}
\algdef{S}[FOR]{ForEach}[1]{\algorithmicforeach\ #1\ \algorithmicdo}
\algnewcommand\algorithmicinput{\textbf{Input:}}
\algnewcommand\algorithmicoutput{\textbf{Output:}}
\algnewcommand\algorithmicmethod{\textbf{Algorithmus:}}
\algnewcommand\Input{\item[\algorithmicinput]}%
\algnewcommand\Output{\item[\algorithmicoutput]}%
\algnewcommand\Method{\item[\algorithmicmethod]}%
\renewcommand{\listalgorithmname}{Algorithmenverzeichnis}       
\floatname{algorithm}{Algorithmus}  

\usepackage{amsmath}        % Mathematische Notationen
\usepackage{amssymb}
\usepackage{xfrac}                  % nice fracs
\usepackage{nccmath}                % mfrac
\usepackage{accents}

\newcommand{\lstmw}[3]{%
    \accentset{\mkern2mu\scriptstyle #2}{#1}^{(i)}_{#3}}
\DeclareMathOperator{\sig}{sig}
\newcommand{\mym}{\mkern-1.5mu-\mkern-3mu 1}    % small minus for subscripts

\begin{document}

\begin{algorithm}[ht]
\caption[short caption]{looooooooo\\ oooooooooo\\oooooooooo\\oooooooooo\\oooooooooo\\oooooooooo\\oooooooooo\\oooooooooo\\ng caption}
\label{alg:sgd_lstm}
\begin{algorithmic}
    % \ttfamily
    \Input $\mathbb{X}$ mit Lösung $\mathbb{Y}$, Lernrate $\eta$, durch $\theta$ bestimmte Netzarchitektur 
    \Method
    \State Initialisiere alle Gewichte $\theta$ zufällig
    \Repeat
    \ForEach{Inputvektor $x\in \mathbb{B}$} \alignedComment{Batchverarbeitung}
        \ForEach{Zeitpunkt $t=1,\dots \tau$}
            \ForEach{Layer $f^{(i)},~i = 1,\ldots n$}  \alignedComment{Forwardpropagation }
                \ForEach{Gate $z \in \{u,i,o,\gamma \}$}
                    \State $\hat{z}_t^{(i)} \gets {\lstmw{\omega}{z}{}}^{\top} z_t^{(i-1)} + {\lstmw{\nu}{z}{}}^{\top} x_{t-1}^{(i)} + \lstmw{b}{z}{} $
                    \State $z_t^{(i)} \gets \varphi_z(\hat{z}_t^{(i)})$
                \EndFor
                \State $c_t^{(i)} = u_t^{(i)} \odot c_{t\mym}^{(i)}+ i_t^{(i)} \odot \gamma_t^{(i)}$
                \State $x_t^{(i)} = \varphi_{\tanh}\left( c_t^{(i)} \right) \odot o_t^{(i)}$ 
            \EndFor
        \State $ C_{x,t} \gets C(y_t, x_t^{(n)}) $      \alignedComment{Berechne Fehler}        
        \State $\delta_{x,t}^{(n)} \gets \frac{\partial C_{x,t}}{\partial x_t^{(n)}} \odot \varphi^{\prime}(\hat{x}_t^{(n)})$ 
        \EndFor % similar to RNN
        \ForEach{Layer $f^{(i)},~i = n,\ldots 1 $}  \alignedComment{Backpropagation}  
            \State $\delta_{c,\tau}^{(i)} \gets {\omega_{x,\tau}^{(i)}} \odot o_t^{(i)} \varphi^{\prime}(c_{\tau}^{(i)})   $
            \ForEach{Zeitpunkt $t=\tau-1,\ldots 1$}
                \State  $\delta_{c,t}^{(i)} \gets {\omega_{x,t}^{(i)}} \odot o_t^{(i)} \varphi^{\prime}(c_{t}^{(i)}) + \delta_{c,t+1}^{(i)} \odot u_{t+1}^{(i)}  $
                \State $\delta_{\hat{\gamma},t}^{(i)} \gets  \delta_{{c},t}^{(i)} \odot i_{t}^{(i)}  \odot \varphi^{\prime}_{\tanh} (\hat{\gamma}_t^{(i)})  $
                \State $\delta_{\hat{u},t}^{(i)} \gets  \delta_{{c},t}^{(i)} \odot c_{t-1}^{(i)}  \odot \varphi^{\prime}_{\sig}(\hat{u}_t^{(i)})   $
                \State $\delta_{\hat{i},t}^{(i)} \gets  \delta_{{c},t}^{(i)} \odot \gamma_{t}^{(i)}  \odot \varphi^{\prime}_{\sig}(\hat{i}_t^{(i)})   $
                \State $\delta_{\hat{o},t}^{(i)} \gets  \delta_{{x},t}^{(i)} \odot \varphi_{\tanh} (c_t^{(i)})  \odot \varphi^{\prime}_{\sig} (\hat{o}_t^{(i)})  $  
                \State $\delta_{x,t}^{(i\mym)} \gets \sum_z {\lstmw{\omega}{z}{}}^{\top} \delta_{\hat{z},t}^{(i)}$
                \State $\delta_{x,t\mym}^{(i)} \gets \sum_z {\lstmw{\nu}{z}{}}^{\top} \delta_{\hat{z},t}^{(i)}$         
            \EndFor
        \EndFor       %%%%%%%%%%%%%%%%% to do
        \State $\nabla_{x,b^{(n)}}C_x \gets  \sum_t  \delta_{x,t}^{(n)}  $ \alignedComment{Gradienten der Gewichte}   
        \State $\nabla_{x,\omega^{(n)}}C_x \gets \sum_t  \delta_{x,t}^{(n)} {x_{t-1}^{(n)}}^{\top}$
        \ForEach{Layer $f^{(i)},~i = n-1,\ldots 1$} 
            \State $\nabla_{x,b^{(i)}}C_x \gets  \sum_t  \delta_{x,t}^{(i)}  $  
            \State $\nabla_{x,\omega^{(i)}}C_x \gets \sum_t \delta_{x,t}^{(i)} {x_{t-1}^{(i)}}^{\top}$
            \State $\nabla_{x,\nu^{(i)}}C_x \gets \sum_t  \delta_{x,t}^{(i)} {x_t^{(i-1)}}^{\top}$
        \EndFor
    \EndFor
    \ForEach{Layer $f^{(i)},~i = 1,\ldots n-1$} \alignedComment{Aktualisierung der Gewichte}   
        \State $b^{(i)} \gets b^{(i)} -\eta \frac{1}{\vert \mathbb{B} \vert} \sum_x \nabla_{x,b^{(i)}}C_x$
        \State $\omega^{(i)} \gets \omega^{(i)}- \eta \frac{1}{\vert \mathbb{B} \vert} \sum_x \nabla_{x,\omega^{(i)}}C_x$
        \State $\nu^{(i)} \gets \nu^{(i)}- \eta \frac{1}{\vert \mathbb{B} \vert} \sum_x \nabla_{x,\nu^{(i)}}C_x$
    \EndFor
    \State $b^{(i)} \gets b^{(i)} -\eta \frac{1}{\vert \mathbb{B} \vert} \sum_x \nabla_{x,b^{(i)}}C_x$
    \State $\omega^{(i)} \gets \omega^{(i)}- \eta \frac{1}{\vert \mathbb{B} \vert} \sum_x \nabla_{x,\omega^{(i)}}C_x$
    \Until{Kovergenz von $\theta$}
    \Output Zielwerte $\mathbb{Y}^*$, erlernte Gewichte $\theta$
\end{algorithmic}
\end{algorithm}

\end{document}

output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.