\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}
\usepackage{minted}
\usemintedstyle{gruvbox-light}

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

%
%
% Custom commands
%
%

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

\newcommand{\res}{src/2025-03-28/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: Minimization of the Code Constraint Polynomial using
Homotopy Continuation Methods}
\subtitle{\small 28.03.2025}
\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}

\newcommand{\largecitereference}[1]
{\textcolor{kit-green100}{ \large \textbf{{[#1]}} }}

%
% - The decoding problem as the search for a solution of polynomial system
% - Homotopy continuation
% - The problem with overdefined systems and the Groebner basis
% - Implementation
%

% TODO: Check example homotopy
% TODO: Add the name of the homotopy construction (t-1)G + tF and note that it
% is not the only possibility
\begin{frame}
    \frametitle{Basic Idea of Homotopy Continuation \largecitereference{CL15}}

    \begin{minipage}[c]{0.65\textwidth}
        \begin{itemize}
            \item Goal: Solve system of equations $F(\bm{x}) = \bm{0},
                \hspace{2mm} F:\mathbb{R}^n \rightarrow \mathbb{R}^n$
            \item Problem: Depending on $F$, solving this directly
                may be difficult
            \item Solution: Define \emph{homotopy function} $H(\bm{x}, t)$ with
                \begin{gather*}
                    H(\bm{x}, 0) = G(\bm{x}), \hspace{5mm} H(\bm{x},
                    1) = F(\bm{x})
                    ,
                \end{gather*}
                i.e., a deformation between two systems $G(\bm{x})$
                and $F(\bm{x})$
                (where the zeros of $G$ can be easily obtained); E.g.,
                \begin{gather*}
                    H(\bm{x}, t) = (t-1)G(\bm{x}) + tF(\bm{x})
                    .
                \end{gather*}
                Then, compute $(\bm{x}_0, 0)$ such that $G(\bm{x}_0) =
                \bm{0}$ and trace path to $(\bm{x}_1, 1)$ with
                $F(\bm{x}_1) = \bm{0}$
        \end{itemize}

        \vspace{5mm}

        \addreferences
        {CL15}{Chen, Tianran, and Tien-Yien Li.: \emph{Homotopy
                continuation method for solving systems of nonlinear and
            polynomial equations}. Communications in Information and
        Systems 15.2 (2015): 119-307.}
        \stopreferences
    \end{minipage}%
    \hfill
    \begin{minipage}[c]{0.3\textwidth}
        \begin{figure}
            \centering

            \newcommand{\figlength}{0.8\textwidth}

            \vspace*{-2mm}

            \begin{tikzpicture}
                \begin{axis}[
                        xmin=-1,xmax=1,
                        ymin=-1,ymax=1,
                        width=\figlength,
                        height=\figlength,
                        ticks=none,
                        view={0}{90},
                        title={$t=0$},
                        title style={yshift=-1mm},
                        % xlabel={$x_1$},
                        % ylabel={$x_2$},
                    ]
                    \addplot3[point meta=\thisrow{Hmag},
                        point meta min=0,
                        point meta max=2.5,
                        quiver={u=\thisrow{H1},
                            v=\thisrow{H2},
                            scale arrows=.25,
                            every arrow/.append style={%
                                line width=.5
                                +\pgfplotspointmetatransformed/1000,
                                -{Latex[length=0pt 5,width=0pt 3]}
                            },
                        },
                        quiver/colored = {mapped color},
                        -stealth,
                    ]
                    table[col sep=comma, discard if not={t}{0.0}]
                    {\res/H.csv};

                    \addplot[mark=*] coordinates {(0,0)} node[above]
                    {$\bm{x}_0$};

                \end{axis}
            \end{tikzpicture}
            \begin{tikzpicture}
                \begin{axis}[
                        xmin=-1,xmax=1,
                        ymin=-1,ymax=1,
                        width=\figlength,
                        height=\figlength,
                        ticks=none,
                        view={0}{90},
                        title={$t=0.5$},
                        title style={yshift=-1mm},
                        % xlabel={$x_1$},
                        % ylabel={$x_2$},
                    ]
                    \addplot3[point meta=\thisrow{Hmag},
                        point meta min=0,
                        point meta max=2.5,
                        quiver={u=\thisrow{H1},
                            v=\thisrow{H2},
                            scale arrows=.25,
                            every arrow/.append style={%
                                line width=.5
                                +\pgfplotspointmetatransformed/1000,
                                -{Latex[length=0pt 5,width=0pt 3]}
                            },
                        },
                        quiver/colored = {mapped color},
                        -stealth,
                    ]
                    table[col sep=comma, discard if not={t}{0.5}]
                    {\res/H.csv};

                    \draw[line width=1pt] (0,0) -- (0.25,-0.25);
                    \addplot[mark=*] coordinates {(0.25, -0.25)};
                \end{axis}
            \end{tikzpicture}

            \vspace{2mm}

            \begin{tikzpicture}
                \begin{axis}[
                        xmin=-1,xmax=1,
                        ymin=-1,ymax=1,
                        width=\figlength,
                        height=\figlength,
                        ticks=none,
                        view={0}{90},
                        title={$t=1$},
                        title style={yshift=-1mm},
                        % xlabel={$x_1$},
                        % ylabel={$x_2$},
                    ]
                    \addplot3[point meta=\thisrow{Hmag},
                        point meta min=0,
                        point meta max=2.5,
                        quiver={u=\thisrow{H1},
                            v=\thisrow{H2},
                            scale arrows=.25,
                            every arrow/.append style={%
                                line width=.5
                                +\pgfplotspointmetatransformed/1000,
                                -{Latex[length=0pt 5,width=0pt 3]}
                            },
                        },
                        quiver/colored = {mapped color},
                        -stealth,
                    ]
                    table[col sep=comma, discard if not={t}{1.0}]
                    {\res/H.csv};

                    \draw[line width=1pt] (0,0) -- (0.5,-0.5);
                    \addplot[mark=*] coordinates {(0.5,-0.5)} node[below right]
                    {$\bm{x}_1$};
                \end{axis}
            \end{tikzpicture}

            \caption{Visualization of ``snapshots'' of $H$ (e.g., $F, G$) as
            vector fields}
        \end{figure}
    \end{minipage}
\end{frame}

\begin{frame}
    \frametitle{Path Tracing}

    \vspace{-4mm}

    \begin{itemize}
        \item Reminder: We are trying to trace the solution curve
            $H(\bm{x}, t) = \bm{0}$ from $t = 0$ to $t = 1$
        \item We can express the solution curve as a system of
            differential equations \citereference{CL15}:
            \begin{align*}
                DH(\bm{y}(s))\cdot \dot{\bm{y}}(s) &= 0 \\
                \text{det}\left(
                    \begin{array}{c} DH(\bm{y}(s)) \\ \dot{\bm{y}}(s)
                \end{array}\right) &= \sigma_0 \\
                \lVert \dot{\bm{y}}(s) \rVert &= 1 \\
                \bm{y}(0) &= (\bm{x}_0, 0)
                ,%
            \end{align*}
            where $DH(\bm{y})$ is the Jacobian of $H(\bm{y})$ and
            $\sigma_0 \in \left\{\pm 1\right\}$ defines the direction along
            which we move on the curve.
        \item For numerical stability, it is beneficial to solve this using a
            predictor-corrector scheme, e.g., Euler's predictor and Newton's
            corrector \citereference{CL15}:
            \begin{align*}
                \hat{\bm{y}} &= \bm{y}_0 + \Delta s \cdot \sigma \cdot
                {\bm{y}}(\bm{s})\\
                \bm{y} &= \mathcal{N}^k(\hat{\bm{y}}), \hspace{5mm}
                \mathcal{N}(\hat{\bm{y}}) := \hat{\bm{y}} -
                (DH(\hat{\bm{y}}))^{+} H(\hat{\bm{y}})
                .%
            \end{align*}
    \end{itemize}

    \addreferences
    {CL15}{Chen, Tianran, and Tien-Yien Li.: \emph{Homotopy
            continuation method for solving systems of nonlinear and
        polynomial equations}. Communications in Information and
    Systems 15.2 (2015): 119-307.}
    \stopreferences
\end{frame}

\begin{frame}
    \frametitle{Channel Decoding and Polynomial Equations}

    \vspace{-5mm}

    \begin{itemize}
        \item To describe the decoding problem we can use the code constraint
            polynomial \citereference{WT22}
            \begin{align*}
                %h(\bm{x}) =
                % \underbrace{\sum_{i=1}^{n}\left(1-x_i^2\right)^2}_{\text{Bipolar
                % constraint}} + \underbrace{\sum_{j=1}^{m}\left(1 -
                % \left(\prod_{i\in
                % A(j)}x_i\right)\right)^2}_{\text{Parity constraint}}
                h(\bm{x}) = \sum_{i=1}^{n}\left(1-x_i^2\right)^2 +
                \sum_{j=1}^{m}\left(1 - \left(\prod_{i\in
                A(j)}x_i\right)\right)^2
                .%
            \end{align*}
            where $A(j) = \left\{i \in [1:n]: \bm{H}_{j,i} = 1\right\},
            \hspace{3mm} j\in [1:m]$
            represents the set of variables involved in parity check $j$.
        \item In a similar vein, we can define a polynomial system whose zeros
            correspond to codewords as
            \begin{align*}
                F(\bm{x}) = \left[
                    \begin{array}{c}1 - x_1^2 \\ \vdots\\ 1 - x_n^2 \\ 1 -
                        \prod_{i \in A(1)}x_i \\ \vdots\\ 1 -
                        \prod_{i \in A(m)}x_i
                \end{array}\right] \overset{!}{=} \bm{0}
                .%
            \end{align*}
    \end{itemize}

    \addreferences
    {WT22}{Tadashi Wadayama; Satoshi Takabe: Proximal Decoding for LDPC
        Codes. IEICE Transactions on Fundamentals of Electronics, Communi-
    cations and Computer Sciences advpub (2022), 2022TAP0002.}
    \stopreferences
\end{frame}

\begin{frame}[fragile]
    \frametitle{Defining Homotopies for Channel Codes}

    \begin{itemize}
        \item Problem: Homotopy continuation algorithms / existing frameworks
            only really support square systems, i.e., \# equations =
            \# variables. The
            system $F(\bm{x}) = \bm{0}$ we previously considered is overdefined
        \item \textit{Gröbner bases} allow us to ``[...] transform F into
            another set G of polynomials [...] such that F and G are
            equivalent''
            \citereference{B01}, i.e., they have the same zeros
        \item Limited tests indicate that, for the systems we are interested in,
            finding a Gröbner basis yields a square system
        \item Example:
    \end{itemize}

    \begin{minipage}{0.45\textwidth}
        \begin{align*}
            \overbrace{\bm{H}}^{\text{Parity check matrix}} &= \left[
                \begin{array}{cc} 1 & 1
            \end{array}\right] \\
            F(\bm{x}) &= \left[
                \begin{array}{c}
                    1 - x_1^2 \\
                    1 - x_2^2\\
                    1 - x_1x_2
            \end{array}\right]
        \end{align*}
    \end{minipage}%
    \begin{minipage}{0.1\textwidth}
        \begin{tikzpicture}
            \draw[-{Latex}] (0,0) -- (1,0);
        \end{tikzpicture}
    \end{minipage}%
    \begin{minipage}{0.45\textwidth}
        \begin{align*}
            \tilde{F}(\bm{x}) &= \left[
                \begin{array}{c}
                    x_1 - x_2 \\
                    x_2^2 - 1
            \end{array}\right] \\
            G(\bm{x}) &= \left[
                \begin{array}{c}
                    x_1\\
                    x_2
            \end{array}\right]\\
            H(\bm{x}, t) &= (1-t)G(\bm{x}) + tF(\bm{x})
        \end{align*}
    \end{minipage} \\

    \vspace{5mm}

    \addreferences
    {B01}{Buchberger, Bruno. "Gröbner bases: A short introduction for systems
        theorists." International Conference on Computer Aided Systems Theory.
    Berlin, Heidelberg: Springer Berlin Heidelberg, 2001.}
    \stopreferences
\end{frame}

\begin{frame}[fragile]
    \frametitle{Path Tracker Implementation (Pseudo Code)}

    \vspace{-6mm}

    \begin{itemize}
        \item Perform a predictor step followed by multiple corrector steps
        \item If the corrector fails to converge, adjust the predictor step
            size and try again \citereference{CL15}
    \end{itemize}

    \vspace{1mm}

    \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
    ]{c}
func perform_prediction_step(y, step_size) {...}
func perform_correction_step(y) {...}
func perform_step(y0) {
    for i in range(max_retries):
        step_size = step_size / 2

        y = perform_prediction_step(y0, step_size)

        for k in range(max_corrector_iterations):
            y = perform_correction_step(y)
            if (corrector converged) break
        if (corrector converged) break

    return y
}
    \end{minted}

    \vspace{1mm}

    \addreferences
    {CL15}{Chen, Tianran, and Tien-Yien Li.: \emph{Homotopy
            continuation method for solving systems of nonlinear and
        polynomial equations}. Communications in Information and
    Systems 15.2 (2015): 119-307.}
    \stopreferences
\end{frame}

\begin{frame}[fragile]
    \frametitle{Decoding Algorithm Implementation (Pseudo Code)}

    \begin{itemize}
        \item If the algorithm doesn't converge, we still return the last
            estimate in the hopes that this will limit the BER
    \end{itemize}

    \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
    ]{c}
func decode(y) {
    for i in range(max_iterations):
        y = perform_step(y)

        x_hat = hard_decision(y)
        if (H @ x_hat == 0) return x_hat

    return x_hat
}
    \end{minted}
\end{frame}

\begin{frame}[fragile]
    \frametitle{Simulation results}

    \vspace*{-5mm}

    \begin{itemize}
        \item Simulation using the all-zeros codeword
        \item Newton homotopy:
            \begin{gather*}
                G(\bm{x}) = F(x) - F(\bm{y}) \hspace{5mm} \Rightarrow
                \hspace{5mm} H(\bm{x}) = F(\bm{x}) - (1 - t) F(\bm{y})
            \end{gather*}
    \end{itemize}

    \begin{figure}[H]
        \centering

        \begin{subfigure}[c]{0.48\textwidth}
            \centering

            \vskip 0pt
            \begin{tikzpicture}
                \begin{axis}[
                        width=\textwidth,
                        height=0.75\textwidth,
                        ylabel={FER (-\,-\,-), BER (---)},
                        ymode=log,
                        legend,
                        xlabel = {$Eb/N0$ (dB)},
                        legend pos= south west,
                        xmax=6
                    ]

                    \addplot+[scol0, densely dashed, mark=none, line
                    width=1pt, forget plot]
                    table[col sep=comma, x=SNR, y=FER]
                    {\res/bch_31_26_hc.csv};
                    \addplot+[scol0, mark=none, line width=1pt]
                    table[col sep=comma, x=SNR, y=BER]
                    {\res/bch_31_26_hc.csv};
                    \addlegendentry{Homotopy continuation}

                    \addplot+[scol2, densely dashed, mark=none, line width=1pt,
                    forget plot]
                    table[col sep=comma, x=SNR, y=FER, discard if
                    not={gamma}{0.05}]
                    {\res/bch_31_26_proximal.csv};
                    \addplot+[scol2, mark=none, line width=1pt]
                    table[col sep=comma, x=SNR, y=BER, discard if
                    not={gamma}{0.05}]
                    {\res/bch_31_26_proximal.csv};
                    \addlegendentry{Proximal decoding}

                \end{axis}
            \end{tikzpicture}

            \caption{BCH(31,26) Code}
        \end{subfigure}%
        \begin{subfigure}[c]{0.48\textwidth}
            \centering

            \vspace*{-17mm}

            \begin{tabular}{rl|ccccc}
                & Parameter & Value \\ \hline
                $n_\text{iter}$ & for homotopy continuation & 20 \\
                $n_\text{iter}$ & for Newton corrector      & 5 \\
                $\delta_\text{max}$ & for Newton corrector      & 0.01 \\
                $\Delta s$ & for Euler predictor       & 0.05 \\
                $n_\text{retries}$ & for Euler predictor       & 5
            \end{tabular}

            \bigskip
            \smallskip

            (No comprehensive investigation into choice of parameters
            completed yet)
        \end{subfigure}
    \end{figure}
\end{frame}

\begin{frame}
    \frametitle{Next steps}

    \begin{itemize}
        \item Simulations for other codes
        \item Thorough investigation into parameter choice
        \item Find more mathematical background / guarantees
            \begin{itemize}
                \item How do we have to choose $\sigma_0$?
                \item Guarantees for convergence? (i.e., what is the cause for
                    decoding failures?)
                \item When do we actually get square systems using
                    the Gröbner basis?
            \end{itemize}
        \item Other ideas:
            \begin{itemize}
                \item Generate more candidates by moving further along the
                    solution curve (if this is possible) and then performing
                    choosing from this list
            \end{itemize}
    \end{itemize}
\end{frame}

\end{document}
