\documentclass[10pt, aspectratio=169, usenames, dvipsnames]{beamer}

\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{spy, external, intersections}
%\tikzexternalize[prefix=build/]

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}


\usepackage{listings}
\usepackage{subcaption}
\usepackage{bbm}

\usepackage{xcolor}
\usepackage[outputdir=build/]{minted}
\usemintedstyle{gruvbox-dark}

\definecolor{gruvbox-bg}{HTML}{282828}


%
%
% Custom commands
%
%


\input{lib/latex-common/common.tex}
\pgfplotsset{colorscheme/cel}

\newcommand{\res}{src/2024-12-03/res}


%
%
% CEL Template
%
%


\newcommand{\templates}{lib/cel-template}

\input{\templates/packages.tex}
\input{\templates/modifications.tex}
\input{\templates/makros_own.tex}

% % Change the way the overview is displayed
% \AtBeginSection[]
% {
%     \begin{frame}[t]
%         \frametitle{Overview}
%     \tableofcontents[sectionstyle=show/shaded,
%                      subsectionstyle=show/show/shaded,
%                      subsubsectionstyle=hide]
%     \end{frame}
% }
% \AtBeginSubsubsection[]{}
% \AtBeginSubsection[]{}


%
%
% Set up document
%
%


\title{HiWi Notes: Minimize Code Constraint Polynomial using Adam}
\subtitle{\small 03.12.2024}
\author{\vspace{1.5mm} Andreas Tsouchlos}
\date{ }

\institute{Karlsruhe Institute of Technology (KIT), \\ Communications Engineering Lab (CEL) }

\tikzstyle{every node}=[font=\small]
\captionsetup[sub]{font=small}


%
%
% Document body
%
%


\begin{document}


\begin{frame}[plain]
	\maketitle
\end{frame}

\begin{frame}[t, fragile]
    \frametitle{Implementation}
    
    \vspace*{-5mm}
    \begin{minted}[
        bgcolor=gruvbox-bg,  % Background color
        fontsize=\small,     % Adjust font size
        framesep=5mm,        % Frame separation
        baselinestretch=1,   % Line spacing
        breaklines,          % Allow line breaking
        tabsize=4,           % Tab width
    ]{python}
def decode(self, y: torch.Tensor) -> torch.Tensor:
    optimizer = torch.optim.Adam([y], lr=self._learning_rate)

    c_hat = (y < 0).int()

    for _ in range(self._K):
        optimizer.zero_grad()
        loss = self._code_constraint_polynomial(y)
        loss.backward()
        optimizer.step()

        c_hat = (y < 0).int()

        if not torch.any(torch.matmul(self._H, c_hat) % 2):
            break

    return c_hat
    \end{minted}
\end{frame}

\begin{frame}[t]
    \frametitle{Performance}

    \begin{minipage}[t]{0.4\textwidth}
        \begin{itemize}
            \item Code: 204.33.484\citereference{Mac24}: (3,6) regular LDPC code
            \item Decoder parameters
                \begin{itemize}
                    \item Learning Rate: $0.05$
                    \item Max. Number of Adam optimizer iterations: $150$
                \end{itemize}
        \end{itemize}


        \vspace{23mm}

        \addreferences
            {Mac24}{David J.C. MacKay: \emph{Encyclopedia of Sparse Graph Codes}.
                Dec. 2024. url: \url{http://www.inference.org.uk/mackay/codes/data.html}}
            {Hel+23}{Michael Helmling et al. \emph{Database of Channel Codes and ML Simulation Results.} Apr. 2023. url: \url{https://www.uni-kl.de/channel-codes}.}
        \stopreferences
    \end{minipage}%
    \begin{minipage}[t]{0.6\textwidth}
        \begin{figure}[H]
            \centering

            \begin{tikzpicture}
                \begin{axis}[
                    width=\textwidth,
                    height=0.7\textwidth,
                    ymode=log,
                    xlabel={$E_\text{b}/N_0 (\text{dB})$},
                    ylabel={FER (-\,-\,-), BER (---)},
                    legend pos=south west,
                    ytick={1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1},
                    grid,
                ]
                    \addplot+[scol0, mark=none, line width=1pt, densely dashed, forget plot]
                        table[col sep=comma, x=Eb_N0, y=FER]
                            {\res/performance_204.33.484.csv};
                    \addplot+[scol0, mark=none, line width=1pt]
                        table[col sep=comma, x=Eb_N0, y=BER]
                            {\res/performance_204.33.484.csv};
                    \addlegendentry{Adam Decoder}

                    \addplot+[scol2, mark=none, line width=1pt, densely dashed, forget plot]
                        table[col sep=comma, x=Eb_N0, y=FER]
                            {\res/proximal_performance_204.33.484.csv};
                    \addplot+[scol2, mark=none, line width=1pt]
                        table[col sep=comma, x=Eb_N0, y=BER]
                            {\res/proximal_performance_204.33.484.csv};
                    \addlegendentry{Proximal Decoder}

                    \addplot+[black, mark=none, line width=1pt, densely dashed, forget plot]
                        table[col sep=comma, x=Eb_N0, y=FER]
                            {\res/ml_performance_204.33.484.csv};
                    \addlegendimage{black, mark=none, line width=1pt}
                    \addlegendentry{ML Decoder\citereference{Hel+23}}
                \end{axis}
            \end{tikzpicture}
        \end{figure}
    \end{minipage}
\end{frame}

\begin{frame}[t]
    \frametitle{Parameter Choice: Learning Rate}

    \begin{minipage}[t]{0.4\textwidth}
        \begin{itemize}
            \item Code: 204.33.484\citereference{Mac24}: (3,6) regular LDPC code
            \item Decoder parameters
                \begin{itemize}
                    \item $E_\text{b}/N_0 = 4 \text{dB}$
                    \item Max. Number of Adam optimizer iterations: $150$
                \end{itemize}
            \vspace{5mm}
            \item Chosen learning rate: $0.05$
        \end{itemize}

        \vspace{17mm}

	    \addreference{\text{Mac24}}{David J.C. MacKay: \emph{Encyclopedia of Sparse Graph Codes}.
	        December 2024. URL: \url{http://www.inference.org.uk/mackay/codes/data.html}}
    \end{minipage}%
    \begin{minipage}[t]{0.6\textwidth}
        \begin{figure}[H]
            \centering

            \begin{tikzpicture}
                \begin{axis}[
                    width=\textwidth,
                    height=0.7\textwidth,
                    xlabel={Learning rate},
                    ylabel={FER (-\,-\,-), BER (---)},
                    ymode=log,
                    grid,
                ]
                    \addplot+[scol0, mark=none, line width=1pt, densely dashed]
                        table[col sep=comma, x=learning_rate, y=FER, discard if not={Eb_N0}{4.0}]
                        {\res/parameter_choice_learning_rate.csv};

                    \addplot+[scol0, mark=none, line width=1pt]
                        table[col sep=comma, x=learning_rate, y=BER, discard if not={Eb_N0}{4.0}]
                        {\res/parameter_choice_learning_rate.csv};

                    \draw[scol1] (axis cs:5e-2,0.001) -- (axis cs:5e-2,2);
                    \addplot[scol1, mark=*] coordinates {(5e-2,0.0074)} node{};
                    \addplot[scol1, mark=*] coordinates {(5e-2,0.27)} node{};
                \end{axis}
            \end{tikzpicture}
        \end{figure}
    \end{minipage}
\end{frame}

\begin{frame}[t]
    \frametitle{Parameter Choice: Max. Number of Iterations}

    \begin{minipage}[t]{0.4\textwidth}
        \begin{itemize}
            \item Code: 204.33.484\citereference{Mac24}: (3,6) regular LDPC code
            \item Decoder parameters
                \begin{itemize}
                    \item $E_\text{b}/N_0 = 4 \text{dB}$
                    \item Learning rate: $0.05$
                \end{itemize}
            \vspace{5mm}
            \item Chosen max. number of iterations: $150$
        \end{itemize}

        \vspace{23mm}

	    \addreference{\text{Mac24}}{David J.C. MacKay: \emph{Encyclopedia of Sparse Graph Codes}.
	        December 2024. URL: \url{http://www.inference.org.uk/mackay/codes/data.html}}
    \end{minipage}%
    \begin{minipage}[t]{0.6\textwidth}
        \begin{figure}[H]
            \centering

            \begin{tikzpicture}
                \begin{axis}[
                    width=\textwidth,
                    height=0.7\textwidth,
                    xlabel={Maximum number of iterations of Adam optimizer},
                    ylabel={FER (-\,-\,-), BER (---)},
                    ymode=log,
                    grid,
                ]
                    \addplot+[scol0, mark=none, line width=1pt, densely dashed]
                        table[col sep=comma, x=max_iter, y=FER]
                        {\res/parameter_choice_max_iterations.csv};

                    \addplot+[scol0, mark=none, line width=1pt]
                        table[col sep=comma, x=max_iter, y=BER]
                        {\res/parameter_choice_max_iterations.csv};

                    \draw[scol1] (axis cs:150,1e-3) -- (axis cs:150,2);
                    \addplot[scol1, mark=*] coordinates {(150,0.0068)} node{};
                    \addplot[scol1, mark=*] coordinates {(150,0.255)} node{};
                \end{axis}
            \end{tikzpicture}
        \end{figure}
    \end{minipage}
\end{frame}

\begin{frame}[t]
    \frametitle{Comparison of Performance for Different Codes}
    
    \captionsetup[subfigure]{font=footnotesize}

    \hspace*{-0.4cm}
    \begin{minipage}[c]{0.9\textwidth}
        \centering
    
        \begin{figure}[H]
            \vspace*{-7mm}
            \centering
        
            \begin{subfigure}[t]{0.5\textwidth}
                \centering
            
                \begin{tikzpicture}[scale=0.8]
                    \begin{axis}[
                        grid=both,
                        xlabel={$E_b / N_0$ (dB)},
                        ylabel={FER (-\,-\,-), BER (---)},
                        ymode=log,
                        ymax=1.5, ymin=8e-5,
                        width=0.9\textwidth,
                        height=0.6\textwidth,
                    ]
                
                        \addplot[scol0, line width=1pt, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma]
                                {\res/performance_bch_31_26.csv};
                        \addplot[scol0, line width=1pt]
                            table [x=Eb_N0, y=BER, col sep=comma]
                                {\res/performance_bch_31_26.csv};

                        \addplot[scol2, line width=1pt, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma]
                                {\res/proximal_performance_bch_31_26.csv};
                        \addplot[scol2, line width=1pt]
                            table [x=Eb_N0, y=BER, col sep=comma]
                                {\res/proximal_performance_bch_31_26.csv};
                    \end{axis}
                \end{tikzpicture}
            
                \vspace*{-2mm}
            
                \caption{BCH code with $n=31, k=26$}
            \end{subfigure}%
            \begin{subfigure}[t]{0.5\textwidth}
                \centering
            
                \begin{tikzpicture}[scale=0.8]
                    \begin{axis}[
                        grid=both,
                        xlabel={$E_b / N_0$ (dB)},
                        ylabel={FER (-\,-\,-), BER (---)},
                        ymode=log,
                        ymax=1.5, ymin=8e-5,
                        width=0.9\textwidth,
                        height=0.6\textwidth,
                    ]

                        \addplot[scol0, line width=1pt, solid, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma]
                                {\res/performance_96.33.965.csv};
                        \addplot[scol0, line width=1pt, solid]
                            table [x=Eb_N0, y=BER, col sep=comma]
                                {\res/performance_96.33.965.csv};

                        \addplot[scol2, line width=1pt, solid, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma]
                                {\res/proximal_performance_96.33.965.csv};
                        \addplot[scol2, line width=1pt, solid]
                            table [x=Eb_N0, y=BER, col sep=comma]
                                {\res/proximal_performance_96.33.965.csv};
                    \end{axis}
                \end{tikzpicture}

                \vspace*{-2mm}
            
                \caption{$\left( 3, 6 \right)$-regular LDPC code with $n=96, k=48$
                    \citereference{Mac24, 96.33.965}}
            \end{subfigure}%

            \vspace*{-5mm}

            \begin{subfigure}[t]{0.5\textwidth}
                \centering
            
                \begin{tikzpicture}[scale=0.8]
                    \begin{axis}[
                        grid=both,
                        xlabel={$E_b / N_0$ (dB)},
                        ylabel={FER (-\,-\,-), BER (---)},
                        ymode=log,
                        ymax=1.5, ymin=8e-5,
                        width=0.9\textwidth,
                        height=0.6\textwidth,
                    ]
                
                        \addplot[scol0, line width=1pt, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma,
                                    discard if gt={Eb_N0}{6}]
                                {\res/performance_204.33.484.csv};
                        \addplot[scol0, line width=1pt]
                            table [x=Eb_N0, y=BER, col sep=comma,
                                    discard if gt={Eb_N0}{6}]
                                {\res/performance_204.33.484.csv};

                        \addplot[scol2, line width=1pt, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma,
                                    discard if gt={Eb_N0}{6}]
                                {\res/proximal_performance_204.33.484.csv};
                        \addplot[scol2, line width=1pt]
                            table [x=Eb_N0, y=BER, col sep=comma,
                                    discard if gt={Eb_N0}{6}]
                                {\res/proximal_performance_204.33.484.csv};
                    \end{axis}
                \end{tikzpicture}
            
                \vspace*{-2mm}
            
                \caption{$\left( 3, 6 \right)$-regular LDPC code with $n=204, k=102$
                    \citereference{Mac24, 204.33.484}}
            \end{subfigure}%
            \begin{subfigure}[t]{0.5\textwidth}
                \centering
            
                \begin{tikzpicture}[scale=0.8]
                    \begin{axis}[
                        grid=both,
                        xlabel={$E_b / N_0$ (dB)},
                        ylabel={FER (-\,-\,-), BER (---)},
                        ymode=log,
                        ymax=1.5, ymin=8e-5,
                        width=0.9\textwidth,
                        height=0.6\textwidth,
                    ]
                
                        \addplot[scol0, line width=1pt, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma]
                                {\res/performance_204.55.187.csv};
                        \addplot[scol0, line width=1pt]
                            table [x=Eb_N0, y=BER, col sep=comma]
                                {\res/performance_204.55.187.csv};

                        \addplot[scol2, line width=1pt, densely dashed]
                            table [x=Eb_N0, y=FER, col sep=comma]
                                {\res/proximal_performance_204.55.187.csv};
                        \addplot[scol2, line width=1pt]
                            table [x=Eb_N0, y=BER, col sep=comma]
                                {\res/proximal_performance_204.55.187.csv};
                    \end{axis}
                \end{tikzpicture}
            
                \vspace*{-2mm}
            
                \caption{$\left( 5, 10 \right)$-regular LDPC code with $n=204, k=102$
                    \citereference{Mac24, 204.55.187}}
            \end{subfigure}%
        \end{figure}
    \end{minipage}%
    \begin{minipage}[c]{0.1\textwidth}
        \centering
    
        \begin{figure}
            \centering
            \vspace*{-1.2cm}
            \hspace*{-2mm}
            \begin{tikzpicture}[scale=0.8]
                \begin{axis}[hide axis,
                             xmin=10, xmax=50,
                             ymin=0, ymax=0.4,
                             legend columns=1,
                             legend style={draw=white!15!black},
                             legend cell align={left}]
                    \addlegendimage{scol0, line width=1pt}
                    \addlegendentry{Adam}

                    \addlegendimage{scol2, line width=1pt}
                    \addlegendentry{Proximal}
                \end{axis}
            \end{tikzpicture}
        \end{figure}
    \end{minipage}

    \vspace*{-2mm}

    \addreference{Mac24}{David J.C. MacKay: \emph{Encyclopedia of Sparse Graph Codes}.
        Dec. 2024. url: \url{http://www.inference.org.uk/mackay/codes/data.html}.}
\end{frame}


\end{document}
